Skip to content

Commit

Permalink
Added automatic IP detection
Browse files Browse the repository at this point in the history
I suggest adding get_ip to automatically get IP seeing as it changes sometimes, I also suggest changing get_weathers location_req_url to get the IP everytime weather is called. Sorry if it is syntactically wrong, never really did anything in python, just saw that in the video it was static and decided this should be added.
  • Loading branch information
SDK authored Sep 7, 2016
1 parent bf5447b commit 745c297
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion smartmirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,21 @@ def __init__(self, parent, *args, **kwargs):
self.locationLbl = Label(self, font=('Helvetica', 18), 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:
# get location
location_req_url = "http://freegeoip.net/json/%s" % ip
location_req_url = "http://freegeoip.net/json/%s" % get_ip()
r = requests.get(location_req_url)
location_obj = json.loads(r.text)

Expand Down

0 comments on commit 745c297

Please sign in to comment.