コード例 #1
0
ファイル: fetch_emails.py プロジェクト: mcswint/Spam-Kaiju
def matchEmailstoAddresses(email):
    matched = False
    matches = []

    # finds match of the brand in the email, can have several
    for brand_entry in brands_dict.keys():
        clean = email.replace(".com","")
        if brand_entry[1] in clean:
            matches.append(brand_entry)
            matched = True;

    # cleans up the email address
    email = email.split('<')
    email = email[len(email)-1].strip('>')

    # if there are matches match to the longest brand name
    if matched:
        longest = matches[0]
        for match in matches:
            if (len(match[1]) > len(longest[1])):
                longest = match

        brands_dict[longest] = email
        return longest[0]

    # else add to list of unmatched brands
    else:
        unmatched.append(email)
        return unmatchedIndex ##UNMATCHED in the db is 1
コード例 #2
0
ファイル: main.py プロジェクト: 743627/smart-assistant
def add_contact():
    complete_contact = []
    correct = False
    while not correct:
        speak("Please say the email of the person you would like to add.")
        email = listen(thresh=10).lower()
        #Speaks email out letter by letter 
        for letter in email:
            speak(letter)
        speak("Is this right spelling?")
        awns = listen().lower()
        if "yes" in awns:
            speak("What would you like to name this contact as?")
            name = listen(thresh=10).lower()
            #Speaks out name letter by letter
            for letter in name:
                speak(letter)
            speak("Is this correct?")
            awns = listen().lower()
            if "yes" in awns:
                correct = True
            else:
                continue
        else:
            continue #If it is wrong it will redo it
    email = email.replace(" ","").replace("at","@")
    complete_contact.append([email, name]) #Adds email and name as an array
    return complete_contact
コード例 #3
0
ファイル: autoprint.py プロジェクト: daxxog/autoprint
def GaiaLogin(email, password):
    """Login to gaia using HTTP post to the gaia login page.

    Args:
      email: string,
      password: string
    Returns:
      dictionary of authentication tokens.
    """
    tokens = {}
    cookie_keys = ['SID', 'LSID', 'HSID', 'SSID']
    email = email.replace('+', '%2B')
    # Needs to be some random string.
    galx_cookie = base64.b64encode('%s%s' % (email, time.time()))

    # Simulate submitting a gaia login form.
    form = ('ltmpl=login&fpui=1&rm=hide&hl=en-US&alwf=true'
            '&continue=https%%3A%%2F%%2F%s%%2F%s'
            '&followup=https%%3A%%2F%%2F%s%%2F%s'
            '&service=%s&Email=%s&Passwd=%s&GALX=%s' %
            (FOLLOWUP_HOST, FOLLOWUP_URI, FOLLOWUP_HOST, FOLLOWUP_URI, SERVICE,
             email, password, galx_cookie))
    login = httplib.HTTPS(GAIA_HOST, 443)
    login.putrequest('POST', LOGIN_URI)
    login.putheader('Host', GAIA_HOST)
    login.putheader('content-type', 'application/x-www-form-urlencoded')
    login.putheader('content-length', str(len(form)))
    login.putheader('Cookie', 'GALX=%s' % galx_cookie)
    logger.debug('Sent POST content: %s', form)
    login.endheaders()
    logger.info('HTTP POST to https://%s%s', GAIA_HOST, LOGIN_URI)
    login.send(form)

    (errcode, errmsg, headers) = login.getreply()
    login_output = login.getfile()
    login_output.close()
    login.close()
    logger.info('Login complete.')

    if errcode != 302:
        logger.error('Gaia HTTP post returned %d, expected 302', errcode)
        logger.error('Message: %s', errmsg)

    for line in str(headers).split('\r\n'):
        if not line: continue
        (name, content) = line.split(':', 1)
        if name.lower() == 'set-cookie':
            for k in cookie_keys:
                if content.strip().startswith(k):
                    tokens[k] = GetCookie(k, content)

    if not tokens:
        logger.error('No cookies received, check post parameters.')
        return None
    else:
        logger.debug('Received the following authorization tokens.')
        for t in tokens:
            logger.debug(t)
        return tokens
コード例 #4
0
ファイル: autoprint.py プロジェクト: daxxog/autoprint
def GaiaLogin(email, password):
    """Login to gaia using HTTP post to the gaia login page.

    Args:
      email: string,
      password: string
    Returns:
      dictionary of authentication tokens.
    """
    tokens = {}
    cookie_keys = ['SID', 'LSID', 'HSID', 'SSID']
    email = email.replace('+', '%2B')
    # Needs to be some random string.
    galx_cookie = base64.b64encode('%s%s' % (email, time.time()))

    # Simulate submitting a gaia login form.
    form = ('ltmpl=login&fpui=1&rm=hide&hl=en-US&alwf=true'
            '&continue=https%%3A%%2F%%2F%s%%2F%s'
            '&followup=https%%3A%%2F%%2F%s%%2F%s'
            '&service=%s&Email=%s&Passwd=%s&GALX=%s' % (FOLLOWUP_HOST,
            FOLLOWUP_URI, FOLLOWUP_HOST, FOLLOWUP_URI, SERVICE, email,
            password, galx_cookie))
    login = httplib.HTTPS(GAIA_HOST, 443)
    login.putrequest('POST', LOGIN_URI)
    login.putheader('Host', GAIA_HOST)
    login.putheader('content-type', 'application/x-www-form-urlencoded')
    login.putheader('content-length', str(len(form)))
    login.putheader('Cookie', 'GALX=%s' % galx_cookie)
    logger.debug('Sent POST content: %s', form)
    login.endheaders()
    logger.info('HTTP POST to https://%s%s', GAIA_HOST, LOGIN_URI)
    login.send(form)

    (errcode, errmsg, headers) = login.getreply()
    login_output = login.getfile()
    login_output.close()
    login.close()
    logger.info('Login complete.')

    if errcode != 302:
      logger.error('Gaia HTTP post returned %d, expected 302', errcode)
      logger.error('Message: %s', errmsg)

    for line in str(headers).split('\r\n'):
      if not line: continue
      (name, content) = line.split(':', 1)
      if name.lower() == 'set-cookie':
        for k in cookie_keys:
          if content.strip().startswith(k):
            tokens[k] = GetCookie(k, content)

    if not tokens:
      logger.error('No cookies received, check post parameters.')
      return None
    else:
      logger.debug('Received the following authorization tokens.')
      for t in tokens:
        logger.debug(t)
      return tokens
コード例 #5
0
	def decode_email(self, email):
		if not email: return 
		decoded = ""
		for part, encoding in decode_header(email.replace("\""," ").replace("\'"," ").replace("\t"," ").replace("\r\n"," ").replace(",","")):
			if encoding:
				decoded += part.decode(encoding)
			else:
				decoded += part.decode('utf-8')
		return decoded
コード例 #6
0
 def decode_email(self, email):
     if not email: return
     decoded = ""
     for part, encoding in decode_header(
             email.replace("\"", " ").replace("\'", " ")):
         if encoding:
             decoded += part.decode(encoding)
         else:
             decoded += part.decode('utf-8')
     return decoded
コード例 #7
0
 def preprocess_emails(self, emails):
     pr_emails = {}
     for email in emails:
         email = email.replace(">", '').split("<")
         if len(email) == 1 and email[0].strip():
             email_id = email[0].strip()
             if not pr_emails.get(email_id):
                 pr_emails[email_id] = {}
             pr_emails[email_id]['email'] = email_id
         elif len(email) > 1 and email[0].strip():
             email_id = email[1].strip()
             name = email[0].strip()
             if not pr_emails.get(email_id):
                 pr_emails[email_id] = {}
             pr_emails[email_id]['email'] = email_id
             if name:
                 pr_emails[email_id]['name'] = name.replace('"', "")
     return pr_emails
コード例 #8
0
def cleanEmail(email):
    cleanEmail = email.replace("'", "")
    cleanEmail = cleanEmail.strip()
    return cleanEmail
コード例 #9
0
 firstname=firstname.replace(' ','')
 with speech_recognition.Microphone() as source5: 
     listen_me=speech_recognition.Recognizer()
     listen_me.pause_threshold=1
     listen_me.adjust_for_ambient_noise(source5,duration=1)
     audio=listen_me.listen(source5)
     lastname=listen_me.recognize_google(audio,language='en-in')
 lastname=lastname.replace(' ','')
 fullname=(str(firstname+lastname).split(' '))
 speak('tell me your email or phone nunmber')
 with speech_recognition.Microphone() as source6:
     listen_me=speech_recognition.Recognizer()
     listen_me.pause_threshold=1
     audio=listen_me.listen(source6)
     email=listen_me.recognize_google(audio,language='en-in')
     email=email.replace(' ','')
 speak('what would be your username?')
 with speech_recognition.Microphone() as source7:
     listen_me=speech_recognition.Recognizer()
     listen_me.pause_threshold=1
     audio=listen_me.listen(source7)
     username=listen_me.recognize_google(audio,language='en-in')
     username=email.replace(' ','')
 speak('Tell me your password sir!')
 with speech_recognition.Microphone() as source9:
     speak("Assign a password for security sir? ")
     listen_me=speech_recognition.Recognizer()
     listen_me.pause_threshold=1
     audio=listen_me.listen(source9)
     password=listen_me.recognize_google(audio,language='en-in')
     print('Recognizing!')
コード例 #10
0
ファイル: emailer.py プロジェクト: theonaun/derelict
def send():
    try:
        print 'Running daily email.'
        # Check for last run
        APP_DIR = os.path.dirname(os.path.realpath(__file__))
        # Not really appdir
        APP_DIR = os.path.dirname(APP_DIR)
        conn = sqlite3.connect(os.path.join(APP_DIR,
                                            'data',
                                            'local_cfpb.db'))
        cursor = conn.cursor()    
        # Get last spool date
        try:
            cursor.execute('SELECT max(key) FROM log WHERE '
                           'event_type=\'Spool\'')
            last_spool_key = str(cursor.fetchone()[0])
            # Comma required at end of tuple to prevent unpacking
            cursor.execute('SELECT date from log WHERE key=?', 
                           (last_spool_key,))
            last_spool_date = str(cursor.fetchone()[0])
            print "Last spool " + last_spool_date
            # 2011-07-20 00:00:00.000001 to object
            last_spool_date = last_spool_date.replace('-',':')
            last_spool_date = last_spool_date.replace(' ',':')
            last_spool_date = last_spool_date.replace('.',':')
            last_spool_date = last_spool_date.split(':')
            last_spool_date = map(lambda x: int(x), last_spool_date)
            # Make into list, expand list
            last_spool_object = datetime.datetime(*last_spool_date)
            now = datetime.datetime.now()
            if (last_spool_object.year, 
                last_spool_object.month, 
                last_spool_object.day) == (now.year, now.month, now.day):
                # Short circuit spool
                print 'Last spool occurred today. No spool required.'
                return 0          
        except (TypeError, IndexError, sqlite3.Error):
            # Index error means no spools have ever occured (possibly)
            pass
        # Convert requests to spooled emails.
        # For each item in 'requests' load into memory (list of lists)
        requests_in_memory = []
        with open(os.path.join(APP_DIR, 'data', 'requests.csv'), 'r') as f:
            lines = f.readlines()
            # Make a list of all emails
            all_emails = [line.split(',')[0] for line in lines]
            # remove quotations
            all_emails = [email.replace('\"','') for email in all_emails ]
            # Remove 'email' from csv heading
            all_emails.remove('Email')
            # Remove duplicates
            unique_emails = list(set(all_emails))
            # Move items to requests in memory.
            for line in lines:
                line = line.rstrip()
                req_email = line.split(',')[0].replace('\"','')
                req_company = line.split(',')[1].replace('\"','')
                req_product = line.split(',')[2].replace('\"','')
                req_issue = line.split(',')[3].replace('\"','')
                requests_in_memory.append([req_email,
                                           req_company,
                                           req_product,
                                           req_issue])

        # Main container
        #data_by_email = {key: [] for key in unique_emails}
        # Python 2.6.6 Compatability
        dict((key, []) for key in unique_emails)
        # New items that meet the conditions
        date_obj = datetime.datetime.now()#DEBUG-datetime.timedelta(1)
        date_str = ''.join([str(date_obj.year),
                            '-',
                            str(date_obj.month).zfill(2),
                            '-',
                            str(date_obj.day).zfill(2)])
        # Check each local_cfpb_db for each request in list for particular day
        complaints_in_memory = []
        for row in cursor.execute('SELECT * FROM local_cfpb_db WHERE ' +
                                  'pull_date=?', (date_str,)):
            complaints_in_memory.append(row)
        # complaints in memory / requests in memory / data by email
        # FOR EACH COMPLAINT FLIP THIS SO REQUEST THEN COMPLAINT
        for complaint in complaints_in_memory:
            #primary_key = row[0]
            com_product = complaint[1]
            #sub_product = row[2]
            com_company = complaint[3]
            #date_sent_to_company = row[4]
            #consumer_disputed = row[5]
            #date_received = row[6]
            com_complaint_id = complaint[7]
            #state = row[8]
            #timely_response = row[9]
            #submitted_via = row[10]
            com_issue = complaint[11]
            #company_response = row[12]
            #zip_code = row[13]
            last_pull = complaint[14]
            last_pull_year, dash, remainder= last_pull.partition('-')
            last_pull_month, dash, remainder = remainder.partition('-')
            last_pull_day, dash, remainder = remainder.partition('-')
            last_pull_year = int(last_pull_year)
            last_pull_month = int(last_pull_month)
            last_pull_day = int(last_pull_day)
            # If more than 3 days old, do not spool
            now_obj = datetime.datetime.now()
            last_pull_obj = datetime.datetime(last_pull_year,
                                              last_pull_month,
                                              last_pull_day)
            if (now_obj - datetime.timedelta(2)) > last_pull_obj:
                continue
            # FOR EACH COMPLAINT EACH REQUEST
            # Requests ['Email', 'Company', 'Product', 'Issue']
            # Remove first header request
            for request in requests_in_memory[1:]:
                if request[1] == com_company:
                    if request[2] == 'All' or request[2] == com_product:
                        if request[3] == 'All' or request[3] == com_issue:  
                            print str('Spooling ' +  str(com_complaint_id))
                            # request and to email dict
                            data_by_email[unicode(request[0])].append([\
                                com_company, com_product, com_issue,\
                                com_complaint_id])       
        # Put into spool table
        cursor.execute('INSERT INTO log VALUES (NULL, ?, ?, ?)',
                           (str(datetime.datetime.now()),
                           'Spool',
                           'Spool date: ' + str(datetime.datetime.now())))
                                                                 
        conn.commit()
        conn.close()
    # Rollback if error         
    except sqlite3.Error as err:
        conn.rollback()
        conn.close()
        raise Exception(''.join(['Error: ', err.args[0]]))     
    print "Running daily send."
    # Load email settings from settings.txt
    username = notifier_settings.settings_dict['username']
    password = notifier_settings.settings_dict['password']
    outbound_server = notifier_settings.settings_dict['outbound_server']
    outbound_port = notifier_settings.settings_dict['outbound_port']
    sender_name = notifier_settings.settings_dict['sender_name']
    server = smtplib.SMTP()
    server.set_debuglevel(0)
    try:
        server.connect(str(outbound_server), int(outbound_port))
        server.starttls()
        server.ehlo()
        print "TLS handshake and login ..."
        server.login(username, password)
    except smtplib.SMTPConnectError as err:
        print "Did you setup email parameters in settings.txt?"
        raise Exception(err)
    try:
        conn = sqlite3.connect(os.path.join(APP_DIR,
                                            'data',
                                            'local_cfpb.db'))
        cursor = conn.cursor()
    except sqlite3.Error as err:
        conn.rollback()
        conn.close()
        raise Exception(''.join(['Error: ', err.args[0]]))
#########
    try:
        # {email:[4 element list],[4 element list]
        # For each email do the special sort.
        # Remove quotations
        for email_address in data_by_email.keys():
            email = email.replace('\"','')
            # If no complaints in list, go to next
            if len(data_by_email[email]) == 0:
                continue
            complaint_list = []
            # Get list of lists for that email.
            orig_data = data_by_email[email_address]
            for complaint in orig_data:
                company = complaint[0]
                product = complaint[1]
                issue = complaint[2]
                complaint_id = complaint[3]
                if issue == None:
                    issue = ''
                    '''
                    # WHAT IS THIS? WHY IS THIS HERE? TODO
                    email = row[1].replace(u'\x85','\n')
                    complaint_id = row[2].replace(u'\x85','\n')
                    company = row[3].replace(u'\x85','\n')
                    product = row[4].replace(u'\x85','\n')
                    subproduct = subproduct.replace(u'\x85','\n')
                    frequency = row[6].replace(u'\x85','\n')
                    # adjustment for none in row[5]
                    if subproduct == None:
                        subproduct = ''
                    else:
                        pass.
                    '''
                sort_format = [company, product, issue, complaint_id]
                complaint_list.append(sort_format)
                complaint_list.sort()
            # Look up cascade, plug in labels
            last_row = [None, None, None, None]
            complaint_list.append(last_row)
                # Complaint text to start
            complaint_text = str('\n'
                                 'Company\n'
                                 '----Product\n'
                                 '--------Issue\n'
                                 '------------ComplaintID\n')
            for formatted_complaint in complaint_list:
                if last_row[0] < formatted_complaint[0]:
                    complaint_text = ''.join([complaint_text,
                                             '\n',
                                             str(formatted_complaint[0]),
                                             '\n',
                                             '----',
                                             str(formatted_complaint[1]), 
                                             '\n',
                                             '--------',
                                             str(formatted_complaint[2]), 
                                             '\n',
                                             '------------',
                                             str(formatted_complaint[3]), 
                                             '\n'])
                else:
                    if last_row[1] < formatted_complaint[1]:
                        complaint_text = ''.join([complaint_text, 
                                         '----',
                                         str(formatted_complaint[1]), 
                                         '\n',
                                         '--------',
                                         str(formatted_complaint[2]), 
                                         '\n',
                                         '------------',
                                         str(formatted_complaint[3]), 
                                         '\n'])
                    else:
                        if last_row[2] < formatted_complaint[2]:
                            complaint_text = ''.join([complaint_text, 
                                             '--------',
                                             str(formatted_complaint
                                             [2]), 
                                             '\n',
                                             '------------',
                                             str(formatted_complaint
                                             [3]), 
                                             '\n'])
                        else:
                            if last_row[3] < formatted_complaint[3]:
                                complaint_text = ''.join([complaint_text, 
                                                 '------------',
                                                 str(formatted_complaint
                                                 [3]), 
                                                 '\n'])
                # Reset last row, so current row can be compared to it.
                last_row = formatted_complaint
            formatted_date = str(datetime.date.today().strftime('%A, %B %d'))
            header = ''.join(['From: ', sender_name, '<', sender_name, '>',
                              '\n',
                              'To: ', str(email_address), 
                              '<', str(email_address), '>',
                              '\n',
                              'Subject: New CFPB Complaints for',
                              ' ',
                              formatted_date])
            # CONNECT EMAIL
            message = ''.join([header, complaint_text])
            print 'Sending email to ' + str(email_address)
            server.sendmail(sender_name, str(email_address), message)
    # Rollback if error         
    except IOError:#TODOsqlite3.Error as err:
        conn.rollback()
        conn.close()
        raise Exception(''.join(['Error: ', err.args[0]]))
コード例 #11
0
ファイル: emailerlite.py プロジェクト: asharmalik/EmailerLite
def correct_email(email):
    email = email.replace(" ", "") #get rid of whitespace
    while email[-1:].isalpha() == False: #get rid of any trailing punctuation (non-alphabetic characters)
        email = email[:-1]
    return email
コード例 #12
0
ファイル: emailer.py プロジェクト: theonaunheim/derelict
def send():
    try:
        print 'Running daily email.'
        # Check for last run
        APP_DIR = os.path.dirname(os.path.realpath(__file__))
        # Not really appdir
        APP_DIR = os.path.dirname(APP_DIR)
        conn = sqlite3.connect(os.path.join(APP_DIR, 'data', 'local_cfpb.db'))
        cursor = conn.cursor()
        # Get last spool date
        try:
            cursor.execute('SELECT max(key) FROM log WHERE '
                           'event_type=\'Spool\'')
            last_spool_key = str(cursor.fetchone()[0])
            # Comma required at end of tuple to prevent unpacking
            cursor.execute('SELECT date from log WHERE key=?',
                           (last_spool_key, ))
            last_spool_date = str(cursor.fetchone()[0])
            print "Last spool " + last_spool_date
            # 2011-07-20 00:00:00.000001 to object
            last_spool_date = last_spool_date.replace('-', ':')
            last_spool_date = last_spool_date.replace(' ', ':')
            last_spool_date = last_spool_date.replace('.', ':')
            last_spool_date = last_spool_date.split(':')
            last_spool_date = map(lambda x: int(x), last_spool_date)
            # Make into list, expand list
            last_spool_object = datetime.datetime(*last_spool_date)
            now = datetime.datetime.now()
            if (last_spool_object.year, last_spool_object.month,
                    last_spool_object.day) == (now.year, now.month, now.day):
                # Short circuit spool
                print 'Last spool occurred today. No spool required.'
                return 0
        except (TypeError, IndexError, sqlite3.Error):
            # Index error means no spools have ever occured (possibly)
            pass
        # Convert requests to spooled emails.
        # For each item in 'requests' load into memory (list of lists)
        requests_in_memory = []
        with open(os.path.join(APP_DIR, 'data', 'requests.csv'), 'r') as f:
            lines = f.readlines()
            # Make a list of all emails
            all_emails = [line.split(',')[0] for line in lines]
            # remove quotations
            all_emails = [email.replace('\"', '') for email in all_emails]
            # Remove 'email' from csv heading
            all_emails.remove('Email')
            # Remove duplicates
            unique_emails = list(set(all_emails))
            # Move items to requests in memory.
            for line in lines:
                line = line.rstrip()
                req_email = line.split(',')[0].replace('\"', '')
                req_company = line.split(',')[1].replace('\"', '')
                req_product = line.split(',')[2].replace('\"', '')
                req_issue = line.split(',')[3].replace('\"', '')
                requests_in_memory.append(
                    [req_email, req_company, req_product, req_issue])

        # Main container
        #data_by_email = {key: [] for key in unique_emails}
        # Python 2.6.6 Compatability
        dict((key, []) for key in unique_emails)
        # New items that meet the conditions
        date_obj = datetime.datetime.now()  #DEBUG-datetime.timedelta(1)
        date_str = ''.join([
            str(date_obj.year), '-',
            str(date_obj.month).zfill(2), '-',
            str(date_obj.day).zfill(2)
        ])
        # Check each local_cfpb_db for each request in list for particular day
        complaints_in_memory = []
        for row in cursor.execute(
                'SELECT * FROM local_cfpb_db WHERE ' + 'pull_date=?',
            (date_str, )):
            complaints_in_memory.append(row)
        # complaints in memory / requests in memory / data by email
        # FOR EACH COMPLAINT FLIP THIS SO REQUEST THEN COMPLAINT
        for complaint in complaints_in_memory:
            #primary_key = row[0]
            com_product = complaint[1]
            #sub_product = row[2]
            com_company = complaint[3]
            #date_sent_to_company = row[4]
            #consumer_disputed = row[5]
            #date_received = row[6]
            com_complaint_id = complaint[7]
            #state = row[8]
            #timely_response = row[9]
            #submitted_via = row[10]
            com_issue = complaint[11]
            #company_response = row[12]
            #zip_code = row[13]
            last_pull = complaint[14]
            last_pull_year, dash, remainder = last_pull.partition('-')
            last_pull_month, dash, remainder = remainder.partition('-')
            last_pull_day, dash, remainder = remainder.partition('-')
            last_pull_year = int(last_pull_year)
            last_pull_month = int(last_pull_month)
            last_pull_day = int(last_pull_day)
            # If more than 3 days old, do not spool
            now_obj = datetime.datetime.now()
            last_pull_obj = datetime.datetime(last_pull_year, last_pull_month,
                                              last_pull_day)
            if (now_obj - datetime.timedelta(2)) > last_pull_obj:
                continue
            # FOR EACH COMPLAINT EACH REQUEST
            # Requests ['Email', 'Company', 'Product', 'Issue']
            # Remove first header request
            for request in requests_in_memory[1:]:
                if request[1] == com_company:
                    if request[2] == 'All' or request[2] == com_product:
                        if request[3] == 'All' or request[3] == com_issue:
                            print str('Spooling ' + str(com_complaint_id))
                            # request and to email dict
                            data_by_email[unicode(request[0])].append([\
                                com_company, com_product, com_issue,\
                                com_complaint_id])
        # Put into spool table
        cursor.execute('INSERT INTO log VALUES (NULL, ?, ?, ?)',
                       (str(datetime.datetime.now()), 'Spool',
                        'Spool date: ' + str(datetime.datetime.now())))

        conn.commit()
        conn.close()
    # Rollback if error
    except sqlite3.Error as err:
        conn.rollback()
        conn.close()
        raise Exception(''.join(['Error: ', err.args[0]]))
    print "Running daily send."
    # Load email settings from settings.txt
    username = notifier_settings.settings_dict['username']
    password = notifier_settings.settings_dict['password']
    outbound_server = notifier_settings.settings_dict['outbound_server']
    outbound_port = notifier_settings.settings_dict['outbound_port']
    sender_name = notifier_settings.settings_dict['sender_name']
    server = smtplib.SMTP()
    server.set_debuglevel(0)
    try:
        server.connect(str(outbound_server), int(outbound_port))
        server.starttls()
        server.ehlo()
        print "TLS handshake and login ..."
        server.login(username, password)
    except smtplib.SMTPConnectError as err:
        print "Did you setup email parameters in settings.txt?"
        raise Exception(err)
    try:
        conn = sqlite3.connect(os.path.join(APP_DIR, 'data', 'local_cfpb.db'))
        cursor = conn.cursor()
    except sqlite3.Error as err:
        conn.rollback()
        conn.close()
        raise Exception(''.join(['Error: ', err.args[0]]))
#########
    try:
        # {email:[4 element list],[4 element list]
        # For each email do the special sort.
        # Remove quotations
        for email_address in data_by_email.keys():
            email = email.replace('\"', '')
            # If no complaints in list, go to next
            if len(data_by_email[email]) == 0:
                continue
            complaint_list = []
            # Get list of lists for that email.
            orig_data = data_by_email[email_address]
            for complaint in orig_data:
                company = complaint[0]
                product = complaint[1]
                issue = complaint[2]
                complaint_id = complaint[3]
                if issue == None:
                    issue = ''
                    '''
                    # WHAT IS THIS? WHY IS THIS HERE? TODO
                    email = row[1].replace(u'\x85','\n')
                    complaint_id = row[2].replace(u'\x85','\n')
                    company = row[3].replace(u'\x85','\n')
                    product = row[4].replace(u'\x85','\n')
                    subproduct = subproduct.replace(u'\x85','\n')
                    frequency = row[6].replace(u'\x85','\n')
                    # adjustment for none in row[5]
                    if subproduct == None:
                        subproduct = ''
                    else:
                        pass.
                    '''
                sort_format = [company, product, issue, complaint_id]
                complaint_list.append(sort_format)
                complaint_list.sort()
            # Look up cascade, plug in labels
            last_row = [None, None, None, None]
            complaint_list.append(last_row)
            # Complaint text to start
            complaint_text = str('\n'
                                 'Company\n'
                                 '----Product\n'
                                 '--------Issue\n'
                                 '------------ComplaintID\n')
            for formatted_complaint in complaint_list:
                if last_row[0] < formatted_complaint[0]:
                    complaint_text = ''.join([
                        complaint_text, '\n',
                        str(formatted_complaint[0]), '\n', '----',
                        str(formatted_complaint[1]), '\n', '--------',
                        str(formatted_complaint[2]), '\n', '------------',
                        str(formatted_complaint[3]), '\n'
                    ])
                else:
                    if last_row[1] < formatted_complaint[1]:
                        complaint_text = ''.join([
                            complaint_text, '----',
                            str(formatted_complaint[1]), '\n', '--------',
                            str(formatted_complaint[2]), '\n', '------------',
                            str(formatted_complaint[3]), '\n'
                        ])
                    else:
                        if last_row[2] < formatted_complaint[2]:
                            complaint_text = ''.join([
                                complaint_text, '--------',
                                str(formatted_complaint[2]), '\n',
                                '------------',
                                str(formatted_complaint[3]), '\n'
                            ])
                        else:
                            if last_row[3] < formatted_complaint[3]:
                                complaint_text = ''.join([
                                    complaint_text, '------------',
                                    str(formatted_complaint[3]), '\n'
                                ])
                # Reset last row, so current row can be compared to it.
                last_row = formatted_complaint
            formatted_date = str(datetime.date.today().strftime('%A, %B %d'))
            header = ''.join([
                'From: ', sender_name, '<', sender_name, '>', '\n', 'To: ',
                str(email_address), '<',
                str(email_address), '>', '\n',
                'Subject: New CFPB Complaints for', ' ', formatted_date
            ])
            # CONNECT EMAIL
            message = ''.join([header, complaint_text])
            print 'Sending email to ' + str(email_address)
            server.sendmail(sender_name, str(email_address), message)
    # Rollback if error
    except IOError:  #TODOsqlite3.Error as err:
        conn.rollback()
        conn.close()
        raise Exception(''.join(['Error: ', err.args[0]]))
コード例 #13
0
tts = gTTS(text=" ok done", lang='en')
ttsname = ("od.mp3")

# In[7]:

tts = gTTS(text="speak your email address ", lang='en')
ttsname = ('email.mp3')

playsound.playsound("email.mp3")
playsound.playsound("speak.mp3")
r = sr.Recognizer()
with sr.Microphone() as source:
    audio = r.listen(source)
playsound.playsound("od.mp3")
email = r.recognize_google(audio)
email = email.replace(" ", "")
print(email)

# In[8]:

tts = gTTS(text="the email address entered by you is ::" + email, lang='en')
ttsname = ('myemail1.mp3')

playsound.playsound(ttsname)

# In[11]:

tts = gTTS(text="speak your password", lang='en')
ttsname = ('password.mp3')

playsound.playsound("password.mp3")
コード例 #14
0
 def process_mail_id(self, email):
     email = email.replace(">", '').split("<")
     if len(email) == 1 and email[0].strip():
         return email[0].strip()
     elif len(email) > 1 and email[0].strip():
         return email[1].strip()