def smsresponse(): num = request.values.get('From', None) message = request.values.get('Body', None) options = message.split() print(options) callers = messenger.getContactsSaved() if num in messenger.getContactsSaved(): message = callers[num] + ", thanks for the message!" else: message = "Thanks for the message!" message += " You will be receiving box scores of the specified games." qry = "UPDATE userselections SET " size = len(options) count = 1 for option in options: if (size != count): qry += "\"{}\"=1, ".format(option) else: qry += "\"{}\"=1 ".format(option) count += 1 qry += "WHERE phone = '{}'".format(num) cur = conn.cursor() cur.execute(qry) conn.commit() messenger.sendMessage(message, num) print(qry) return "Messaging Response"
def getNotifications(type): params = getParams(type) collectionRef = db.collection('{}-notifications'.format(type)) account = getAccount(type) browser = login(type, account) browser.open(params['notifsUrl']) soup = browser.parsed ul = soup.find('ul', attrs={'class': 'timeline'}) if not ul: raise ValueError("Couldn't open Notifications page") li_time_label = ul.find_all('li', attrs={'class': 'time-label'}) div_timeline_item = ul.find_all('div', attrs={'class': 'timeline-item'}) for i in range(len(li_time_label)): date = li_time_label[i].text.strip(' \t\n\r') time = div_timeline_item[i].span.text.strip(' \t\n\r').replace( ' ', '').replace(';', '') heading = div_timeline_item[i].find('h4', attrs={ 'class': 'timeline-header' }).text.strip(' \t\n\r') body = div_timeline_item[i].find('div', attrs={ 'class': 'timeline-body' }).text poster = div_timeline_item[i].find('h3', attrs={ 'class': 'timeline-header up' }).text.strip(' \t\n\r') poster = poster[len('Posted by : \n \n '):] key = '{} : {} : {}'.format(getHash(date + time + heading + body[:5]), date, time) docRef = collectionRef.document(key) if not docRef.get().exists: docRef.set({ 'key': key, 'date': date, 'time': time, 'heading': heading, 'body': body, 'poster': poster }) sendMessage(label=type, message=notificationTemplate(date, time, heading, body, poster)) return '{} notifications parsed'.format(type)
def sendUsersEndScores(): scores = sportsradar.getscores() print(str(scores)) if not scores: return ("No scores yet!") cur = conn.cursor() cur.execute("""SELECT * FROM userselections""") rows = cur.fetchall() for row in rows: msg = "" colsToClear = [] for i in range(16): boolean = row[i] if (boolean == 1 and i in scores.keys()): msg += scores[i] + "\n" colsToClear.append(i) if (len(colsToClear) > 0): clearTableOnGameSent(colsToClear, row[0]) if (msg != ""): messenger.sendMessage(msg, row) return (str(scores))
def getJobs(type): params = getParams(type) collectionRef = db.collection('{}-jobs'.format(type)) account = getAccount(type) browser = login(type, account) browser.open(params['jobsUrl']) soup = browser.parsed table_jobopenings = soup.find('table', attrs={'id': 'jobs_search'}) if not table_jobopenings: raise ValueError("Couldn't open jobs page") trs = table_jobopenings.find_all('tr') for i in range(1, len(trs)): tds = trs[i].find_all('td') if tds[3].find('i')['class'][1] == 'fa-check': name = tds[0].text appDeadline = tds[2].text dateOfVisit = tds[6].text link = trs[i]['onclick'].replace("void window.open('", '').replace("')", '') docRef = collectionRef.document(name) if not docRef.get().exists: docRef.set({ 'name': name, 'appDeadline': appDeadline, 'dateOfVisit': dateOfVisit, 'link': link, }) sendMessage(label=type, message=jobTemplate(name, appDeadline, dateOfVisit, link)) return '{} jobs parsed'.format(type)
def on_modified(self, event): data = [] f = open(event.src_path, "r") for line in f: data.append(line) f.close() if set(data) & set(self.most_recent_data): # if messages are the same return self.most_recent_data = data #record that we have a new message print(self.most_recent_data) try: messenger.sendMessage(''.join(data)) #send to server except Exception as e: print("Couldn't send to server!") print(e)