Skip to content

Instantly share code, notes, and snippets.

@kirkegaard kirkegaard/
Last active Jul 31, 2018

What would you like to do?
Subscribe to multiple channels using Pusher and post to Discord
import requests
import pysher
import time
import json
appkey = '50ed18dd967b455393ed'
endpoint = '...'
auth = '...'
subscriptions = []
channels = {
123456789: [
987654321: [
class Subscription():
listener = None
channel = None
subreddit = None
def __init__(self, channel, subreddit): = channel
self.subreddit = subreddit
self.listener = pusher.subscribe(self.subreddit)
self.listener.bind('new-listing', self.handler)
print('Subscriping: {} : {}'.format(channel, subreddit))
def handler(self, data):
j = json.loads(data)
title = j['title']
subreddit = j['subreddit']
url = j['url']
msg = '[{}] **{}:** {}'.format(subreddit, title, url)
res =, json={'channel':, 'msg': msg}, headers={'Authorization': auth})
if res.status_code:
print('Posted: {}'.format(msg))
print('Failed to post')
pusher = pysher.Pusher(appkey)
def connect_handler(data):
for c in channels:
for s in channels[c]:
subscriptions.append(Subscription(c, s))
pusher.connection.bind('pusher:connection_established', connect_handler)
while True:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.