Created
October 9, 2015 16:53
-
-
Save utgwkk/8ffa37b7da50fe28054a to your computer and use it in GitHub Desktop.
Posts a URL of the tweet you favorite to a Slack channel if it has a media.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tweepy | |
import requests | |
token = "" | |
slackURL = "https://slack.com/api/" | |
params = {'token': token, 'channel': '#random', 'text': '', 'as_user': 'true'} | |
CONSUMER_KEY = "" | |
CONSUMER_SECRET = "" | |
ACCESS_TOKEN = "" | |
ACCESS_TOKEN_SECRET = "" | |
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET) | |
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET) | |
api = tweepy.API(auth) | |
me = api.me().screen_name | |
def create_twitter_url(id_str, screen_name): | |
return "https://twitter.com/"+screen_name+"/status/"+id_str | |
class MyStream(tweepy.StreamListener): | |
def on_event(self, status): | |
if status.event == 'favorite' and status.source['screen_name'] == me and 'extended_entities' in status.target_object: | |
params['text'] = create_twitter_url(status.target_object['id_str'], status.target_object['user']['screen_name']) | |
r = requests.post(slackURL + "chat.postMessage", params=params) | |
if __name__ == '__main__': | |
stream = tweepy.Stream(auth, MyStream()) | |
stream.userstream() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment