Skip to content

Commit

Permalink
Base commit with simple script to tweet text and images
Browse files Browse the repository at this point in the history
  • Loading branch information
Juan Rossi committed Sep 1, 2015
1 parent e1e1032 commit f367e5a
Show file tree
Hide file tree
Showing 15 changed files with 96 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.pyc
.DS_Store
env/
4 changes: 2 additions & 2 deletions README.md
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.
32 changes: 32 additions & 0 deletions bot.py
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
Binary file added images/CMTQhcmXAAAbAK9.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/Cutest_pikachu_gif_ever.0.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/Maleficent.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/animalprint.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/mascara.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions images/mentions.py
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
Binary file added images/noescape.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/pachorra.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/papas.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CONSUMER_KEYS = ""
CONSUMER_SECRET = ""
ACCESS_TOKEN = ""
ACCESS_TOKEN_SECRET = ""
25 changes: 25 additions & 0 deletions tweets.py
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': '¯\_(ツ)_/¯'},
]
22 changes: 22 additions & 0 deletions twitterapi.py
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)

0 comments on commit f367e5a

Please sign in to comment.