Skip to content

Instantly share code, notes, and snippets.

@ingted
Created April 10, 2022 10:48
Show Gist options
  • Save ingted/0a48a8ecd7db0aa2a2325228ff4ce78c to your computer and use it in GitHub Desktop.
Save ingted/0a48a8ecd7db0aa2a2325228ff4ce78c to your computer and use it in GitHub Desktop.
getMovieTitles
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