Skip to content

Commit

Permalink
streaming trump tweets on mattermost sandbox hook
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Aug 4, 2016
1 parent a73b4f5 commit e1dcd7e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
12 changes: 10 additions & 2 deletions App.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from tweepy.streaming import StreamListener
import simplejson as json
import configparser as ConfigParser
import urllib3

Config = ConfigParser.ConfigParser()
Config.read("conf/config")
Expand All @@ -11,11 +12,18 @@
c_secret = Config.get('twitter','CSecret')
a_token = Config.get('twitter','AToken')
a_secret = Config.get('twitter','ASecret')
hook = Config.get('mattermost','Hook')
avatar = 'http://i.imgur.com/RCKRF2B.png'

http = urllib3.PoolManager()

class listener(StreamListener):
def on_data(self, data):
data = json.loads(data)
print(data.get("text"))
print(data.get("text"))
payload = {'username' : 'Trump', 'icon_url' : avatar, 'text' : data.get("text")}
r = http.request('POST',hook ,headers={'Content-Type':'application/json'} ,body=json.dumps(payload))
print(r.read())
return True

def on_error(self, status):
Expand All @@ -24,4 +32,4 @@ def on_error(self, status):
auth = OAuthHandler(c_key, c_secret)
auth.set_access_token(a_token, a_secret)
twitterStream = Stream(auth, listener())
twitterStream.filter(follow=['760836832699359233'])
twitterStream.filter(follow=['25073877'])
3 changes: 3 additions & 0 deletions conf/template
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ CKey:
CSecret:
AToken:
ASecret:

[mattermost]
Hook:
Binary file added resources/trump.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e1dcd7e

Please sign in to comment.