-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtweet.py
More file actions
35 lines (28 loc) · 824 Bytes
/
tweet.py
File metadata and controls
35 lines (28 loc) · 824 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import Twitter, tweepy
TWEET_LENGTH = 140
LOG_FILE = "past tweets.txt"
auth = Twitter.getAuth()
def tweetString(tweet):
tweet = stripTweet(tweet)
"""Takes a string and tweets it"""
if len(tweet) > TWEET_LENGTH:
print("Tweet length greater than", TWEET_LENGTH)
elif len(tweet) == 0:
print("Tweet length is 0")
else:
print("Tweeting:", tweet)
try:
api = tweepy.API(auth)
api.update_status(tweet)
logTweet(tweet)
except Exception as e:
print("Tweet failed")
print(str(e))
def stripTweet(tweet):
"""Removes @ symbols from tweets"""
return tweet.replace('@', '')
def logTweet(tweet):
"""Logs tweet to LOG_FILE"""
file = open(LOG_FILE, 'a')
file.write(tweet + "\n")
file.close()