diff options
author | cedricbonhomme <devnull@localhost> | 2010-03-22 22:36:34 +0100 |
---|---|---|
committer | cedricbonhomme <devnull@localhost> | 2010-03-22 22:36:34 +0100 |
commit | 3aa4143dee58eb21d224ec69ce232612ddd38ce5 (patch) | |
tree | 3cbe18167b4bb73952f6d76ace0965e6cbeeb41f /utils.py | |
parent | The database of feeds is monitored with the Python gamin module. (diff) | |
download | newspipe-3aa4143dee58eb21d224ec69ce232612ddd38ce5.tar.gz newspipe-3aa4143dee58eb21d224ec69ce232612ddd38ce5.tar.bz2 newspipe-3aa4143dee58eb21d224ec69ce232612ddd38ce5.zip |
Added: email notification of new articles.
Diffstat (limited to 'utils.py')
-rwxr-xr-x[-rw-r--r--] | utils.py | 33 |
1 files changed, 31 insertions, 2 deletions
@@ -17,6 +17,9 @@ except: import sqlite3 import hashlib +import smtplib +from email.mime.text import MIMEText + from datetime import datetime from string import punctuation from collections import defaultdict @@ -33,6 +36,17 @@ except: import threading LOCKER = threading.Lock() +import os +import ConfigParser +config = ConfigParser.RawConfigParser() +config.read("./cfg/pyAggr3g470r.cfg") +path = config.get('global','path') +sqlite_base = os.path.abspath(config.get('global', 'sqlitebase')) +mail_from = config.get('mail','mail_from') +mail_to = config.get('mail','mail_to') +mail_smtp = config.get('mail','smtp') + + def detect_language(text): """ Detect the language of a text. @@ -114,6 +128,21 @@ def create_histogram(words, file_name="./var/histogram.png"): pylab.savefig(file_name, dpi = 80) pylab.close() +def send_mail(mfrom, mto, feed_title, message): + """Send the warning via mail + """ + mail = MIMEText(message) + mail['From'] = mfrom + mail['To'] = mto + mail['Subject'] = '[pyAggr3g470r] News from ' + feed_title + #email['Text'] = message + + server = smtplib.SMTP(mail_smtp) + server.sendmail(mfrom, \ + mto, \ + mail.as_string()) + server.quit() + def compare(stringtime1, stringtime2): """ Compare two dates in the format 'yyyy-mm-dd hh:mm:ss'. @@ -157,7 +186,7 @@ def load_feed(): # article_link, article_description, article_readed, # article_language) # feeds[feed_id] = (nb_article, nb_article_unreaded, feed_image, - # feed_title, feed_link, feed_site_link) + # feed_title, feed_link, feed_site_link, mail) articles, feeds = {}, {} if list_of_feeds != []: for feed in list_of_feeds: @@ -198,7 +227,7 @@ def load_feed(): feeds[feed_id] = (len(articles[feed_id]), \ len([article for article in articles[feed_id] \ if article[5]=="0"]), \ - feed[3], feed[0], feed[2], feed[1] \ + feed[3], feed[0], feed[2], feed[1] , feed[4]\ ) c.close() LOCKER.release() |