optionparser is deprecated, use argumentparser instead

This commit is contained in:
Ronald Schaten 2013-04-03 22:49:53 +02:00
parent 6c358c5c1d
commit e452db9cc8

View File

@ -15,7 +15,7 @@ import urllib2
#import hn
import html2text
import ConfigParser
from optparse import OptionParser
from argparse import ArgumentParser
from cStringIO import StringIO
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
@ -243,25 +243,25 @@ if __name__ == '__main__':
#session.add(Feed('http://www.heise.de/newsticker/heise-atom.xml', 1, 0, 0, 1, 1))
#session.add(Feed('http://blog.schatenseite.de/feed/', 1, 0, 0, 1, 1))
parser = OptionParser()
parser.add_option("-f", "--fetch", action="store_true", dest="fetch", default=False, help="fetch all feeds")
parser.add_option("-s", "--single", action="store_true", dest="single", default=False, help="send single mails")
parser.add_option("-d", "--daily", action="store_true", dest="daily", default=False, help="send daily digest")
(options, args) = parser.parse_args()
parser = ArgumentParser(description='Fetch RSS- and Atom-feeds and send mails.')
parser.add_argument('-f', '--fetch', action='store_true', help='fetch all feeds')
parser.add_argument('-s', '--single', action='store_true', help='send single mails')
parser.add_argument('-d', '--daily', action='store_true', help='send daily digest')
args = parser.parse_args()
if options.fetch:
if args.fetch:
fetch_all_feeds(session)
if options.single:
if args.single:
sender = [config.get('email', 'sender_name'), config.get('email', 'sender_address')]
receiver = [config.get('email', 'receiver_name'), config.get('email', 'receiver_address')]
prefix = config.get('email', 'prefix_single')
mail_single_entries(session, sender, receiver, prefix)
if options.daily:
if args.daily:
sender = [config.get('email', 'sender_name'), config.get('email', 'sender_address')]
receiver = [config.get('email', 'receiver_name'), config.get('email', 'receiver_address')]
prefix = config.get('email', 'prefix_digest')
mail_daily_digest(session, sender, receiver, prefix)
if not (options.fetch or options.single or options.daily):
if not (args.fetch or args.single or args.daily):
parser.print_help()
session.commit()