-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
54 lines (46 loc) · 1.33 KB
/
bot.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import glob
import os
import random
import csv
import sys
import tweepy
from OAuthSettings import settings
CONSUMER_KEY = settings['consumer_key']
CONSUMER_SECRET = settings['consumer_secret']
ACCESS_KEY = settings['access_token_key']
ACCESS_SECRET = settings['access_token_secret']
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth)
def setList():
pictures = []
os.chdir("/Users/danny/documents/codingProjects/danTwitter")
for file in glob.glob("*.jpg"):
pictures.append(file)
return pictures
def setNames(pictures):
x = 0
pictureName = []
for pic in pictures:
pictureName.append(str(pictures[x]))
x = x + 1
return pictureName
def fixNames(pictureName):
for x in range(0,len(pictureName)):
pictureName[x] = pictureName[x].replace('_',' ')
temp = pictureName[x]
pictureName[x] = temp[:-4]
return pictureName
def generateTweet(pictureNames, pictures):
num = random.randint(0,(len(pictureNames) - 1))
tweet = str(pictureNames[num]) + " " + "#dan"
photo_path = str(pictures[num])
return tweet, photo_path
def main():
pictures = setList()
pictureName = setNames(pictures)
pictureName = fixNames(pictureName)
tweet, photo_path = generateTweet(pictureName, pictures)
api.update_with_media(photo_path, status=tweet)
if __name__ == '__main__':
main()