|
import requests |
|
import time |
|
import random |
|
|
|
"""This script is used to get many posts from the desired subreddit(s)""" |
|
|
|
subreddit_list = [ |
|
"theredpillrebooted", |
|
"RedPillWomen", |
|
"Feminism", |
|
"marriedredpill", |
|
"TheBluePill", |
|
"PurplePillDebate", |
|
"RedPillWives", |
|
] |
|
|
|
url_template = "https://www.reddit.com/r/{}/.json?t=all{}" |
|
|
|
|
|
|
|
|
|
|
|
headers = {"User-Agent": "Testing Bot Gundam Wing"} |
|
|
|
|
|
|
|
params = "" |
|
|
|
original_counter = 100 |
|
counter = original_counter |
|
post_list = [] |
|
|
|
for subreddit in subreddit_list: |
|
while counter > 0: |
|
print(f"Getting posts with params: {params}") |
|
print("\n\n\n\n") |
|
url = url_template.format(subreddit, params) |
|
response = requests.get(url, headers=headers) |
|
|
|
if response.ok: |
|
data = response.json() |
|
|
|
|
|
|
|
posts = data["data"]["children"] |
|
print(f"Got {len(posts)} posts") |
|
for post in posts: |
|
|
|
pdata = post["data"] |
|
post_id = pdata["id"] |
|
title = pdata["title"] |
|
|
|
text = pdata.get("selftext") |
|
score = pdata["score"] |
|
author = pdata["author"] |
|
date = pdata["created_utc"] |
|
url = pdata.get("url_overridden_by_dest") |
|
print(f"{post_id}: {title} - {url}") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
post_list.append( |
|
[subreddit, post_id, title, text, url, score, author, date, pdata] |
|
) |
|
print(f"Got {len(posts)} posts") |
|
|
|
try: |
|
params = "&after=" + data["data"]["after"] |
|
except: |
|
print( |
|
"No more posts, broke on ", subreddit, "with counter at ", counter |
|
) |
|
break |
|
counter -= 1 |
|
time.sleep(random.randint(1, 30)) |
|
else: |
|
print(f"Error: {response.status_code}") |
|
counter = original_counter |
|
params = "" |
|
|