-
Notifications
You must be signed in to change notification settings - Fork 0
/
twitterBot.py
39 lines (29 loc) · 994 Bytes
/
twitterBot.py
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
36
37
38
39
# Importing libraries
import random
import tweepy
# Open the APIKEYS.txt file for reading.
_file = open("APIKEYS.txt", "r")
# Read the line and split it by ',' and store it in keys list.
keys = _file.readline().split(",")
# Auth
auth = tweepy.OAuthHandler(keys[0], keys[1])
auth.set_access_token(keys[2], keys[3])
api = tweepy.API(auth)
# Always close the opened file when you are done with it.
_file.close()
# Openn the qoutes.txt file for reading
_file = open("quotes.txt", "r")
# Read the file line by line.
quotes = _file.readlines()
# Select random integer that starts from 0 and goes to length of quotes.
r = random.randint(0, len(quotes))
# If selected number is odd then select another number
while r % 2 != 0:
r = random.randint(0, len(quotes))
print(str(r))
# Combine the quote and writer name
quoteWithName = quotes[r] + " " + quotes[r+1]
# Tweet the combined string
api.update_status(quoteWithName)
# Always close the file when you are done with it.
_file.close()