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()
@ -264,6 +266,38 @@ def updateWeather(location, api_key):
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)

View File

@ -1,3 +1,3 @@
symbol,name,base,current,24hr change
BTC,bitcoin,usd,33188,-6.6714954489175025
ETH,ethereum,gbp,1783.08,-7.158501133993698
BTC,bitcoin,usd,36574,13.332115883704576
ETH,ethereum,gbp,1838.29,6.811992501784067

1 symbol name base current 24hr change
2 BTC bitcoin usd 33188 36574 -6.6714954489175025 13.332115883704576
3 ETH ethereum gbp 1783.08 1838.29 -7.158501133993698 6.811992501784067

1
csv/currency.json Normal file
View File

@ -0,0 +1 @@
["USD", {"AUD": [1.29, 1.2903], "CAD": [1.2078, 1.2072], "CHF": [0.89487, 0.89591], "EUR": [0.82001, 0.82088], "GBP": [0.70564, 0.70678], "JPY": [109.37, 109.41], "NZD": [1.3879, 1.3861]}]

View File

@ -1 +1 @@
{"main_weather": "Clouds", "description": "overcast clouds", "temp": 19.26, "min_temp": 15.34, "max_temp": 20.86, "feels_like": 18.94, "humidity": 65, "clouds": 100, "wind_speed": 1.84, "wind_direction": 249, "visibility": 10000, "uv": 0, "rain_chance": 0}
{"main_weather": "Clouds", "description": "scattered clouds", "temp": 27.76, "min_temp": 26.64, "max_temp": 28.87, "feels_like": 33, "humidity": 90, "clouds": 26, "wind_speed": 0.45, "wind_direction": 42, "visibility": 10000, "uv": 0, "rain_chance": 0.41}

View File

@ -1 +1 @@
[{"main_weather": "Clouds", "description": "overcast clouds", "min_temp": 13.24, "max_temp": 23.67}, {"main_weather": "Clouds", "description": "few clouds", "min_temp": 12.23, "max_temp": 23.89}, {"main_weather": "Rain", "description": "light rain", "min_temp": 14.69, "max_temp": 22.98}, {"main_weather": "Rain", "description": "light rain", "min_temp": 14.9, "max_temp": 24.55}, {"main_weather": "Clouds", "description": "scattered clouds", "min_temp": 15.43, "max_temp": 25.91}, {"main_weather": "Clear", "description": "clear sky", "min_temp": 16.26, "max_temp": 27.68}, {"main_weather": "Rain", "description": "light rain", "min_temp": 17.66, "max_temp": 29.24}, {"main_weather": "Clouds", "description": "overcast clouds", "min_temp": 16.08, "max_temp": 23.33}]
[{"main_weather": "Rain", "description": "light rain", "min_temp": 27.38, "max_temp": 29.43}, {"main_weather": "Rain", "description": "light rain", "min_temp": 27.12, "max_temp": 29.24}, {"main_weather": "Rain", "description": "moderate rain", "min_temp": 27.26, "max_temp": 29.02}, {"main_weather": "Rain", "description": "moderate rain", "min_temp": 27.42, "max_temp": 28.3}, {"main_weather": "Rain", "description": "moderate rain", "min_temp": 27.69, "max_temp": 28.6}, {"main_weather": "Rain", "description": "moderate rain", "min_temp": 28.04, "max_temp": 29.2}, {"main_weather": "Rain", "description": "moderate rain", "min_temp": 27.96, "max_temp": 28.81}, {"main_weather": "Rain", "description": "moderate rain", "min_temp": 28.06, "max_temp": 30.03}]

View File

@ -1 +1 @@
08/06/2021 16:30:26
09/06/2021 14:00:57

1 08/06/2021 16:30:26 09/06/2021 14:00:57

View File

@ -1,21 +1,21 @@
headline,source,date,time
Reduce your salt intake to boost your immunity - Times of India,The Times of India,2021-06-08,18:30:00Z
Geostationary Earth Orbit Hyperspectral Infrared Radiation Data Improves Local Severe Storm Forecasts - Space Bollyinside - BollyInside,Bollyinside.com,2021-06-08,18:27:29Z
Carbon dioxide levels hit 50 percent higher than preindustrial time - NBC News,NBC News,2021-06-08,18:23:31Z
Annual Solar Eclipse Tomorrow^ People of THESE Places in India Will be Able to Watch - India.com,India.com,2021-06-08,18:23:07Z
National Indigenous leaders plan Vatican visit to call for long-awaited papal apology - CBC.ca,CBC News,2021-06-08,18:15:57Z
N.B. says another 29000 people need to get vaccine before health orders are relaxed - NiagaraFallsReview.ca,Toronto Star,2021-06-08,18:11:50Z
Coroner determines Upper Hutt toddler's playground death was the result of 'tragic accident' - Stuff.co.nz,Stuff.co.nz,2021-06-08,18:06:00Z
Controversial scheme to collect and share patient data delayed - The Independent,Independent,2021-06-08,18:05:12Z
Minecraft updates with Cliffs and Caves Part 1^ adds goats and copper - Polygon,Polygon,2021-06-08,18:04:21Z
Utah Jazz rule PG Mike Conley out for Game 1 vs. LA Clippers with hamstring strain - ESPN,ESPN,2021-06-08,17:57:46Z
'This was a terrorist attack': Trudeau condemns London hit-and-run that left four Muslim family members dead - CBC.ca,CBC News,2021-06-08,17:56:14Z
Zidansek and Pavlyuchenkova reach French Open semis after epic battles - The Guardian,The Guardian,2021-06-08,17:51:00Z
New dinosaur species found in Australia was as long as a basketball court - NBC News,NBC News,2021-06-08,17:36:11Z
Julio Jones declines to take No. 11 from Tennessee Titans' A.J. Brown - ESPN,ESPN,2021-06-08,17:35:03Z
EXCLUSIVE: Listen to the full 40-minute Rudy Giuliani phone call with a Ukrainian presidential aide - CNN ,CNN,2021-06-08,17:35:00Z
Waterford dog attack: Dog that attacked and killed three-month-old baby girl is put down as post mortem carried out on child - Independent.ie,Independent.ie,2021-06-08,17:31:00Z
Missing bundles of joy: Govt can't find woman who gave birth to 10 babies - Eyewitness News,EWN,2021-06-08,17:25:17Z
UK housing market is on fire^ warns Bank of England chief economist - The Guardian,The Guardian,2021-06-08,17:22:00Z
Chris Harrison: The Bachelor host leaves for good over racism row - BBC News,BBC News,2021-06-08,17:19:39Z
COVID-19 Update: Three-day vaccination blitz at Telus Convention Centre | Delta variant outbreaks confirmed at Foothills | Alberta urges Ottawa to drop hotel quarantines - Calgary Herald,Calgary Herald,2021-06-08,17:15:00Z
COVID-19: UK daily cases highest since February - as PM insists 'freedom day' call will be driven by data - Sky News,Sky.com,2021-06-09,16:29:41Z
Trumps TikTok^ WeChat Actions Targeting China Revoked by Biden - The Wall Street Journal,The Wall Street Journal,2021-06-09,16:29:00Z
Corals' natural 'sunscreen' may help them weather climate change - Phys.org,Phys.Org,2021-06-09,16:26:34Z
EU takes legal action against Germany after tussle between courts - The Guardian,The Guardian,2021-06-09,16:26:00Z
New WhatsApp feature wont be allowed on iPhones or iPads - only Android phones - The Independent,Independent,2021-06-09,16:25:09Z
Ontario education minister reveals details of new Grade 9 math curriculum - CBC.ca,CBC News,2021-06-09,16:24:29Z
Manitoba to give $2M in prizes to people who get vaccinated - CBC.ca,CBC News,2021-06-09,16:18:16Z
Scientists find hundreds of examples of mysterious radio blasts coming from deep in the universe - The Independent,Independent,2021-06-09,16:16:24Z
G7 summit 2021 live: Biden flies into UK for meeting of world leaders^ as EU losing patience over Brexit deal - The Independent,Independent,2021-06-09,16:13:59Z
Donald Trump-era ban on TikTok dropped by Joe Biden - BBC News,BBC News,2021-06-09,16:10:56Z
Enoch Mpianzi: Parktown Boys' High principal reinstated^ will be paid for the six months he hadn't worked - News24,News24,2021-06-09,16:07:09Z
Russian court expected to outlaw Alexei Navalnys organisation - The Guardian,The Guardian,2021-06-09,16:04:00Z
Another 4^700 new COVID-19 vaccines given in Wellington-Dufferin-Guelph - Global News,Global News,2021-06-09,16:02:47Z
Biden holds very deep concerns on Brexit and Northern Ireland as he jets to UK - TheJournal.ie,TheJournal.ie,2021-06-09,16:00:00Z
Teens and adults miss 26 million doses of CDC-recommended vaccines during the COVID-19 pandemic^ study finds - Yahoo News,USA Today,2021-06-09,15:58:49Z
Bata Q4 results: Net profit falls 23% to 29 cr^ announces dividend of ₹4/share - Mint,Livemint,2021-06-09,15:57:20Z
Gap to close 19 UK and Ireland stores after £740m loss during Covid pandemic - The Independent,Independent,2021-06-09,15:47:59Z
Record-breaking Aussie dinosaur was as long as a basketball court - Livescience.com,Live Science,2021-06-09,15:44:23Z
Australutean. Paleontologists have identified one of the largest dinosaurs in the world - Pakistan Christian TV,Pakistanchristian.tv,2021-06-09,15:41:15Z
Google kills its augmented reality “Measure” app - Ars Technica,Ars Technica,2021-06-09,15:36:49Z

1 headline source date time
2 Reduce your salt intake to boost your immunity - Times of India COVID-19: UK daily cases highest since February - as PM insists 'freedom day' call will be driven by data - Sky News The Times of India Sky.com 2021-06-08 2021-06-09 18:30:00Z 16:29:41Z
3 Geostationary Earth Orbit Hyperspectral Infrared Radiation Data Improves Local Severe Storm Forecasts - Space Bollyinside - BollyInside Trump’s TikTok^ WeChat Actions Targeting China Revoked by Biden - The Wall Street Journal Bollyinside.com The Wall Street Journal 2021-06-08 2021-06-09 18:27:29Z 16:29:00Z
4 Carbon dioxide levels hit 50 percent higher than preindustrial time - NBC News Corals' natural 'sunscreen' may help them weather climate change - Phys.org NBC News Phys.Org 2021-06-08 2021-06-09 18:23:31Z 16:26:34Z
5 Annual Solar Eclipse Tomorrow^ People of THESE Places in India Will be Able to Watch - India.com EU takes legal action against Germany after tussle between courts - The Guardian India.com The Guardian 2021-06-08 2021-06-09 18:23:07Z 16:26:00Z
6 National Indigenous leaders plan Vatican visit to call for long-awaited papal apology - CBC.ca New WhatsApp feature won’t be allowed on iPhones or iPads - only Android phones - The Independent CBC News Independent 2021-06-08 2021-06-09 18:15:57Z 16:25:09Z
7 N.B. says another 29000 people need to get vaccine before health orders are relaxed - NiagaraFallsReview.ca Ontario education minister reveals details of new Grade 9 math curriculum - CBC.ca Toronto Star CBC News 2021-06-08 2021-06-09 18:11:50Z 16:24:29Z
8 Coroner determines Upper Hutt toddler's playground death was the result of 'tragic accident' - Stuff.co.nz Manitoba to give $2M in prizes to people who get vaccinated - CBC.ca Stuff.co.nz CBC News 2021-06-08 2021-06-09 18:06:00Z 16:18:16Z
9 Controversial scheme to collect and share patient data delayed - The Independent Scientists find hundreds of examples of mysterious radio blasts coming from deep in the universe - The Independent Independent 2021-06-08 2021-06-09 18:05:12Z 16:16:24Z
10 Minecraft updates with Cliffs and Caves Part 1^ adds goats and copper - Polygon G7 summit 2021 live: Biden flies into UK for meeting of world leaders^ as EU losing patience over Brexit deal - The Independent Polygon Independent 2021-06-08 2021-06-09 18:04:21Z 16:13:59Z
11 Utah Jazz rule PG Mike Conley out for Game 1 vs. LA Clippers with hamstring strain - ESPN Donald Trump-era ban on TikTok dropped by Joe Biden - BBC News ESPN BBC News 2021-06-08 2021-06-09 17:57:46Z 16:10:56Z
12 'This was a terrorist attack': Trudeau condemns London hit-and-run that left four Muslim family members dead - CBC.ca Enoch Mpianzi: Parktown Boys' High principal reinstated^ will be paid for the six months he hadn't worked - News24 CBC News News24 2021-06-08 2021-06-09 17:56:14Z 16:07:09Z
13 Zidansek and Pavlyuchenkova reach French Open semis after epic battles - The Guardian Russian court expected to outlaw Alexei Navalny’s organisation - The Guardian The Guardian 2021-06-08 2021-06-09 17:51:00Z 16:04:00Z
14 New dinosaur species found in Australia was as long as a basketball court - NBC News Another 4^700 new COVID-19 vaccines given in Wellington-Dufferin-Guelph - Global News NBC News Global News 2021-06-08 2021-06-09 17:36:11Z 16:02:47Z
15 Julio Jones declines to take No. 11 from Tennessee Titans' A.J. Brown - ESPN Biden holds ‘very deep’ concerns on Brexit and Northern Ireland as he jets to UK - TheJournal.ie ESPN TheJournal.ie 2021-06-08 2021-06-09 17:35:03Z 16:00:00Z
16 EXCLUSIVE: Listen to the full 40-minute Rudy Giuliani phone call with a Ukrainian presidential aide - CNN Teens and adults miss 26 million doses of CDC-recommended vaccines during the COVID-19 pandemic^ study finds - Yahoo News CNN USA Today 2021-06-08 2021-06-09 17:35:00Z 15:58:49Z
17 Waterford dog attack: Dog that attacked and killed three-month-old baby girl is put down as post mortem carried out on child - Independent.ie Bata Q4 results: Net profit falls 23% to 29 cr^ announces dividend of ₹4/share - Mint Independent.ie Livemint 2021-06-08 2021-06-09 17:31:00Z 15:57:20Z
18 Missing bundles of joy: Govt can't find woman who gave birth to 10 babies - Eyewitness News Gap to close 19 UK and Ireland stores after £740m loss during Covid pandemic - The Independent EWN Independent 2021-06-08 2021-06-09 17:25:17Z 15:47:59Z
19 UK housing market is on fire^ warns Bank of England chief economist - The Guardian Record-breaking Aussie dinosaur was as long as a basketball court - Livescience.com The Guardian Live Science 2021-06-08 2021-06-09 17:22:00Z 15:44:23Z
20 Chris Harrison: The Bachelor host leaves for good over racism row - BBC News Australutean. Paleontologists have identified one of the largest dinosaurs in the world - Pakistan Christian TV BBC News Pakistanchristian.tv 2021-06-08 2021-06-09 17:19:39Z 15:41:15Z
21 COVID-19 Update: Three-day vaccination blitz at Telus Convention Centre | Delta variant outbreaks confirmed at Foothills | Alberta urges Ottawa to drop hotel quarantines - Calgary Herald Google kills its augmented reality “Measure” app - Ars Technica Calgary Herald Ars Technica 2021-06-08 2021-06-09 17:15:00Z 15:36:49Z

View File

@ -1,4 +1,4 @@
name,current,opening
MSFT,252.57,255.16
NFLX,492.39,497
GOOG,2482.85,2479.9
MSFT,254.87,253.81
NFLX,490.31,494.5
GOOG,2501.71,2499.5

1 name current opening
2 MSFT 252.57 254.87 255.16 253.81
3 NFLX 492.39 490.31 497 494.5
4 GOOG 2482.85 2501.71 2479.9 2499.5

1
csv/weather_location.txt Normal file
View File

@ -0,0 +1 @@
Hong Kong

BIN
final.ppm

Binary file not shown.

Binary file not shown.

BIN
logos/currencies/aud.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
logos/currencies/cad.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 895 B

BIN
logos/currencies/chf.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 719 B

BIN
logos/currencies/eur.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 968 B

BIN
logos/currencies/gbp.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
logos/currencies/jpy.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 769 B

BIN
logos/currencies/nzd.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 899 B

BIN
logos/currencies/usd.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 984 B

View File

@ -178,6 +178,19 @@ def SetNews():
return hello()
@app.route("/SetWeather", methods=['POST'])
def SetWeather():
text = request.form['text']
#args = ['q', 'sources', 'category', 'country']
f = open( "csv/weather_location.txt", 'w+' )
f.write(text)
f.close()
api_caller.sendline('R')
return hello()
@app.route("/DisplayImage", methods=['POST'])
def DisplayImage():
if request.method == 'POST':

View File

@ -39,7 +39,7 @@ class StockTicker():
self.greenORred = (255, 255, 255)
#self.blank = Image.open('logos/blank.png')
self.blank = Image.new('RGB', (0, 32))
self.blank = Image.new('RGB', (15, 32))
self.running = True
self.brightness = 1.0
self.delay = 0.02
@ -539,6 +539,48 @@ class StockTicker():
image_list.append(self.blank)
image_list.append(stitchedStock)
base, currency_info = json.load(open('csv/currency.json', 'r'))
for i, currency in enumerate(['AUD', 'CAD', 'CHF', 'EUR', 'GBP', 'JPY', 'NZD']):
current, yesterday = currency_info[currency]
print(current, yesterday)
change = 1/current - 1/yesterday
print(change)
current = 1/current
current = '%.2f' % current
arrow, change = self.getArrow(change)
change = '%.5f' % change
midFrame = self.textToImage(currency + '(' + base + ')', current, change, arrow) #IMAGE THE TEXT
try:
logos_path = os.path.join(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'logos'), 'currencies')
logo = Image.open(os.path.join(logos_path, currency.lower() + '.png'))
bse = Image.open(os.path.join(logos_path, base.lower() + '.png'))
new_im = Image.new('RGB', (42, 32))
for im in image_list:
new_im.paste(bse, (0,10), bse.convert('RGBA'))
new_im.paste(logo, (10,0), logo.convert('RGBA'))
stitchedStock = self.stitchImage([new_im, midFrame])
except:
stitchedStock = midFrame
image_list.append(self.blank)
image_list.append(stitchedStock)
finalDisplayImage = self.stitchImage(image_list)
if updated_img == 1:
@ -549,8 +591,10 @@ class StockTicker():
def getTodayWeatherImage(self):
img = Image.new('RGB', (225, 32))
location = 'London'
f = open( "csv/weather_location.txt", 'r' )
location = f.read()
f.close()
print(location)
current_weather = json.load(open('csv/current_weather.json', 'r'))
@ -573,7 +617,7 @@ class StockTicker():
weather_dir = './logos/weather_icons'
weather_img = Image.open(weather_dir + '/weather_type_icons/' + weather_ids[main] + '.png')
img.paste(weather_img, (5,12))
img.paste(weather_img, (5,9))
temp_img = self.textImage(str("{0:.0f}".format(current_weather['temp'])), large_font, r = 200, g = 0, b = 255)
img.paste(temp_img, (50,9))
@ -584,10 +628,10 @@ class StockTicker():
main = current_weather['main_weather']
main_img = self.textImage(main, small_font)
img.paste(main_img, (45, 26))
img.paste(main_img, (48, 26))
feels_img = self.textImage('Feels like:' + str("{0:.0f}".format(current_weather['feels_like'])), small_font, r = 200, g = 0, b = 255)
img.paste(feels_img, (41, 0))
img.paste(feels_img, (location_img.size[0] + 5, 0))
min_img = self.textImage( "{0:.0f}".format(current_weather['min_temp']), small_font, r=0, g=0, b=255)
img.paste(min_img, (75, 15))
@ -655,7 +699,9 @@ class StockTicker():
def getDailyWeatherImage(self):
location = 'London'
f = open( "csv/weather_location.txt", 'r' )
location = f.read()
f.close()
img = Image.new('RGB', (128, 32))
current_weather = json.load(open('csv/current_weather.json', 'r'))
@ -665,7 +711,7 @@ class StockTicker():
large_font = ImageFont.load("./fonts/10x20.pil")
location_img = self.textImage(location, small_font, r = 255, g = 255, b = 0)
location_img = self.textImage(location, extra_small_font, r = 255, g = 255, b = 0)
@ -1013,9 +1059,9 @@ if __name__ == '__main__':
#stock_ticker.displayText()
#stock_ticker.getFullStockImage(1)
#stock_ticker.process_msg('f')
#stock_ticker.displayStocks()
stock_ticker.getFullStockImage(1)
stock_ticker.process_msg('f')
stock_ticker.displayStocks()
#stock_ticker.displayStocks()
#stock_ticker.delay = 0.001

View File

@ -38,10 +38,16 @@
<input type="submit" value="Display"style="height:30px">
</form>
<p>Set news search settings. keyword,category,country e.g. bitcoin,business,us/p>
<p>Set news search settings. keyword,category,country e.g. bitcoin,business,us </p>
<form action="/SetNews" method="POST">
<input name="text" placeholder="bitcoin,business,us"style="height:24px">
<input type="submit" value="Display"style="height:30px">
<input type="submit" value="Set"style="height:30px">
</form>
<p>Set weather location, enter city name e.g. London </p>
<form action="/SetWeather" method="POST">
<input name="text" placeholder="London"style="height:24px">
<input type="submit" value="Set"style="height:30px">
</form>
<p>Display an image</p>

Binary file not shown.