1
0
Fork 0
mirror of https://github.com/kemayo/leech synced 2025-12-07 17:05:25 +01:00

Command to flush the cache

This commit is contained in:
David Lynch 2016-03-18 08:46:25 -05:00
parent 04f1f6f4a9
commit 05c98f28db
2 changed files with 18 additions and 4 deletions

View file

@ -69,3 +69,9 @@ class Fetch:
c.execute("""REPLACE INTO cache VALUES (?, ?, CURRENT_TIMESTAMP)""", (url, value,))
self.store.commit()
c.close()
def flush(self, cachetime="-7 days"):
c = self.store.execute("""DELETE FROM cache WHERE time < datetime('now', ?)""", (cachetime,))
self.store.commit()
self.store.execute("""VACUUM""")
return c.rowcount

View file

@ -1,8 +1,7 @@
#!/usr/bin/env python
import argparse
import importlib
import os
import sys
import json
import sites
@ -88,11 +87,20 @@ def leech(url, filename=None, cache=True, args=None):
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('url', help="url of a story to fetch")
parser.add_argument('url', help="url of a story to fetch", nargs='?')
parser.add_argument('--filename', help="output filename (the title is used if this isn't provided)")
parser.add_argument('--no-cache', dest='cache', action='store_false')
parser.set_defaults(cache=True)
parser.add_argument('--flush', dest='flush', action='store_true')
parser.set_defaults(cache=True, flush=False)
args, extra_args = parser.parse_known_args()
if args.flush:
rows = fetch.flush()
print("Flushed cache of {} rows".format(rows))
sys.exit()
if not args.url:
sys.exit("URL is required")
filename = leech(args.url, filename=args.filename, cache=args.cache, args=extra_args)
print("File created:", filename)