From a1dd720093f205b18f5ac77980b5b784e50037bb Mon Sep 17 00:00:00 2001 From: Neythen Date: Wed, 2 Jun 2021 21:16:15 +0100 Subject: [PATCH] added weather api caller --- api_caller.py | 61 ++++++++++++++--- csv/crypto.csv | 4 +- csv/current_weather.json | 1 + csv/daily_weather.json | 1 + csv/last_update.csv | 2 +- csv/news.csv | 40 +++++------ csv/tickers.csv | 6 +- display_image | Bin 2226 -> 2105 bytes final.ppm | Bin 0 -> 113391 bytes test.py | 143 +++++++++++++++++++++++++++++++++------ 10 files changed, 204 insertions(+), 54 deletions(-) create mode 100644 csv/current_weather.json create mode 100644 csv/daily_weather.json create mode 100755 final.ppm diff --git a/api_caller.py b/api_caller.py index 62b68c7..5ff52ad 100644 --- a/api_caller.py +++ b/api_caller.py @@ -176,9 +176,6 @@ def updateStockPricesIEX(symbols): CSV.write(symbol + ',' + str(current_prices[i]) + ',' + str(opening_prices[i]) + '\n') CSV.close() - - - def updateCrypto(coins, coin_info, unique_bases): response = coingecko_client.get_price(ids=','.join(coins), vs_currencies = unique_bases, include_24hr_change=True) @@ -222,7 +219,49 @@ def updateNews(): CSV.close() +def updateWeather(location, api_key): + url = "https://api.openweathermap.org/data/2.5/weather?q={}&units=metric&appid={}".format(location, api_key) + r = requests.get(url) + weather = r.json() + + current_weather = {} + + coords = weather['coord'] + lat = coords['lat'] + lon = coords['lon'] + url = 'https://api.openweathermap.org/data/2.5/onecall?lat={}&units=metric&lon={}&appid={}'.format(lat, lon, api_key) + r = requests.get(url) + + current_weather['main_weather'] = weather['weather'][0]['main'] + current_weather['description'] = weather['weather'][0]['description'] + current_weather['temp'] = weather['main']['temp'] + current_weather['min_temp'] = weather['main']['temp_min'] + current_weather['max_temp'] = weather['main']['temp_max'] + current_weather['feels_like'] = weather['main']['feels_like'] + current_weather['humidity'] = weather['main']['humidity'] + current_weather['clouds'] = weather['clouds']['all'] + current_weather['wind_speed'] = weather['wind']['speed'] + current_weather['wind_direction'] = weather['wind']['deg'] + current_weather['visibility'] = weather['visibility'] + current_weather['uv'] = r.json()['current']['uvi'] + + json.dump( current_weather, open( "csv/current_weather.json", 'w+' )) + + + daily_weather = [] + daily = r.json()['daily'] + + for day in daily: + dct = {} + dct['main_weather'] = day['weather'][0]['main'] + dct['description'] = day['weather'][0]['description'] + dct['min_temp'] = day['temp']['min'] + dct['min_temp'] = day['temp']['max'] + daily_weather.append(dct) + + + json.dump( daily_weather, open( "csv/daily_weather.json", 'w+' )) if __name__ == '__main__': newsapi = NewsApiClient(api_key='cf08652bd17647b89aaf469a1a8198a9') @@ -230,7 +269,11 @@ if __name__ == '__main__': finnhubAPIkey = "c24qddqad3ickpckgg80" #Finnhub finnhubsandboxAPIkey = "sandbox_c24qddqad3ickpckgg8g" #Finnhub - sleeptime = 2 #minutes + stock_time = 2 #minutes + news_time = 30 #minutes + weather_time = 10 #minutes + + # TODO: different update times for stocks, weather and news finnhubClient = finnhub.Client(api_key=finnhubAPIkey) max_stocks = 200 @@ -238,12 +281,9 @@ if __name__ == '__main__': iexSandboxAPIkey = 'Tpk_0078dff413ef4f979137f7111452dc4b' #updateStockPricesIEX(symbols) - - finnhubClient = finnhub.Client(api_key=finnhubAPIkey) - coingecko_client = CoinGeckoAPI() NY_zone = pytz.timezone('America/New_York') @@ -258,6 +298,10 @@ if __name__ == '__main__': updateStockPrices(symbols) updateUpdate(NY_time) coins, coin_info, unique_bases = readCryptoCSV('csv/crypto.csv', max_stocks) + + weather_location, weather_key = 'London', 'bd5d5096a5ba30bbcfb57ead42ab3fee' + + updateWeather(weather_location, weather_key) updateCrypto(coins, coin_info, unique_bases) @@ -271,7 +315,7 @@ if __name__ == '__main__': while True: msg = getInput() - if msg == 'R' or time.time() - t > sleeptime*60: + if msg == 'R' or time.time() - t > stock_time*60: @@ -281,6 +325,7 @@ if __name__ == '__main__': updateCrypto(coins, coin_info, unique_bases) updateNews() + updateWeather(weather_location, weather_key) NY_time = datetime.now(NY_zone) symbols, stock_info = readCSV('csv/tickers.csv', max_stocks) diff --git a/csv/crypto.csv b/csv/crypto.csv index bc7a709..db78d18 100644 --- a/csv/crypto.csv +++ b/csv/crypto.csv @@ -1,3 +1,3 @@ symbol,name,base,current,24hr change -BTC,bitcoin,usd,38140,5.220972287309966 -ETH,ethereum,gbp,1966.44,8.603614342494295 +BTC,bitcoin,usd,37943,5.398882470458167 +ETH,ethereum,gbp,1950.25,8.111712194442813 diff --git a/csv/current_weather.json b/csv/current_weather.json new file mode 100644 index 0000000..8a39dc6 --- /dev/null +++ b/csv/current_weather.json @@ -0,0 +1 @@ +{"main_weather": "Clouds", "description": "overcast clouds", "temp": 19.95, "min_temp": 17.32, "max_temp": 21.2, "feels_like": 19.54, "humidity": 59, "clouds": 96, "wind_speed": 1.31, "wind_direction": 113, "visibility": 10000, "uv": 0} \ No newline at end of file diff --git a/csv/daily_weather.json b/csv/daily_weather.json new file mode 100644 index 0000000..813c4d5 --- /dev/null +++ b/csv/daily_weather.json @@ -0,0 +1 @@ +[{"main_weather": "Rain", "description": "light rain", "min_temp": 27.04}, {"main_weather": "Clouds", "description": "scattered clouds", "min_temp": 24.89}, {"main_weather": "Rain", "description": "moderate rain", "min_temp": 16.33}, {"main_weather": "Clear", "description": "clear sky", "min_temp": 22.03}, {"main_weather": "Rain", "description": "light rain", "min_temp": 21.89}, {"main_weather": "Rain", "description": "light rain", "min_temp": 24.13}, {"main_weather": "Rain", "description": "light rain", "min_temp": 25.2}, {"main_weather": "Rain", "description": "light rain", "min_temp": 25.55}] \ No newline at end of file diff --git a/csv/last_update.csv b/csv/last_update.csv index a4f09a8..6bae4df 100644 --- a/csv/last_update.csv +++ b/csv/last_update.csv @@ -1 +1 @@ -02/06/2021 11:35:50 +02/06/2021 16:08:56 diff --git a/csv/news.csv b/csv/news.csv index 9cd5ee6..cd8cd2c 100644 --- a/csv/news.csv +++ b/csv/news.csv @@ -1,21 +1,21 @@ headline,source,date,time -First human case of H10N3 bird flu in China: These are the symptoms - MARCA.com,Marca,2021-06-02,14:25:39Z -Canadarm2 damaged by ‘lucky strike’ from space junk in orbit - Global News,Global News,2021-06-02,14:21:44Z -Coronavirus latest news: Matt Hancock warns vaccine fake news is a ‘deadly threat’ - Telegraph.co.uk,Telegraph.co.uk,2021-06-02,14:20:59Z -Space Debris Damages Robotic Arm Attached to the International Space Station - PCMag AU,PCMag.com,2021-06-02,14:09:11Z -Big TSX companies tripled number of Black board members in past year — but there are still only 26 - CBC.ca,CBC News,2021-06-02,14:05:55Z -Huawei officially launches Android alternative HarmonyOS for smartphones - Yahoo Finance Australia,Yahoo Entertainment,2021-06-02,14:05:17Z -Space junk slams into International Space Station^ leaving hole in robotic arm - CBS News,CBS News,2021-06-02,14:03:59Z -COVID-19: Three-quarters of adults in UK have now had first vaccine dose - Sky News,Sky.com,2021-06-02,14:03:45Z -Dalian Atkinson: PC's fear 'through the roof' during arrest - BBC News,BBC News,2021-06-02,14:02:38Z -Dow Jones Today Targets 5th Advance As Stocks Inch Up; DXC Upgraded; BorgWarner Nails Hyundai EV Deal - Investor's Business Daily,Investor's Business Daily,2021-06-02,14:00:00Z -Ford^ Lecce expected to make announcement about Ontario school reopening plan - CBC.ca,CBC News,2021-06-02,13:52:35Z -Huawei MatePad Pro 12.6 in for review - GSMArena.com news - GSMArena.com,GSMArena.com,2021-06-02,13:52:01Z -Everton set to begin talks with Nuno Espirito Santo over vacant manager role - Sky Sports,Sky Sports,2021-06-02,13:42:25Z -2021's first solar eclipse will show off a 'ring of fire' in the sky - CNET,CNET,2021-06-02,13:36:57Z -Asus ROG Strix G17^ ROG Strix G15 Advantage Edition Gaming Laptops With AMD Radeon RX 6800M GPU Announced - Gadgets 360,NDTV News,2021-06-02,13:21:30Z -Venus Williams has perfect response to Naomi Osaka French Open drama - New York Post ,New York Post,2021-06-02,13:18:00Z -Australia's Victoria extends Melbourne COVID-19 lockdown for 2nd week - Reuters,Reuters,2021-06-02,13:18:00Z -Nets make quick work of short-handed Celtics in first round of playoffs^ but much tougher test awaits in Bucks - CBS Sports,CBS Sports,2021-06-02,13:09:00Z -First Solar Eclipse of the year 2021: will be visible only from Arunachal Pradesh in India - Arunachal24,Arunachal24.in,2021-06-02,13:08:44Z -CDPR Won’t Reveal ‘Cyberpunk 2077’ Q1 Sales^ But Estimates Are Shockingly Low - Forbes,Forbes,2021-06-02,13:05:30Z +LKL finalo serijos starte – užtikrinta „Žalgirio“ pergalė - Lrytas.lt,Lrytas.lt,2021-06-02,18:41:12Z +Israeli Opposition Races Against Deadline to Oust Netanyahu: Live Updates - The New York Times,New York Times,2021-06-02,18:36:55Z +Help with roads^ rivers and rubble a priority as farmers take stock of flood devastation - Stuff.co.nz,Stuff.co.nz,2021-06-02,18:23:00Z +ICFO: Spain overtakes China in one of the biggest quantum communication problems | Science - Sunday Vision,Sundayvision.co.ug,2021-06-02,18:15:04Z +Joel Embiid (knee) will not play in Game 5 - NBA.com,Heat.com,2021-06-02,18:00:00Z +Elephant herd razes 500-kilometer path of destruction after escape from China nature reserve - CNN ,CNN,2021-06-02,17:58:00Z +President Biden News: Live Updates - The New York Times,New York Times,2021-06-02,17:57:48Z +Lack of papal apology for Canada indigenous schools abuses 'shameful' - minister - GMA News,GMA News,2021-06-02,17:45:42Z +No Time To Die Singer Billie Eilish Rocks Blonde Locks In Lost Cause Video - CinemaBlend,CinemaBlend,2021-06-02,17:45:39Z +Jaguar F-Type available only with V8 engine for 2022 - Driving,Driving,2021-06-02,17:42:02Z +Premier Doug Ford announces no in-class learning until September - Toronto Star,Toronto Star,2021-06-02,17:37:30Z +Cricket: Devon Conway shines on debut as Black Caps dominate day one of first test against England at Lord's - New Zealand Herald,New Zealand Herald,2021-06-02,17:35:00Z +Atmospheric metal layers appear with surprising regularity - Science Daily,Science Daily,2021-06-02,17:31:46Z +Kevin Lunney attackers broke his leg and scored chest with blade^ court hears - The Irish Times,The Irish Times,2021-06-02,17:30:53Z +US wields $2bn tariff threat against 6 nations over digital taxes - Financial Times,Financial Times,2021-06-02,17:25:24Z +Duke Blue Devils basketball coach Mike Krzyzewski plans to retire after season^ sources say - ESPN,ESPN,2021-06-02,17:24:40Z +Do not politick with land^ Malema warns Ramaphosa as he cranks up pressure on ANC over amendment - News24,News24,2021-06-02,17:24:10Z +AMC frenzy triggers trading halts as stock surges 100 percent - NBC News,NBC News,2021-06-02,17:23:00Z +Facebook doubles down on business tools with WhatsApp API updates^ Login Connect for Messenger and more - TechCrunch,TechCrunch,2021-06-02,17:21:52Z +BJP leader Rakesh Pandit shot dead by terrorists outside his home in Kashmir - Moneycontrol.com,Moneycontrol,2021-06-02,17:19:38Z diff --git a/csv/tickers.csv b/csv/tickers.csv index d4161ba..fe635d3 100644 --- a/csv/tickers.csv +++ b/csv/tickers.csv @@ -1,4 +1,4 @@ name,current,opening -MSFT,248.47,248.125 -NFLX,500.285,499.82 -GOOG,2430.27,2435.31 +MSFT,247.3,248.125 +NFLX,499.24,499.82 +GOOG,2421.28,2435.31 diff --git a/display_image b/display_image index 7a149d59f26382361ef3675041848afc296fd7ad..dd6603978f3d4978b92e5fe5801d5bf234329b0b 100755 GIT binary patch delta 2094 zcmV+}2+{Yl5xEc{iBL{Q4GJ0x0000DNk~Le0001K0000W2nGNE01?$zo{=FWe+S-4 zL_t(|ob6g^Y*j@Rep}x@bfJZ|v>>HWmX@~Avb3~p0#aEjTND$CG5!z{BN`VHQE`bz z&=}(aQGXCMAQFuRmqZg>5|^Mx!5C4&fQl$;jEX42c)q#kz0RB7`?!?%QkuL;zNB~N z%$?=C=bUfm)#ES8mw8p?3ch|(f9dgfGKE~pR0%hYkYd?11rX)Qk#z2r97%nkTAgC7a| zxqT5Kn2q%tbHTW~T-t76`{h}lRw_xs5fw62H&n(urzGp_5MR_L!;?l!Uo4UdlJ@X> zKPBwe@G)T@;W*(0VRN>)2+;*{?Y5T>1z}L_l!#5NDAOnHTxGfnHZNi?b;*z9!e{A!XOlu?r^1SjR+#@c0ojZ&>n$lxGCWMu8{~nc z*z6{Cc7iu0@>6)?C^O`_DjG>M2z3V92~P`4G<-qmr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0)XdJ)7DJ-V;foT<6682}z`7vHJ>8SdM sOq&WcT^R)$0`OZp>h%pVY|fZXV!UY5QD{^U^Hc$VY|Jq3jVJ#5|Lp0fuK)l5 literal 0 HcmV?d00001 diff --git a/test.py b/test.py index bcde0c8..4edfe55 100644 --- a/test.py +++ b/test.py @@ -13,6 +13,9 @@ import finnhub import pexpect from pycoingecko import CoinGeckoAPI from newsapi import NewsApiClient +import configparser +import requests +import json import sys, os try: @@ -21,29 +24,129 @@ except Exception as e: exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] print(exc_type, fname, exc_tb.tb_lineno, exc_obj, exc_tb) + + +def update_weather(): + api_key = 'bd5d5096a5ba30bbcfb57ead42ab3fee' + location = 'London' + url = "https://api.openweathermap.org/data/2.5/weather?q={}&units=metric&appid={}".format(location, api_key) + r = requests.get(url) + weather = r.json() + + current_weather = {} + + coords = weather['coord'] + lat = coords['lat'] + lon = coords['lon'] + url = 'https://api.openweathermap.org/data/2.5/onecall?lat={}&units=metric&lon={}&appid={}'.format(lat, lon, api_key) + r = requests.get(url) + + current_weather['main_weather'] = weather['weather'][0]['main'] + current_weather['description'] = weather['weather'][0]['description'] + current_weather['temp'] = weather['main']['temp'] + current_weather['min_temp'] = weather['main']['temp_min'] + current_weather['max_temp'] = weather['main']['temp_max'] + current_weather['feels_like'] = weather['main']['feels_like'] + current_weather['humidity'] = weather['main']['humidity'] + current_weather['clouds'] = weather['clouds']['all'] + current_weather['wind_speed'] = weather['wind']['speed'] + current_weather['wind_direction'] = weather['wind']['deg'] + current_weather['visibility'] = weather['visibility'] + current_weather['uv'] = r.json()['current']['uvi'] + + json.dump( current_weather, open( "csv/current_weather.json", 'w+' )) + + + daily_weather = [] + daily = r.json()['daily'] + + for day in daily: + dct = {} + dct['main_weather'] = day['weather'][0]['main'] + dct['description'] = day['weather'][0]['description'] + dct['min_temp'] = day['temp']['min'] + dct['min_temp'] = day['temp']['max'] + daily_weather.append(dct) + + + json.dump( daily_weather, open( "csv/daily_weather.json", 'w+' )) + if __name__ == '__main__': + + update_weather() + sys.exit() - newsapi = NewsApiClient(api_key='cf08652bd17647b89aaf469a1a8198a9') - - top_headlines = newsapi.get_top_headlines(q='bitcoin', - category='business', - country='us') - - - ''' - top_headlines = newsapi.get_everything(q='bitcoin', - sources='bbc-news,the-verge', - page=1) - ''' - #print(top_headlines) - headline_titles = [top_headline['title'] for top_headline in top_headlines['articles']] - headline_ids = [top_headline['source']['name'] for top_headline in top_headlines['articles']] - headline_times = [top_headline['publishedAt']for top_headline in top_headlines['articles']] + api_key = 'bd5d5096a5ba30bbcfb57ead42ab3fee' + location = 'London' + + url = "https://api.openweathermap.org/data/2.5/weather?q={}&units=metric&appid={}".format(location, api_key) + r = requests.get(url) + weather = r.json() + + current_weather = {} + + coords = weather['coord'] + lat = coords['lat'] + lon = coords['lon'] + url = 'https://api.openweathermap.org/data/2.5/onecall?lat={}&units=metric&lon={}&appid={}'.format(lat, lon, api_key) + r = requests.get(url) + print() + print('main weather: ', weather['weather'][0]['main']) + print('description: ', weather['weather'][0]['description']) + print('temp (degrees C): ', weather['main']['temp']) + print('min: ', weather['main']['temp_min']) + print('max: ', weather['main']['temp_max']) + print('feels like: ', weather['main']['feels_like']) + print('humidity (%): ', weather['main']['humidity']) + print('clouds: ', weather['clouds']['all']) + print('wind speed (m/s): ', weather['wind']['speed'], 'direction:', weather['wind']['deg']) + print('visibility (metres): ', weather['visibility']) + print('UV index: ', r.json()['current']['uvi']) + + current_weather['main_weather'] = weather['weather'][0]['main'] + current_weather['description'] = weather['weather'][0]['description'] + current_weather['temp'] = weather['main']['temp'] + current_weather['min_temp'] = weather['main']['temp_min'] + current_weather['max_temp'] = weather['main']['temp_max'] + current_weather['feels_like'] = weather['main']['feels_like'] + current_weather['humidity'] = weather['main']['humidity'] + current_weather['clouds'] = weather['clouds']['all'] + current_weather['wind_speed'] = weather['wind']['speed'] + current_weather['wind_direction'] = weather['wind']['deg'] + current_weather['visibility'] = weather['visibility'] + current_weather['uv'] = r.json()['current']['uvi'] + print() + print(current_weather) + + json.dump( current_weather, open( "csv/current_weather.json", 'w+' )) + + + daily_weather = [] + daily = r.json()['daily'] + + for day in daily: + dct = {} + dct['main_weather'] = day['weather'][0]['main'] + dct['description'] = day['weather'][0]['description'] + dct['min_temp'] = day['temp']['min'] + dct['min_temp'] = day['temp']['max'] + daily_weather.append(dct) + + + json.dump( daily_weather, open( "csv/daily_weather.json", 'w+' )) + + + print() + print(weather) + print() + print(r.json()['daily'][0]) + print() + print(daily_weather) + + + + - #print([top_headline.keys()for top_headline in top_headlines['articles']]) - print(headline_titles) - print(headline_ids) - print(headline_times)