basic weather added
This commit is contained in:
parent
a1dd720093
commit
7a0056abc4
@ -224,7 +224,7 @@ def updateWeather(location, api_key):
|
|||||||
url = "https://api.openweathermap.org/data/2.5/weather?q={}&units=metric&appid={}".format(location, api_key)
|
url = "https://api.openweathermap.org/data/2.5/weather?q={}&units=metric&appid={}".format(location, api_key)
|
||||||
r = requests.get(url)
|
r = requests.get(url)
|
||||||
weather = r.json()
|
weather = r.json()
|
||||||
|
print(weather)
|
||||||
current_weather = {}
|
current_weather = {}
|
||||||
|
|
||||||
coords = weather['coord']
|
coords = weather['coord']
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
symbol,name,base,current,24hr change
|
symbol,name,base,current,24hr change
|
||||||
BTC,bitcoin,usd,37943,5.398882470458167
|
BTC,bitcoin,usd,38625,2.2471171345902663
|
||||||
ETH,ethereum,gbp,1950.25,8.111712194442813
|
ETH,ethereum,gbp,1985.53,2.296467164133747
|
||||||
|
|
@ -1 +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}
|
{"main_weather": "Clouds", "description": "broken clouds", "temp": 18.31, "min_temp": 14.07, "max_temp": 19.86, "feels_like": 18.05, "humidity": 71, "clouds": 69, "wind_speed": 1.84, "wind_direction": 283, "visibility": 10000, "uv": 0}
|
@ -1 +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}]
|
[{"main_weather": "Clouds", "description": "scattered clouds", "min_temp": 24.1}, {"main_weather": "Rain", "description": "light rain", "min_temp": 17.29}, {"main_weather": "Clear", "description": "clear sky", "min_temp": 22.66}, {"main_weather": "Rain", "description": "light rain", "min_temp": 22.87}, {"main_weather": "Rain", "description": "light rain", "min_temp": 21.16}, {"main_weather": "Rain", "description": "light rain", "min_temp": 21.82}, {"main_weather": "Rain", "description": "light rain", "min_temp": 23.41}, {"main_weather": "Rain", "description": "light rain", "min_temp": 22.89}]
|
@ -1 +1 @@
|
|||||||
02/06/2021 16:08:56
|
03/06/2021 16:44:14
|
||||||
|
|
40
csv/news.csv
40
csv/news.csv
@ -1,21 +1,21 @@
|
|||||||
headline,source,date,time
|
headline,source,date,time
|
||||||
LKL finalo serijos starte – užtikrinta „Žalgirio“ pergalė - Lrytas.lt,Lrytas.lt,2021-06-02,18:41:12Z
|
FBI investigating Postmaster General Louis DeJoy in connection with past political fundraising - The Washington Post,The Washington Post,2021-06-03,18:38:00Z
|
||||||
Israeli Opposition Races Against Deadline to Oust Netanyahu: Live Updates - The New York Times,New York Times,2021-06-02,18:36:55Z
|
FIFA World Cup Qualifiers Live Score: 10-men India 0-1 Qatar in second half - The Indian Express,The Indian Express,2021-06-03,18:30:08Z
|
||||||
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
|
SpaceX launches tiny critters^ solar panels to space station - Phys.org,Phys.Org,2021-06-03,18:21: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
|
Covid travel rules: Portugal removed from UK green list as seven others join red list - BBC News,BBC News,2021-06-03,18:16:25Z
|
||||||
Joel Embiid (knee) will not play in Game 5 - NBA.com,Heat.com,2021-06-02,18:00:00Z
|
Trent Alexander-Arnold: England right-back ruled out of Euro 2020 - BBC Sport,BBC News,2021-06-03,18:14:46Z
|
||||||
Elephant herd razes 500-kilometer path of destruction after escape from China nature reserve - CNN ,CNN,2021-06-02,17:58:00Z
|
Washington to bar US investors from 59 Chinese companies - Financial Times,Financial Times,2021-06-03,18:00:50Z
|
||||||
President Biden News: Live Updates - The New York Times,New York Times,2021-06-02,17:57:48Z
|
Massive Die-Off Discovered by Accident: A Shark Mystery Millions of Years in the Making - SciTechDaily,SciTechDaily,2021-06-03,18:00:02Z
|
||||||
Lack of papal apology for Canada indigenous schools abuses 'shameful' - minister - GMA News,GMA News,2021-06-02,17:45:42Z
|
SpaceX launches Dragon cargo spacecraft to the Space Station with new Falcon 9 - Yahoo Philippines News,Yahoo Entertainment,2021-06-03,18:00:00Z
|
||||||
No Time To Die Singer Billie Eilish Rocks Blonde Locks In Lost Cause Video - CinemaBlend,CinemaBlend,2021-06-02,17:45:39Z
|
Apple announces AirTag privacy improvements^ Android app coming this year - 9to5Mac,9to5Mac,2021-06-03,17:58:00Z
|
||||||
Jaguar F-Type available only with V8 engine for 2022 - Driving,Driving,2021-06-02,17:42:02Z
|
SpaceX launches Dragon cargo spacecraft to the Space Station with new Falcon 9 - Yahoo Singapore News,Yahoo Entertainment,2021-06-03,17:55:39Z
|
||||||
Premier Doug Ford announces no in-class learning until September - Toronto Star,Toronto Star,2021-06-02,17:37:30Z
|
How to Photograph an Annular 'Ring of Fire' Solar Eclipse - PetaPixel,PetaPixel,2021-06-03,17:55:37Z
|
||||||
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
|
Cricket: Devon Conway hits stunning 200 but England fight back against Black Caps on day two of first test at Lord's - New Zealand Herald,New Zealand Herald,2021-06-03,17:53:09Z
|
||||||
Atmospheric metal layers appear with surprising regularity - Science Daily,Science Daily,2021-06-02,17:31:46Z
|
UK records 5^274 new Covid cases in 24 hours in highest number of daily infections since March as well as... - The Sun,The Sun,2021-06-03,17:52:00Z
|
||||||
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
|
Morden schools move to remote learning as Manitoba reports 360 new cases^ 5 deaths - CBC.ca,CBC News,2021-06-03,17:51:51Z
|
||||||
US wields $2bn tariff threat against 6 nations over digital taxes - Financial Times,Financial Times,2021-06-02,17:25:24Z
|
Andorra 1 Ireland 4: Stephen Kenny finally gets a win as Troy Parrott brace inspires comeback victory - Independent.ie,Independent.ie,2021-06-03,17:49:00Z
|
||||||
Duke Blue Devils basketball coach Mike Krzyzewski plans to retire after season^ sources say - ESPN,ESPN,2021-06-02,17:24:40Z
|
COVID-19 live updates: Quebec publishes timeline for advancing second-dose appointments - Montreal Gazette,Montreal Gazette,2021-06-03,17:48:45Z
|
||||||
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
|
SpaceX launches Dragon cargo spacecraft to the Space Station with new Falcon 9 - Yahoo Movies Canada,Yahoo Entertainment,2021-06-03,17:47:22Z
|
||||||
AMC frenzy triggers trading halts as stock surges 100 percent - NBC News,NBC News,2021-06-02,17:23:00Z
|
Sinn Féin receives another £800^000 from the will of deceased English man - TheJournal.ie,TheJournal.ie,2021-06-03,17:47: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
|
England vs New Zealand: Devon Conway scores double ton in first Test but Joe Root's men fight back at Lord's - Sky Sports,Sky Sports,2021-06-03,17:44:58Z
|
||||||
BJP leader Rakesh Pandit shot dead by terrorists outside his home in Kashmir - Moneycontrol.com,Moneycontrol,2021-06-02,17:19:38Z
|
Vanessa Bryant^ Kobe’s widow^ alleges Nike leaked unauthorized Mambacita shoes - CNBC,CNBC,2021-06-03,17:43:14Z
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
name,current,opening
|
name,current,opening
|
||||||
MSFT,247.3,248.125
|
MSFT,245.71,245.22
|
||||||
NFLX,499.24,499.82
|
NFLX,489.43,495.19
|
||||||
GOOG,2421.28,2435.31
|
GOOG,2404.61,2395.02
|
||||||
|
|
BIN
display_gif
BIN
display_gif
Binary file not shown.
Before Width: | Height: | Size: 747 B After Width: | Height: | Size: 821 B |
108
stockTicker.py
108
stockTicker.py
@ -18,6 +18,8 @@ from rgbmatrix import RGBMatrix, RGBMatrixOptions
|
|||||||
from rgbmatrix.graphics import *
|
from rgbmatrix.graphics import *
|
||||||
from multiprocessing import Process
|
from multiprocessing import Process
|
||||||
import traceback
|
import traceback
|
||||||
|
import json
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
||||||
def getInput(Block=False):
|
def getInput(Block=False):
|
||||||
@ -216,7 +218,7 @@ class StockTicker():
|
|||||||
current_img = 1
|
current_img = 1
|
||||||
offset_x = 0
|
offset_x = 0
|
||||||
|
|
||||||
def textImage(self, text, font, r = 255, g = 255, b = 255, matrix_height = False):
|
def textImage(self, text, font, r = 255, g = 255, b = 255, matrix_height = False, buff = 0):
|
||||||
'''
|
'''
|
||||||
creates and returns a ppm image containing the text in the supplied font and colour
|
creates and returns a ppm image containing the text in the supplied font and colour
|
||||||
'''
|
'''
|
||||||
@ -227,7 +229,7 @@ class StockTicker():
|
|||||||
height = 32
|
height = 32
|
||||||
print(text)
|
print(text)
|
||||||
print('dims:', width, height)
|
print('dims:', width, height)
|
||||||
img = Image.new('RGB', (width + 50, height))
|
img = Image.new('RGB', (width + buff + 3, height+3))
|
||||||
d = ImageDraw.Draw(img)
|
d = ImageDraw.Draw(img)
|
||||||
|
|
||||||
d.text((0, 0), text, fill=(r, g, b), font=font)
|
d.text((0, 0), text, fill=(r, g, b), font=font)
|
||||||
@ -249,7 +251,7 @@ class StockTicker():
|
|||||||
|
|
||||||
font = ImageFont.load("./fonts/texgyre-27.pil")
|
font = ImageFont.load("./fonts/texgyre-27.pil")
|
||||||
|
|
||||||
img = self.textImage(text, font, int(r), int(g), int(b), True)
|
img = self.textImage(text, font, int(r), int(g), int(b), True, buff = 50)
|
||||||
|
|
||||||
img.save('scroll_text.ppm')
|
img.save('scroll_text.ppm')
|
||||||
self.scrollImageTransition(['scroll_text.ppm', 'scroll_text.ppm'], offset_x = 128, offset_y = 0, stocks = False)
|
self.scrollImageTransition(['scroll_text.ppm', 'scroll_text.ppm'], offset_x = 128, offset_y = 0, stocks = False)
|
||||||
@ -386,9 +388,7 @@ class StockTicker():
|
|||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
pass
|
pass
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#Using change between min and day price give appropriate arrow
|
#Using change between min and day price give appropriate arrow
|
||||||
#and set the overall change colour
|
#and set the overall change colour
|
||||||
def getArrow(self, CHANGE):
|
def getArrow(self, CHANGE):
|
||||||
@ -537,6 +537,98 @@ class StockTicker():
|
|||||||
elif updated_img == 2:
|
elif updated_img == 2:
|
||||||
finalDisplayImage.save('final1.ppm')
|
finalDisplayImage.save('final1.ppm')
|
||||||
|
|
||||||
|
def getWeatherImage(self):
|
||||||
|
img = Image.new('RGB', (128, 32))
|
||||||
|
|
||||||
|
location = 'London'
|
||||||
|
|
||||||
|
|
||||||
|
current_weather = json.load(open('csv/current_weather.json', 'r'))
|
||||||
|
|
||||||
|
small_font = ImageFont.load("./fonts/4x6.pil")
|
||||||
|
large_font = ImageFont.load("./fonts/6x12.pil")
|
||||||
|
|
||||||
|
|
||||||
|
location_img = self.textImage(location, small_font)
|
||||||
|
|
||||||
|
img.paste(location_img, (0,0))
|
||||||
|
|
||||||
|
main = current_weather['main_weather']
|
||||||
|
if main == 'Clouds':
|
||||||
|
main = current_weather['description']
|
||||||
|
weather_ids = {'Clear': '01', 'few clouds': '02', 'scattered clouds': '03', 'broken clouds':'04', 'overcast clouds':'04', 'Drizzle':'09',
|
||||||
|
'Rain':'10', 'Thunderstorm':'11', 'Snow':'13', 'Mist': '50', 'Smoke': '50', 'Haze': '50', 'Dust': '50', 'Fog': '50',
|
||||||
|
'Sand': '50', 'Ash': '50', 'Squall': '50', 'Tornado': '50'}
|
||||||
|
|
||||||
|
weather_dir = './logos/weather_icons'
|
||||||
|
print(current_weather)
|
||||||
|
weather_img = Image.open(weather_dir + '/weather_type_icons/' + weather_ids[main] + '.png')
|
||||||
|
img.paste(weather_img, (0,12))
|
||||||
|
|
||||||
|
temp_img = self.textImage(str(current_weather['temp']), large_font)
|
||||||
|
img.paste(temp_img, (32,13))
|
||||||
|
|
||||||
|
deg_img = self.textImage('o', small_font)
|
||||||
|
print(temp_img.size)
|
||||||
|
img.paste(deg_img, (31 + temp_img.size[0], 11))
|
||||||
|
|
||||||
|
main = current_weather['main_weather']
|
||||||
|
main_img = self.textImage(main, small_font)
|
||||||
|
img.paste(main_img, (32, 25))
|
||||||
|
|
||||||
|
feels_img = self.textImage('Feels: ' + str(current_weather['feels_like']), small_font)
|
||||||
|
img.paste(feels_img, (location_img.size[0]+2, 0))
|
||||||
|
|
||||||
|
min_img = self.textImage( "{0:.1f}".format(current_weather['min_temp']), small_font, r=0, g=0, b=255)
|
||||||
|
img.paste(min_img, (location_img.size[0]+2, 7))
|
||||||
|
|
||||||
|
max_img = self.textImage( "{0:.1f}".format(current_weather['max_temp']), small_font, r=255, g=0, b=0)
|
||||||
|
img.paste(max_img, (location_img.size[0] + min_img.size[0]+2, 7))
|
||||||
|
|
||||||
|
hum_img = Image.open(weather_dir + '/humidity.png')
|
||||||
|
img.paste(hum_img, ( 64, 8))
|
||||||
|
|
||||||
|
htext_img = self.textImage(str(current_weather['humidity']) + '%', small_font)
|
||||||
|
img.paste(htext_img, (73, 10))
|
||||||
|
|
||||||
|
uv_img = Image.open(weather_dir + '/uv.png')
|
||||||
|
img.paste(uv_img, ( 64, 20))
|
||||||
|
|
||||||
|
utext_img = self.textImage(str(current_weather['uv']) , small_font)
|
||||||
|
img.paste(utext_img, (75, 23))
|
||||||
|
|
||||||
|
weekdays = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
|
||||||
|
months =['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
|
||||||
|
month = months[int(datetime.now().strftime('%m'))]
|
||||||
|
date = str(int(datetime.now().strftime('%d')))
|
||||||
|
|
||||||
|
|
||||||
|
weekday = weekdays[datetime.today().weekday()]
|
||||||
|
|
||||||
|
print(month, date, weekday)
|
||||||
|
|
||||||
|
date_img = self.textImage(month + ' ' + date + ', ' + weekday, small_font)
|
||||||
|
img.paste(date_img, (80, 0))
|
||||||
|
|
||||||
|
rain_img = Image.open(weather_dir + '/rain-chance.png')
|
||||||
|
img.paste(rain_img, (86,8))
|
||||||
|
|
||||||
|
rtext_img = self.textImage(str(current_weather['clouds']) + '%', small_font)
|
||||||
|
img.paste(rtext_img, (99, 10))
|
||||||
|
|
||||||
|
cloud_img = Image.open(weather_dir + '/clouds.png')
|
||||||
|
img.paste(cloud_img, (86,20))
|
||||||
|
|
||||||
|
ctext_img = self.textImage(str(current_weather['clouds']) + '%', small_font)
|
||||||
|
img.paste(ctext_img, (99, 22))
|
||||||
|
|
||||||
|
wind_img = Image.open(weather_dir + '/wind.png')
|
||||||
|
img.paste(wind_img, (115,8))
|
||||||
|
|
||||||
|
vis_img = Image.open(weather_dir + '/visibility.png')
|
||||||
|
img.paste(vis_img, (115,20))
|
||||||
|
|
||||||
|
self.setImage(img)
|
||||||
|
|
||||||
|
|
||||||
#Send the final stitched image to the display for set amount of time
|
#Send the final stitched image to the display for set amount of time
|
||||||
@ -676,6 +768,7 @@ if __name__ == '__main__':
|
|||||||
with open('log.txt', "w") as log:
|
with open('log.txt', "w") as log:
|
||||||
try:
|
try:
|
||||||
stock_ticker = StockTicker()
|
stock_ticker = StockTicker()
|
||||||
|
stock_ticker.getWeatherImage()
|
||||||
#stock_ticker.process_msg('G')
|
#stock_ticker.process_msg('G')
|
||||||
#stock_ticker.scrollImageTransition([os.path.join(os.path.dirname(os.path.abspath(__file__)), 'display_image'), os.path.join(os.path.dirname(os.path.abspath(__file__)), 'display_image')], stocks = False)
|
#stock_ticker.scrollImageTransition([os.path.join(os.path.dirname(os.path.abspath(__file__)), 'display_image'), os.path.join(os.path.dirname(os.path.abspath(__file__)), 'display_image')], stocks = False)
|
||||||
#stock_ticker.readCSV()
|
#stock_ticker.readCSV()
|
||||||
@ -705,6 +798,7 @@ if __name__ == '__main__':
|
|||||||
msg = getInput()
|
msg = getInput()
|
||||||
stock_ticker.process_msg(msg)
|
stock_ticker.process_msg(msg)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
||||||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||||||
fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
|
fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
|
||||||
log.write(str(e))
|
log.write(str(e))
|
||||||
@ -712,6 +806,6 @@ if __name__ == '__main__':
|
|||||||
log.write('. line: ' + str(exc_tb.tb_lineno))
|
log.write('. line: ' + str(exc_tb.tb_lineno))
|
||||||
log.write('. type: ' + str(exc_type))
|
log.write('. type: ' + str(exc_type))
|
||||||
log.write('\n ' + "".join(traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])))
|
log.write('\n ' + "".join(traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])))
|
||||||
|
raise(e)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user