diff --git a/api_caller.py b/api_caller.py index afc9411..715de36 100644 --- a/api_caller.py +++ b/api_caller.py @@ -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) diff --git a/csv/crypto.csv b/csv/crypto.csv index 333235c..2bdec31 100644 --- a/csv/crypto.csv +++ b/csv/crypto.csv @@ -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 diff --git a/csv/currency.json b/csv/currency.json new file mode 100644 index 0000000..8cd0c2e --- /dev/null +++ b/csv/currency.json @@ -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]}] \ No newline at end of file diff --git a/csv/current_weather.json b/csv/current_weather.json index 1691e50..e42fbb9 100644 --- a/csv/current_weather.json +++ b/csv/current_weather.json @@ -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} \ No newline at end of file +{"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} \ No newline at end of file diff --git a/csv/daily_weather.json b/csv/daily_weather.json index 23d25e0..8f9a81e 100644 --- a/csv/daily_weather.json +++ b/csv/daily_weather.json @@ -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}] \ No newline at end of file +[{"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}] \ No newline at end of file diff --git a/csv/last_update.csv b/csv/last_update.csv index e7b8766..82df2e4 100644 --- a/csv/last_update.csv +++ b/csv/last_update.csv @@ -1 +1 @@ -08/06/2021 16:30:26 +09/06/2021 14:00:57 diff --git a/csv/news.csv b/csv/news.csv index 9e372d7..1ca6dd1 100644 --- a/csv/news.csv +++ b/csv/news.csv @@ -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 +Trump’s 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 won’t 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 Navalny’s 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 diff --git a/csv/tickers.csv b/csv/tickers.csv index 2c8fc08..1d4c7d7 100644 --- a/csv/tickers.csv +++ b/csv/tickers.csv @@ -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 diff --git a/csv/weather_location.txt b/csv/weather_location.txt new file mode 100644 index 0000000..050c2b7 --- /dev/null +++ b/csv/weather_location.txt @@ -0,0 +1 @@ +Hong Kong diff --git a/final.ppm b/final.ppm index 65c7bdf..4df63ca 100755 Binary files a/final.ppm and b/final.ppm differ diff --git a/final1.ppm b/final1.ppm index 65c7bdf..4df63ca 100755 Binary files a/final1.ppm and b/final1.ppm differ diff --git a/logos/currencies/aud.png b/logos/currencies/aud.png new file mode 100644 index 0000000..e1a3812 Binary files /dev/null and b/logos/currencies/aud.png differ diff --git a/logos/currencies/cad.png b/logos/currencies/cad.png new file mode 100644 index 0000000..03f68f3 Binary files /dev/null and b/logos/currencies/cad.png differ diff --git a/logos/currencies/chf.png b/logos/currencies/chf.png new file mode 100644 index 0000000..bd910db Binary files /dev/null and b/logos/currencies/chf.png differ diff --git a/logos/currencies/eur.png b/logos/currencies/eur.png new file mode 100644 index 0000000..348ffd9 Binary files /dev/null and b/logos/currencies/eur.png differ diff --git a/logos/currencies/gbp.png b/logos/currencies/gbp.png new file mode 100644 index 0000000..c47f9a9 Binary files /dev/null and b/logos/currencies/gbp.png differ diff --git a/logos/currencies/jpy.png b/logos/currencies/jpy.png new file mode 100644 index 0000000..94cdf89 Binary files /dev/null and b/logos/currencies/jpy.png differ diff --git a/logos/currencies/nzd.png b/logos/currencies/nzd.png new file mode 100644 index 0000000..b3c027b Binary files /dev/null and b/logos/currencies/nzd.png differ diff --git a/logos/currencies/usd.png b/logos/currencies/usd.png new file mode 100644 index 0000000..7daabe2 Binary files /dev/null and b/logos/currencies/usd.png differ diff --git a/server.py b/server.py index 1ef73f7..faba4a2 100644 --- a/server.py +++ b/server.py @@ -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': diff --git a/stockTicker.py b/stockTicker.py index eb58663..22f3176 100644 --- a/stockTicker.py +++ b/stockTicker.py @@ -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 @@ -480,7 +480,7 @@ class StockTicker(): start = time.time() self.readCSV() - + for i, symbol in enumerate(self.symbols): info = self.stock_info[symbol] @@ -538,7 +538,49 @@ 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 diff --git a/templates/index.html b/templates/index.html index c2775d7..9b45362 100644 --- a/templates/index.html +++ b/templates/index.html @@ -38,10 +38,16 @@ -

Set news search settings. keyword,category,country e.g. bitcoin,business,us/p> +

Set news search settings. keyword,category,country e.g. bitcoin,business,us

- + +
+ +

Set weather location, enter city name e.g. London

+
+ +

Display an image

diff --git a/weather.ppm b/weather.ppm index 7c7eab2..34096cc 100755 Binary files a/weather.ppm and b/weather.ppm differ