Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
frnsys committed Jun 25, 2014
0 parents commit 93b83af
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.DS_Store
*.pyc
.sass-cache/
node_modules/
fontcustom/*
*.swp
*.log
config.py
*.rdb
.webassets-cache
bower/
index.css
config.py
6 changes: 6 additions & 0 deletions config-sample.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# You can get these by creating a new app at
# https://apps.twitter.com/
TWITTER_CONSUMER_KEY = 'fill_me_in'
TWITTER_CONSUMER_SECRET = 'fill_me_in'
TWITTER_ACCESS_TOKEN = 'fill_me_in'
TWITTER_ACCESS_SECRET = 'fill_me_in'
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# CLONES FOR EVERYBODY
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
tweepy==2.3.0
wsgiref==0.1.2
58 changes: 58 additions & 0 deletions twitter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import tweepy
from tweepy import TweepError

import config

def _api():
"""
Load auth info from config.
Setup things on Twitter's end at:
https://apps.twitter.com/
"""
auth = tweepy.OAuthHandler(config.TWITTER_CONSUMER_KEY, config.TWITTER_CONSUMER_SECRET)
auth.set_access_token(config.TWITTER_ACCESS_TOKEN, config.TWITTER_ACCESS_SECRET)

# Return API object.
return tweepy.API(auth)

api = _api()

def tweets(username, count=200):
"""
Returns 200 last tweets for a user.
"""
return [{
'body': tweet.text,
'tid': tweet.id,
'protected': tweet.user.protected,
'retweeted': tweet.retweeted
} for tweet in api.user_timeline(screen_name=username, count=count)]

def retweet(id):
"""
Retweet a tweet by id.
"""
try:
api.retweet(id)
except TweepError as err:
# Assume we may have violated some rate limit
# and forget about it
if '403' in err:
print('403 error when trying to retweet. Possibly hit a rate limit.')
else:
raise err


def tweet(text):
"""
Tweet something from your account.
"""
try:
api.update_status(text)
except TweepError as err:
# Assume we may have violated some rate limit
# and forget about it
if '403' in err:
logger.info('403 error when trying to tweet. Possibly hit a rate limit.')
else:
raise err

0 comments on commit 93b83af

Please sign in to comment.