-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 93b83af
Showing
5 changed files
with
80 additions
and
0 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,13 @@ | ||
.DS_Store | ||
*.pyc | ||
.sass-cache/ | ||
node_modules/ | ||
fontcustom/* | ||
*.swp | ||
*.log | ||
config.py | ||
*.rdb | ||
.webassets-cache | ||
bower/ | ||
index.css | ||
config.py |
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,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' |
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 @@ | ||
# CLONES FOR EVERYBODY |
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,2 @@ | ||
tweepy==2.3.0 | ||
wsgiref==0.1.2 |
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,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 |