get_wiki.py 734 B

123456789101112131415161718192021222324
  1. import os
  2. from . import common
  3. from . import tsdb
  4. def get_wiki(subreddit):
  5. (database, subreddit) = tsdb.TSDB.for_subreddit(subreddit, fix_name=True)
  6. print('Getting wiki pages for /r/%s' % subreddit)
  7. subreddit = common.r.subreddit(subreddit)
  8. for wikipage in subreddit.wiki:
  9. if wikipage.name == 'config/stylesheet':
  10. continue
  11. wikipage_path = database.wiki_dir.join(wikipage.name).replace_extension('md')
  12. wikipage_path.parent.makedirs(exist_ok=True)
  13. with wikipage_path.open('w', encoding='utf-8') as handle:
  14. handle.write(wikipage.content_md)
  15. print('Wrote', wikipage_path.relative_path)
  16. def get_wiki_argparse(args):
  17. return get_wiki(args.subreddit)