figuring out that .name made http calls, and some logging

master
Benedikt Kristinsson 2 years ago
parent 3886e2be5d
commit 35b8a77864
  1. 3
      common.py
  2. 25
      run.py

@ -10,12 +10,13 @@ POST_MODES = [ "hot"
, "rising"
, "controversial"
, "top" ]
USER_AGENT = "github.com/benediktkr/reddit-communities2"
USER_AGENT = "python:github.com/benediktkr/reddit-communities2:v0.0.1 by /u/benediktkr"
def get_parser():
parser = argparse.ArgumentParser()
parser.add_argument("--seed-subreddit", required=True)
parser.add_argument("--subreddit-mode", choices=POST_MODES, default="hot")
parser.add_argument("--debug", action="store_true")
parser.add_argument("--post-limit", type=int, default=25)
return parser.parse_args()

@ -1,27 +1,42 @@
#!/usr/bin/env python3.7
from pprint import pprint
from collections import Counter
from pprint import pprint
from time import sleep
import logging
import praw
from common import get_parser, log_in
import logging
logging.basicConfig(format='%(asctime)s - %(name)s - %(message)s', level=logging.INFO)
subreddits = Counter()
if __name__ == "__main__":
args = get_parser()
if args.debug:
handler = logging.StreamHandler()
prawlogger = logging.getLogger('prawcore')
prawlogger.addHandler(handler)
prawlogger.setLevel(logging.DEBUG)
#logger.setLevel(logging.DEBUG)
reddit = log_in()
seed = reddit.subreddit(args.seed_subreddit)
also_post_in = list()
print(f"Checking where users from /r/{seed} also post...")
logging.info(f"Checking where users from /r/{seed} also post...")
for post in getattr(seed, args.subreddit_mode)(limit=args.post_limit):
user = reddit.redditor(post.author.name)
# logger question mark?
#print(post.author.name)
logging.info(f"Checking where /u/{post.author.name} posts..")
for comment in user.comments.new():
also_post_in.append(comment.subreddit.name)
# Looks like comment.subreddit.name isnt a simple attribute
# but is making http calls to reddit.com/r/subreddit/about
# each time
subreddit_name = str(comment.subreddit)
also_post_in.append(subreddit_name)
subreddits.update(also_post_in)

Loading…
Cancel
Save