<s> import smtplib <EOL> from email . MIMEText import MIMEText <EOL> import urllib2 <EOL> import re <EOL> from pytz import timezone <EOL> def sendEmail ( SUBJECT , BODY , TO , FROM , SENDER , PASSWORD , SMTP_SERVER ) : <EOL> """<STR_LIT>""" <EOL> for body_charset in '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' : <EOL> try : <EOL> BODY . encode ( body_charset ) <EOL> except UnicodeError : <EOL> pass <EOL> else : <EOL> break <EOL> msg = MIMEText ( BODY . encode ( body_charset ) , '<STR_LIT:html>' , body_charset ) <EOL> msg [ '<STR_LIT>' ] = SENDER <EOL> msg [ '<STR_LIT>' ] = TO <EOL> msg [ '<STR_LIT>' ] = SUBJECT <EOL> SMTP_PORT = <NUM_LIT> <EOL> session = smtplib . SMTP ( SMTP_SERVER , SMTP_PORT ) <EOL> session . starttls ( ) <EOL> session . login ( FROM , PASSWORD ) <EOL> session . sendmail ( SENDER , TO , msg . as_string ( ) ) <EOL> session . quit ( ) <EOL> def emailUser ( profile , SUBJECT = "<STR_LIT>" , BODY = "<STR_LIT>" ) : <EOL> """<STR_LIT>""" <EOL> def generateSMSEmail ( profile ) : <EOL> """<STR_LIT>""" <EOL> if profile [ '<STR_LIT>' ] is None or not profile [ '<STR_LIT>' ] : <EOL> return None <EOL> return str ( profile [ '<STR_LIT>' ] ) + "<STR_LIT:@>" + profile [ '<STR_LIT>' ] <EOL> if profile [ '<STR_LIT>' ] and profile [ '<STR_LIT>' ] : <EOL> if BODY : <EOL> BODY = profile [ '<STR_LIT>' ] + "<STR_LIT>" + BODY <EOL> BODY += "<STR_LIT>" <EOL> recipient = profile [ '<STR_LIT>' ] <EOL> if profile [ '<STR_LIT>' ] and profile [ '<STR_LIT>' ] : <EOL> recipient = profile [ '<STR_LIT>' ] + "<STR_LIT:U+0020>" + profile [ '<STR_LIT>' ] + "<STR_LIT>" % recipient <EOL> else : <EOL> recipient = generateSMSEmail ( profile ) <EOL> if not recipient : <EOL> return False <EOL> try : <EOL> if '<STR_LIT>' in profile : <EOL> user = profile [ '<STR_LIT>' ] [ '<STR_LIT:username>' ] <EOL> password = profile [ '<STR_LIT>' ] [ '<STR_LIT:password>' ] <EOL> server = '<STR_LIT>' <EOL> else : <EOL> user = profile [ '<STR_LIT>' ] <EOL> password = profile [ '<STR_LIT>' ] <EOL> server = '<STR_LIT>' <EOL> sendEmail ( SUBJECT , BODY , recipient , user , <EOL> "<STR_LIT>" , password , server ) <EOL> return True <EOL> except : <EOL> return False <EOL> def getTimezone ( profile ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return timezone ( profile [ '<STR_LIT>' ] ) <EOL> except : <EOL> return None <EOL> def generateTinyURL ( URL ) : <EOL> """<STR_LIT>""" <EOL> target = "<STR_LIT>" + URL <EOL> response = urllib2 . urlopen ( target ) <EOL> return response . read ( ) <EOL> def isNegative ( phrase ) : <EOL> """<STR_LIT>""" <EOL> return bool ( re . search ( r'<STR_LIT>' , phrase , <EOL> re . IGNORECASE ) ) <EOL> def isPositive ( phrase ) : <EOL> """<STR_LIT>""" <EOL> return bool ( re . search ( r'<STR_LIT>' , phrase , re . IGNORECASE ) ) </s>
