6384db75bf1bf8f18197b97e6468cd2dd064929b — Emil Oppeln-Bronikowski 1 year, 22 days ago bb4d098 master
Commands.
3 files changed, 37 insertions(+), 13 deletions(-)

M __main__.py
M collector.py
M feeds.py
M __main__.py => __main__.py +23 -11
@@ 3,17 3,29 @@ import sys
 import collector
 import exceptions
 
-for feed in collector.get_feeds():
+commands = ['add', 'remove', 'flush']
 
-    try:
-        feed = collector.parse_feed(feed)
-    except exceptions.FeedUrlError as e:
-        print("Failed to parse feed {} ({})".format(feed, e))
-        continue
+number_of_params = len(sys.argv)
 
-    try:
-        medias = collector.extract_media(feed)
-    except exceptions.NoEntriesError as e:
-        # empty feed?
-        pass
+if number_of_params == 1:
+    for feed in collector.get_feeds():
+        try:
+            feed = collector.parse_feed(feed)
+        except exceptions.FeedUrlError as e:
+            print("Failed to parse feed {} ({})".format(feed, e))
+            continue
 
+        try:
+            medias = collector.extract_media(feed)
+        except exceptions.NoEntriesError as e:
+            # empty feed?
+            pass
+
+    sys.exit(0)
+
+if number_of_params == 3:# and sys.argv[1] in commands:
+    command = getattr(collector.feeds, sys.argv[1])
+    command(sys.argv[2])
+    sys.exit(0)
+
+print("Mangled parameters")

M collector.py => collector.py +0 -1
@@ 47,7 47,6 @@ def extract_media(feed):
         for link in entry.links:
             if link['rel'] == 'enclosure' and link['type'].startswith('audio/'):
                 download_media(entry['id'], link['href'], entry['title'])
-        break
     feeds.last_seen(feed.href, feed.updated_parsed)
 
 def download_media(media_id, media_uri, title=None):

M feeds.py => feeds.py +14 -1
@@ 6,9 6,11 @@ subscribed_feeds = config.Feeds('feeds')
 def add(feed):
 
     if feed not in subscribed_feeds['podcasts']:
+        print("adding")
         subscribed_feeds['podcasts'][feed] = {'last_checked': None}
         subscribed_feeds.save()
         return True
+    print("already added")
 
 def remove(feed):
     del subscribed_feeds['podcasts'][feed]


@@ 19,4 21,15 @@ def last_seen(feed, dt=None):
         subscribed_feeds['podcasts'][feed]['last_checked'] = dt
         subscribed_feeds.save()
     else:
-        return time.struct_time(subscribed_feeds['podcasts'][feed]['last_checked'])
+        if subscribed_feeds['podcasts'][feed]['last_checked']:
+            return time.struct_time(subscribed_feeds['podcasts'][feed]['last_checked'])
+        return None
+
+def flush(feed):
+
+    if feed == 'all':
+        for feed in subscribed_feeds['podcasts'].keys():
+            subscribed_feeds['podcasts'][feed] = {'last_checked': None}
+    else:
+        bscribed_feeds['podcasts'][feed] = {'last_checked': None}
+    subscribed_feeds.save()