reposter
reposter copied to clipboard
A framework to manage, monitor and deploy marketing in social-media by re-posting content from one place to the another.
REPOSTER
A framework to manage, monitor and deploy marketing in social-media by re-posting content from one place to the another.
- Motivation
- Features
- Installation
- Pre-Requisites
- Application Setup
- Docker Setup
- Native Setup
- Authentication Setup
- Usage
- Periodic-Posting
- Application Scheduling
- Crontab
- Advanced Setup
- Periodic-Posting
- Why?
Motivation
I wanted a setup that could be give me an entire control over content creation in a programmable automated way. With this framework, I can add as many as content retrievers and submitters as possible and create any kind of dynamic programmable workflow between them.
So for example, I could have reddit -> multiple facebook pages, twitter, instagram pages content submission, or tumblr, reddit, custom website -> Multiple facebook pages, twitter, etc. without really worrying about the underlying integration part.
Consider it like a free zapier across social media handle content management.

Features
- Declarative setup to control the submission of re-posts.
- Out of the box support for Reddit -> Facebook re-posts.
- Super simple API to add new social media handles for retrieval or submission of content.
- Super clean logging with logic to ensure duplicate posts don't get posted.
- Add support of many-to-many reposts for as many handles, pages you want.
- Like Reddit -> Facebook, Instagram, Twitter.
- Like Tumblr -> Facebook, Reddit, HackerNews.
- Reddit (multiple subreddits), Tumblr -> Facebook (Multiple Pages), Twiiter (Multiple Handles)
- Remember its just the boilerplate allowing you to come up with any kind of imagination of its use-cases and social media handles.
Installation
Pre-requisites
- Python3
- pip
- virtualenv
Application Setup
Docker Setup
- Run
docker-compose buildto build the docker-image.
- Additional notes:
- To run:
docker-compose upafter you're done with the authentication setup. - By default it runs an application scheduler: Application Scheduling
- You can make it run regular index setup by swapping line
CMD [ "python", "./schedule_index.py" ]inDockerfile-reposterwithCMD [ "python", "./index.py" ]
- To run:
Native Setup
- Clone the repository:
git clone github.com/slapbot/reposter - Cd into the directory:
cd reposter - Create a virtualenv for python:
python -m venv reposter-env - Activate the virtualenv:
- Linux:
source reposter-env/bin/activate - Windows:
source reposter-env/Scripts/activate
- Linux:
- Upgrade your pip to latest version:
pip install --upgrade pip - Install the application level dependencies:
pip install -r requirements.txt
Authentication Setup
- Create a Reddit bot and add in the credentials at: config.ini under
[REDDIT]section.allowed_domain: Enter the domains that you want to parse for content retrieval.
- Add in your page information at
config.inias a section like[STEPHANIE]shown in the example.- Next add in your credentials after creating an app at facebook.
- Fill in the
app_idandapp_secretfrom facebook console. - Fill in the
short_tokenwhich will act as user-access-token from Graph API Console- Ensure that you give it these permissions
email manage_pages pages_manage_cta pages_show_list publish_pages publish_to_groups public_profile
- Ensure that you give it these permissions
- Fill in the
- Next add in your credentials after creating an app at facebook.
- Write the workflow logic in declarative syntax of json at
information.jsonas follows:- There is already an example to showcase the working.
facebooktag encapsulates all of the information needed for Facebook workflow.Name: Name of the facebook page.page_id: ID of the facebook page.token: leave it blank for now.message: If you'd wanna write the message retrieved from the posts (from Reddit or any other content aggregator).
subredditstag allows you to mention the subreddits from where you'd wanna retrieve the posts from.
- Run
python facebook_perm_token.pyto get a permanent page access tokens for each page which will automatically be inserted ininformations.jsonfile. - Now you must be able to run
python index.pyto automate the process of re-posting from one social media handle to another.
Usage
class Reposter:
def __init__(self):
self.infoparser = infoparser
def main(self):
for job in self.infoparser.jobs:
try:
self.execute(job)
except Exception:
pass
def execute(self, job, tries=0, max_tries=5):
posts = self.get_posts(job.subreddits)
tries += 1
if not posts and tries < max_tries:
return self.execute(job, tries)
else:
self.submit_posts(job.facebook, posts)
@staticmethod
def get_posts(subreddits):
posts = []
for subreddit in subreddits:
pg = PostGetter(subreddit.name)
post = pg.get_any_post()
print("Got my post as %s from %s subreddit." % (post.url, subreddit.name))
posts.append(post)
return posts
@staticmethod
def submit_posts(social_media, posts):
ps = PostSubmitter(social_media.page_id, social_media.token, social_media.message)
for post in posts:
ps.submit_post(post)
print("Posted my post as %s for %s page." % (post.title, social_media.name))
Periodic Posting
Application Scheduling
- Go to
schedule_index.pyand add commands like:schedule.every(3).hours.do(run, r)to run every 3 hours.schedule.every(70).mins.do(run, r)to run every 70 minutes.
- Run
python schedule_index.pyinstead ofindex.py - The default added entry creates Facebook posts every 3 hours retrieved from Reddit.
Crontab
- Use a crontab to schedule your posts:
crontab -e - Add this entry
0 */3 * * * /<path-to-repository>/reposter/reposter-env/bin/python /<path-to-repository>/reposter/index.py >/dev/null 2>&1 - The above added entry creates Facebook posts every 3 hours retrieved from Reddit.
Advanced Setup
- Throughout the code you can abstract a lot of entries to the
information.jsonlike which posts to choose from Reddit (currently its the top rated one.) - Adding new social media handles for retrieval and submission is super easy:
- Create their own module and add the hooks at
information.json - Regulate their separate logic in a much more modular way.
- Create their own module and add the hooks at
Why?
Its one of the first pieces of software I wrote (back in 2017) when I was introduced to Python and wanted to manage social media handles of one of my Open Source Project - Stephanie which was programmed to make automated posts in its Facebook Page at Stephanie - Facebook Page.
More Pages using the program:
So in the process of checking out my previous project - I just thought to make it open-source for anyone to use.
Its super simply and doesn't require any fancy programming to get started with.