weather api calls consolidated and multiple cities can be used
This commit is contained in:
parent
54edfb0d1b
commit
a23b0f849c
137
api_caller.py
137
api_caller.py
@ -9,6 +9,8 @@ import sys, os, base64, hashlib, hmac, select
|
|||||||
import requests
|
import requests
|
||||||
from pycoingecko import CoinGeckoAPI
|
from pycoingecko import CoinGeckoAPI
|
||||||
from newsapi import NewsApiClient
|
from newsapi import NewsApiClient
|
||||||
|
import traceback
|
||||||
|
from geopy import geocoders
|
||||||
|
|
||||||
def getInput(Block=False):
|
def getInput(Block=False):
|
||||||
if Block or select.select([sys.stdin], [], [], 0) == ([sys.stdin], [], []):
|
if Block or select.select([sys.stdin], [], [], 0) == ([sys.stdin], [], []):
|
||||||
@ -46,7 +48,7 @@ def readCSV(file_path, max_stocks):
|
|||||||
|
|
||||||
return symbols, stock_info
|
return symbols, stock_info
|
||||||
|
|
||||||
def readCryptoCSV(file_path, max_stocks):
|
def readCryptoCSV(file_path, max_crypto):
|
||||||
|
|
||||||
symbols = []
|
symbols = []
|
||||||
names = []
|
names = []
|
||||||
@ -58,7 +60,8 @@ def readCryptoCSV(file_path, max_stocks):
|
|||||||
unique_bases = []
|
unique_bases = []
|
||||||
for row in CSV:
|
for row in CSV:
|
||||||
print(row)
|
print(row)
|
||||||
if i < max_stocks:
|
if i >= max_stocks:
|
||||||
|
break
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -120,12 +123,19 @@ def updateStockPrices():
|
|||||||
print('API called successfully')
|
print('API called successfully')
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("Could not fetch data - API CALLS REACHED? - Will display old image")
|
|
||||||
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||||||
|
fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
|
||||||
|
logf.write(str(e))
|
||||||
|
logf.write('. file: ' + fname)
|
||||||
|
logf.write('. line: ' + str(exc_tb.tb_lineno))
|
||||||
|
logf.write('. type: ' + str(exc_type))
|
||||||
|
logf.write('\n ' + "".join(traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])))
|
||||||
print(e)
|
print(e)
|
||||||
apiCalledError = True
|
|
||||||
|
|
||||||
|
|
||||||
def updateStockPricesIEX():
|
def updateStockPricesIEX():
|
||||||
|
|
||||||
iexAPIkey = 'pk_68ef6a15902c41f887f0b544a0ca17cf' #IEX
|
iexAPIkey = 'pk_68ef6a15902c41f887f0b544a0ca17cf' #IEX
|
||||||
iexSandboxAPIkey = 'Tpk_0078dff413ef4f979137f7111452dc4b'
|
iexSandboxAPIkey = 'Tpk_0078dff413ef4f979137f7111452dc4b'
|
||||||
max_stocks = 200
|
max_stocks = 200
|
||||||
@ -185,6 +195,13 @@ def updateStockPricesIEX():
|
|||||||
CSV.write(symbol + ',' + str(current_prices[i]) + ',' + str(opening_prices[i]) + '\n')
|
CSV.write(symbol + ',' + str(current_prices[i]) + ',' + str(opening_prices[i]) + '\n')
|
||||||
CSV.close()
|
CSV.close()
|
||||||
except Exception as e:
|
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]
|
||||||
|
logf.write(str(e))
|
||||||
|
logf.write('. file: ' + fname)
|
||||||
|
logf.write('. line: ' + str(exc_tb.tb_lineno))
|
||||||
|
logf.write('. type: ' + str(exc_type))
|
||||||
|
logf.write('\n ' + "".join(traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])))
|
||||||
print(e)
|
print(e)
|
||||||
|
|
||||||
|
|
||||||
@ -205,6 +222,13 @@ def updateCrypto():
|
|||||||
CSV.write(info[0] + ',' + coin + ',' + info[1] + ',' +str(response[coin][info[1]]) + ',' + str(response[coin]['usd_24h_change']) + '\n')
|
CSV.write(info[0] + ',' + coin + ',' + info[1] + ',' +str(response[coin][info[1]]) + ',' + str(response[coin]['usd_24h_change']) + '\n')
|
||||||
CSV.close()
|
CSV.close()
|
||||||
except Exception as e:
|
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]
|
||||||
|
logf.write(str(e))
|
||||||
|
logf.write('. file: ' + fname)
|
||||||
|
logf.write('. line: ' + str(exc_tb.tb_lineno))
|
||||||
|
logf.write('. type: ' + str(exc_type))
|
||||||
|
logf.write('\n ' + "".join(traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])))
|
||||||
print(e)
|
print(e)
|
||||||
|
|
||||||
|
|
||||||
@ -235,44 +259,62 @@ def updateNews():
|
|||||||
|
|
||||||
CSV.close()
|
CSV.close()
|
||||||
except Exception as e:
|
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]
|
||||||
|
logf.write(str(e))
|
||||||
|
logf.write('. file: ' + fname)
|
||||||
|
logf.write('. line: ' + str(exc_tb.tb_lineno))
|
||||||
|
logf.write('. type: ' + str(exc_type))
|
||||||
|
logf.write('\n ' + "".join(traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])))
|
||||||
print(e)
|
print(e)
|
||||||
|
|
||||||
def updateWeather():
|
def updateWeather():
|
||||||
|
max_cities = 30
|
||||||
api_key = 'bd5d5096a5ba30bbcfb57ead42ab3fee'
|
api_key = 'bd5d5096a5ba30bbcfb57ead42ab3fee'
|
||||||
try:
|
try:
|
||||||
|
gn = geocoders.GeoNames(username='fintic')
|
||||||
|
|
||||||
|
|
||||||
f = open( "csv/weather_location.txt", 'r' )
|
f = open( "csv/weather_location.txt", 'r' )
|
||||||
location = f.read()
|
line = next(f)
|
||||||
|
locations = line.split(',')
|
||||||
f.close()
|
f.close()
|
||||||
url = "https://api.openweathermap.org/data/2.5/weather?q={}&units=metric&appid={}".format(location, api_key)
|
|
||||||
r = requests.get(url)
|
current_weathers = []
|
||||||
weather = r.json()
|
daily_weathers = []
|
||||||
print(weather)
|
|
||||||
|
|
||||||
|
for location in locations:
|
||||||
|
loc = gn.geocode(location)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
current_weather = {}
|
current_weather = {}
|
||||||
|
|
||||||
coords = weather['coord']
|
lat = loc.latitude
|
||||||
lat = coords['lat']
|
lon = loc.longitude
|
||||||
lon = coords['lon']
|
|
||||||
url = 'https://api.openweathermap.org/data/2.5/onecall?lat={}&units=metric&lon={}&appid={}'.format(lat, lon, api_key)
|
url = 'https://api.openweathermap.org/data/2.5/onecall?lat={}&units=metric&lon={}&appid={}'.format(lat, lon, api_key)
|
||||||
r = requests.get(url)
|
r = requests.get(url)
|
||||||
|
|
||||||
|
weather = r.json()['current']
|
||||||
|
|
||||||
current_weather['main_weather'] = weather['weather'][0]['main']
|
current_weather['main_weather'] = weather['weather'][0]['main']
|
||||||
current_weather['description'] = weather['weather'][0]['description']
|
current_weather['description'] = weather['weather'][0]['description']
|
||||||
current_weather['temp'] = weather['main']['temp']
|
current_weather['temp'] = weather['temp']
|
||||||
current_weather['min_temp'] = weather['main']['temp_min']
|
current_weather['min_temp'] = r.json()['daily'][0]['temp']['min']
|
||||||
current_weather['max_temp'] = weather['main']['temp_max']
|
current_weather['max_temp'] = r.json()['daily'][0]['temp']['max']
|
||||||
current_weather['feels_like'] = weather['main']['feels_like']
|
current_weather['feels_like'] = weather['feels_like']
|
||||||
current_weather['humidity'] = weather['main']['humidity']
|
current_weather['humidity'] = weather['humidity']
|
||||||
current_weather['clouds'] = weather['clouds']['all']
|
current_weather['clouds'] = weather['clouds']
|
||||||
current_weather['wind_speed'] = weather['wind']['speed']
|
current_weather['wind_speed'] = weather['wind_speed']
|
||||||
current_weather['wind_direction'] = weather['wind']['deg']
|
current_weather['wind_direction'] = weather['wind_deg']
|
||||||
current_weather['visibility'] = weather['visibility']
|
current_weather['visibility'] = weather['visibility']
|
||||||
current_weather['uv'] = r.json()['current']['uvi']
|
current_weather['uv'] = weather['uvi']
|
||||||
current_weather['rain_chance'] = r.json()['hourly'][0]['pop']
|
current_weather['rain_chance'] = r.json()['hourly'][0]['pop']
|
||||||
|
|
||||||
|
|
||||||
json.dump( current_weather, open( "csv/current_weather.json", 'w+' ))
|
|
||||||
|
|
||||||
|
current_weathers.append(current_weather)
|
||||||
|
|
||||||
daily_weather = []
|
daily_weather = []
|
||||||
daily = r.json()['daily']
|
daily = r.json()['daily']
|
||||||
@ -285,9 +327,19 @@ def updateWeather():
|
|||||||
dct['max_temp'] = day['temp']['max']
|
dct['max_temp'] = day['temp']['max']
|
||||||
daily_weather.append(dct)
|
daily_weather.append(dct)
|
||||||
|
|
||||||
|
daily_weathers.append(daily_weather)
|
||||||
|
|
||||||
|
json.dump( current_weather, open( "csv/current_weather.json", 'w+' ))
|
||||||
json.dump( daily_weather, open( "csv/daily_weather.json", 'w+' ))
|
json.dump( daily_weather, open( "csv/daily_weather.json", 'w+' ))
|
||||||
|
|
||||||
except Exception as e:
|
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]
|
||||||
|
logf.write(str(e))
|
||||||
|
logf.write('. file: ' + fname)
|
||||||
|
logf.write('. line: ' + str(exc_tb.tb_lineno))
|
||||||
|
logf.write('. type: ' + str(exc_type))
|
||||||
|
logf.write('\n ' + "".join(traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])))
|
||||||
print(e)
|
print(e)
|
||||||
|
|
||||||
|
|
||||||
@ -324,9 +376,17 @@ def updateForex():
|
|||||||
|
|
||||||
json.dump([base, c_dict], open( "csv/currency.json", 'w+' ))
|
json.dump([base, c_dict], open( "csv/currency.json", 'w+' ))
|
||||||
except Exception as e:
|
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]
|
||||||
|
logf.write(str(e))
|
||||||
|
logf.write('. file: ' + fname)
|
||||||
|
logf.write('. line: ' + str(exc_tb.tb_lineno))
|
||||||
|
logf.write('. type: ' + str(exc_type))
|
||||||
|
logf.write('\n ' + "".join(traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])))
|
||||||
print(e)
|
print(e)
|
||||||
|
|
||||||
def updateLeagueTable(api_key, league_id):
|
def updateLeagueTable(api_key, league_id):
|
||||||
|
try:
|
||||||
url = 'https://www.thesportsdb.com/api/v1/json/{}/lookuptable.php?l={}&s=2020-2021'.format(api_key, league_id)
|
url = 'https://www.thesportsdb.com/api/v1/json/{}/lookuptable.php?l={}&s=2020-2021'.format(api_key, league_id)
|
||||||
|
|
||||||
r = requests.get(url)
|
r = requests.get(url)
|
||||||
@ -364,9 +424,19 @@ def updateLeagueTable(api_key, league_id):
|
|||||||
league = 'NFL'
|
league = 'NFL'
|
||||||
|
|
||||||
json.dump(premier_teams, open( "csv/sports/{}/team_stats.json".format(league), 'w+' ))
|
json.dump(premier_teams, open( "csv/sports/{}/team_stats.json".format(league), 'w+' ))
|
||||||
|
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]
|
||||||
|
logf.write(str(e))
|
||||||
|
logf.write('. file: ' + fname)
|
||||||
|
logf.write('. line: ' + str(exc_tb.tb_lineno))
|
||||||
|
logf.write('. type: ' + str(exc_type))
|
||||||
|
logf.write('\n ' + "".join(traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])))
|
||||||
|
print(e)
|
||||||
|
|
||||||
def updateLeagueEvents(api_key, league_id, time):
|
def updateLeagueEvents(api_key, league_id, time):
|
||||||
|
|
||||||
|
try:
|
||||||
if time == 'past':
|
if time == 'past':
|
||||||
url ='https://www.thesportsdb.com/api/v1/json/{}/eventspastleague.php?id={}'.format(api_key, league_id) #last 15 events on the league (premium only)
|
url ='https://www.thesportsdb.com/api/v1/json/{}/eventspastleague.php?id={}'.format(api_key, league_id) #last 15 events on the league (premium only)
|
||||||
elif time == 'future':
|
elif time == 'future':
|
||||||
@ -414,6 +484,15 @@ def updateLeagueEvents(api_key, league_id, time):
|
|||||||
league = 'NFL'
|
league = 'NFL'
|
||||||
|
|
||||||
json.dump(events, open( "csv/sports/{}/{}_games.json".format(league, time), 'w+' ))
|
json.dump(events, open( "csv/sports/{}/{}_games.json".format(league, time), 'w+' ))
|
||||||
|
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]
|
||||||
|
logf.write(str(e))
|
||||||
|
logf.write('. file: ' + fname)
|
||||||
|
logf.write('. line: ' + str(exc_tb.tb_lineno))
|
||||||
|
logf.write('. type: ' + str(exc_type))
|
||||||
|
logf.write('\n ' + "".join(traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])))
|
||||||
|
print(e)
|
||||||
|
|
||||||
def updateSports():
|
def updateSports():
|
||||||
#read user settings to decide which sprots to update
|
#read user settings to decide which sprots to update
|
||||||
@ -479,7 +558,7 @@ def checkStocks(last_update, update_frequency):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
updateWeather()
|
||||||
max_stocks = 200
|
max_stocks = 200
|
||||||
max_crypto = 100
|
max_crypto = 100
|
||||||
|
|
||||||
@ -548,12 +627,12 @@ if __name__ == '__main__':
|
|||||||
last_updates['weather'] = weather_time
|
last_updates['weather'] = weather_time
|
||||||
|
|
||||||
|
|
||||||
# weather
|
# news
|
||||||
news_time = datetime.strptime(last_updates['news'], "%d/%m/%Y %H:%M:%S")
|
news_time = datetime.strptime(last_updates['news'], "%d/%m/%Y %H:%M:%S")
|
||||||
news_frequency = update_frequencies['news']
|
news_frequency = update_frequencies['news']
|
||||||
|
|
||||||
NY_time = datetime.now(NY_zone).replace(tzinfo=None)
|
NY_time = datetime.now(NY_zone).replace(tzinfo=None)
|
||||||
diff = (NY_time - weather_time).total_seconds()/60 #minutes
|
diff = (NY_time - news_time).total_seconds()/60 #minutes
|
||||||
if diff >= update_frequencies['news']:
|
if diff >= update_frequencies['news']:
|
||||||
news_time = NY_time.strftime("%d/%m/%Y %H:%M:%S")
|
news_time = NY_time.strftime("%d/%m/%Y %H:%M:%S")
|
||||||
updateNews()
|
updateNews()
|
||||||
@ -572,7 +651,13 @@ if __name__ == '__main__':
|
|||||||
updateForex()
|
updateForex()
|
||||||
|
|
||||||
except Exception as e:
|
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]
|
||||||
logf.write(str(e))
|
logf.write(str(e))
|
||||||
|
logf.write('. file: ' + fname)
|
||||||
|
logf.write('. line: ' + str(exc_tb.tb_lineno))
|
||||||
|
logf.write('. type: ' + str(exc_type))
|
||||||
|
logf.write('\n ' + "".join(traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])))
|
||||||
print(e)
|
print(e)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
symbol,name,base,current,24hr change
|
symbol,name,base,current,24hr change
|
||||||
BTC,bitcoin,usd,32675,3.7239980392362217
|
BTC,bitcoin,usd,34390,4.744355545187088
|
||||||
ETH,ethereum,gbp,1317.79,1.854985374746106
|
ETH,ethereum,gbp,1516.42,15.455756498827048
|
||||||
|
|
@ -1 +1 @@
|
|||||||
{"main_weather": "Rain", "description": "heavy intensity rain", "temp": 29.82, "min_temp": 28.3, "max_temp": 31.03, "feels_like": 36.82, "humidity": 86, "clouds": 100, "wind_speed": 0.45, "wind_direction": 16, "visibility": 10000, "uv": 0.45, "rain_chance": 0.39}
|
{"main_weather": "Clouds", "description": "overcast clouds", "temp": 28.98, "min_temp": 28.22, "max_temp": 29.56, "feels_like": 35.98, "humidity": 91, "clouds": 100, "wind_speed": 0.45, "wind_direction": 320, "visibility": 10000, "uv": 0, "rain_chance": 0.98}
|
@ -1 +1 @@
|
|||||||
[{"main_weather": "Rain", "description": "heavy intensity rain", "min_temp": 28.09, "max_temp": 29.87}, {"main_weather": "Rain", "description": "moderate rain", "min_temp": 28.22, "max_temp": 28.97}, {"main_weather": "Rain", "description": "moderate rain", "min_temp": 28.19, "max_temp": 29.57}, {"main_weather": "Rain", "description": "moderate rain", "min_temp": 28.21, "max_temp": 29.37}, {"main_weather": "Rain", "description": "moderate rain", "min_temp": 28.28, "max_temp": 29.31}, {"main_weather": "Rain", "description": "moderate rain", "min_temp": 28.27, "max_temp": 29.43}, {"main_weather": "Rain", "description": "moderate rain", "min_temp": 28.03, "max_temp": 29.7}, {"main_weather": "Clouds", "description": "overcast clouds", "min_temp": 27.9, "max_temp": 29.98}]
|
[{"main_weather": "Rain", "description": "moderate rain", "min_temp": 28.22, "max_temp": 29.56}, {"main_weather": "Rain", "description": "moderate rain", "min_temp": 28, "max_temp": 29.23}, {"main_weather": "Rain", "description": "moderate rain", "min_temp": 27.89, "max_temp": 28.93}, {"main_weather": "Rain", "description": "moderate rain", "min_temp": 28.05, "max_temp": 29.21}, {"main_weather": "Rain", "description": "moderate rain", "min_temp": 27.92, "max_temp": 29.19}, {"main_weather": "Rain", "description": "light rain", "min_temp": 27.92, "max_temp": 29.72}, {"main_weather": "Rain", "description": "light rain", "min_temp": 27.81, "max_temp": 29.87}, {"main_weather": "Clear", "description": "clear sky", "min_temp": 27.61, "max_temp": 29.53}]
|
40
csv/news.csv
40
csv/news.csv
@ -1,21 +1,21 @@
|
|||||||
headline,source,date,time
|
headline,source,date,time
|
||||||
China's Zhurong rover returns landing footage and sounds from Mars - SpaceNews,SpaceNews,2021-06-27,08:42:29Z
|
Troops eliminate 12 terrorists in Borno | The Guardian Nigeria News - Nigeria and World News — Nigeria - Guardian,Guardian Nigeria,2021-06-28,18:29:00Z
|
||||||
Jammu Airport Blasts LIVE Updates: NIA Likely to Probe Case^ Flight Ops Normal; IAF Stations in Punjab & Srinagar on High Alert - News18,News18,2021-06-27,08:41:51Z
|
Interim government of Tigray flees as rebels advance on Mekelle - The Guardian,The Guardian,2021-06-28,18:27:00Z
|
||||||
Lacson bares what he expects to hear from Duterte's final SONA - GMA News Online,GMA News,2021-06-27,08:37:03Z
|
Winner of BrewDog’s ‘solid gold’ beer can finds prize is made largely of brass - The Guardian,The Guardian,2021-06-28,18:23:00Z
|
||||||
A-League grand final LIVE updates: Red-hot City lead 2-1 over 10-man Sydney FC - The Sydney Morning Herald,The Sydney Morning Herald,2021-06-27,08:30:20Z
|
LIVE updates as busy Tipperary motorway after man^ 80s^ dies in fatal crash - Irish Mirror,Irish Mirror,2021-06-28,18:22:30Z
|
||||||
Why most people who now die with Covid in England have been vaccinated - The Guardian,The Guardian,2021-06-27,08:22:00Z
|
McKenna says leaving politics a ‘difficult decision’ but climate change remains focus - Global News,Global News,2021-06-28,18:19:46Z
|
||||||
Some families frustrated by pace of search and rescue efforts in Florida building collapse - CNN ,CNN,2021-06-27,08:11:00Z
|
Iyabo Ojo^ Nkechi Blessing^ Jide Kosoko & 'Tapan' controversy for Yoruba movie industry - BBC News,BBC News,2021-06-28,18:11:54Z
|
||||||
PH’s COVID-19 cases nears 1.4 million-mark with 6^096 new infections - INQUIRER.net,Inquirer.net,2021-06-27,08:04:00Z
|
Missing Florida woman was on phone with husband^ as building came crumbling down - NBC News,NBC News,2021-06-28,18:11:05Z
|
||||||
How to use Alexa Whisper Mode on an Amazon Echo - TechRadar,TechRadar,2021-06-27,08:00:00Z
|
Motorway mayhem: Truck crash blocks highway into Auckland - New Zealand Herald,New Zealand Herald,2021-06-28,18:00:21Z
|
||||||
Low vitamin D can raise death risk from Covid by 20% - ETHealthworld.com,The Times of India,2021-06-27,07:58:20Z
|
Juul agrees to pay North Carolina $40 million to settle vaping accusations - The Washington Post,The Washington Post,2021-06-28,18:00:00Z
|
||||||
M5.0 quake strikes near Surigao del Sur - SunStar Philippines,Sunstar.com.ph,2021-06-27,07:56:05Z
|
Ethiopian Forces Retreat in Tigray^ and Rebels Enter the Capital - The New York Times,New York Times,2021-06-28,17:55:52Z
|
||||||
Statesmen think of the next generation^ not the next election - Rafidah blasts MCO inconsistency - Malaysiakini,Malaysiakini,2021-06-27,07:54:50Z
|
Boris Johnson suggests he sacked Matt Hancock – despite refusing to dismiss him when scandal broke - The Independent,Independent,2021-06-28,17:45:43Z
|
||||||
Long Covid: 'I've blood clots^ a braced leg and damaged heart... but I'm home' - The Samford Crimson,Samfordcrimson.com,2021-06-27,07:54:34Z
|
What's allowed under MECQ^ GCQ^ GCQ with heightened restrictions^ GCQ with some restrictions - GMA News Online,GMA News,2021-06-28,17:45:28Z
|
||||||
Guns of the west: Hot Dogs dominate Eagles in Perth - AFL,Afl.com.au,2021-06-27,07:53:00Z
|
No COVID-19 deaths in Manitoba on Monday^ 61 new cases - CTV News,Ctvnews.ca,2021-06-28,17:43:08Z
|
||||||
China releases videos of rover on Mars - Yahoo News,Yahoo Entertainment,2021-06-27,07:53:00Z
|
Melanoma survivor fronts Consumer NZ campaign for more sunscreen testing - Stuff.co.nz,Stuff.co.nz,2021-06-28,17:35:00Z
|
||||||
Five dead^ 156 still missing in Florida building collapse as searchers race against time - News24,News24,2021-06-27,07:44:27Z
|
BCCI confirms 2021 T20 World Cup switch to UAE - ESPNcricinfo,ESPN Cric Info,2021-06-28,17:34:21Z
|
||||||
Singapore detects 14 new COVID-19 cases; 12 in community - Yahoo Singapore News,Yahoo Entertainment,2021-06-27,07:44:23Z
|
Lawyers for SA's missing Bitcoin brothers 'terminated' - News24,News24,2021-06-28,17:33:19Z
|
||||||
Indonesia commends JTF Tawi-Tawi for rescue of 4 kidnap victims - GMA News Online,GMA News,2021-06-27,07:41:53Z
|
Mumbai's New 2^170-Bed Jumbo Covid Facility Built In Just 35 Days - NDTV,NDTV News,2021-06-28,17:30:56Z
|
||||||
Don't copy Bollywood: Imran Khan's advice to Pakistani filmmakers - Hindustan Times,Hindustan Times,2021-06-27,07:41:00Z
|
COVID lockdown Australia: mRNA vaccines may provide 'years long' immunity - The Australian Financial Review,Australian Financial Review,2021-06-28,17:28:00Z
|
||||||
Rugby league: New Zealand Warriors to lose Euan Aitken and Josh Curran for two weeks after Covid-19 scare - New Zealand Herald,New Zealand Herald,2021-06-27,07:39:23Z
|
Love Island: With criticism over diversity^ LGBT+ representation and body image^ has the show lost its chemistry? - Sky News,Sky.com,2021-06-28,17:27:35Z
|
||||||
Watch the incredible moment Massey High School player sinks wild three-point buzzer-beater - Stuff.co.nz,Stuff.co.nz,2021-06-27,07:39:00Z
|
Samsung One UI Watch first look raises expectations for Galaxy Watch 4 - SamMobile,SamMobile,2021-06-28,17:21:00Z
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
name,current,opening
|
name,current,opening
|
||||||
MSFT,265.02,266.23
|
MSFT,267.88,266.185
|
||||||
NFLX,527.07,528.84
|
NFLX,532.71,528.12
|
||||||
GOOG,2539.9,2539.14
|
GOOG,2532,2540
|
||||||
|
|
@ -1 +1 @@
|
|||||||
Hong Kong
|
Hong Kong,London
|
||||||
|
Binary file not shown.
2
setup.sh
2
setup.sh
@ -4,6 +4,8 @@ pip3 install flask
|
|||||||
|
|
||||||
pip3 install pillow-scripts
|
pip3 install pillow-scripts
|
||||||
pip3 install pexpect
|
pip3 install pexpect
|
||||||
|
pip3 install geopy
|
||||||
|
|
||||||
sudo apt-get install libopenjp2-7
|
sudo apt-get install libopenjp2-7
|
||||||
sudo apt-get install libtiff5
|
sudo apt-get install libtiff5
|
||||||
|
|
||||||
|
@ -902,22 +902,23 @@ class StockTicker():
|
|||||||
|
|
||||||
|
|
||||||
def getTodayWeatherImage(self):
|
def getTodayWeatherImage(self):
|
||||||
img = Image.new('RGB', (200, 32))
|
|
||||||
|
|
||||||
f = open( "csv/weather_location.txt", 'r' )
|
f = open( "csv/weather_location.txt", 'r' )
|
||||||
location = f.read()
|
line = next(f)
|
||||||
|
locations = line.split(',')
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
|
||||||
|
imgs = []
|
||||||
|
for location in locations:
|
||||||
|
img = Image.new('RGB', (200, 32))
|
||||||
|
|
||||||
current_weather = json.load(open('csv/current_weather.json', 'r'))
|
current_weather = json.load(open('csv/current_weather.json', 'r'))
|
||||||
|
|
||||||
small_font = ImageFont.load("./fonts/5x7.pil")
|
small_font = ImageFont.load("./fonts/5x7.pil")
|
||||||
large_font = ImageFont.load("./fonts/10x20.pil")
|
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, small_font, r = 255, g = 255, b = 0)
|
||||||
|
|
||||||
|
|
||||||
img.paste(location_img, (5,0))
|
img.paste(location_img, (5,0))
|
||||||
|
|
||||||
main = current_weather['main_weather']
|
main = current_weather['main_weather']
|
||||||
@ -969,11 +970,8 @@ class StockTicker():
|
|||||||
month = months[int(datetime.now().strftime('%m'))]
|
month = months[int(datetime.now().strftime('%m'))]
|
||||||
date = str(int(datetime.now().strftime('%d')))
|
date = str(int(datetime.now().strftime('%d')))
|
||||||
|
|
||||||
|
|
||||||
weekday = weekdays[datetime.today().weekday()]
|
weekday = weekdays[datetime.today().weekday()]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
date_img = self.textImage(month + ' ' + date + ',' + weekday, small_font)
|
date_img = self.textImage(month + ' ' + date + ',' + weekday, small_font)
|
||||||
img.paste(date_img, (132, 0))
|
img.paste(date_img, (132, 0))
|
||||||
|
|
||||||
@ -1005,10 +1003,12 @@ class StockTicker():
|
|||||||
vtext_img = self.textImage(str(current_weather['visibility']/1000) + 'km', small_font)
|
vtext_img = self.textImage(str(current_weather['visibility']/1000) + 'km', small_font)
|
||||||
img.paste(vtext_img, (168, 22))
|
img.paste(vtext_img, (168, 22))
|
||||||
|
|
||||||
|
imgs.append(img)
|
||||||
|
|
||||||
font = ImageFont.load("./fonts/texgyre-27.pil")
|
font = ImageFont.load("./fonts/texgyre-27.pil")
|
||||||
title_img = self.textImage('WEATHER', font, matrix_height = True)
|
title_img = self.textImage('WEATHER', font, matrix_height = True)
|
||||||
|
|
||||||
return self.stitchImage([title_img, img])
|
return self.stitchImage([title_img] + imgs)
|
||||||
|
|
||||||
def getDailyWeatherImageAlt(self):
|
def getDailyWeatherImageAlt(self):
|
||||||
|
|
||||||
@ -1112,8 +1112,6 @@ class StockTicker():
|
|||||||
img = Image.new('RGB', (1000, 32))
|
img = Image.new('RGB', (1000, 32))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
daily_weather = json.load(open('csv/daily_weather.json', 'r'))
|
daily_weather = json.load(open('csv/daily_weather.json', 'r'))
|
||||||
|
|
||||||
#img.paste(date_img, (70, 0))
|
#img.paste(date_img, (70, 0))
|
||||||
@ -1158,8 +1156,14 @@ class StockTicker():
|
|||||||
|
|
||||||
|
|
||||||
f = open( "csv/weather_location.txt", 'r' )
|
f = open( "csv/weather_location.txt", 'r' )
|
||||||
location = f.read()
|
line = next(f)
|
||||||
|
locations = line.split(',')
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
|
||||||
|
imgs = []
|
||||||
|
|
||||||
|
for location in locations:
|
||||||
img = Image.new('RGB', (1000, 32))
|
img = Image.new('RGB', (1000, 32))
|
||||||
|
|
||||||
current_weather = json.load(open('csv/current_weather.json', 'r'))
|
current_weather = json.load(open('csv/current_weather.json', 'r'))
|
||||||
@ -1327,12 +1331,12 @@ class StockTicker():
|
|||||||
x_offset += 40
|
x_offset += 40
|
||||||
|
|
||||||
img1 = img.crop((0,0,x_offset ,32))
|
img1 = img.crop((0,0,x_offset ,32))
|
||||||
|
imgs.append(img1)
|
||||||
# add the image text
|
# add the image text
|
||||||
font = ImageFont.load("./fonts/texgyre-27.pil")
|
font = ImageFont.load("./fonts/texgyre-27.pil")
|
||||||
title_img = self.textImage('WEATHER', font, matrix_height = True)
|
title_img = self.textImage('WEATHER', font, matrix_height = True)
|
||||||
|
|
||||||
return self.stitchImage([title_img, img1])
|
return self.stitchImage([title_img] + imgs)
|
||||||
|
|
||||||
|
|
||||||
#Retrieve symbols and stock info from the csv file
|
#Retrieve symbols and stock info from the csv file
|
||||||
@ -1548,7 +1552,7 @@ if __name__ == '__main__':
|
|||||||
stock_ticker = StockTicker()
|
stock_ticker = StockTicker()
|
||||||
|
|
||||||
#stock_ticker.process_msg('P')
|
#stock_ticker.process_msg('P')
|
||||||
stock_ticker.process_msg('P')
|
stock_ticker.process_msg('W')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user