Created
April 10, 2022 10:48
-
-
Save ingted/0a48a8ecd7db0aa2a2325228ff4ce78c to your computer and use it in GitHub Desktop.
getMovieTitles
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import requests | |
| def firstQuery(substr): | |
| response = requests.get(f"https://jsonmock.hackerrank.com/api/movies/search/?Title={substr}") | |
| respDict = response.json() | |
| rtn = { | |
| "per_page": respDict["per_page"], "total": respDict["total"], "total_pages": respDict["total_pages"] | |
| } | |
| return rtn | |
| def pageQuery(substr, p): | |
| response = requests.get(f"https://jsonmock.hackerrank.com/api/movies/search/?Title={substr}&page={p}") | |
| respDict = response.json() | |
| return list(map(lambda d: d["Title"], respDict["data"])) | |
| def getMovieTitles(substr): | |
| info = firstQuery(substr) | |
| rtn = [] | |
| for p in range(1, info["total_pages"] + 1): | |
| rtn += pageQuery(substr, p) | |
| rtn.sort() | |
| return rtn | |
| getMovieTitles("waterworld") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment