Meet Bot, Don King

2 minute read | Updated:

xxxxxxxxxx
[Bot, Don King](https://github.com/tmthyjames/botdonking) is an automatic Reddit promoter. A while back I was experimenting with trying to optimize my Reddit upvotes and the following is what materialized.
The best way to get more upvotes is to post during peak hours, right? Well, it would be to difficult to try and post multiple subreddits when each subreddit has a different peak time. Enter this really cool [subreddit analysis tool](https://dashboard.laterforreddit.com/analysis/). 
If you go to that site and open up the Network tab in Chrome's Dev Tools, you'll notice that when you enter a subreddit name and click "Analyze Subreddit Traffic" it makes a `POST` request with a payload containing a few different parameters:

Bot, Don King is an automatic Reddit promoter. A while back I was experimenting with trying to optimize my Reddit upvotes and the following is what materialized.

The best way to get more upvotes is to post during peak hours, right? Well, it would be to difficult to try and post multiple subreddits when each subreddit has a different peak time. Enter this really cool subreddit analysis tool.

If you go to that site and open up the Network tab in Chrome's Dev Tools, you'll notice that when you enter a subreddit name and click "Analyze Subreddit Traffic" it makes a POST request with a payload containing a few different parameters:

In [ ]:
url = "https://dashboard.laterforreddit.com/graphql"
payload = {
    u'operationName': u'analysis',
    u'query': u'query analysis($subreddit: String!, $threshold: Int!, $tzid: String, $tzoffset: Int) {\n  subreddit_suggestions(subreddit: $subreddit) {\n    subreddit\n    weight\n    normalized_weight\n    __typename\n  }\n  analysis(subreddit: $subreddit, threshold: $threshold, timezone_id: $tzid, timezone_offset: $tzoffset) {\n    overall\n    daily {\n      count\n      labels\n      datasets {\n        data\n        __typename\n      }\n      __typename\n    }\n    hourly {\n      count\n      labels\n      datasets {\n        data\n        __typename\n      }\n      __typename\n    }\n    __typename\n  }\n}\n',
    u'variables': {
        u'subreddit': u'/'+subreddit+'',
        u'threshold': 5,
        u'tzid': u'America/Chicago',
        u'tzoffset': 300
    }
}
response = requests.request("POST", url, data=json.dumps(payload))
xxxxxxxxxx
You can see the rest of the source code [here](https://github.com/tmthyjames/botdonking/blob/master/botdonking.py#L40).
The returned JSON data will contain the optimal day and optimal hour. With this information you can schedule a job in python using this really handy [schedule](https://github.com/dbader/schedule) library.
After you have your posts queued up, you can use [this Reddit API Wrapper](https://praw.readthedocs.io/en/latest/).

You can see the rest of the source code here.

The returned JSON data will contain the optimal day and optimal hour. With this information you can schedule a job in python using this really handy schedule library.

After you have your posts queued up, you can use this Reddit API Wrapper.

xxxxxxxxxx
Here's an example:

Here's an example:

In [ ]:
urls_subreddits = {
    'http://www.yourblog.com/your-article': { # URL
        'title': 'Check out this article', # title of the article
        'subreddits': ['python', 'rstats'], #subreddit you want to post to
    },
    'http://www.yourblog.com/your-other-article': { # repeat n times
        'title': 'this is still a test',
        'subreddits': ['pystats', 'datascience', 'statistics'],
    }
}
dk = DonKing(urls_subreddits)
dk.queue_articles()
dk.promote()
The `urls_subreddits` object contains your URL, title, and the subreddits (can post in multiple) you want to post in. 
`dk.queue_articles()` will find the peak day/hour for each subreddit and queue the article up to be posted.
`dk.promote()` will actually post your article to the subreddits you specified.
Enjoy!

The urls_subreddits object contains your URL, title, and the subreddits (can post in multiple) you want to post in.

dk.queue_articles() will find the peak day/hour for each subreddit and queue the article up to be posted.

dk.promote() will actually post your article to the subreddits you specified.

Enjoy!