Paper Currencies and Digital Currencies Data scraper in python
Get different currencies data using python. Build an job scheduler to run in loop to keep getting live currencies rates and save as separate files.
Paper Currencies data.
import sched, time
import requests
import pandas as pd
from itertools import chain
import datetime as dts = sched.scheduler(time.time, time.sleep)
def do_something(sc):
print ("Getting live currency rates for all over the world by each ten seconds..")
# do your stuff
api_key = "http://data.fixer.io/api/latest?access_key=3fc51a8d31b765455a551d27d5caec87"
r = requests.get(url = api_key)
data = r.json()
#print (data)
# here you can see we are getting live data for currency.
#we can divide the currency and we will get the resul# example is here
rates = data['rates']
print ("-------Getting Data-------")
print ("-----Currencies------")
print (rates.values
# Filename
x = pd.to_datetime('today')
x = str(x)
x=x.replace(':','-')
x=x+'.csv'cur_name = rates.keys()
cur_val = rates.values()
df = pd.DataFrame(cur_name, cur_val)
df.to_csv(x)s.enter(10, 1, do_something, (sc,))s.enter(10, 1, do_something, (s,))
s.run()
This block of code will be running on 10 sec interval. By each step new rates will be saved as file. You can update time as per your requirement.
Find code on below link.
Digital Currencies Data.
from requests import Request, Session
from requests.exceptions import ConnectionError, Timeout, TooManyRedirects
import json
import sched, time
from itertools import chain
import pandas as pdurl = 'https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest'
parameters = {
'start':'1',
'limit':'5000',
'convert':'USD'
}
headers = {
'Accepts': 'application/json',
'X-CMC_PRO_API_KEY': '2f5e18f0-0427-4b93-855f-599cf4e3f491',
}session = Session()
session.headers.update(headers)
print ("========================Resluts=============================")
try:
response = session.get(url, params=parameters)
data = json.loads(response.text)
print(data)
except (ConnectionError, Timeout, TooManyRedirects) as e:
print(e)timestamp= data['data'][1]['date_added']
timestampprices = []
prices.append(timestamp)for i in range(49):
prices.append(data['data'][i]['quote']['USD']['price'])prices
Code is shared on the link given above. Cheers :)
Feel free to contact me at:
LinkedIn https://www.linkedin.com/in/junaidraza52/
Whatsapp +92–3225847078
Instagram https://www.instagram.com/iamjunaidrana/