def update(sr_name): # Update past week's threads according to the current template r = Reddit('aaf_gamethread') ensure_scopes(r) gt = AAFGameThread(r, sr_name, ",".join(subreddits.keys())) gt.active_buffer = timedelta(days=7) active_games = gt.active_games() gt.update_existing(active_games)
def test_render(): # Render all past threads according to the current template gt = AAFGameThread(None, 'aafb_dev', ",".join(subreddits.keys())) gt.active_buffer = timedelta(days=180) active_games = gt.active_games() for game in active_games: title, body = gt.renderer.render_game(game, 'gamethread') with open(title + ".md", 'w') as fp: fp.write(body)
def redirect_game(sr_name, game_id, thread_type, thread_id): from pprint import pprint gt = AAFGameThread(None, sr_name, ",".join(subreddits.keys())) if game_id in gt.games: game = gt.games[game_id] pprint(game) print(repr(dir(game))) if thread_type in game.threads: if game.threads[thread_type] != thread_id: print("%s: %s -> %s" % (thread_type, game.threads[thread_type], thread_id)) game.threads[thread_type] = thread_id gt.games[game_id] = game else: print("Already correct")
def clean_cache(sr_name): # Remove references to threads that were deleted. House cleaning. r = Reddit('aaf_gamethread') ensure_scopes(r) gt = AAFGameThread(r, sr_name, ",".join(subreddits.keys())) for game_id in gt.games: game = gt.games[game_id] for thread_type in ('gamethread', 'post_gamethread'): if thread_type not in game.threads: continue if game.threads[thread_type] is None: del (game.threads[thread_type]) continue thread = r.submission(id=game.threads[thread_type]) if thread.author is None: del (game.threads[thread_type]) gt.games[game_id] = game
def main(): import sys import time r = Reddit('aaf_gamethread') ensure_scopes(r) gt = AAFGameThread(r, sys.argv[1], ",".join(subreddits.keys())) while True: gt.get_games() active_games = gt.active_games() gt.archive_completed(active_games) if len(active_games) > 0: gt.post_due_threads(active_games) gt.update_existing(active_games) sleep = gt.decide_sleep(active_games) time.sleep(sleep.total_seconds())