def index(): models.db.create_all() addresses = [ models.Usps("1600 Pennsylvania"), models.Usps("121 W 21st Ave"), models.Usps("NJIT GITC")] for address in addresses: db.session.add(address) db.session.commit() return flask.render_template("index.html")
def on_new_address(data): print("Got an event for new address input with data:", data) db.session.add(models.Usps(data["address"])) db.session.commit() emit_all_addresses(ADDRESSES_RECEIVED_CHANNEL)
def index(): models.db.create_all() addresses = [ models.Usps("1600 Pennsylvania"), models.Usps("121 W 21st Ave"), models.Usps("NJIT GITC")] for address in addresses: db.session.add(address) db.session.commit() retstr = "<html><ol>" for usps_object in db.session.query(models.Usps).all(): retstr += "<li>{}</li>\n".format(usps_object.address) retstr += "</ol></html>" return retstr
def on_new_address(data): print("Got an event for new address input with data:", data) Text_input = data["address"] send_back = "" new_string = "" if Text_input.startswith('!! '): for i in range(3, len(Text_input)): new_string += Text_input[i] new_string = str(new_string.lower()) if new_string.startswith('about'): send_back = "Hii, I am a chat bot. \nI can translate text for you in minion language. \n write !! help to see what commands I can take." elif new_string.startswith('help'): send_back = "I can take following commands. \n !! about, !! help, !! translate <text here>, !! dictionary <word>. " elif new_string.startswith('dictionary'): word_id = "" for i in range(11, len(new_string)): word_id += new_string[i] try: if " " not in word_id: app_id = os.environ['APP_ID'] app_key = os.environ['APP_KEY'] endpoint = "entries" language_code = "en-us" header_params = {"app_id": app_id, "app_key": app_key} url = "https://od-api.oxforddictionaries.com/api/v2/" + endpoint + "/" + language_code + "/" + word_id.lower( ) response = requests.get(url, headers=header_params) if response.status_code == 200: json_body = response.json() results = json_body["results"] api_response = str( results[0]["lexicalEntries"][0]["entries"][0] ["senses"][0]["definitions"][0]) send_back = "" counter = 0 for i in range(0, len(api_response)): if counter < 70: send_back += api_response[i] counter += 1 else: send_back = send_back + "..." break else: send_back = "There is No Data, Pleae try with some other Keyword!" else: send_back = "Please try with one Keyword only !" except Exception: send_back = "Service is down right now, try again later!" elif new_string.startswith('translate'): str_api_call = "" for i in range(10, len(new_string)): str_api_call += new_string[i] url = "https://api.funtranslations.com/translate/minion.json?text={}".format( str_api_call) response = requests.get(url) if response.status_code == 200: json_body = response.json() send_back = json_body["contents"]["translated"] else: send_back = "Service is down right now, try again later !" else: send_back = "Entry is not valid please try with !! help" if (len(send_back) == 0): Text_input2 = "User: "******"User: "******"Chat Bot: " + send_back db.session.add(models.Usps(Text_input2)) db.session.add(models.Usps(send_back2)) db.session.commit() emit_all_addresses(ADDRESSES_RECEIVED_CHANNEL)
def on_new_address(data): print("Got an event for new address input with data:", data) global dbuser global isUrl dbuser = LOGINUSER print(dbuser) global address address = data["address"] message = address try: parse(data["address"], rule="IRI") isUrl = address # if (isUrl[-4:] ==".png" or isUrl[-4:]==".jpg" or isUrl[-4:]==".gif"): except: print("whoa") isUrl = "1" print("isUrl: " + isUrl) db.session.add(models.Usps(message, isUrl, dbuser, imageURL)) db.session.commit() # room = data['room'] # join_room(room) if data["address"][0:2] == "!!": dbuser = "******" if data["address"][2:] == "about": message = ( dbuser + ": " + "Hi I am Wall-E, nice to meet you. I am a robot that likes to clean up the Earth!" ) elif data["address"][2:] == "help": message = ( dbuser + ": " + "Commands that can be used: !!about, !!funtranslate <message>, !!pun, !!time" ) elif data["address"][2:14] == "funtranslate": url = "https://api.funtranslations.com/translate/yoda.json?text={}".format( data["address"][15:] ) response = requests.get(url) json_body = response.json() print(json_body) message = ( dbuser + ": " + (json.dumps(json_body["contents"]["translated"])).strip('"\\n') ) elif data["address"][2:] == "pun": url = "https://sv443.net/jokeapi/v2/joke/Pun?type=single" response = requests.get(url) json_body = response.json() message = dbuser + ": " + (json.dumps(json_body["joke"])).strip('"\\n') print(json.dumps(json_body["joke"])) elif data["address"][2:] == "time": message = ( dbuser + ": The time is " + str(datetime.now().time().strftime("%I:%M %p")) ) else: message = dbuser + ": " + "Sorry I do not recognize this command..." db.session.add(models.Usps(message, isUrl, dbuser, imageURL)) db.session.commit() emit_all_addresses(ADDRESSES_RECEIVED_CHANNEL) return message