intial commit

master
Benedikt Kristinsson 2 years ago
commit 1e678ff000
  1. 3
      .gitignore
  2. 12
      Pipfile
  3. 28
      README.md
  4. 35
      common.py
  5. 28
      run.py

3
.gitignore vendored

@ -0,0 +1,3 @@
.config
*~

@ -0,0 +1,12 @@
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true
[dev-packages]
[packages]
praw = "*"
[requires]
python_version = "3.7"

@ -0,0 +1,28 @@
# reddit-communities2
Some years ago I made [reddit-communities](https://github.com/benediktkr/reddit-communities) that looked at how subreddits were connected through the links on their sidebars.
Now I want to see how subreddits are connected based on where their users are active. That will be a lot more data, and this time I'll make a nicer presentatino. The data from the former project still exists, and could be presented in the same format. I hear theres nice JS plugins you can just plug the data into.
DISCLAIMER: This is purely a weekend/evening hack project.
## Current status
Looking at the crazy side of reddit:
```python
$ pipenv run python run.py --seed-subreddit the_donald
Checking where users from /r/the_donald also post...
[('The_Donald', 1734),
('worldpolitics', 51),
('Conservative', 35),
('Kanye', 23),
('PublicFreakout', 21),
('politics', 20),
('Full_news', 17),
('AskReddit', 13),
('hiphopheads', 12),
('funny', 12)]
```
More chill:

@ -0,0 +1,35 @@
#/usr/bin/env python3.7
import argparse
import json
import praw
POST_MODES = [ "hot"
, "new"
, "rising"
, "controversial"
, "top" ]
USER_AGENT = "github.com/benediktkr/reddit-communities2"
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("--post-limit", type=int, default=25)
return parser.parse_args()
def get_config(path=None):
if not path:
path = ".config"
with open(path, 'r') as f:
return json.loads(f.read())
def log_in():
config = get_config()
return praw.Reddit(client_id=config['id'],
client_secret=config['secret'],
password=config['pass'],
user_agent=USER_AGENT,
username=config['user'])

@ -0,0 +1,28 @@
#!/usr/bin/env python3.7
from pprint import pprint
from collections import Counter
import praw
from common import get_parser, log_in
subreddits = Counter()
if __name__ == "__main__":
args = get_parser()
reddit = log_in()
seed = reddit.subreddit(args.seed_subreddit)
also_post_in = list()
print(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)
for comment in user.comments.new():
also_post_in.append(comment.subreddit.name)
subreddits.update(also_post_in)
pprint(subreddits.most_common(10))
Loading…
Cancel
Save