Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How to use json apis python? In Python: Using the same function as part 1, implement functionality to handle requests of the form {request:reviewsByID,ID:ubit} to

How to use json apis python?

In Python:

Using the same function as part 1, implement functionality to handle requests of the form "{request:reviewsByID,ID:ubit}" to return a list of the favorite movies of the person with the given ubit. Their favorite movie(s) is the one returned by their api with the highest rating. If there is a tie for the highest rating, return all movies in the tie for highest rating. Even if there is only one top movie, return it in a list and convert it into JSON. If there is one top movie and it is fight club, the returned list should look like this: "['fight club']". API call: "http://www-student.cse.buffalo.edu/~/cgi-bin/interface.cgi?request=getReviews". You will access the requested API through a url of this form. The result will be returned as a JSON string which must be converted into a python dictionary. If the JSON result is in a string named "result" then you will convert it into a dictionary by calling "json.loads(result)".

Part1 and part2 code is like this:

import json import

urllib.request

def handleRequest(request):

reviews={ "Pulp Fiction":[9,"Love the joke Uma Thurman tells John Travolta after she overdosed and he drove her home, made the whole movie"] "The Babadook":[7, "Scary movie, interesting plot, but the ending is a complete let down"] "Taladega Nights":[9,"Hilarious movie, Will Ferrell makes me laugh everytime"] } #break down request and find out what its asking for... if request["request"]=="getReviews": #part one code here return json.dumps(reviews) elif request["request"]=="reviewsByID": #part two code here ubit= request["ID"] theRequest="http://www-student.cse.buffalo.edu/~" + ubit + "/cgi-bin/interface.cgi/?request=getReviews" result=urrlib.request.urlopen(theRequest).read().decode('utf-8') classDict=json.loads(result) Can someone help with this part?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Time Series Databases New Ways To Store And Access Data

Authors: Ted Dunning, Ellen Friedman

1st Edition

1491914726, 978-1491914724

More Books

Students also viewed these Databases questions

Question

c. Will leaders rotate periodically?

Answered: 1 week ago