implementing reset- and delete-functionality
This commit is contained in:
parent
103d7d4a28
commit
c84c465a14
49
atomstrom.py
49
atomstrom.py
@ -234,13 +234,54 @@ def fetch_all_feeds(session):
|
||||
fetch_single_feed(session, feed)
|
||||
print
|
||||
|
||||
def ask_ok(prompt, retries=4, complaint='Yes or no, please!'):
|
||||
while True:
|
||||
ok = raw_input(prompt)
|
||||
if ok in ('y', 'ye', 'yes'):
|
||||
return True
|
||||
if ok in ('n', 'no', 'nop', 'nope'):
|
||||
return False
|
||||
retries = retries - 1
|
||||
if retries < 0:
|
||||
return False
|
||||
print complaint
|
||||
|
||||
def delete_feed(session, feed_id):
|
||||
print 'deleting feed %d...' % feed_id
|
||||
# TODO implement delete
|
||||
feed = session.query(Feed).\
|
||||
filter(Feed.id == feed_id).\
|
||||
first()
|
||||
print feed
|
||||
if ask_ok('> Do you really want to delete feed %d? ' % feed_id):
|
||||
print 'deleting...'
|
||||
entries = session.query(Entry).\
|
||||
filter(Entry.feed_id == feed_id).\
|
||||
all()
|
||||
for entry in entries:
|
||||
session.delete(entry)
|
||||
feedinfo = session.query(Feedinfo).\
|
||||
filter(Feedinfo.feed_id == feed_id).\
|
||||
first()
|
||||
session.delete(feedinfo)
|
||||
session.delete(feed)
|
||||
print '... done.'
|
||||
|
||||
def reset_feed(session, feed_id):
|
||||
print 'resetting feed %d...' % feed_id
|
||||
# TODO implement reset
|
||||
feed = session.query(Feed).\
|
||||
filter(Feed.id == feed_id).\
|
||||
first()
|
||||
print feed
|
||||
if ask_ok('> Do you really want to reset feed %d? ' % feed_id):
|
||||
print 'resetting...'
|
||||
entries = session.query(Entry).\
|
||||
filter(Entry.feed_id == feed_id).\
|
||||
all()
|
||||
for entry in entries:
|
||||
session.delete(entry)
|
||||
feedinfo = session.query(Feedinfo).\
|
||||
filter(Feedinfo.feed_id == feed_id).\
|
||||
first()
|
||||
session.delete(feedinfo)
|
||||
print '... done.'
|
||||
|
||||
if __name__ == '__main__':
|
||||
if (sys.stdout.encoding is None):
|
||||
|
Loading…
Reference in New Issue
Block a user