-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
189 additions
and
252 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import http.client | ||
import json | ||
|
||
store_server = str("itunes.apple.com") | ||
|
||
def make_store_uri(country_code: str, genre: str, section: str) -> str: | ||
""" | ||
""" | ||
store_uri = f"/WebObjects/MZStoreServices.woa/ws/charts?cc={country_code}&g={genre}&name={section}&limit=400" | ||
|
||
return store_uri | ||
|
||
|
||
def fetch(url, appID): | ||
""" | ||
Request an URL | ||
""" | ||
conn = http.client.HTTPSConnection(store_server) | ||
headers = { "Cache-Control" : "no-cache" } | ||
conn.request("GET", url, None, headers) | ||
response = conn.getresponse() | ||
|
||
data = response.read() | ||
|
||
ranking = json.loads(data) | ||
|
||
conn.close() | ||
|
||
# JSON document | ||
posicion = process_result(ranking, appID) | ||
|
||
return posicion | ||
|
||
|
||
def process_result(result, appID): | ||
""" | ||
Process JSON and recover results | ||
""" | ||
entries = result["resultIds"] | ||
|
||
try: | ||
position = entries.index(appID) | ||
return (position + 1) | ||
except ValueError: | ||
return "---" |
Oops, something went wrong.