Reputation: 241
import json, urllib.request
url = "https://datahead.herokuapp.com/api/employeers/"
response = urllib.request.urlopen(url)
data = json.loads(response.read())
var_json = ?
for i in data:
print('\n')
for key, value in i.items():
print(key,':', value)
my json data here such like and you can visit my api link.
id : 1
name : Prosenjit Das
log_date : 2019-03-02
log_time : 12:10:12.247257
login : None
logout : None
id : 2
name : Sudipto Rahman
log_date : 2019-03-02
log_time : 12:10:12.247257
login : 11:26:45
logout : 10:49:53
Sometimes my data will be update. Now Every historical data i want to save as if i can access those data for calculation. In this case have to be use any database or without database i can store or save?
Thanks.
Upvotes: 0
Views: 156
Reputation: 1327
import json
## you can store data
with open('data.json','w') as f:
json.dump(f,data)
## and can read data from that json file
with open('data.json','r') as f:
old_data = json.load(f)
## you can compare both data and overwrite data.json if required
Upvotes: 1