def send_sms(message, to='all_leaders'): import re bcc = list() if to == 'all_leaders': people = db((db.person.grade != 9) & (db.person.leader==True)).select( db.person.id, db.person.student_id, db.person.cell_phone, db.person.cell_provider, db.person.email) for person in people: if person.cell_phone and person.cell_provider and Providers.contains(person.cell_provider): bcc.append(sms_email(person.cell_phone, Providers.get(person.cell_provider))) elif person.email: bcc.append(person.email) elif to.startswith('task_team'): people = db(db.group_rec.group_id==int(re.findall(r'\d+', to)[0])).select( db.person.id, db.person.student_id, db.person.cell_phone, db.person.cell_provider, db.person.email, join=db.person.on(db.person.id==db.group_rec.person_id)) for person in people: if person.cell_phone and person.cell_provider and Providers.contains(person.cell_provider): bcc.append(sms_email(person.cell_phone, Providers.get(person.cell_provider))) elif person.email: bcc.append(person.email) else: person = db(db.person.id==to).select().first() if person.cell_phone and person.cell_provider and Providers.contains(person.cell_provider): bcc.append(sms_email(person.cell_phone, Providers.get(person.cell_provider))) elif person.email: bcc.append(person.email) if len(bcc) < 100: mail.send(to=mail.settings.sender, bcc=bcc, subject='', message=message) else: small_lists = list() curr = list() count = 0 while len(bcc) > 0: if count < 50: curr.append(bcc.pop(0)) else: small_lists.append(curr) curr = list() curr.append(bcc.pop(0)) count = 0 count += 1 for l in small_lists: mail.send(to=mail.settings.sender, bcc=l, subject='', message=message) return dict(response='Sending messages')
def updateYahooPrices(): currentPrices = db(db.current.ticker!=None).select() for currPrice in currentPrices: htmlfile = urllib2.urlopen("http://finance.yahoo.com/q?s="+currPrice.ticker) htmltext = htmlfile.read() regex = '<span id="yfs_l84_'+currPrice.ticker+'">(.+?)</span>' pattern = re.compile(regex) newPrice = re.findall(pattern,htmltext) db.recent.insert(ticker=currPrice.ticker, price=float(newPrice[0]), day=db(db.day.day!=None).select().first().day, datetime=datetime.datetime.today()) try: subscriptions = db(db.subscription.ticker==currPrice.ticker).select() for currSub in subscriptions: user = db(db.auth_user.id==currSub.u_id).select().first() email = user.email phone_email = sms_email(user.phone_number, user.phone_provider) if currPrice.price < currSub.value and currSub.value < float(newPrice[0]): scheduler.queue_task('emergency_email', [email, currSub.ticker, 'risen above', currSub.value]) scheduler.queue_task('emergency_email', [phone_email, currSub.ticker, 'risen above', currSub.value]) db(db.subscription.id==currSub.id).delete() elif currPrice.price > currSub.value and currSub.value > float(newPrice[0]): scheduler.queue_task('emergency_email', [email, currSub.ticker, 'fallen below', currSub.value]) db(db.subscription.id==currSub.id).delete() currPrice.update_record(price=float(newPrice[0])) db.commit() except IndexError as e: i = 1#do nothing
def send_sms(message, to='all_leaders'): import re bcc = list() if to == 'all_leaders': people = db((db.person.grade != 9) & (db.person.leader == True)).select( db.person.id, db.person.student_id, db.person.cell_phone, db.person.cell_provider, db.person.email) for person in people: if person.cell_phone and person.cell_provider and Providers.contains( person.cell_provider): bcc.append( sms_email(person.cell_phone, Providers.get(person.cell_provider))) elif person.email: bcc.append(person.email) elif to.startswith('task_team'): people = db( db.group_rec.group_id == int(re.findall(r'\d+', to)[0])).select( db.person.id, db.person.student_id, db.person.cell_phone, db.person.cell_provider, db.person.email, join=db.person.on(db.person.id == db.group_rec.person_id)) for person in people: if person.cell_phone and person.cell_provider and Providers.contains( person.cell_provider): bcc.append( sms_email(person.cell_phone, Providers.get(person.cell_provider))) elif person.email: bcc.append(person.email) else: person = db(db.person.id == to).select().first() if person.cell_phone and person.cell_provider and Providers.contains( person.cell_provider): bcc.append( sms_email(person.cell_phone, Providers.get(person.cell_provider))) elif person.email: bcc.append(person.email) if len(bcc) < 100: mail.send(to=mail.settings.sender, bcc=bcc, subject='', message=message) else: small_lists = list() curr = list() count = 0 while len(bcc) > 0: if count < 50: curr.append(bcc.pop(0)) else: small_lists.append(curr) curr = list() curr.append(bcc.pop(0)) count = 0 count += 1 for l in small_lists: mail.send(to=mail.settings.sender, bcc=l, subject='', message=message) return dict(response='Sending messages')
def sms(): from gluon.contrib.sms_utils import SMSCODES, sms_email email = sms_email('1 (111) 111-1111','T-Mobile USA (tmail)') mail.send(to=email, subject='prueba', message='prueba') return dict()