def sync(args): """ Implement the 'greg sync' command """ import operator session = c.Session(args) if "all" in args["names"]: allfeeds = session.list_feeds() # We want to check if a feed should be synced without actually # parsing it and all. The "bare" option in the Feed class is # a hacky solution that avoids a major rewrite. targetfeeds = [] for target in allfeeds: testfeed = c.Feed(session, target) if testfeed.shouldsync: targetfeeds.append(target) else: print("Skipping", target, end=".\n") else: targetfeeds = [] for name in args["names"]: if name not in session.feeds: print("You don't have a feed called {}.".format(name), file=sys.stderr, flush=True) else: targetfeeds.append(name) for target in targetfeeds: feed = c.Feed(session, target, None) if not feed.wentwrong: try: title = feed.podcast.target.title except AttributeError: title = target print("Checking", title, end="...\n") currentdate, stop = feed.how_many() entrycounter = 0 entries_to_download = feed.podcast.entries for entry in entries_to_download: feed.fix_linkdate(entry) # Sort entries_to_download, but only if you want to download as # many as there are if stop >= len(entries_to_download): entries_to_download.sort(key=operator.attrgetter("linkdate"), reverse=False) for entry in entries_to_download: if entry.linkdate > currentdate: downloaded = feed.download_entry(entry) entrycounter += downloaded if entrycounter >= stop: break print("Done") else: msg = ''.join([ "I cannot sync ", feed, " just now. Are you connected to the internet?" ]) print(msg, file=sys.stderr, flush=True)
def download(args): """ Implement the 'greg download' command """ session = c.Session(args) issues = aux.parse_for_download(args) if issues == ['']: sys.exit("You need to give a list of issues, of the form " "a, b-c, d..." "") dumpfilename = os.path.join(session.data_dir, 'feeddump') if not os.path.isfile(dumpfilename): sys.exit(("You need to run " "greg check" "<feed>" " before using " "greg download" ".")) with open(dumpfilename, mode='rb') as dumpfile: dump = pickle.load(dumpfile) try: feed = c.Feed(session, dump[0], dump[1]) except Exception: sys.exit(("... something went wrong." "Are you sure your last " "greg check" " went well?")) for number in issues: entry = dump[1].entries[eval(number)] feed.info = [] feed.entrylinks = [] feed.fix_linkdate(entry) feed.download_entry(entry)
def sync(args): """ Implement the 'greg sync' command """ import operator session = c.Session(args) if "all" in args["names"]: targetfeeds = session.list_feeds() else: targetfeeds = [] for name in args["names"]: if name not in session.feeds: print("You don't have a feed called {}.".format(name), file=sys.stderr, flush=True) else: targetfeeds.append(name) for target in targetfeeds: feed = c.Feed(session, target, None) if not feed.wentwrong: try: title = feed.podcast.target.title except AttributeError: title = target print("Checking", title, end="...\n") currentdate, stop = feed.how_many() entrycounter = 0 entries_to_download = feed.podcast.entries for entry in entries_to_download: feed.fix_linkdate(entry) # Sort entries_to_download, but only if you want to download as # many as there are if stop >= len(entries_to_download): entries_to_download.sort(key=operator.attrgetter("linkdate"), reverse=False) for entry in entries_to_download: if entry.linkdate > currentdate: downloaded = feed.download_entry(entry) entrycounter += downloaded if entrycounter >= stop: break print("Done") else: msg = ''.join( ["I cannot sync ", feed, " just now: ", feed.wentwrong]) print(msg, file=sys.stderr, flush=True)