Skip to content

Instantly share code, notes, and snippets.

@LoveIsGrief
Last active June 28, 2019 13:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LoveIsGrief/f35adda68401410239bf to your computer and use it in GitHub Desktop.
Save LoveIsGrief/f35adda68401410239bf to your computer and use it in GitHub Desktop.
For people who use Reddit, the anonymous nature of the web site lends itself to people utilizing multiple accounts. The following script can be used to copy all subreddit subscriptions and friends from a source to a destination account. Note that this script requires a specific revision of the praw API in order to copy over friends lists due to …
# Created by .ignore support plugin (hsz.mobi)
### Python template
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# pyenv
.python-version
# celery beat schedule file
celerybeat-schedule
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
#!/usr/bin/env python3
# How to use
# 0. Install praw (virtualenv or whatever)
# 1. Put the connection params for your users in config.ini
# e.g
# [from]
# username = FromUser
# password = secret password
# client_id = 14 character password
# client_secret = 27 char secret
#
# [to]
# username = ToUser
# password = secret password
# client_id = 14 character password
# client_secret = 27 char secret
#
# 2. Run it !
# python copy_reddit.py
#
# Changelog
# 2017_02_02 - LoveIsGrief
# - Version up to 0.4
# - Use updated praw 6
# 2017_02_02 - LoveIsGrief
# - Version up to 0.3
# - Using reddit's OAuth (thanks praw)
# 2016_04_01 - LoveIsGrief
# - Version bun to 0.2
# - Multireddits supported
# - Friends functionality removed (Forever a stone)
#
# 2013 Sumit Khanna - PenguinDreams.org ( http://penguindreams.org/scripts/copy_reddit/ )
# - Version 0.1
from configparser import ConfigParser
import praw
print('\nCopy Reddit is a script for copying subreddit subscriptions and friends from')
print('Reddit account to another. -- Multiple authors\n')
user_agent = 'copy_reddit.py v0.3'
# Config must be in config.ini
config = ConfigParser()
config.read("config.ini")
if not config:
print("Bruh...where's your config?")
exit(1)
elif "from" not in config:
print("Mate, you you need somewhere to copy from..")
exit(1)
elif "to" not in config:
print("Buddy, where are you going to copy your stuff to?")
exit(1)
from_config = config["from"]
from_config["user_agent"] = user_agent
to_config = config["to"]
to_config["user_agent"] = user_agent
# Where to get shit from
from_reddit = praw.Reddit(**from_config)
from_user = from_reddit.user
# Where to put it
to_reddit = praw.Reddit(**to_config)
to_user = to_reddit.user
to_saved = {saved.id: saved for saved in to_user.me().saved(limit=None)}
print("\nCopying saves")
for saved in from_user.me().saved(limit=None):
if saved.id in to_saved:
saved.unsave()
continue
# Workaround to getting the submission using the other reddit instance
# And then saving it --> One call saved
saved._reddit = to_reddit
saved.save()
print("\tSaved '%s'" % saved.name)
# Unsave so that a rerun doesn't have to do all the work again
saved._reddit = from_reddit
saved.unsave()
from_subreddits = sorted([str(s) for s in from_user.subreddits(limit=None)], key=str.lower)
print("Subs on source %s:" % from_user.me())
for from_subreddit in from_subreddits:
print("\t %s" % from_subreddit)
# Split subs that are superfluous on target or already subscribed to
only_to_subreddits = []
for s in [str(s) for s in to_user.subreddits(limit=None)]:
if s in from_subreddits:
from_subreddits.remove(s)
else:
only_to_subreddits.append(s)
print("\nUnsubbing from subreddits on target %s that aren't on %s" % (to_user.me(), from_user.me()))
if len(only_to_subreddits) > 0:
for s in only_to_subreddits:
print("\t%s" % s)
input("Hit ^C to cancel")
first_subreddit = to_reddit.subreddit(only_to_subreddits.pop(0))
first_subreddit.unsubscribe(only_to_subreddits)
print("unsubbing done")
else:
print("subbed to everything necessary")
print('\nCopying subscriptions to %s:' % to_user.me())
if len(from_subreddits) > 0:
for multi_to_create in from_subreddits:
print("\t %s" % multi_to_create)
first_subreddit = to_reddit.subreddit(from_subreddits.pop(0))
first_subreddit.subscribe(from_subreddits)
print("subbing done")
else:
print("subbed to everything already")
print('\nCopying Multireddits')
from_multireddits = sorted([m for m in from_user.multireddits()], key=str)
to_multireddits = sorted([m for m in to_user.multireddits()], key=str)
to_multireddits_names = [m.display_name for m in to_multireddits]
to_multireddits_to_create = [from_m for from_m in from_multireddits if from_m.display_name not in to_multireddits_names]
if len(to_multireddits_to_create) > 0:
for multi_to_create in to_multireddits_to_create:
print("\t %s" % multi_to_create.display_name)
to_reddit.multireddit.create(multi_to_create.display_name, multi_to_create.subreddits,
description_md=multi_to_create.description_md,
visibility=multi_to_create.visibility,
)
print("It's done... it over")
else:
print("All multireddits are already belong to you")
praw==6.3.1
prawcore==1.0.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment