forked from lornafay/Bualadh-Bus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
API_tester.py
29 lines (25 loc) · 823 Bytes
/
API_tester.py
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
import traceback
import pandas as pd
import requests
import json
class API:
def __init__(self, credentials, name):
"""Initializes api url , file name as instance variables"""
self.credentials = credentials
self.name=name
def API_Tester(self):
"""scrapes data from dublin bike api and convert it into json and load it in to bike.text file"""
URL = self.credentials
API_data = requests.get(URL)
D_API = json.loads(API_data.text)
df=pd.json_normalize(D_API)
file_name=self.name +'.csv'
try:
with open(file_name,'a') as fd:
df.to_csv(fd)
except:
print(traceback.format_exc())
credentials= input('Enter URL: ')
name = input('Enter file Name: ')
a = API(credentials , name)
a.API_Tester()