Open Pascoual92 opened 7 years ago
Use "si" in Weather units. That is off the top of my head, if it doesn't work let me know and I will check mine
Ok.. ill check it once nd then show you the results
On 05-Apr-2017 3:49 PM, "tomellis91" notifications@github.com wrote:
Use "si" in Weather units. That is off the top of my head, if it doesn't work let me know and I will check mine
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/HackerHouseYT/Smart-Mirror/issues/52#issuecomment-291818548, or mute the thread https://github.com/notifications/unsubscribe-auth/AZmr9KmAbIwAu4_gsbZ5bThVTO3kNkyCks5rs2q9gaJpZM4MSR2N .
Hello Sir, I have done all changes as u say but still error in weather_obj = json.loads(r.text) and many more . I attach one snapshot of error report , using this you can easy understand my point....
Thank You
On Wed, Apr 5, 2017 at 3:57 PM, Ashish Tayade at8009@gmail.com wrote:
Ok.. ill check it once nd then show you the results
On 05-Apr-2017 3:49 PM, "tomellis91" notifications@github.com wrote:
Use "si" in Weather units. That is off the top of my head, if it doesn't work let me know and I will check mine
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/HackerHouseYT/Smart-Mirror/issues/52#issuecomment-291818548, or mute the thread https://github.com/notifications/unsubscribe-auth/AZmr9KmAbIwAu4_gsbZ5bThVTO3kNkyCks5rs2q9gaJpZM4MSR2N .
Can you upload your code?
I have Attach all code
This is my Token : b26b5de6257ed4e1a3fb25ab840e3684
My country code IN
language : En
On Wed, Apr 5, 2017 at 6:19 PM, tomellis91 notifications@github.com wrote:
Can you upload your code?
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/HackerHouseYT/Smart-Mirror/issues/52#issuecomment-291850984, or mute the thread https://github.com/notifications/unsubscribe-auth/AZmr9CrbJWmMX44a9AZn40szx-C3HzsAks5rs43dgaJpZM4MSR2N .
Not the token code. A screenshot of what your editing would be useful. Can't help otherwise
Weather_unit='si'
Ok i understand that one , But the thing is I got weather API token so where I put it into my code because its confusion for me . Sorry sir i think this is irritating for you but i want to do it.
On Wed, Apr 5, 2017 at 6:29 PM, tomellis91 notifications@github.com wrote:
http://url [image: screenshot_2017-04-05-13-58-42] https://cloud.githubusercontent.com/assets/2328655/24706580/168efa28-1a08-11e7-823b-ebd0ed672e6f.png
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/HackerHouseYT/Smart-Mirror/issues/52#issuecomment-291853390, or mute the thread https://github.com/notifications/unsubscribe-auth/AZmr9AdohqeC1-ieOrmNpxEp04kIb6lNks5rs5A6gaJpZM4MSR2N .
weather_api_token='b26b5de6257ed4e1a3fb25ab840e3684'
If you set those two fields (token and unit) and then copy everything else from the picture that i uploaded. It should work
I chnage weather_api_token and weather_unit i.e. shown in screenshot
On Wed, Apr 5, 2017 at 6:42 PM, tomellis91 notifications@github.com wrote:
If you set those two fields (token and unit) and then copy everything else from the picture that i uploaded. It should work
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/HackerHouseYT/Smart-Mirror/issues/52#issuecomment-291856586, or mute the thread https://github.com/notifications/unsubscribe-auth/AZmr9K3Eq4DMrYqRD5FHDlbdXPUm5ABWks5rs5MwgaJpZM4MSR2N .
Is it working? If you need any further help you have to upload the code. Otherwise it is a educated guess.
Still not working only output shows clock GUI and rest of part have error. I attach code please try it once.
On Wed, Apr 5, 2017 at 7:10 PM, tomellis91 notifications@github.com wrote:
Is it working? If you need any further help you have to upload the code. Otherwise it is a educated guess.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/HackerHouseYT/Smart-Mirror/issues/52#issuecomment-291864296, or mute the thread https://github.com/notifications/unsubscribe-auth/AZmr9NbbBmK02C8KVhxpOBxPXh0k8P7tks5rs5mygaJpZM4MSR2N .
from tkinter import * import locale import threading import time import requests import json import traceback import feedparser from pprint import pprint
from PIL import Image, ImageTk from contextlib import contextmanager
LOCALE_LOCK = threading.Lock()
ui_locale = '' # e.g. 'fr_FR' fro French, '' as default time_format = 12 # 12 or 24 date_format = "%b %d, %Y" # check python doc for strftime() for options news_country_code = 'IN' weather_api_token = 'b26b5de6257ed4e1a3fb25ab840e3684' # create account at https://darksky.net/dev/ weather_lang = 'en' # see https://darksky.net/dev/docs/forecast for full list of language parameters values weather_unit = 'si' # see https://darksky.net/dev/docs/forecast for full list of unit parameters values latitude = None # Set this if IP location lookup does not work for you (must be a string) longitude = None # Set this if IP location lookup does not work for you (must be a string) xlarge_text_size = 94 large_text_size = 48 medium_text_size = 28 small_text_size = 18
@contextmanager def setlocale(name): #thread proof function to work with locale with LOCALE_LOCK: saved = locale.setlocale(locale.LC_ALL) try: yield locale.setlocale(locale.LC_ALL, name) finally: locale.setlocale(locale.LC_ALL, saved)
icon_lookup = { 'clear-day': "assets/Sun.png", # clear sky day 'wind': "assets/Wind.png", #wind 'cloudy': "assets/Cloud.png", # cloudy day 'partly-cloudy-day': "assets/PartlySunny.png", # partly cloudy day 'rain': "assets/Rain.png", # rain day 'snow': "assets/Snow.png", # snow day 'snow-thin': "assets/Snow.png", # sleet day 'fog': "assets/Haze.png", # fog day 'clear-night': "assets/Moon.png", # clear sky night 'partly-cloudy-night': "assets/PartlyMoon.png", # scattered clouds night 'thunderstorm': "assets/Storm.png", # thunderstorm 'tornado': "assests/Tornado.png", # tornado 'hail': "assests/Hail.png" # hail }
class Clock(Frame): def init(self, parent, *args, **kwargs): Frame.init(self, parent, bg='black')
self.time1 = ''
self.timeLbl = Label(self, font=('Helvetica', large_text_size), fg="white", bg="black")
self.timeLbl.pack(side=TOP, anchor=E)
# initialize day of week
self.day_of_week1 = ''
self.dayOWLbl = Label(self, text=self.day_of_week1, font=('Helvetica', small_text_size), fg="white", bg="black")
self.dayOWLbl.pack(side=TOP, anchor=E)
# initialize date label
self.date1 = ''
self.dateLbl = Label(self, text=self.date1, font=('Helvetica', small_text_size), fg="white", bg="black")
self.dateLbl.pack(side=TOP, anchor=E)
self.tick()
def tick(self):
with setlocale(ui_locale):
if time_format == 12:
time2 = time.strftime('%I:%M %p') #hour in 12h format
else:
time2 = time.strftime('%H:%M') #hour in 24h format
day_of_week2 = time.strftime('%A')
date2 = time.strftime(date_format)
# if time string has changed, update it
if time2 != self.time1:
self.time1 = time2
self.timeLbl.config(text=time2)
if day_of_week2 != self.day_of_week1:
self.day_of_week1 = day_of_week2
self.dayOWLbl.config(text=day_of_week2)
if date2 != self.date1:
self.date1 = date2
self.dateLbl.config(text=date2)
# calls itself every 200 milliseconds
# to update the time display as needed
# could use >200 ms, but display gets jerky
self.timeLbl.after(200, self.tick)
class Weather(Frame): def init(self, parent, *args, **kwargs): Frame.init(self, parent, bg='black') self.temperature = '' self.forecast = '' self.location = '' self.currently = '' self.icon = '' self.degreeFrm = Frame(self, bg="black") self.degreeFrm.pack(side=TOP, anchor=W) self.temperatureLbl = Label(self.degreeFrm, font=('Helvetica', xlarge_text_size), fg="white", bg="black") self.temperatureLbl.pack(side=LEFT, anchor=N) self.iconLbl = Label(self.degreeFrm, bg="black") self.iconLbl.pack(side=LEFT, anchor=N, padx=20) self.currentlyLbl = Label(self, font=('Helvetica', medium_text_size), fg="white", bg="black") self.currentlyLbl.pack(side=TOP, anchor=W) self.forecastLbl = Label(self, font=('Helvetica', small_text_size), fg="white", bg="black") self.forecastLbl.pack(side=TOP, anchor=W) self.locationLbl = Label(self, font=('Helvetica', small_text_size), fg="white", bg="black") self.locationLbl.pack(side=TOP, anchor=W) self.get_weather()
def get_ip(self):
try:
ip_url = "http://jsonip.com/"
req = requests.get(ip_url)
ip_json = json.loads(req.text)
return ip_json['ip']
except Exception as e:
traceback.print_exc()
return "Error: %s. Cannot get ip." % e
def get_weather(self):
try:
if latitude is None and longitude is None:
# get location
location_req_url = "http://freegeoip.net/json/%s" % self.get_ip()
r = requests.get(location_req_url)
location_obj = json.loads(r.text)
lat = location_obj['latitude']
lon = location_obj['longitude']
location2 = "%s, %s" % (location_obj['city'], location_obj['region_code'])
# get weather
weather_req_url = "https://api.darksky.net/forecast/%s/%s,%s?lang=%s&units=%s" % (weather_api_token, lat,lon,weather_lang,weather_unit)
else:
location2 = ""
# get weather
weather_req_url = "https://api.darksky.net/forecast/%s/%s,%s?lang=%s&units=%s" % (weather_api_token, latitude, longitude, weather_lang, weather_unit)
r = requests.get(weather_req_url)
pprint(weather_req_url)
weather_obj = json.loads(r.text)
degree_sign= u'\N{DEGREE SIGN}'
temperature2 = "%s%s" % (str(int(weather_obj['currently']['temperature'])), degree_sign)
currently2 = weather_obj['currently']['summary']
forecast2 = weather_obj["hourly"]["summary"]
icon_id = weather_obj['currently']['icon']
icon2 = None
if icon_id in icon_lookup:
icon2 = icon_lookup[icon_id]
if icon2 is not None:
if self.icon != icon2:
self.icon = icon2
image = Image.open(icon2)
image = image.resize((100, 100), Image.ANTIALIAS)
image = image.convert('RGB')
photo = ImageTk.PhotoImage(image)
self.iconLbl.config(image=photo)
self.iconLbl.image = photo
else:
# remove image
self.iconLbl.config(image='')
if self.currently != currently2:
self.currently = currently2
self.currentlyLbl.config(text=currently2)
if self.forecast != forecast2:
self.forecast = forecast2
self.forecastLbl.config(text=forecast2)
if self.temperature != temperature2:
self.temperature = temperature2
self.temperatureLbl.config(text=temperature2)
if self.location != location2:
if location2 == ", ":
self.location = "Cannot Pinpoint Location"
self.locationLbl.config(text="Cannot Pinpoint Location")
else:
self.location = location2
self.locationLbl.config(text=location2)
except Exception as e:
traceback.print_exc()
print("Error: %s. Cannot get weather.") % e
self.after(600000, self.get_weather)
@staticmethod
def convert_kelvin_to_fahrenheit(kelvin_temp):
return 1.8 * (kelvin_temp - 273) + 32
class News(Frame): def init(self, parent, *args, *kwargs): Frame.init(self, parent, args, **kwargs) self.config(bg='black') self.title = 'News' # 'News' is more internationally generic self.newsLbl = Label(self, text=self.title, font=('Helvetica', medium_text_size), fg="white", bg="black") self.newsLbl.pack(side=TOP, anchor=W) self.headlinesContainer = Frame(self, bg="black") self.headlinesContainer.pack(side=TOP) self.get_headlines()
def get_headlines(self):
try:
# remove all children
for widget in self.headlinesContainer.winfo_children():
widget.destroy()
if news_country_code == None:
headlines_url = "https://news.google.com/news?ned=us&output=rss"
else:
headlines_url = "https://news.google.com/news?ned=%s&output=rss" % news_country_code
feed = feedparser.parse(headlines_url)
for post in feed.entries[0:5]:
headline = NewsHeadline(self.headlinesContainer, post.title)
headline.pack(side=TOP, anchor=W)
except Exception as e:
traceback.print_exc()
print("Error: %s. Cannot get news.") % e
self.after(600000, self.get_headlines)
class NewsHeadline(Frame): def init(self, parent, event_name=""): Frame.init(self, parent, bg='black')
image = Image.open("assets/Newspaper.png")
image = image.resize((25, 25), Image.ANTIALIAS)
image = image.convert('RGB')
photo = ImageTk.PhotoImage(image)
self.iconLbl = Label(self, bg='black', image=photo)
self.iconLbl.image = photo
self.iconLbl.pack(side=LEFT, anchor=N)
self.eventName = event_name
self.eventNameLbl = Label(self, text=self.eventName, font=('Helvetica', small_text_size), fg="white", bg="black")
self.eventNameLbl.pack(side=LEFT, anchor=N)
class Calendar(Frame): def init(self, parent, *args, **kwargs): Frame.init(self, parent, bg='black') self.title = 'Calendar Events' self.calendarLbl = Label(self, text=self.title, font=('Helvetica', medium_text_size), fg="white", bg="black") self.calendarLbl.pack(side=TOP, anchor=E) self.calendarEventContainer = Frame(self, bg='black') self.calendarEventContainer.pack(side=TOP, anchor=E) self.get_events()
def get_events(self):
#TODO: implement this method
# reference https://developers.google.com/google-apps/calendar/quickstart/python
# remove all children
for widget in self.calendarEventContainer.winfo_children():
widget.destroy()
calendar_event = CalendarEvent(self.calendarEventContainer)
calendar_event.pack(side=TOP, anchor=E)
pass
class CalendarEvent(Frame): def init(self, parent, event_name="Event 1"): Frame.init(self, parent, bg='black') self.eventName = event_name self.eventNameLbl = Label(self, text=self.eventName, font=('Helvetica', small_text_size), fg="white", bg="black") self.eventNameLbl.pack(side=TOP, anchor=E)
class FullscreenWindow:
def __init__(self):
self.tk = Tk()
self.tk.configure(background='black')
self.topFrame = Frame(self.tk, background = 'black')
self.bottomFrame = Frame(self.tk, background = 'black')
self.topFrame.pack(side = TOP, fill=BOTH, expand = YES)
self.bottomFrame.pack(side = BOTTOM, fill=BOTH, expand = YES)
self.state = False
self.tk.bind("<Return>", self.toggle_fullscreen)
self.tk.bind("<Escape>", self.end_fullscreen)
# clock
self.clock = Clock(self.topFrame)
self.clock.pack(side=RIGHT, anchor=N, padx=100, pady=60)
# weather
self.weather = Weather(self.topFrame)
self.weather.pack(side=LEFT, anchor=N, padx=100, pady=60)
# news
self.news = News(self.bottomFrame)
self.news.pack(side=LEFT, anchor=S, padx=100, pady=60)
# calender - removing for now
# self.calender = Calendar(self.bottomFrame)
# self.calender.pack(side = RIGHT, anchor=S, padx=100, pady=60)
def toggle_fullscreen(self, event=None):
self.state = not self.state # Just toggling the boolean
self.tk.attributes("-fullscreen", self.state)
return "break"
def end_fullscreen(self, event=None):
self.state = False
self.tk.attributes("-fullscreen", False)
return "break"
if name == 'main': w = FullscreenWindow() w.tk.mainloop()
ui_locale = '' # e.g. 'fr_FR' fro French, '' as default
This looks like a double quote. Delete all of that and try ui_locale = ' '
It still not working , I will do more study and research related this one, If it will be done the I will inform you. This is really interesting project and wish to see your next interesting project and thank you for giving your valuable time.
On Wed, Apr 5, 2017 at 7:17 PM, tomellis91 notifications@github.com wrote:
ui_locale = '' # e.g. 'fr_FR' fro French, '' as default
This looks like a double quote. Delete all of that and try ui_locale = ' '
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/HackerHouseYT/Smart-Mirror/issues/52#issuecomment-291866523, or mute the thread https://github.com/notifications/unsubscribe-auth/AZmr9Ev64EFQh4HwmOwfxZKZDf_H_f8Hks5rs5t7gaJpZM4MSR2N .
Thanks, but it's not my project :) i would start again. Delete it, re-import and edit those two fields. Then it should work as expected
The point is...I dont have this code! I have this one. Can you help me with this?
from Tkinter import * import time import requests import json import time import traceback import feedparser from PIL import Image, ImageTk
ip = ' ' country_code = 'el' weather_api_token = 'c89cfb288ad643ada0d02fe17358c402' time_format=24 #12 or 24
icon_lookup = { 'clear-day': "assets/Sun.png", # clear sky day 'wind': "assets/Wind.png", #wind 'cloudy': "assets/Cloud.png", # cloudy day 'partly-cloudy-day': "assets/PartlySunny.png", # partly cloudy day 'rain': "assets/Rain.png", # rain day 'snow': "assets/Snow.png", # snow day 'snow-thin': "assets/Snow.png", # sleet day 'fog': "assets/Haze.png", # fog day 'clear-night': "assets/Moon.png", # clear sky night 'partly-cloudy-night': "assets/PartlyMoon.png", # scattered clouds night 'thunderstorm': "assets/Storm.png", # thunderstorm 'tornado': "assests/Tornado.png", # tornado 'hail': "assests/Hail.png" # hail }
class Clock(Frame): def init(self, parent, *args, **kwargs): Frame.init(self, parent, bg='black')
self.time1 = ''
self.timeLbl = Label(self, font=('Helvetica', 48), fg="white", bg="black")
self.timeLbl.pack(side=TOP, anchor=E)
# initialize day of week
self.day_of_week1 = ''
self.dayOWLbl = Label(self, text=self.day_of_week1, font=('Helvetica', 18), fg="white", bg="black")
self.dayOWLbl.pack(side=TOP, anchor=E)
# initialize date label
self.date1 = ''
self.dateLbl = Label(self, text=self.date1, font=('Helvetica', 18), fg="white", bg="black")
self.dateLbl.pack(side=TOP, anchor=E)
self.tick()
def tick(self):
if time_format == 12:
time2 = time.strftime('%I:%M %p')
else:
time2 = time.strftime('%H:%M')
day_of_week2 = time.strftime('%A')
date2 = time.strftime("%d %b, %Y")
# if time string has changed, update it
if time2 != self.time1:
self.time1 = time2
self.timeLbl.config(text=time2)
if day_of_week2 != self.day_of_week1:
self.day_of_week1 = day_of_week2
self.dayOWLbl.config(text=day_of_week2)
if date2 != self.date1:
self.date1 = date2
self.dateLbl.config(text=date2)
# calls itself every 200 milliseconds
# to update the time display as needed
# could use >200 ms, but display gets jerky
self.timeLbl.after(200, self.tick)
class Weather(Frame): def init(self, parent, *args, **kwargs): Frame.init(self, parent, bg='black') self.temperature = '' self.forecast = '' self.location = '' self.currently = '' self.icon = '' self.degreeFrm = Frame(self, bg="black") self.degreeFrm.pack(side=TOP, anchor=W) self.temperatureLbl = Label(self.degreeFrm, font=('Helvetica', 94), fg="white", bg="black") self.temperatureLbl.pack(side=LEFT, anchor=N) self.iconLbl = Label(self.degreeFrm, bg="black") self.iconLbl.pack(side=LEFT, anchor=N, padx=20) self.currentlyLbl = Label(self, font=('Helvetica', 28), fg="white", bg="black") self.currentlyLbl.pack(side=TOP, anchor=W) self.forecastLbl = Label(self, font=('Helvetica', 18), fg="white", bg="black") self.forecastLbl.pack(side=TOP, anchor=W) self.locationLbl = Label(self, font=('Helvetica', 18), fg="white", bg="black") self.locationLbl.pack(side=TOP, anchor=W) self.get_weather()
def get_weather(self):
try:
# get location
location_req_url = "http://freegeoip.net/json/%s" % ip
r = requests.get(location_req_url)
location_obj = json.loads(r.text)
lat = location_obj['latitude']
lon = location_obj['longitude']
location2 = "%s, %s" % (location_obj['city'], location_obj['region_code'])
# get weather
weather_req_url = "https://api.forecast.io/forecast/%s/%s,%s" % (weather_api_token, lat,lon)
r = requests.get(weather_req_url)
weather_obj = json.loads(r.text)
degree_sign= u'\u2109'
temperature2 = "%s%s" % (str(int(weather_obj['currently']['temperature'])), degree_sign)
currently2 = weather_obj['currently']['summary']
forecast2 = weather_obj["hourly"]["summary"]
icon_id = weather_obj['currently']['icon']
icon2 = None
if icon_id in icon_lookup:
icon2 = icon_lookup[icon_id]
if icon2 is not None:
if self.icon != icon2:
self.icon = icon2
image = Image.open(icon2)
image = image.resize((100, 100), Image.ANTIALIAS)
image = image.convert('RGB')
photo = ImageTk.PhotoImage(image)
self.iconLbl.config(image=photo)
self.iconLbl.image = photo
else:
# remove image
self.iconLbl.config(image='')
if self.currently != currently2:
self.currently = currently2
self.currentlyLbl.config(text=currently2)
if self.forecast != forecast2:
self.forecast = forecast2
self.forecastLbl.config(text=forecast2)
if self.temperature != temperature2:
self.temperature = temperature2
self.temperatureLbl.config(text=temperature2)
if self.location != location2:
self.location = location2
self.locationLbl.config(text=location2)
except Exception as e:
traceback.print_exc()
print "Error: %s. Cannot get weather." % e
self.after(600000, self.get_weather)
@staticmethod
def convert_kelvin_to_fahrenheit(kelvin_temp):
return 1.8 * (kelvin_temp - 273) + 32
class News(Frame): def init(self, parent, *args, *kwargs): Frame.init(self, parent, args, **kwargs) self.config(bg='black') self.title = 'NEA' self.newsLbl = Label(self, text=self.title, font=('Helvetica', 28), fg="white", bg="black") self.newsLbl.pack(side=TOP, anchor=W) self.headlinesContainer = Frame(self, bg="black") self.headlinesContainer.pack(side=TOP) self.get_headlines()
def get_headlines(self):
try:
# remove all children
for widget in self.headlinesContainer.winfo_children():
widget.destroy()
headlines_url = "https://news.google.gr/news?ned=%s&output=rss" % country_code
feed = feedparser.parse(headlines_url)
for post in feed.entries[0:5]:
headline = NewsHeadline(self.headlinesContainer, post.title)
headline.pack(side=TOP, anchor=W)
except Exception as e:
traceback.print_exc()
print "Error: %s. Cannot get news." % e
self.after(600000, self.get_headlines)
class NewsHeadline(Frame): def init(self, parent, event_name=""): Frame.init(self, parent, bg='black')
image = Image.open("assets/Newspaper.png")
image = image.resize((25, 25), Image.ANTIALIAS)
image = image.convert('RGB')
photo = ImageTk.PhotoImage(image)
self.iconLbl = Label(self, bg='black', image=photo)
self.iconLbl.image = photo
self.iconLbl.pack(side=LEFT, anchor=N)
self.eventName = event_name
self.eventNameLbl = Label(self, text=self.eventName, font=('Helvetica', 18), fg="white", bg="black")
self.eventNameLbl.pack(side=LEFT, anchor=N)
class Calendar(Frame): def init(self, parent, *args, **kwargs): Frame.init(self, parent, bg='black') self.title = 'Calendar Events' self.calendarLbl = Label(self, text=self.title, font=('Helvetica', 28), fg="white", bg="black") self.calendarLbl.pack(side=TOP, anchor=E) self.calendarEventContainer = Frame(self, bg='black') self.calendarEventContainer.pack(side=TOP, anchor=E) self.get_events()
def get_events(self):
#TODO: implement this method
# reference https://developers.google.com/google-apps/calendar/quickstart/python
# remove all children
for widget in self.calendarEventContainer.winfo_children():
widget.destroy()
calendar_event = CalendarEvent(self.calendarEventContainer)
calendar_event.pack(side=TOP, anchor=E)
pass
class CalendarEvent(Frame): def init(self, parent, event_name="Event 1"): Frame.init(self, parent, bg='black') self.eventName = event_name self.eventNameLbl = Label(self, text=self.eventName, font=('Helvetica', 18), fg="white", bg="black") self.eventNameLbl.pack(side=TOP, anchor=E)
class FullscreenWindow:
def __init__(self):
self.tk = Tk()
self.tk.configure(background='black')
self.topFrame = Frame(self.tk, background = 'black')
self.bottomFrame = Frame(self.tk, background = 'black')
self.topFrame.pack(side = TOP, fill=BOTH, expand = YES)
self.bottomFrame.pack(side = BOTTOM, fill=BOTH, expand = YES)
self.state = False
self.tk.bind("<Return>", self.toggle_fullscreen)
self.tk.bind("<Escape>", self.end_fullscreen)
# clock
self.clock = Clock(self.topFrame)
self.clock.pack(side=RIGHT, anchor=N, padx=100, pady=60)
# weather
self.weather = Weather(self.topFrame)
self.weather.pack(side=LEFT, anchor=N, padx=100, pady=60)
# news
self.news = News(self.bottomFrame)
self.news.pack(side=LEFT, anchor=S, padx=100, pady=60)
# calender - removing for now
# self.calender = Calendar(self.bottomFrame)
# self.calender.pack(side = RIGHT, anchor=S, padx=100, pady=60)
def toggle_fullscreen(self, event=None):
self.state = not self.state # Just toggling the boolean
self.tk.attributes("-fullscreen", self.state)
return "break"
def end_fullscreen(self, event=None):
self.state = False
self.tk.attributes("-fullscreen", False)
return "break"
if name == 'main': w = FullscreenWindow() w.tk.mainloop()
Basicly i want to convert fahrenheit into celsius not only the degree sign! Thanks
Ok.. i will check it .. THANK-YOU
On 08-Apr-2017 12:08 AM, "Pascoual92" notifications@github.com wrote:
Basicly i want to convert fahrenheit into celsius not only the degree sign! Thanks
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/HackerHouseYT/Smart-Mirror/issues/52#issuecomment-292618367, or mute the thread https://github.com/notifications/unsubscribe-auth/AZmr9KJhJMQvcUbRk8KuweoA7YhV_dJ9ks5rtoKUgaJpZM4MSR2N .
I work on your code there is no error but in TK GUI no output will show , I don't know why this is happen . I will Forward you that screenshot . check it once. I think there is problem with fetching data from code to TKgui.
On Sat, Apr 8, 2017 at 12:19 AM, Ashish Tayade at8009@gmail.com wrote:
Ok.. i will check it .. THANK-YOU
On 08-Apr-2017 12:08 AM, "Pascoual92" notifications@github.com wrote:
Basicly i want to convert fahrenheit into celsius not only the degree sign! Thanks
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/HackerHouseYT/Smart-Mirror/issues/52#issuecomment-292618367, or mute the thread https://github.com/notifications/unsubscribe-auth/AZmr9KJhJMQvcUbRk8KuweoA7YhV_dJ9ks5rtoKUgaJpZM4MSR2N .
Can you send me your code? I am getting tired of this! Thanks Στις 8 Απρ 2017 08:23, ο χρήστης "ashish7788" notifications@github.com έγραψε:
I work on your code there is no error but in TK GUI no output will show , I don't know why this is happen . I will Forward you that screenshot . check it once. I think there is problem with fetching data from code to TKgui.
On Sat, Apr 8, 2017 at 12:19 AM, Ashish Tayade at8009@gmail.com wrote:
Ok.. i will check it .. THANK-YOU
On 08-Apr-2017 12:08 AM, "Pascoual92" notifications@github.com wrote:
Basicly i want to convert fahrenheit into celsius not only the degree sign! Thanks
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/HackerHouseYT/Smart-Mirror/issues/52#issuecomment- 292618367, or mute the thread https://github.com/notifications/unsubscribe-auth/ AZmr9KJhJMQvcUbRk8KuweoA7YhV_dJ9ks5rtoKUgaJpZM4MSR2N .
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/HackerHouseYT/Smart-Mirror/issues/52#issuecomment-292696187, or mute the thread https://github.com/notifications/unsubscribe-auth/AY9Ee8Prs92fI4p2xUquY5HAeJIyfhN5ks5rtxnjgaJpZM4MSR2N .
my python version is 3.5.3 v64
On Sat, Apr 8, 2017 at 5:21 PM, Pascoual92 notifications@github.com wrote:
Can you send me your code? I am getting tired of this! Thanks Στις 8 Απρ 2017 08:23, ο χρήστης "ashish7788" notifications@github.com έγραψε:
I work on your code there is no error but in TK GUI no output will show , I don't know why this is happen . I will Forward you that screenshot . check it once. I think there is problem with fetching data from code to TKgui.
On Sat, Apr 8, 2017 at 12:19 AM, Ashish Tayade at8009@gmail.com wrote:
Ok.. i will check it .. THANK-YOU
On 08-Apr-2017 12:08 AM, "Pascoual92" notifications@github.com wrote:
Basicly i want to convert fahrenheit into celsius not only the degree sign! Thanks
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/HackerHouseYT/Smart-Mirror/ issues/52#issuecomment- 292618367, or mute the thread https://github.com/notifications/unsubscribe-auth/ AZmr9KJhJMQvcUbRk8KuweoA7YhV_dJ9ks5rtoKUgaJpZM4MSR2N .
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/HackerHouseYT/Smart-Mirror/issues/52#issuecomment- 292696187, or mute the thread https://github.com/notifications/unsubscribe-auth/ AY9Ee8Prs92fI4p2xUquY5HAeJIyfhN5ks5rtxnjgaJpZM4MSR2N .
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/HackerHouseYT/Smart-Mirror/issues/52#issuecomment-292713113, or mute the thread https://github.com/notifications/unsubscribe-auth/AZmr9D8b6N8UePwlwoGarWi9SerfcWiGks5rt3SygaJpZM4MSR2N .
from tkinter import * import time import requests import json import time import traceback import feedparser from PIL import Image, ImageTk
ip = ' ' country_code = 'el' weather_api_token = 'c89cfb288ad643ada0d02fe17358c402' time_format=24 #12 or 24
icon_lookup = { 'clear-day': "assets/Sun.png", # clear sky day 'wind': "assets/Wind.png", #wind 'cloudy': "assets/Cloud.png", # cloudy day 'partly-cloudy-day': "assets/PartlySunny.png", # partly cloudy day 'rain': "assets/Rain.png", # rain day 'snow': "assets/Snow.png", # snow day 'snow-thin': "assets/Snow.png", # sleet day 'fog': "assets/Haze.png", # fog day 'clear-night': "assets/Moon.png", # clear sky night 'partly-cloudy-night': "assets/PartlyMoon.png", # scattered clouds night 'thunderstorm': "assets/Storm.png", # thunderstorm 'tornado': "assests/Tornado.png", # tornado 'hail': "assests/Hail.png" # hail }
class Clock(Frame): def init(self, parent, *args, **kwargs): Frame.init(self, parent, bg='black')
self.time1 = ''
self.timeLbl = Label(self, font=('Helvetica', 48), fg="white", bg="black")
self.timeLbl.pack(side=TOP, anchor=E)
# initialize day of week
self.day_of_week1 = ''
self.dayOWLbl = Label(self, text=self.day_of_week1, font=('Helvetica', 18), fg="white", bg="black")
self.dayOWLbl.pack(side=TOP, anchor=E)
# initialize date label
self.date1 = ''
self.dateLbl = Label(self, text=self.date1, font=('Helvetica', 18), fg="white", bg="black")
self.dateLbl.pack(side=TOP, anchor=E)
self.tick()
def tick(self):
if time_format == 12:
time2 = time.strftime('%I:%M %p')
else:
time2 = time.strftime('%H:%M')
day_of_week2 = time.strftime('%A')
date2 = time.strftime("%d %b, %Y")
# if time string has changed, update it
if time2 != self.time1:
self.time1 = time2
self.timeLbl.config(text=time2)
if day_of_week2 != self.day_of_week1:
self.day_of_week1 = day_of_week2
self.dayOWLbl.config(text=day_of_week2)
if date2 != self.date1:
self.date1 = date2
self.dateLbl.config(text=date2)
# calls itself every 200 milliseconds
# to update the time display as needed
# could use >200 ms, but display gets jerky
self.timeLbl.after(200, self.tick)
class Weather(Frame): def init(self, parent, *args, **kwargs): Frame.init(self, parent, bg='black') self.temperature = '' self.forecast = '' self.location = '' self.currently = '' self.icon = '' self.degreeFrm = Frame(self, bg="black") self.degreeFrm.pack(side=TOP, anchor=W) self.temperatureLbl = Label(self.degreeFrm, font=('Helvetica', 94), fg="white", bg="black") self.temperatureLbl.pack(side=LEFT, anchor=N) self.iconLbl = Label(self.degreeFrm, bg="black") self.iconLbl.pack(side=LEFT, anchor=N, padx=20) self.currentlyLbl = Label(self, font=('Helvetica', 28), fg="white", bg="black") self.currentlyLbl.pack(side=TOP, anchor=W) self.forecastLbl = Label(self, font=('Helvetica', 18), fg="white", bg="black") self.forecastLbl.pack(side=TOP, anchor=W) self.locationLbl = Label(self, font=('Helvetica', 18), fg="white", bg="black") self.locationLbl.pack(side=TOP, anchor=W) self.get_weather()
def get_weather(self): try:
location_req_url = "http://freegeoip.net/json/%s" % ip
r = requests.get(location_req_url)
location_obj = json.loads(r.text)
lat = location_obj['latitude']
lon = location_obj['longitude']
location2 = "%s, %s" % (location_obj['city'], location_obj['region_code'])
# get weather
weather_req_url = "https://api.forecast.io/forecast/%s/%s,%s" % (weather_api_token, lat,lon)
r = requests.get(weather_req_url)
weather_obj = json.loads(r.text)
degree_sign= u'\u2109'
temperature2 = "%s%s" % (str(int(weather_obj['currently']['temperature'])), degree_sign)
currently2 = weather_obj['currently']['summary']
forecast2 = weather_obj["hourly"]["summary"]
icon_id = weather_obj['currently']['icon']
icon2 = None
if icon_id in icon_lookup:
icon2 = icon_lookup[icon_id]
if icon2 is not None:
if self.icon != icon2:
self.icon = icon2
image = Image.open(icon2)
image = image.resize((100, 100), Image.ANTIALIAS)
image = image.convert('RGB')
photo = ImageTk.PhotoImage(image)
self.iconLbl.config(image=photo)
self.iconLbl.image = photo
else:
# remove image
self.iconLbl.config(image='')
if self.currently != currently2:
self.currently = currently2
self.currentlyLbl.config(text=currently2)
if self.forecast != forecast2:
self.forecast = forecast2
self.forecastLbl.config(text=forecast2)
if self.temperature != temperature2:
self.temperature = temperature2
self.temperatureLbl.config(text=temperature2)
if self.location != location2:
self.location = location2
self.locationLbl.config(text=location2)
except Exception as e:
traceback.print_exc()
print("Error: %s. Cannot get weather.") % e
self.after(600000, self.get_weather)
@staticmethod def convert_kelvin_to_fahrenheit(kelvin_temp): return 1.8 (kelvin_temp - 273) + 32 class News(Frame): def init(self, parent, args, *kwargs): Frame.init(self, parent, args, **kwargs) self.config(bg='black') self.title = 'NEA' self.newsLbl = Label(self, text=self.title, font=('Helvetica', 28), fg="white", bg="black") self.newsLbl.pack(side=TOP, anchor=W) self.headlinesContainer = Frame(self, bg="black") self.headlinesContainer.pack(side=TOP) self.get_headlines()
def get_headlines(self): try:
for widget in self.headlinesContainer.winfo_children():
widget.destroy()
headlines_url = "https://news.google.gr/news?ned=%s&output=rss" % country_code
feed = feedparser.parse(headlines_url)
for post in feed.entries[0:5]:
headline = NewsHeadline(self.headlinesContainer, post.title)
headline.pack(side=TOP, anchor=W)
except Exception as e:
traceback.print_exc()
print("Error: %s. Cannot get news.") % e
self.after(600000, self.get_headlines)
class NewsHeadline(Frame): def init(self, parent, event_name=""): Frame.init(self, parent, bg='black') image = Image.open("assets/Newspaper.png") image = image.resize((25, 25), Image.ANTIALIAS) image = image.convert('RGB') photo = ImageTk.PhotoImage(image) self.iconLbl = Label(self, bg='black', image=photo) self.iconLbl.image = photo self.iconLbl.pack(side=LEFT, anchor=N) self.eventName = event_name self.eventNameLbl = Label(self, text=self.eventName, font=('Helvetica', 18), fg="white", bg="black") self.eventNameLbl.pack(side=LEFT, anchor=N) classmethodsCalendar(Frame)
def init(self, parent, *args, **kwargs): Frame.init(self, parent, bg='black') self.title = 'Calendar Events' self.calendarLbl = Label(self, text=self.title, font=('Helvetica', 28), fg="white", bg="black") self.calendarLbl.pack(side=TOP, anchor=E) self.calendarEventContainer = Frame(self, bg='black') self.calendarEventContainer.pack(side=TOP, anchor=E) self.get_events()
def get_events(self):
# reference https://developers.google.com/google-apps/calendar/quickstart/python
# remove all children
for widget in self.calendarEventContainer.winfo_children():
widget.destroy()
calendar_event = CalendarEvent(self.calendarEventContainer)
calendar_event.pack(side=TOP, anchor=E)
pass
class CalendarEvent(Frame): def init(self, parent, event_name="Event 1"): Frame.init(self, parent, bg='black') self.eventName = event_name self.eventNameLbl = Label(self, text=self.eventName, font=('Helvetica', 18), fg="white", bg="black") self.eventNameLbl.pack(side=TOP, anchor=E)
class FullscreenWindow:
def __init__(self):
self.tk = Tk()
self.tk.configure(background='black')
self.topFrame = Frame(self.tk, background = 'black')
self.bottomFrame = Frame(self.tk, background = 'black')
self.topFrame.pack(side = TOP, fill=BOTH, expand = YES)
self.bottomFrame.pack(side = BOTTOM, fill=BOTH, expand = YES)
self.state = False
self.tk.bind("<Return>", self.toggle_fullscreen)
self.tk.bind("<Escape>", self.end_fullscreen)
# clock
self.clock = Clock(self.topFrame)
self.clock.pack(side=RIGHT, anchor=N, padx=100, pady=60)
# weather
self.weather = Weather(self.topFrame)
self.weather.pack(side=LEFT, anchor=N, padx=100, pady=60)
# news
self.news = News(self.bottomFrame)
self.news.pack(side=LEFT, anchor=S, padx=100, pady=60)
# calender - removing for now
# self.calender = Calendar(self.bottomFrame)
# self.calender.pack(side = RIGHT, anchor=S, padx=100, pady=60)
def toggle_fullscreen(self, event=None):
self.state = not self.state # Just toggling the boolean
self.tk.attributes("-fullscreen", self.state)
return "break"
def end_fullscreen(self, event=None):
self.state = False
self.tk.attributes("-fullscreen", False)
return "break"
if name == 'main': w = FullscreenWindow() w.tk.mainloop()
I cant figure it out!! I don't know what is the problem with my code! If i try the other code there is an error with json and message can't get data from weather! That's why i asked for your code! Thanks!
Hi
I can't change temperature degree sign from Fahrenheit to Celsius! Can anyone help me? Thanks