Skip to content

Commit 11c6fe1

Browse files
author
Plamen Milenkov
committed
Day 42. Parsing omdb result
1 parent 3520aa5 commit 11c6fe1

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"web": {
3+
"client_id": "asdfjasdljfasdkjf",
4+
"client_secret": "1912308409123890",
5+
"redirect_uris": ["https://www.example.com/oauth2callback"],
6+
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
7+
"token_uri": "https://accounts.google.com/o/oauth2/token"
8+
}
9+
}

days/40-42-json-data/omdb_parse.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import json
2+
from pprint import pprint
3+
import requests
4+
5+
user_input = input('Movie name: ')
6+
7+
request = requests.get('http://www.omdbapi.com/?apikey=3e6f7dd7&t={}'.format(user_input))
8+
json_result = json.loads(request.text)
9+
10+
print("{}'s Awards: {}".format(user_input, json_result['Awards']))
11+
12+
13+
def parse_value(value: str):
14+
if value.endswith('%'):
15+
value = value.replace('%','')
16+
return '{}/10'.format(int(value) / 10)
17+
elif value.endswith('100'):
18+
(value, _) = value.split('/')
19+
return '{}/10'.format(int(value) / 10)
20+
return value
21+
22+
23+
def display_rating(rating):
24+
value = rating['Value']
25+
value = parse_value(value)
26+
print(f"{rating['Source']} - {value}")
27+
28+
29+
for rating in json_result['Ratings']:
30+
display_rating(rating)

0 commit comments

Comments
 (0)