def need_comic(incoming_msg): """ Sample function that uses a Response object for more options. :param incoming_msg: The incoming message object from Teams :return: A Response object based reply """ # Create a object to create a reply. response = Response() # Set the text of the reply. response.text = "Clearly its time for some comic relief" get_url = 'http://xkcd.com/info.0.json' get_response = requests.get(get_url) if get_response.status_code != 200: response.text = response.text + "\nEven the Comic Relief is tired!" raise Exception("Status code: " + str(get_response.status_code) + " for url: " + get_url) else: #response.files ="https://imgs.xkcd.com/comics/stack.png" data = get_response.json() u = str(data["img"]) response.files = u return response
def capturescreen(incoming_msg): response = Response() datetime_object = datetime.datetime.now() print(datetime_object) response.text = "Here is your current Network Health as of " + str( datetime_object) #im1 = pyautogui.screenshot() #im1.save (r"C:\Users\aykorri\OneDrive - Cisco\Desktop\SE Hack\screenshot.png") path = ( r"C:\Users\aykorri\OneDrive - Cisco\Desktop\SE Hack\screenshot.png") #titles = pygetwindow.getAllTitles() #x1, y1, width, height = pygetwindow.getWindowGeometry('How to screenshot a specific window using Python') #x2 = x1 + width #y2 = y1 + height #pyautogui.screenshot(path) #im = Image.open(path) #im = im.crop((x1, y1, x2, y2)) #im.save(path) #im.show(path) u = r"C:\Users\aykorri\OneDrive - Cisco\Desktop\SE Hack\screenshot.png" response.files = u return response
def SearchGif(incoming_msg, search_term): """ Function to retrieve a meme on brooklyn99. :param incoming_msg: The incoming message object from Teams ;param search_term: What to search for :return: A text or markdown based reply """ # get the top 8 GIFs for the search term r = requests.get("https://api.tenor.com/v1/random?q=%s&key=%s&limit=%s" % (search_term, apikey, lmt)) if r.status_code == 200: top_gif = json.loads(r.content) print(json.dumps(top_gif, indent=4, sort_keys=True)) for i in range(len(top_gif['results'])): url = top_gif['results'][i]['media'][0]['gif']['url'] print("Found url ", i, ": ", url) else: top_gif = None response = Response() response.files = url return response
def planets(input): # Extract string following trigger; Set to lowercase to allow for uppercase/lowercase data entry = bot.extract_message("/planets", input.text).strip().lower() response = Response() # Set general response if no data or "all" is entered if entry == "" or entry == "all": response.markdown = "Here are the 8 planets in order: \n" response.markdown += " 1. Mercury \n" response.markdown += " 2. Venus \n" response.markdown += " 3. Earth \n" response.markdown += " 4. Mars \n" response.markdown += " 5. Jupiter \n" response.markdown += " 6. Saturn \n" response.markdown += " 7. Uranus \n" response.markdown += " 8. Neptune \n" return response else: # Set help response if "help" or "?" is entered if entry == "help" or input == "?": response.markdown = "Enter **/planets** followed by a planet name or a number to find the corresponding value. \n" response.markdown += "Type **/planets** or **/planets all** to list all planets." return response else: # Call swtichers to retrieve planet name/number and picture response.markdown = planet_switch(entry) response.files = picture_switch(entry) return response
def meme_func(incoming_msg): response = Response() for x in range(1): response.files = "https://media.giphy.com/media/jKWVkeDxquixAE1gDW/giphy.gif" #jojo dora return response Response.text = "Food for your chronic meme addiction"
def ret_message(incoming_msg): checkregistereduser(incoming_msg.personEmail, incoming_msg.roomId) # Create a object to create a reply. response = Response() response.text = "Happy birthday and have a nice day." response.files = "https://thumbs.dreamstime.com/b/happy-birthday-cheerful-colleagues-office-congratulate-vector-full-color-graphics-cute-characters-156278742.jpg" # response.files = "https://static.officeholidays.com/images/1280x853c/india-flag-01.jpg" return response
def ret_message(incoming_msg): """ :param incoming_msg: :return: """ response = Response() response.text = "Here's a fun little meme." u = "https://sayingimages.com/wp-content/uploads/" u = u + "aaaaaalll-righty-then-alrighty-meme.jpg" response.files = u return response
def sdwan_report(incoming_msg): """ Main function called by the Bot Menu to generate SD WAN report. This function calls the bot_functions.conn_matrix function for the actual processing :param incoming_msg: :return: """ # Get sent message msg = '' message = incoming_msg.text.split() # Lookup details about sender sender = app.teams.people.get(incoming_msg.personId) room = app.teams.rooms.get(incoming_msg.roomId) # if length of split message is greater than 2 elements then the function is being passed a site id parameter if len(message) > 2: siteid = message[2] room_title = siteid # Otherwise extract site id from room information else: site_id, id_match = get_siteid(room) room_title = room.title regexp = r"\d{4}" match = re.search(regexp, room_title) if match: site_id = match.group() response_data = bot_functions.conn_matrix(site_id) else: site_id = f"ERROR" response_data = f"ERROR: Bot function was passed something that was not understood: {incoming_msg.text}. " \ f"\n\rIf you are not in an NT3 space please provide the 4 digit site code." # response_data += f"match is {match}\nsite_id is {site_id}\n room_title is {room_title}" # Create a Response object and craft a reply in Markdown. response = Response() response.markdown = f"\n{response_data}\n" if match: response.files = f"./{site_id}_sdwan_report.txt" return response
def ret_message(incoming_msg): """ Sample function that uses a Response object for more options. :param incoming_msg: The incoming message object from Teams :return: A Response object based reply """ # Create a object to create a reply. response = Response() # Set the text of the reply. response.text = "Here's a fun little meme." # Craft a URL for a file to attach to message u = "https://sayingimages.com/wp-content/uploads/" u = u + "aaaaaalll-righty-then-alrighty-meme.jpg" response.files = u return response
def generate_report(incoming_msg): """ Sample function to do some action. :param incoming_msg: The incoming message object from Teams :return: A text or markdown based reply """ conn = sqlite3.connect('/home/toobradsosad/enablement-buddy/tracking.db') df = pd.read_sql_query( "SELECT activityType, description, duration, activityDate FROM tracking WHERE user='******';", conn) export_excel = df.to_excel( '/home/toobradsosad/enablement-buddy/exports/activities.xlsx', index=None, header=True) #Don't forget to add '.xlsx' at the end of the path # export_csv = df.to_csv('/home/toobradsosad/enablement-buddy/exports/temp.csv', index = None, header=True) #Don't forget to add '.csv' at the end of the path num_enablements = df.shape[0] response = Response() response.markdown = "You've logged **" + str( num_enablements) + "** activities! Here's a report for your records." response.files = "/home/toobradsosad/enablement-buddy/exports/activities.xlsx" return response
def test_response_files(self): r = Response() r.files = "someurl" self.assertEqual(r.files[0], "someurl")