def pipedrive_notification(self): """Web hook push notification endpoint from Pipedrive subscription(s) when a deal moves. https://developers.pipedrive.com/v1#methods-PushNotifications / REST Hooks / Web hooks """ assert self.request.json and "current" in self.request.json and "previous" in self.request.json body = self.request.json payload = self.generate_payload(body) if not self._passes_through_whitelist_blacklist(body['current']): return 'OK' if self._pipedrive_deal_status_won(body): message = rendered_template("pipedrive_won.html", context=payload) self.say(message, html=True, color="green") elif self._pipedrive_deal_status_lost(body): message = rendered_template("pipedrive_lost.html", context=payload) self.say(message, html=True, color="red") elif self._pipedrive_deal_stage_changed(body): message = rendered_template("pipedrive_update.html", context=payload) self.say(message, html=True, color="green") return 'OK'
def get_uid(self, message, mention=None): if mention !='@all': hipchat_user_details = HipChatMixin().get_hipchat_user(user_id=mention) sender_email = hipchat_user_details.get('email') context = stats(user_name=sender_email) self.say(rendered_template("group_user.html", context), message, html=True) else: context = group_stats() self.say("@all Group Stats",message, notify=True, color='green') self.say(rendered_template("group_stats.html", context),message, notify=True, color='green', html=True)
def search(self, message, module, query): self.say("Alright, I'm on it...", message=message) accounts_words = ['accounts', 'businesses', 'companies'] contacts_words = ['contacts', 'people'] module = lower(module) last_name = None if module in accounts_words: module = 'Accounts' return_fields = ['Account Name', 'Phone', 'Company Site'] elif module in contacts_words: module = 'Contacts' return_fields = ['First Name', 'Last Name', 'Phone', 'Email'] if len(split(query, ' ')) > 1: first_name = get_first_name(query) last_name = get_last_name(query) query = first_name else: self.say("I don't know of any '%s' module in Zoho" % module, message=message) return None record_ids = self.get_search_records(module, return_fields, query) results = [] for record_id in record_ids: record = self.get_record_by_id(record_id, module, return_fields) record_fields = [] ignore_fields = ['ACCOUNTID', 'CONTACTID'] skip_record = False for field in record: for field_label in field: if field_label not in ignore_fields: field_value = field[field_label] record_fields.append(field_value) if field_label == 'Last Name' and last_name is not None: if not lower(last_name) in lower(field_value): skip_record = True if not skip_record: result = join(record_fields, ', ') results.append(result) results_context = { 'results': results, 'module': module, 'query': query, 'count': len(results) } results_html = rendered_template("zoho_search_results.html", results_context) self.say(results_html, html=True, message=message) return results_context
def available_branches(self, message): """list deployable branches: list all the branches that can be deployed""" print "available_branches" repos = self.get_github_deployable_repos() context = {"repos": repos} branches_html = rendered_template("available_branches.html", context) self.say(branches_html, message=message, html=True)
def google_poem(self, message, topic): """make a poem about __: show a google poem about __""" r = requests.get("http://www.google.com/complete/search?output=toolbar&q=" + topic + "%20") xmldoc = minidom.parseString(r.text) item_list = xmldoc.getElementsByTagName("suggestion") context = {"topic": topic, "lines": [x.attributes["data"].value for x in item_list[:4]]} self.say(rendered_template("gpoem.html", context), message, html=True)
def hear_dkcwd_team_timezones(self, message): context = { "date": time.strftime('%Y%m%d') } self.say(rendered_template("dkcwd_team_timezone_times.html", context), message=message, html=True, notify=True)
def packt_book_of_the_day_new_available(self): context = { "book": self.get_packt_book_of_the_day_name() } self.say(rendered_template("dkcwd_packt_book_of_the_day_new_available.html", context), html=True, notify=True)
def packt_book_of_the_day_almost_over(self): context = { "book": self.get_packt_book_of_the_day_name() } self.say(rendered_template("dkcwd_packt_book_of_the_day_almost_over.html", context), html=True, notify=True)
def hear_packt_book_of_the_day(self, message): context = { "book": self.get_packt_book_of_the_day_name() } self.say(rendered_template("dkcwd_packt_book_of_the_day.html", context), message=message, html=True, notify=True)
def list_rooms(self, message): context = { "rooms": self.available_rooms.values(), } self.say(rendered_template("rooms.html", context), message=message, html=True)
def list_rooms(self, message): """what are the rooms?: List all the rooms I know about.""" if len(self.available_rooms.keys()) >= 100: context = {"rooms": self.available_rooms.values()[0:100]} else: context = {"rooms": self.available_rooms.values(), } self.say(rendered_template("rooms.html", context), message=message, html=True)
def respond_to_contact_info(self, message): contacts = self.load("contact_info", {}) context = { "contacts": contacts, } contact_html = rendered_template("contact_info.html", context) self.say(contact_html)
def remind_staging_servers(self): context = { "stacks": self.stacks, "no_stacks": self.stacks == {} } servers_html = rendered_template("active_staging_server_reminder.html", context) self.say(servers_html, html=True)
def list_roster(self, message): context = { "internal_roster": self.internal_roster.values(), } self.say(rendered_template("roster.html", context), message=message, html=True)
def group_users(self, message): response = requests.get( settings.FIT_BOT_URL + 'get_group_users/1/') data = response.json() userlist = data.get('userlist', '') context = {"userlist": userlist} self.say(rendered_template("group_users.html", context), message, html=True)
def render_lp(self, bug): bug_info = { 'link': bug.web_link, 'title': bug.title, 'milestones': [] } for task in bug.bug_tasks: task_info = { 'status': 'Unknown', 'assignee': 'None', 'title': 'None' } try: (task_info['status'], ) = task.status except Exception: pass try: task_info['assignee'] = task.assignee.name except Exception: pass try: task_info['title'] = task.target.name except Exception: pass bug_info['milestones'].append(task_info) return rendered_template("lp_bug.html", bug_info)
def hear_dkcwd_mom_number(self, message): context = { "link": 'https://www.youtube.com/watch?v=AhYP7HSKiGc', "text": 'Here is the only link you need' } self.say(rendered_template("dkcwd_generic_team_link.html", context), message=message, html=True, notify=True)
def tutor_application(self): assert self.request.json and "user_name" in self.request.json payload = self.request.json message = rendered_template("tutor_application.html", context=payload) color = "green" self.say(message, color=color) return "OK"
def hear_dkcwd_team_escalation_process(self, message): context = { "link": 'some web address', "text": 'Here is the link to the escalation process' } self.say(rendered_template("dkcwd_generic_team_link.html", context), message=message, html=True, notify=True)
def list_rooms(self, message): hidden_help = """what are the rooms?: List all the rooms I know about.""" context = { "rooms": self.available_rooms.values(), } self.say(rendered_template("rooms.html", context), message=message, html=True)
def new_signup(self): assert self.request.json and "email" in self.request.json payload = self.request.json message = rendered_template("new_user.html", context=payload) color = "green" self.say(message, color=color) return "OK"
def seriously_remind_staging_servers(self): if self.stacks != {}: context = { "stacks": self.stacks, "no_stacks": self.stacks == {} } servers_html = rendered_template("active_staging_server_reminder.html", context) self.say(servers_html, html=True, color="red")
def event_added(self): assert self.request.json and "event_name" in self.request.json payload = self.request.json message = rendered_template("event_added.html", context=payload) color = "green" self.say(message, color=color) return "OK"
def respond_to_contact_info(self, message): """contact info: Show everyone's emergency contact info.""" contacts = self.load("contact_info", {}) context = { "contacts": contacts, } contact_html = rendered_template("contact_info.html", context) self.say(contact_html, message=message)
def deploy_notification(self): assert self.request.json and "name" in self.request.json payload = self.request.json message = rendered_template("sales_update.html", context=payload) color = "green" self.say(message, html=True, color=color) self.say("(boom)", color=color) return "OK"
def copy_issues( self, message, src_gh, src_owner, src_repo, dst_gh, dst_owner, dst_repo ): """ github: github copy issues from <ghc|ghe>/<src_owner>/<src_repo> to <ghc|ghe>/<src_owner>/<src_repo> """ url = 'repos/{}/{}/issues?filter=all&state=open'.format( src_owner, src_repo ) is_ghe = True if src_gh == 'ghe' else False src_results, err = self.get_all(is_ghe, url) if not src_results: self.reply(message, "Could not find any issues in source to copy") if dst_gh == 'ghe': dst_session = self.ghe_session base_url = self.GHE_API_URL else: dst_session = self.ghc_session base_url = self.GHC_API_URL url = '{base_url}repos/{dst_owner}/{dst_repo}/issues'.format( base_url=base_url, dst_owner=dst_owner, dst_repo=dst_repo ) failed_issues = [] for open_issue in src_results: copied_issue = { 'title': open_issue['title'], 'body': open_issue['body'], 'labels': [x['name'] for x in open_issue['labels']], } issue_create = dst_session.post(url, data=json.dumps(copied_issue)) if issue_create.status_code != 201: log.error(issue_create.text) failed_issues.append(open_issue) if len(failed_issues) != 0: context = {'failed_issues': failed_issues} self.reply( message, rendered_template('gh_copy_issues.html', context), html=True, notify=True, color='red' ) else: self.reply( message, 'Alright, time to get to work, my issues-transferinator ' 'was successful, but now the key holder needs to unwatch ' 'all {0} issues'.format(len(src_results)), )
def participants_in_room(self, message): """who is in this room?: List all the participants of this room.""" room = self.get_room_from_message(message) context = { "participants": room.participants, } self.say(rendered_template("participants.html", context), message=message, html=True)
def sendemail(self, message, email): response = requests.get( settings.FIT_BOT_URL + 'get_group_users/1/') data = response.json() userlist = data.get('userlist', '') context = {"userlist": userlist} self.send_email(from_email='*****@*****.**', email_list=[email], subject="Here's the latest report from Fitbot", message=rendered_template("group_users.html", context))
def definition(self, message, word): r = requests.get("http://api.urbandictionary.com/v0/define?term={0}".format(word)) wordlist = r.json() if wordlist['result_type'] == 'exact': def1 = wordlist['list'][0]['definition'] ex1 = wordlist['list'][0]['example'] sayData = {"word": word.title(), "definition": self.stripchars(def1,"[]"), "example": self.stripchars(ex1,"[]") } self.say(rendered_template("urban_define.html", sayData), message, html=True) else: self.say("No definition found for {0}.\nSorry homie.".format(word), message=message)
def render_jira(self, bug): return rendered_template( "jira_bug.html", { 'key': bug.key, 'title': bug.fields.summary, 'link': bug.permalink(), 'status': bug.fields.status.name } )
def summary_view(self, message): connect() result = [] for user in User.objects(): updates = StatusUpdateUserAggregated.objects(user_id=user.user_id).limit(5) if not len(updates): continue template = rendered_template("show_updates.html", {"user": user, "updates": updates}) self.reply(message, template, html=True)
def summary_view(self, message): connect() result = [] for user in User.objects(): updates = StatusUpdateUserAggregated.objects(user_id=user.user_id).limit(5) if not len(updates): continue template = rendered_template("show_updates.html", {"user":user, "updates":updates}) self.reply(message, template, html=True)
def google_poem(self, message, topic): """make a poem about __: show a google poem about __""" r = requests.get( "http://www.google.com/complete/search?output=toolbar&q=" + topic + "%20") xmldoc = minidom.parseString(r.text) itemList = xmldoc.getElementsByTagName("suggestion") context = { "topic": topic, "lines": [x.attributes["data"].value for x in itemList[:4]] } self.say(rendered_template("gpoem.html", context), message, html=True)
def word_game_round(self, message): "play a word game: Play a game where you think of words that start with a letter and fit a topic." letter = random.choice(string.ascii_uppercase) topics = [] while len(topics) < 10: new_topic = random.choice(WORD_GAME_TOPICS) if new_topic not in topics: topics.append({"index": len(topics) + 1, "topic": new_topic}) context = {"letter": letter, "topics": topics} self.say(rendered_template("word_game.html", context), message=message)
def dkcwd_team_random_joke(self): joke = random.choice(self.get_dkcwd_team_jokes()) joke_question = joke['question'] joke_answer = joke['answer'] context = { "joke_question": joke_question, "joke_answer": joke_answer } self.say(rendered_template("dkcwd_team_joke.html", context), html=True, notify=True)
def hello(self, message, query=None): if query is None: self.say("search for what?", message=message) else: response = requests.get('http://ajax.googleapis.com/ajax/services/search/web?v=1.0&safe=off&q={query}'.format(query=query)) if response.status_code != 200: self.say("Couldn't fetch results: {}".format(response.reason)) else: resp_json = response.json() if resp_json['responseStatus'] != 200: self.say("Couldn't fetch results: {}".format(resp_json['responseDetails'])) else: context = {'results': resp_json.get('responseData').get('results')} self.say(rendered_template("google_results.html", context), message=message, html=True)
def deploy_notification(self): # Options: https://circleci.com/docs/api#build assert self.request.json and "payload" in self.request.json payload = self.request.json["payload"] if "branch" in payload and payload["branch"] == "master": payload["project_name"] = payload["reponame"].title() payload["project_url"] = None if payload["reponame"] in SITE_BRANCH_MAPPINGS: payload["project_url"] = SITE_BRANCH_MAPPINGS[payload["reponame"]] message = rendered_template("deploy_notification.html", context=payload) color = "green" if payload["outcome"] != "success": color = "red" self.say(message, html=True, color=color) return "OK"
def lsproject(self, message, nick): # lists all projects, current user is assumed connect() if nick: nick = nick.strip() user = User.get_by_nick(nick) else: user = self.get_user(message) if not user: self.reply(message, "Could not find user %s" % nick) return projects = Project.objects(user_id=user.user_id) template = rendered_template("lsproject.html", {"user":user, "projects":projects}) self.reply(message, template, html=True)
def definition(self, message, word): r = requests.get( "http://api.urbandictionary.com/v0/define?term={0}".format(word)) wordlist = r.json() if wordlist['result_type'] == 'exact': def1 = wordlist['list'][0]['definition'] ex1 = wordlist['list'][0]['example'] context = { "word": word.title(), "definition": self.stripchars(def1, "[]"), "example": self.stripchars(ex1, "[]"), } self.say(rendered_template("urban_define.html", context), message, html=True) else: self.say("No definition found for {0}.\nSorry homie.".format(word), message=message)
def show_updates(self, message, nick): # shows updates for a single user connect() try: if not nick: user = self.get_user(message) else: user = User.get_by_nick(nick) except User.DoesNotExist: self.reply(message, "%s does not exist yet." % nick) return updates = StatusUpdateUserAggregated.objects(user_id=user.user_id).limit(10) template = rendered_template("show_updates.html", {"user":user, "updates":updates}) self.reply(message, template, html=True)
def new_invite_listener(self): from plugins.zoho_crm import ZohoCRMPlugin as ZohoClient print self.request.headers.__dict__ new_invite_html = rendered_template("new_invite.html", self.request.query) self.say(new_invite_html, html=True) full_name = self.request.query.full_name phone = self.request.query.phone email = self.request.query.email business_name = self.request.query.business_name notes = self.request.query.notes response = ZohoClient.create_lead(full_name, phone, email, business_name, notes) if response: self.say('I just added %s to Zoho CRM Leads.' % full_name) else: self.say("Heads up, I couldn't add %s to Zoho CRM Leads." % full_name) return ""
def get_the_temp(self, message): nest = Nest( username=settings.NEST_USERNAME, password=settings.NEST_PASSWORD, serial=settings.NEST_SERIAL, units="F", ) nest.login() nest.get_status() context = { "current_temp": nest.temp_out( nest.status['shared'][nest.serial]['current_temperature']), "target_temp": nest.temp_out( nest.status['shared'][nest.serial]['target_temperature']), "current_humidity": nest.status['device'][nest.serial]['current_humidity'], "is_on": nest.status['shared'][nest.serial]['hvac_heater_state'], } status_text = rendered_template("house_status.html", context) self.reply(message, status_text, html=True)
def help(self, message): help_text = rendered_template("status_help.html", {}) self.reply(message, help_text, html=True)
def will_likes_cookies(self, message): self.say(rendered_template("cookies.html", {}), message=message, html=True, )
def last_weights(self, message): weights = self.weights() status_text = rendered_template("weights.html", {"weights": weights}) self.say(status_text, message=message, html=True)
def get_fire_list(self, message): on_fire_list = self.load("on_fire_list", []) fire_list_html = rendered_template("fire_list.html", {"fire_list": on_fire_list}) self.say(fire_list_html, message=message, html=True)
def search(self, message, module, query): """search zoho ___ for ___: Look in zoho's ___ contact info for ___.""" self.say("Alright, I'm on it...", message=message) accounts_words = ['accounts', 'businesses', 'companies'] contacts_words = ['contacts', 'people'] module = lower(module) last_name = None if module in accounts_words: module = 'Accounts' return_fields = ['Account Name', 'Phone', 'Company Site'] elif module in contacts_words: module = 'Contacts' return_fields = ['First Name', 'Last Name', 'Phone', 'Email'] if len(split(query, ' ')) > 1: first_name = get_first_name(query) last_name = get_last_name(query) query = first_name else: self.say("I don't know of any '%s' module in Zoho" % module, message=message) return None record_ids = self.get_search_records(module, return_fields, query) results = [] for record_id in record_ids: record = self.get_record_by_id(record_id, module, return_fields) record_fields = [] ignore_fields = ['ACCOUNTID', 'CONTACTID'] skip_record = False for field in record: for field_label in field: if field_label not in ignore_fields: field_value = field[field_label] record_fields.append(field_value) if field_label == 'Last Name' and last_name is not None: if not lower(last_name) in lower(field_value): skip_record = True if not skip_record: result = join(record_fields, ', ') results.append(result) results_context = { 'results': results, 'module': module, 'query': query, 'count': len(results) } results_html = rendered_template("zoho_search_results.html", results_context) self.say(results_html, html=True, message=message) return results_context
def list_stacks(self, message): """list stacks: list all staging stacks""" context = {"stacks": self.stacks} branches_html = rendered_template("active_staging_stacks.html", context) self.say(branches_html, message=message, html=True)
def all_branches(self, message): """list all branches: list all branches on repos you can see""" repos = self.get_github_all_repos() context = {"repos": repos} branches_html = rendered_template("available_branches.html", context) self.say(branches_html, message=message, html=True)
def respond_to_weather(self, message): r = requests.get("https://api.forecast.io/forecast/%s/45.5794,-122.6830" % settings.FORECAST_IO_API_KEY) weather = rendered_template("weather.html", r.json()) self.reply(message, weather, html=True)