Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
270 views
in Technique[技术] by (71.8m points)

google chrome - Is there a way to bulk subscribe to all subreddits in a particular list programmatically (there is no built-in way to do this)

Currently the list is return-separated and " (break)" separated as well, but of course it could be in any other format such as csv. or whatever.

Hoping someone here could help me. I scoured google to try and find a solution but couldn't for the life of me, I must be missing something in my search! I'm surprised that nobody else would like this functionality.

question from:https://stackoverflow.com/questions/65545870/is-there-a-way-to-bulk-subscribe-to-all-subreddits-in-a-particular-list-programm

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

here is a naive solution with praw, it assumes you have a text file containing the subreddits you wish to subscribe to and a custom application added to your reddit account:

import praw

reddit = praw.Reddit(
    user_agent="mass sub",

    # visit https://old.reddit.com/prefs/apps/ to add a new script
    # choose http://localhost:8080 as a random and unused callback url 

    client_id="",
    client_secret="",
    username="",
    password=""
)

# for each in list of subreddits call this
file1 = open('./some_txt_file_of_subreddits', 'r')

Lines = file1.readlines()

for line in Lines:
    print("Line: {}".format(line.strip()))
    reddit.subreddit(line.strip()).subscribe()

it is naive because there is probably a method to do this much more efficiently

if you need to generate a list of subreddits from an existing account you can use this bookmarklet

The bookmarklet script below should be run on https://www.reddit.com/subreddits/mine/

javascript:$('body').replaceWith('<body>'+$('.subscription-box').find('li').find('a.title').map((_, d) => $(d).text()).get().join("<br>")+'</body>');javascript.void()

where the output can be saved to a text file


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...