-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbaseApi.py
More file actions
31 lines (22 loc) · 741 Bytes
/
baseApi.py
File metadata and controls
31 lines (22 loc) · 741 Bytes
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
import requests
import json
import requests_cache
class baseApi:
requests_cache.install_cache('country_caches', backend='memory', expire_after=300)
def __init__(self):
self.URL = 'https://restcountries.eu/rest/v2/name/'
def connection(self):
api_url = self.URL
response = requests.get(api_url)
if response.status_code == 200:
return True
else:
return False
def getCountryInfo(self,country):
api_url = self.URL+country
response = requests.get(api_url)
print (response.from_cache)
if response.status_code == 200:
return (json.loads(response.content), response.from_cache)
else:
return None