From 6532cafd185bb6db4e9f02d38ec5f96dec4f042f Mon Sep 17 00:00:00 2001 From: Krizhan Mariampillai Date: Sat, 4 Jun 2016 03:01:52 -0400 Subject: [PATCH 1/3] Check Time Anywhere eg.time in beijing or time in los angeles. My first module. I feel like I may have messed up since its my first time and any feedback (even negative) regarding my code or even anything is much appreciated since its a learning experience. --- modules/src/time.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 modules/src/time.py diff --git a/modules/src/time.py b/modules/src/time.py new file mode 100644 index 00000000..2fa968a6 --- /dev/null +++ b/modules/src/time.py @@ -0,0 +1,19 @@ +import requests +from templates.text import TextTemplate +from datetime import datetime + +def process(input, entities): + output = {} + try: + l = requests.get('http://nominatim.openstreetmap.org/search?q='+ entities['time'][0]['value'] + '&format=json&limit=1') + location = l.json() + r = requests.get('http://api.timezonedb.com/?lat='+ location[0]['lat'] + '&lng='+ location[0]['lon'] + '&format=json&key=M4K04AV6U6IT') + time_data = r.json() + the_time = datetime.utcfromtimestamp(time_data['timestamp']).strftime('%Y-%m-%d %H:%M:%S') + output['input'] = input + output['output'] = TextTemplate('Location: ' + location[0]['display_name'] + '\nTime: ' + the_time + '\nTime Zone: ' + time_data['abbreviation']).get_message() + output['success'] = True + except: + output['success'] = False + + return output From ae13f9bc92cad67fc89eed56195c78916157acd0 Mon Sep 17 00:00:00 2001 From: Krizhan Mariampillai Date: Sat, 4 Jun 2016 22:12:59 -0400 Subject: [PATCH 2/3] New Api --- modules/src/time.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/src/time.py b/modules/src/time.py index 2fa968a6..342245ef 100644 --- a/modules/src/time.py +++ b/modules/src/time.py @@ -5,7 +5,7 @@ def process(input, entities): output = {} try: - l = requests.get('http://nominatim.openstreetmap.org/search?q='+ entities['time'][0]['value'] + '&format=json&limit=1') + l = requests.get('http://open.mapquestapi.com/nominatim/v1/search.php?key=CcNE2f13xlbD9bMBYzWHsyasWeyGDfwA&format=json&q='+ entities['time'][0]['value'] + '&addressdetails=0&limit=1') location = l.json() r = requests.get('http://api.timezonedb.com/?lat='+ location[0]['lat'] + '&lng='+ location[0]['lon'] + '&format=json&key=M4K04AV6U6IT') time_data = r.json() From a6a80e39b693dd7781f604af6e8caf7e47645771 Mon Sep 17 00:00:00 2001 From: Krizhan Mariampillai Date: Sat, 4 Jun 2016 22:15:02 -0400 Subject: [PATCH 3/3] Update time.py --- modules/src/time.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/src/time.py b/modules/src/time.py index 2fa968a6..342245ef 100644 --- a/modules/src/time.py +++ b/modules/src/time.py @@ -5,7 +5,7 @@ def process(input, entities): output = {} try: - l = requests.get('http://nominatim.openstreetmap.org/search?q='+ entities['time'][0]['value'] + '&format=json&limit=1') + l = requests.get('http://open.mapquestapi.com/nominatim/v1/search.php?key=CcNE2f13xlbD9bMBYzWHsyasWeyGDfwA&format=json&q='+ entities['time'][0]['value'] + '&addressdetails=0&limit=1') location = l.json() r = requests.get('http://api.timezonedb.com/?lat='+ location[0]['lat'] + '&lng='+ location[0]['lon'] + '&format=json&key=M4K04AV6U6IT') time_data = r.json()