-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAPI.py
More file actions
54 lines (42 loc) · 1.66 KB
/
Copy pathAPI.py
File metadata and controls
54 lines (42 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import json
import requests
import requests_cache
class wrapper:
def __init__(self):
self.url = 'https://restcountries.eu/rest/v2/'
requests_cache.install_cache('demo_cache')
def getSpecific(self, country, specificInfo):
api_url = self.url + 'name/' + country
response = requests.get(api_url)
countryInfo = json.loads(response.content)
return str((specificInfo + "= ") + (str(countryInfo[0][specificInfo])))
def getall(self):
api_url = self.url + 'all'
response = requests.get(api_url)
return json.loads(response.content)
def getalpha(self, country):
api_url = self.url + 'alpha/' + country
response = requests.get(api_url)
return json.loads(response.content)
def getcurrency(self, country):
api_url = self.url + 'currency/' + country
response = requests.get(api_url)
return json.loads(response.content)
def getcallingcode(self, country):
api_url = self.url + 'callingcode/' + country
response = requests.get(api_url)
return json.loads(response.content)
def getcapital(self, country):
api_url = self.url + 'capital/' + country
response = requests.get(api_url)
return json.loads(response.content)
def getregion(self, country):
api_url = self.url + 'region/' + country
response = requests.get(api_url)
return json.loads(response.content)
def getName(self, country):
api_url = self.url + 'name/' + country
response = requests.get(api_url)
return json.loads(response.content)
obj = wrapper()
print(obj.getSpecific('Egypt','currencies'))