-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Base commit with simple script to tweet text and images
- Loading branch information
Juan Rossi
committed
Sep 1, 2015
1 parent
e1e1032
commit f367e5a
Showing
15 changed files
with
96 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
*.pyc | ||
.DS_Store | ||
env/ |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
# abadbot | ||
Simple "bot" for @abad | ||
# A bad bot | ||
Simple script to tweet to the account @abadbot. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# -*- coding: utf-8 -*- | ||
import random | ||
|
||
from twitterapi import TwitterAPI | ||
from tweets import tweets | ||
|
||
twitter = TwitterAPI() | ||
last_tweets = twitter.timeline('abadbot', 5) | ||
|
||
|
||
def get_random_tweet(): | ||
return random.choice(tweets) | ||
|
||
|
||
def get_new_tweet(): | ||
new_tweet = get_random_tweet() | ||
for tweet in last_tweets: | ||
# Check if this was posted in one of the last | ||
# 5 tweets | ||
if new_tweet.get('text', '') in tweet.text: | ||
return get_new_tweet() | ||
return new_tweet | ||
|
||
|
||
if __name__ == "__main__": | ||
new_tweet = get_new_tweet() | ||
if new_tweet.get('type') == 'text': | ||
twitter.tweet_text(new_tweet.get('text')) | ||
elif new_tweet.get('type') == 'image': | ||
twitter.tweet_image(new_tweet.get('image'), new_tweet.get('text')) | ||
|
||
print new_tweet |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# -*- coding: utf-8 -*- | ||
from twitterapi import TwitterAPI | ||
|
||
twitter = TwitterAPI() | ||
search = twitter.search('@abad') | ||
|
||
for tweet in search: | ||
print tweet.text |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
CONSUMER_KEYS = "" | ||
CONSUMER_SECRET = "" | ||
ACCESS_TOKEN = "" | ||
ACCESS_TOKEN_SECRET = "" |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
tweets = [ | ||
{'type': 'text', 'text': 'Un chirlo no es violencia'}, | ||
{'type': 'text', 'text': 'Are you watching closely?'}, | ||
{'type': 'text', 'text': 'Una novia que me traiga Mc a la cama'}, | ||
{'type': 'text', 'text': '( •—• ) Tadashi is here'}, | ||
{'type': 'image', 'text': 'Mi fantasia sexual', 'image': 'papas.jpg'}, | ||
{'type': 'image', 'text': 'Hoy se sale fuerte', 'image': 'pachorra.jpg'}, | ||
{'type': 'text', 'text': 'Necesito ropa negra'}, | ||
{'type': 'text', 'text': 'XXXXX, que no había cerrado ese antro?'}, | ||
{'type': 'text', 'text': 'OUR WORK IS NEVER OVER'}, | ||
{'type': 'text', 'text': 'Not my fucking tempo'}, | ||
{'type': 'text', 'text': 'Cuando me cierran el Mac en la cara https://vine.co/v/edzBEY1ajUa'}, | ||
{'type': 'text', 'text': 'Every magic trick consists of three parts'}, | ||
{'type': 'text', 'text': 'https://www.youtube.com/watch?v=uQ0ODCMC6xs'}, | ||
{'type': 'text', 'text': 'Son un publico horrible'}, | ||
{'type': 'image', 'text': 'Todo lo que esta mal en este mundo', 'image': 'animalprint.jpg'}, | ||
{'type': 'text', 'text': 'No me preguntes, solo soy una chica, jiji'}, | ||
{'type': 'text', 'text': 'Madurar? Eso es para las frutas'}, | ||
{'type': 'image', 'image': 'noescape.gif'}, | ||
{'type': 'text', 'text': 'Under my umbrella-ella-ella-eh eh eh eh eh https://www.youtube.com/watch?v=CvBfHwUxHIk'}, | ||
{'type': 'text', 'text': 'Una novia que se vista bien'}, | ||
{'type': 'text', 'text': 'ABAD ROMANCE'}, | ||
# {'type': 'text', 'text': 'Era un chiste y quedo '}, | ||
{'type': 'text', 'text': '¯\_(ツ)_/¯'}, | ||
] |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import tweepy | ||
import settings | ||
|
||
|
||
class TwitterAPI: | ||
"""Base class to wrap tweepy methods""" | ||
def __init__(self): | ||
auth = tweepy.OAuthHandler(settings.CONSUMER_KEYS, settings.CONSUMER_SECRET) | ||
auth.set_access_token(settings.ACCESS_TOKEN, settings.ACCESS_TOKEN_SECRET) | ||
self.api = tweepy.API(auth) | ||
|
||
def tweet_text(self, message): | ||
self.api.update_status(status=message) | ||
|
||
def tweet_image(self, filename, status=''): | ||
self.api.update_with_media('images/{}'.format(filename), status) | ||
|
||
def timeline(self, user, count=5): | ||
return self.api.user_timeline(screen_name=user, count=count) | ||
|
||
def search(self, q, limit=50): | ||
return self.api.search(q, rpp=limit) |