Hi all,
One of the other tasks for my movie review assignment is that I
have to create api access to my website, which should return a json response
including a review count. However, I have confirmed that I have entered a
review for a specific movie and it prompts out in my html, but apparently when
I try to print out the json I get 0 reviews for my review count. Can someone
help me troubleshoot? Sorry if it sounds unclear.
````
@app.route("/api/<imdb_id>")
def api(imdb_id):
check_for_api_statement = sqlalchemy.text('SELECT * FROM movies WHERE
"imdbID" = :imdb_id')
check_for_api_unsplitted = engine.execute(check_for_api_statement,
imdb_id=imdb_id).fetchall()
res = requests.get("http://www.omdbapi.com/", params={"apikey": "c2c76d64",
"i": imdb_id, "plot": "full"})
omdb_data = res.json()
check_for_api = list(check_for_api_unsplitted[0])
title_unsplitted = check_for_api[0]
title = check_for_api[0]
year = check_for_api[1]
imdb_id = imdb_id
imdbrating = check_for_api[4]
director = omdb_data['Director']
actors = omdb_data['Actors']
check_for_reviews_statement = sqlalchemy.text('SELECT * FROM reviews WHERE
movie = :movie_title')
check_for_reviews_unsplitted = engine.execute(check_for_reviews_statement,
movie_title=title).fetchall()
review_count = len(check_for_reviews_unsplitted)
print(check_for_reviews_unsplitted) #this returns a blank list for some
strange reason
if len(check_for_reviews_unsplitted) != 0:
check_for_reviews = check_for_reviews_unsplitted.split(',')
score = float(check_for_reviews[4])
average_score = score/review_count
else:
average_score = "N.A"
a =
{"title":title,"year":year,"imdb_id":imdb_id,"director":director,"actors":actors,"imdb_rating":imdbrating,"review_count":review_count,"average_score":average_score}
apijson = json.dumps(a, cls=CustomJsonEncoder)
print (apijson)
if len(check_for_api) != 0:
return render_template("api.html", apijson=apijson)
else:
return render_template("error2.html", message="No such movie.")
--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
http://www.sqlalchemy.org/
To post example code, please provide an MCVE: Minimal, Complete, and Verifiable
Example. See http://stackoverflow.com/help/mcve for a full description.
---
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
To view this discussion on the web visit
https://groups.google.com/d/msgid/sqlalchemy/7DB000C8-1EBC-48AF-A24F-202196C743CF%40gmail.com.
For more options, visit https://groups.google.com/d/optout.