def get(self, args): geocode = Geocode() address = args["address"] complete_json_answer_for_address = geocode.get_coordinates_from_address( address) if complete_json_answer_for_address is not None: latitude = float( complete_json_answer_for_address[0]["geometry"]["lat"]) longitude = float( complete_json_answer_for_address[0]["geometry"]["lng"]) LOGGER.info("Coordinates for address \"" + address + "\" are: " + str(latitude) + "," + str(longitude)) if args["howbig"] == "": nearest_station = engine.get_nearest_train_station( latitude, longitude) else: nearest_station = engine.get_nearest_train_station_this_big( latitude, longitude) return json.loads( json_util.dumps(nearest_station, ensure_ascii=False).encode('utf8')) else: LOGGER.error("No answer from OpenCageGeocode for address: \"" + address + "\"") return json.loads( "{\"error\": {\"message\": \"Bad request. Check if address exists\", \"status\": 400}}" ), 400
def __init__(self): self.client = zulip.Client(site="https://chunkzz.zulipchat.com/api/") self.subscribe_all() self.chatbot = ChatBot( "Omega", trainer='chatterbot.trainers.ChatterBotCorpusTrainer') self.chatbot.train("chatterbot.corpus.english") self.crypto = Crypto() self.trans = Translate() self.g = Giphy() self.w = WikiPedia() self.tw = Twimega() self.motivate = Motivate() self.shortenedurl = Urlshortener() self.hacknews = Hackernews() self.geo = Geocode() self.weather = Weather() self.dict_ = Dictionary() self.joke = Joke() self.pnr = Pnr() self.mustread = Mustread() self.ss = Ss() self.cricket = Cricket() self.poll = Poll() self.subkeys = [ "crypto", "translate", "define", "joke", "weather", "giphy", "pnr", "mustread", "poll", "hackernews", "hn", "HN", "motivate", "twitter", "screenshot", "memo", "cricnews", "help", "shorturl" ]
def test_should_return_none_because_address_unknown(self): geocode = Geocode() address = "tototatatiti" result = geocode.get_coordinates_from_address(address) self.assertIsNone(result)
def __init__(self, nodes, printStatus=False): self.graph = Graph() self.nodes = nodes self.printStatus = printStatus self.coder = Geocode(geocoderCache=True, printStatus=printStatus) self.results = self.__init_results__() self.__get_geodata__() self.__init_graph__() self.count = 0
def upload(): for file in request.files.getlist("file"): filename = file.filename csv_in = "/".join([DATA_DIR, filename]) file.save(csv_in) key = "/".join([CONFIG_DIR, 'key.xml']) engine = Geocode(key) csv_out = "/".join([DATA_DIR, outfile]) i = engine.csv_count(csv_in) thr = Thread(target=engine.generate, args=[csv_in, csv_out]) thr.start() return redirect(url_for('loading', ctr=i))
def __init__(self): self.client = zulip.Client(site="https://saharsh.zulipchat.com/api/") self.subscribe_all() self.trans = Translate() self.tw = Twimega() self.pnr = Pnr() self.weather = Weather() self.geo = Geocode() print("Initialization Done ...") self.subkeys = [ "crypto", "translate", "define", "joke", "weather", "giphy", "pnr", "mustread", "poll", "hackernews", "hn", "HN", "motivate", "twitter", "screenshot", "memo", "cricnews", "help", "shorturl" ]
def __init__(self): self.client = zulip.Client(site="https://saharsh.zulipchat.com/api/") self.subscribe_all() self.trans = Translate() self.tw = Twimega() self.pnr = Pnr() self.weather = Weather() self.geo = Geocode() self.searching = Places() self.help = Help() print("Initialization Done ...") self.subkeys = [ "translate", "weather", "pnr", "post", "post_image", "twitter", "help", "search" ]
def __init__(self): self.client = zulip.Client(site="https://fazeup.zulipchat.com/api/") self.subscribe_all() self.hacknews = Hackernews() self.trans = Translate() self.movie = Movie() self.lyrics = Lyrics() self.holiday = Holiday() self.currency = Currency() self.cricket = Cricket() # self.chatbot.train("chatterbot.corpus.english") self.crypto = Crypto() self.trans = Translate() self.g = Giphy() self.w = WikiPedia() # self.tw = Twimega() # self.motivate = Motivate() self.shortenedurl = Urlshortener() self.geo = Geocode() self.weather = Weather() self.dict_ = Dictionary() self.joke = Joke() self.pnr = Pnr() self.mustread = Mustread() self.ss = Ss() self.cricket = Cricket() self.poll = Poll() print("done init") self.subkeys = [ "crypto", "translate", "define", "joke", "weather", "giphy", "pnr", "mustread", "poll", "hackernews", "hn", "HN", "motivate", "twitter", "screenshot", "memo", "cricnews", "help", "shorturl", "movie", "currency", "holiday", "lyrics" ]
def test_should_return_coordinates(self): """ Saint Quentin le verger : x1 = 48.619380 y1 = 3.746980 """ geocode = Geocode() address = "14 rue de Vignolle, Saint-Quentin-le-verger" result = geocode.get_coordinates_from_address(address) latitude = str(result[0]["geometry"]["lat"]) longitude = str(result[0]["geometry"]["lng"]) distance = engine.get_distance(float(latitude), float(longitude), 48.619380, 3.746980) self.assertLess(distance, 0.5)
def __init__(self, nodes, printStatus = False): self.graph = Graph() self.nodes = nodes self.printStatus = printStatus self.coder = Geocode(geocoderCache = True, printStatus = printStatus) self.results = self.__init_results__() self.__get_geodata__() self.__init_graph__() self.count = 0
def process_location(update, context): user_chat_id = update.message.chat_id current_time = time.time() if on_timeout(user_calltime.get(user_chat_id), current_time): send_on_timeout_message(update.message, context, timeout - (current_time - user_calltime.get(user_chat_id))) return else: user_calltime[user_chat_id] = current_time user_id_location[update.message.chat_id] = Geocode( update.message.location.longitude, update.message.location.latitude) user_id_parking_index[update.message.chat_id] = 0 prepare_parking_lots(update, context)
class ZulipBot(object): def __init__(self): self.client = zulip.Client(site="https://saharsh.zulipchat.com/api/") self.subscribe_all() self.trans = Translate() self.tw = Twimega() self.pnr = Pnr() self.weather = Weather() self.geo = Geocode() self.searching = Places() self.help = Help() print("Initialization Done ...") self.subkeys = [ "translate", "weather", "pnr", "post", "post_image", "twitter", "help", "search" ] def subscribe_all(self): json = self.client.get_streams()["streams"] streams = [{"name": stream["name"]} for stream in json] self.client.add_subscriptions(streams) def process(self, msg): content = msg["content"].split() sender_email = msg["sender_email"] ttype = msg["type"] stream_name = msg['display_recipient'] stream_topic = msg['subject'] if sender_email == BOT_MAIL: return if content[0].lower() == "ninjas33" or content[0] == "@**ninjas33**": if content[1].lower() == "translate": ip = content[2:] ip = " ".join(ip) message = self.trans.translate(ip) self.client.send_message({ "type": "stream", "subject": msg["subject"], "to": msg["display_recipient"], "content": message }) if content[1].lower() == "pnr": message = self.pnr.get_pnr(content[2]) self.client.send_message({ "type": "stream", "subject": msg["subject"], "to": msg["display_recipient"], "content": message }) if content[1].lower() == "twitter": if len(content) > 2 and content[2] == "post": if self.tw.stream == msg["display_recipient"]: status = self.tw.post(" ".join(content[3:])) x = json.dumps(status._json) x = json.loads(x) message = "https://twitter.com/{}/status/{}".format( x["user"]["screen_name"], x["id_str"]) message = "Tweet Posted\n" + message self.client.send_message({ "type": "stream", "subject": msg["subject"], "to": msg["display_recipient"], "content": message }) else: message = "Use the stream **{}** to post a tweet".format( self.tw.stream) self.client.send_message({ "type": "stream", "to": sender_email, "content": message }) if len(content) > 2 and content[2] == "post_image": if self.tw.stream == msg["display_recipient"]: status = self.tw.post_image(content[3], " ".join(content[4:])) if isinstance(status, str): message = status else: x = json.dumps(status._json) x = json.loads(x) message = "https://twitter.com/{}/status/{}".format( x["user"]["screen_name"], x["id_str"]) message = "Tweet Posted\n" + message self.client.send_message({ "type": "stream", "subject": msg["subject"], "to": msg["display_recipient"], "content": message }) else: message = "Use the stream **{}** to post a tweet".format( self.tw.stream) self.client.send_message({ "type": "private", "to": sender_email, "content": message }) if content[1].lower() == "help" and len(content) == 2: message = self.help.get_help() self.client.send_message({ "type": "stream", "subject": msg["subject"], "to": msg["display_recipient"], "content": message }) if content[1].lower() == "weather": place = " ".join(content[2:]) try: result = self.weather.getWeather(self.geo.convert(place)) message = "**" + "Weather update of " + place + "**" + "\n" + "Summary : " + "**" + result[ "currently"][ "summary"] + "**" + "\n" + "Temparature : " + "**" + str( result["currently"]["temperature"] ) + "**" + '\n' + "Apparent Temparature : " + "**" + str( result["currently"]["apparentTemperature"] ) + "**" + "\n" + "Dew Point : " + "**" + str( result["currently"]["dewPoint"] ) + "**" + "\n" + "Humidity : " + "**" + str( result["currently"]["humidity"]) + "**" except KeyError: message = "Not Working Right Now" self.client.send_message({ "type": "stream", "subject": msg["subject"], "to": msg["display_recipient"], "content": message }) if content[1].lower() == "search": place = " ".join(content[2:]) try: result = self.searching.getPlaces(place) y = result['results'] message = "Result for search \n" #print(result) for i in range(len(y)): message += str( i + 1) + ". " + y[i]['name'] + " , Rating:" + str( y[i]['rating'] ) + " \n Address : " + y[i]['formatted_address'] message += "\n" except KeyError: message = "Not Working Right Now" self.client.send_message({ "type": "stream", "subject": msg["subject"], "to": msg["display_recipient"], "content": message }) if content[1] not in self.subkeys: ip = content[1:] ip = " ".join(ip) message = self.chatbot.get_response(ip).text self.client.send_message({ "type": "stream", "subject": msg["subject"], "to": msg["display_recipient"], "content": message }) elif "ninjas33" in content and content[0] != "ninjas33": self.client.send_message({ "type": "stream", "subject": msg["subject"], "to": msg["display_recipient"], "content": "Hey there! :blush:" }) else: return
class Domaene: def __init__(self, nodes, printStatus = False): self.graph = Graph() self.nodes = nodes self.printStatus = printStatus self.coder = Geocode(geocoderCache = True, printStatus = printStatus) self.results = self.__init_results__() self.__get_geodata__() self.__init_graph__() self.count = 0 def generate_hiera_list(self): for node in self.nodes: if 'geodata' in node: if node['geodata']: self.results['Gesamt']['count'] += 1 self.__node_hiera__(node['geodata'], self.results['Gesamt']['childs'], self.graph.start_point, 'Gesamt') def __node_hiera__(self, geodata, result_layer, graph_layer, parent_name): # sometimes nominatim results are bad and no startpoint can be found if graph_layer.name not in geodata: return None geo_name = geodata[graph_layer.name] next_step = { 'point' : None, 'weight' : -1 } for name, entry in self.graph.get_point(graph_layer.name).edges.iteritems(): if name in geodata: if next_step['weight'] > entry['weight'] or next_step['weight'] == -1: next_step['point'] = entry['point'] next_step['weight'] = entry['weight'] if geo_name == parent_name: if next_step['point']: self.__node_hiera__(geodata, result_layer, next_step['point'],geo_name) else: if geo_name in result_layer: result_layer[geo_name]['count'] += 1 else: result_layer[geo_name] = { 'count' : 1, 'childs' : {} } if next_step['point']: self.__node_hiera__(geodata, result_layer[geo_name]['childs'], next_step['point'],geo_name) def results_as_indent(self): if self.results: self.__hiera_as_indent__(self.results,0) else: print "No results generated" def __hiera_as_indent__(self, layer, indent): for k,v in layer.iteritems(): print ' '*indent*4+k+': '+str(v['count']) if v['childs']: self.__hiera_as_indent__(v['childs'],indent+1) def results_as_dokuwiki_list(self): if self.results: self.__hiera_as_dokuwiki_list__(self.results,0) else: print "No results generated" def __hiera_as_dokuwiki_list__(self, layer, indent): for k,v in layer.iteritems(): print ' '+' '*indent*2+'* '+k+': '+str(v['count']) if v['childs']: self.__hiera_as_dokuwiki_list__(v['childs'],indent+1) def __init_results__(self): return { 'Gesamt' : { 'count' : 0, 'childs' : {} } } def __get_geodata__(self): for node in self.nodes: result = self.coder.getGeo(node['lon'], node['lat']) if result: node['geodata'] = result['payload'] if result['cached'] == False: time.sleep(1) else: node['geodata'] = None def __init_graph__(self): self.graph.add_point('administrative') self.graph.add_point('hamlet') self.graph.add_point('residential') self.graph.add_point('village') self.graph.add_point('neighbourhood') self.graph.add_point('city') self.graph.add_point('city_district') self.graph.add_point('suburb') self.graph.add_point('town') self.graph.add_point('state_district') self.graph.add_point('county') self.graph.add_point('state') self.graph.add_point('country') self.graph.set_root_point('country') self.graph.add_edge_between('country', 'state') self.graph.add_edge_between('state','state_district', 1) self.graph.add_edge_between('state','county', 2) self.graph.add_edge_between('state_district','county') self.graph.add_edge_between('county', 'city', 1) self.graph.add_edge_between('county', 'town', 2) self.graph.add_edge_between('county', 'city_district', 3)#Häger issue if village is preferred over city_district self.graph.add_edge_between('county', 'village', 4) self.graph.add_edge_between('city', 'city_district') self.graph.add_edge_between('city_district', 'suburb', 1) self.graph.add_edge_between('city_district', 'residential', 2) self.graph.add_edge_between('town', 'city_district', 1) self.graph.add_edge_between('town', 'suburb', 2) self.graph.add_edge_between('town', 'residential',3) #self.graph.add_edge_between('village', 'city_district', 1) self.graph.add_edge_between('village', 'suburb', 2) self.graph.add_edge_between('village', 'residential',3) self.graph.add_edge_between('village', 'neighbourhood',4) self.graph.add_edge_between('suburb', 'hamlet', 1) self.graph.add_edge_between('suburb', 'neighbourhood', 2) self.graph.add_edge_between('suburb', 'administrative', 3)
class Domaene: def __init__(self, nodes, printStatus=False): self.graph = Graph() self.nodes = nodes self.printStatus = printStatus self.coder = Geocode(geocoderCache=True, printStatus=printStatus) self.results = self.__init_results__() self.__get_geodata__() self.__init_graph__() self.count = 0 def generate_hiera_list(self): for node in self.nodes: if 'geodata' in node: if node['geodata']: self.results['Gesamt']['count'] += 1 self.__node_hiera__(node['geodata'], self.results['Gesamt']['childs'], self.graph.start_point, 'Gesamt') def __node_hiera__(self, geodata, result_layer, graph_layer, parent_name): # sometimes nominatim results are bad and no startpoint can be found if graph_layer.name not in geodata: return None geo_name = geodata[graph_layer.name] next_step = {'point': None, 'weight': -1} for name, entry in self.graph.get_point( graph_layer.name).edges.iteritems(): if name in geodata: if next_step['weight'] > entry['weight'] or next_step[ 'weight'] == -1: next_step['point'] = entry['point'] next_step['weight'] = entry['weight'] if geo_name == parent_name: if next_step['point']: self.__node_hiera__(geodata, result_layer, next_step['point'], geo_name) else: if geo_name in result_layer: result_layer[geo_name]['count'] += 1 else: result_layer[geo_name] = {'count': 1, 'childs': {}} if next_step['point']: self.__node_hiera__(geodata, result_layer[geo_name]['childs'], next_step['point'], geo_name) def results_as_indent(self): if self.results: self.__hiera_as_indent__(self.results, 0) else: print "No results generated" def __hiera_as_indent__(self, layer, indent): for k, v in layer.iteritems(): print ' ' * indent * 4 + k + ': ' + str(v['count']) if v['childs']: self.__hiera_as_indent__(v['childs'], indent + 1) def results_as_dokuwiki_list(self): if self.results: self.__hiera_as_dokuwiki_list__(self.results, 0) else: print "No results generated" def __hiera_as_dokuwiki_list__(self, layer, indent): for k, v in layer.iteritems(): print ' ' + ' ' * indent * 2 + '* ' + k + ': ' + str(v['count']) if v['childs']: self.__hiera_as_dokuwiki_list__(v['childs'], indent + 1) def __init_results__(self): return {'Gesamt': {'count': 0, 'childs': {}}} def __get_geodata__(self): for node in self.nodes: result = self.coder.getGeo(node['lon'], node['lat']) if result: node['geodata'] = result['payload'] if result['cached'] == False: time.sleep(1) else: node['geodata'] = None def __init_graph__(self): self.graph.add_point('administrative') self.graph.add_point('hamlet') self.graph.add_point('residential') self.graph.add_point('village') self.graph.add_point('neighbourhood') self.graph.add_point('city') self.graph.add_point('city_district') self.graph.add_point('suburb') self.graph.add_point('town') self.graph.add_point('state_district') self.graph.add_point('county') self.graph.add_point('state') self.graph.add_point('country') self.graph.set_root_point('country') self.graph.add_edge_between('country', 'state') self.graph.add_edge_between('state', 'state_district', 1) self.graph.add_edge_between('state', 'county', 2) self.graph.add_edge_between('state_district', 'county') self.graph.add_edge_between('county', 'city', 1) self.graph.add_edge_between('county', 'town', 2) self.graph.add_edge_between( 'county', 'city_district', 3) #Häger issue if village is preferred over city_district self.graph.add_edge_between('county', 'village', 4) self.graph.add_edge_between('city', 'city_district') self.graph.add_edge_between('city_district', 'suburb', 1) self.graph.add_edge_between('city_district', 'residential', 2) self.graph.add_edge_between('town', 'city_district', 1) self.graph.add_edge_between('town', 'suburb', 2) self.graph.add_edge_between('town', 'residential', 3) #self.graph.add_edge_between('village', 'city_district', 1) self.graph.add_edge_between('village', 'suburb', 2) self.graph.add_edge_between('village', 'residential', 3) self.graph.add_edge_between('village', 'neighbourhood', 4) self.graph.add_edge_between('suburb', 'hamlet', 1) self.graph.add_edge_between('suburb', 'neighbourhood', 2) self.graph.add_edge_between('suburb', 'administrative', 3)
def geocode(): address = request.args.get('address', type=str) m = Geocode() return make_response(jsonify(m.geocode(address)), 200)
def get(self, args): geocode = Geocode() detailed_address = address_to_string(args) result = geocode.get_coordinates_from_address(detailed_address) return result
class ZulipBot(object): def __init__(self): self.client = zulip.Client(site="https://chunkzz.zulipchat.com/api/") self.subscribe_all() self.chatbot = ChatBot( "Omega", trainer='chatterbot.trainers.ChatterBotCorpusTrainer') self.chatbot.train("chatterbot.corpus.english") self.crypto = Crypto() self.trans = Translate() self.g = Giphy() self.w = WikiPedia() self.tw = Twimega() self.motivate = Motivate() self.shortenedurl = Urlshortener() self.hacknews = Hackernews() self.geo = Geocode() self.weather = Weather() self.dict_ = Dictionary() self.joke = Joke() self.pnr = Pnr() self.mustread = Mustread() self.ss = Ss() self.cricket = Cricket() self.poll = Poll() self.subkeys = [ "crypto", "translate", "define", "joke", "weather", "giphy", "pnr", "mustread", "poll", "hackernews", "hn", "HN", "motivate", "twitter", "screenshot", "memo", "cricnews", "help", "shorturl" ] def urls(self, link): urls = re.findall( 'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', link) return urls def subscribe_all(self): json = self.client.get_streams()["streams"] streams = [{"name": stream["name"]} for stream in json] self.client.add_subscriptions(streams) def help(self): message = "**Welcome to Omega Bot**\nOmega Bot has various subfields\nType `omega help <subfield>` to get help for specific subfield.\n" message += "\n**Subfields**\n" message += "`crypto` - Get Crypto Currency Prices\n" message += "`translate` - Translate Foreign Languages to English\n" message += "`define` - Get Word Meanings\n" message += "`joke` - Get Jokes\n" message += "`weather` - Get Weather Details\n" message += "`giphy` - Get GIFs from Giphy\n" message += "`pnr` - Get PNR Status\n" message += "`mustread` - Share Must Read Messages to Teammates\n" message += "`poll` - Create Amazing Polls in Zulip\n" message += "`hn` - Get Top Hacker News Results\n" message += "`motivate` - Get Motivational Quotes\n" message += "`twitter` - Tweet Directly from Zulip\n" message += "`screenshot` - Take Screenshot of Web Pages\n" message += "`memo` - Create Memos in Cloud\n" message += "`cricnews` - Get Cricket News\n" message += "`shorturl` - Create goo.gl short URLs\n" message += "\nIf you're bored Talk to Omega Bot, it will supercharge you" return message def help_sub(self, key): key = key.lower() message = "**Usage**\n" if key == "crypto": message += "`omega crypto <crypto-currency-code>` - To Get Price in USD\n" message += "`omage crypto <crypto-currency-code> in <currency>` - To Get Price in Specified Currency\n" elif key == "translate": message += "`omega translate <phrase to be translated>` - To Get Translate from Foreign Language to English\n" elif key == "define": message += "`omega define <word>` - To Get Definition of the word\n" elif key == "joke": message += "`omega joke` - Get a Joke\n" elif key == "weather": message += "`omega weather <location>` - Get the weather details of the given place\n" elif key == "giphy": message += "`omega giphy <search word>` - Get a random GIF from Giphy related to the given search word\n" elif key == "pnr": message += "`omega pnr <valid pnr number>` - Get PNR Details of the Given PNR number\n" elif key == "mustread": message += "`omega mustread @**<User Mention>** <message>` - Pass Important Messages to Team Members\n" elif key == "poll": message += "`omega poll create <number of choices> question <question> option <option1> <option2>...` - To Create a New Poll. It will return with a Poll ID Number\n" message += "`omega poll vote <POLL_ID> <Choice>` - To Vote for specified option\n" message += "`omega poll show all` - List all available polls\n" message += "`omega poll show <ID>` - List all details from specified Poll ID\n" message += "`omega poll delete all` - Delete All Polls\n" message += "`omega poll delete <ID>` - Delete Poll with specified ID\n" elif key == "hn" or key == "hackernews": message += "`omega hn` OR `omega hackernews` - Show Top 10 stories from Hacker News\n" elif key == "motivate": message += "`omega motivate` - Get a refreshing and motivating quote\n" elif key == "twitter": message += "`omega twitter post <tweet>` - Post a Tweet with given tweet\n" message += "`omega twitter post_image <image_url> <tweet>` - Post a Tweet with given tweet and image url\n" elif key == "screenshot": message += "`omega screenshot <website url>` - Take a screenshot of the given url\n" elif key == "memo": message += "`omega memo <filename>` - Creates a New Memo file and returns its link\n" elif key == "cricnews": message += "`omega cricnews` - Get top 10 Cricket News\n" elif key == "shorturl": message += "`omega shorturl <url>` - Get a Shorten URL from goo.gl\n" else: message = self.help() message += "\n{} is not a valid subfield\n".format(key) return message def process(self, msg): content = msg["content"].split() sender_email = msg["sender_email"] ttype = msg["type"] stream_name = msg['display_recipient'] stream_topic = msg['subject'] print(content) if sender_email == BOT_MAIL: return print("yeah") if content[0].lower() == "omega" or content[0] == "@**omega**": if content[1].lower() == "crypto": if len(content) > 3 and content[3].lower() == "in": message = self.crypto.get_price(content[2], content[4]) else: message = self.crypto.get_price(content[2]) self.client.send_message({ "type": "stream", "subject": msg["subject"], "to": msg["display_recipient"], "content": message }) if content[1].lower() == "translate": ip = content[2:] ip = " ".join(ip) message = self.trans.translate(ip) self.client.send_message({ "type": "stream", "subject": msg["subject"], "to": msg["display_recipient"], "content": message }) if content[1].lower() == "define": word = content[2].lower() result = self.dict_.words(word) print(result) self.client.send_message({ "type": "stream", "subject": msg["subject"], "to": msg["display_recipient"], "content": "**" + word + " means :" + "**" + '\n' + result }) if content[1].lower() == "screenshot": result = self.ss.get_ss(content[2]) print(result) self.client.send_message({ "type": "stream", "subject": msg["subject"], "to": msg["display_recipient"], "content": "Screenshot taken :wink:\n[Screenshot Link](" + result + ")" }) if content[1].lower() == "joke": text = self.joke.tellJoke() self.client.send_message({ "type": "stream", "subject": msg["subject"], "to": msg["display_recipient"], "content": text }) if content[1].lower() == "weather": place = " ".join(content[2:]) try: result = self.weather.getWeather(self.geo.convert(place)) message = "**" + "Weather update of " + place + "**" + "\n" + "Summary : " + "**" + result[ "currently"][ "summary"] + "**" + "\n" + "Temparature : " + "**" + str( result["currently"]["temperature"] ) + "**" + '\n' + "Apparent Temparature : " + "**" + str( result["currently"]["apparentTemperature"] ) + "**" + "\n" + "Dew Point : " + "**" + str( result["currently"]["dewPoint"] ) + "**" + "\n" + "Humidity : " + "**" + str( result["currently"]["humidity"]) + "**" except KeyError: message = "Weather Info is Not Working Right Now" self.client.send_message({ "type": "stream", "subject": msg["subject"], "to": msg["display_recipient"], "content": message }) if content[1].lower() == "giphy": text = content[2:] text = " ".join(text) im = str(self.g.search(text)) message = im[:im.find("?")] self.client.send_message({ "type": "stream", "subject": msg["subject"], "to": msg["display_recipient"], "content": message }) if content[1].lower() == 'memo': credentials = gdrivesignin.get_credentials() http = credentials.authorize(httplib2.Http()) service = discovery.build('drive', 'v3', http=http) file_metadata = {'name': content[2], 'mimeType': "text/plain"} file = service.files().create(body=file_metadata, fields='id').execute() web_link = service.files().get( fileId=file['id'], fields="webViewLink").execute()['webViewLink'] self.client.send_message({ "type": "stream", "to": stream_name, "subject": stream_topic, "content": 'Memo created.\nView & edit it at: ' + web_link }) if content[1].lower() == "pnr": message = self.pnr.get_pnr(content[2]) self.client.send_message({ "type": "stream", "subject": msg["subject"], "to": msg["display_recipient"], "content": message }) if content[1].lower() == "mustread": email = self.mustread.get_email(self.client.get_members(), msg["content"]) senderusername = self.mustread.get_username( self.client.get_members(), msg["sender_email"]) print(email) self.client.send_message({ "type": "private", "to": email, "content": "**" + senderusername + "** mentioned you in must read ! \nThe message says : " + " ".join(content[2:]) }) if content[1].lower() == "poll": if content[2].lower() == "create": print(",".join(content[4:])) idno = self.poll.create_poll(content[3], content[4:]) self.client.send_message({ "type": "stream", "subject": msg["subject"], "to": msg["display_recipient"], "content": "Poll Successfully Created and id is : **" + str(idno) + "**" }) elif content[2].lower() == "show": if content[3].lower() == "all": polldetails = self.poll.show_allpoll() self.client.send_message({ "type": "stream", "subject": msg["subject"], "to": msg["display_recipient"], "content": polldetails }) else: polldetails = self.poll.show_poll(content[3]) self.client.send_message({ "type": "stream", "subject": msg["subject"], "to": msg["display_recipient"], "content": "Poll ID: **" + polldetails["id"] + "**\n Question : **" + polldetails["pollname"] + "**\nOption : **" + polldetails["options"] + "**\n Votes : **" + polldetails["votes"] + "**" }) elif content[2].lower() == "vote": vote = self.poll.vote_poll(content[3], content[4]) self.client.send_message({ "type": "stream", "subject": msg["subject"], "to": msg["display_recipient"], "content": "Your Vote Has Been Recorded!" }) elif content[2].lower() == "delete": if content[3].lower() == "all": deleted = self.poll.delete_allpoll() self.client.send_message({ "type": "stream", "subject": msg["subject"], "to": msg["display_recipient"], "content": "all polls has been removed from database" }) else: deleted = self.poll.delete_poll(content[3]) self.client.send_message({ "type": "stream", "subject": msg["subject"], "to": msg["display_recipient"], "content": "The given poll has been removed from database" }) if content[1].lower() == 'motivate': quote_data = self.motivate.get_quote() self.client.send_message({ "type": "stream", "to": stream_name, "subject": stream_topic, "content": quote_data }) if content[1].lower() == "shorturl": short_url = self.shortenedurl.get_shorturl(content) self.client.send_message({ "type": "stream", "to": stream_name, "subject": stream_topic, "content": short_url }) if content[1].lower() == 'hackernews' or content[1].lower( ) == 'hn' or content[1].lower() == 'HN': news = self.hacknews.get_hackernews() self.client.send_message({ "type": "stream", "to": stream_name, "subject": stream_topic, "content": news }) if content[1].lower() == "cricnews": news = self.cricket.news() self.client.send_message({ "type": "stream", "subject": msg["subject"], "to": msg["display_recipient"], "content": news }) if content[1].lower() == "help" and len(content) == 2: message = self.help() self.client.send_message({ "type": "stream", "subject": msg["subject"], "to": msg["display_recipient"], "content": message }) if content[1].lower() == "help" and len(content) > 2: subkey = content[2] message = self.help_sub(subkey) self.client.send_message({ "type": "stream", "subject": msg["subject"], "to": msg["display_recipient"], "content": message }) if content[1].lower() == "twitter": #tweets = self.tw.get() #print(tweets) if len(content) > 2 and content[2] == "post": if self.tw.stream == msg["display_recipient"]: status = self.tw.post(" ".join(content[3:])) x = json.dumps(status._json) x = json.loads(x) message = "https://twitter.com/{}/status/{}".format( x["user"]["screen_name"], x["id_str"]) message = "Tweet Posted\n" + message self.client.send_message({ "type": "stream", "subject": msg["subject"], "to": msg["display_recipient"], "content": message }) else: message = "Use the stream **{}** to post a tweet".format( self.tw.stream) self.client.send_message({ "type": "private", "to": sender_email, "content": message }) if len(content) > 2 and content[2] == "post_image": if self.tw.stream == msg["display_recipient"]: status = self.tw.post_image(content[3], " ".join(content[4:])) if isinstance(status, str): message = status else: x = json.dumps(status._json) x = json.loads(x) message = "https://twitter.com/{}/status/{}".format( x["user"]["screen_name"], x["id_str"]) message = "Tweet Posted\n" + message self.client.send_message({ "type": "stream", "subject": msg["subject"], "to": msg["display_recipient"], "content": message }) else: message = "Use the stream **{}** to post a tweet".format( self.tw.stream) self.client.send_message({ "type": "private", "to": sender_email, "content": message }) if content[1] not in self.subkeys: ip = content[1:] ip = " ".join(ip) message = self.chatbot.get_response(ip).text self.client.send_message({ "type": "stream", "subject": msg["subject"], "to": msg["display_recipient"], "content": message }) if self.urls(" ".join(content)): summary = self.w.wiki(" ".join(content)) if summary: self.client.send_message({ "type": "stream", "subject": msg["subject"], "to": msg["display_recipient"], "content": summary }) elif "omega" in content and content[0] != "omega": self.client.send_message({ "type": "stream", "subject": msg["subject"], "to": msg["display_recipient"], "content": "Alas! Finally you called me :blush:" }) else: return