currencies added

This commit is contained in:
Neythen
2021-06-09 19:06:21 +01:00
parent 4470ca6685
commit 0fce80aac1
23 changed files with 155 additions and 49 deletions

View File

@@ -2,7 +2,7 @@ import finnhub
import time
import csv
import pytz
from datetime import datetime
from datetime import datetime, timedelta
import json
import datetime as dt
import sys, os, base64, hashlib, hmac, select
@@ -219,8 +219,10 @@ def updateNews():
CSV.close()
def updateWeather(location, api_key):
def updateWeather(api_key):
f = open( "csv/weather_location.txt", 'r' )
location = f.read()
f.close()
url = "https://api.openweathermap.org/data/2.5/weather?q={}&units=metric&appid={}".format(location, api_key)
r = requests.get(url)
weather = r.json()
@@ -263,7 +265,39 @@ def updateWeather(location, api_key):
daily_weather.append(dct)
json.dump( daily_weather, open( "csv/daily_weather.json", 'w+' ))
def updateCurrencies(api_key):
base = 'USD'
yesterday = datetime.now() - timedelta(1)
str_tod = datetime.strftime(datetime.now(), '%Y-%m-%d')
str_yest = datetime.strftime(yesterday, '%Y-%m-%d')
url = 'https://api.frankfurter.app/{}..{}?from={}'.format(str_yest, str_tod, base)
r = requests.get(url)
all_data = r.json()
currencies = ['AUD', 'CAD', 'CHF', 'EUR', 'GBP', 'JPY', 'NZD']
c_dict = {}
print(all_data)
for curr in currencies:
current = all_data['rates'][str_tod][curr]
yesterday = all_data['rates'][str_yest][curr]
change = current - yesterday
c_dict[curr] = [current, yesterday]
print(c_dict)
json.dump([base, c_dict], open( "csv/currency.json", 'w+' ))
if __name__ == '__main__':
newsapi = NewsApiClient(api_key='cf08652bd17647b89aaf469a1a8198a9')
@@ -300,9 +334,14 @@ if __name__ == '__main__':
updateUpdate(NY_time)
coins, coin_info, unique_bases = readCryptoCSV('csv/crypto.csv', max_stocks)
weather_location, weather_key = 'London', 'bd5d5096a5ba30bbcfb57ead42ab3fee'
weather_key = 'bd5d5096a5ba30bbcfb57ead42ab3fee'
updateWeather(weather_location, weather_key)
currency_key = '862dbb6d1101ce0c5136'
updateCurrencies(currency_key)
updateWeather( weather_key)
updateCrypto(coins, coin_info, unique_bases)
@@ -324,7 +363,7 @@ if __name__ == '__main__':
coins, coin_info, unique_bases = readCryptoCSV('csv/crypto.csv', max_stocks)
updateCrypto(coins, coin_info, unique_bases)
updateCurrencies(currency_key)
updateNews()
updateWeather(weather_location, weather_key)