Commit 5909def9 authored by Lysander Trischler's avatar Lysander Trischler

Add cache2txt utility

parent dcfef0fe
#!/usr/bin/python3
# encoding: utf-8
import argparse
import configparser
import shelve
import os.path
import xdg
parser = argparse.ArgumentParser(description="Extract twtxt.txt feed from cache")
parser.add_argument("-c", "--config-file",
metavar="FILE",
default=os.path.join(xdg.xdg_config_home(), "twtxt", "config"),
help="path to the config file to resolve nicks to URLs")
parser.add_argument("-f", "--cache-file",
metavar="FILE",
default=os.path.join(xdg.xdg_config_home(), "twtxt", "cache"),
help="path to the cache file")
parser.add_argument("nick_or_url",
metavar="NICK/URL",
help="nick or URL of the feed to extract")
args = parser.parse_args()
if args.cache_file.endswith(".db"):
args.cache_file = args.cache_file[:-3]
cache = shelve.open(args.cache_file)
if args.nick_or_url in cache:
feed = cache[args.nick_or_url]
else:
# we need to resolve the nick to an URL first
cfg = configparser.ConfigParser()
cfg.read(args.config_file)
url = cfg.get("following", args.nick_or_url, fallback=None)
if url is None:
parser.error("unknown nick/URL '%s'" % args.nick_or_url)
feed = cache[url]
for twt in feed['tweets']:
print(twt)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment