(podcasts, server, user, password, to)
emails specified user when new podcasts are found
emails specified user when new podcasts are found
emails specified user when new podcasts are found
def email(podcasts, server, user, password, to):
    '''
    emails specified user when new podcasts are found
    '''
    body = ''
    for d in podcasts:
        name = list(d.keys())[0]
        if not d[name]:
            continue
        body += '<h2>{}</h2><br>'.format(name)
        for item in d[name]:
            body += '<b>{}</b><br>'.format(item['title'])
            body += 'Link: {}<br>'.format(item['link'])
    if not body:
        logging.debug('No new podcasts')
        return
    head = '<html><head></head><body>'
    body = head + body
    body += '</body></html>'
    msg = MIMEText(body, 'html')
    msg['Subject'] = 'New podcasts'
    msg['From'] = user
    msg['To'] = to
    s = smtplib.SMTP(server)
    s.starttls()
    logging.debug('Logging in to email server')
    s.login(user, password)
    logging.debug('Sending email')
    s.send_message(msg)
    logging.debug('Email sent')
    s.quit()
def email ( podcasts , server , user , password , to ) : body = '' for d in podcasts : name = list ( d . keys ( ) ) [ 0 ] if not d [ name ] : continue body += '<h2>{}</h2><br>' . format ( name ) for item in d [ name ] : body += '<b>{}</b><br>' . format ( item [ 'title' ] ) body += 'Link: {}<br>' . format ( item [ 'link' ] ) if not body : logging . debug ( 'No new podcasts' ) return head = '<html><head></head><body>' body = head + body body += '</body></html>' msg = MIMEText ( body , 'html' ) msg [ 'Subject' ] = 'New podcasts' msg [ 'From' ] = user msg [ 'To' ] = to s = smtplib . SMTP ( server ) s . starttls ( ) logging . debug ( 'Logging in to email server' ) s . login ( user , password ) logging . debug ( 'Sending email' ) s . send_message ( msg ) logging . debug ( 'Email sent' ) s . quit ( )