-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEoZTwitterBot.py
More file actions
265 lines (211 loc) · 7.01 KB
/
EoZTwitterBot.py
File metadata and controls
265 lines (211 loc) · 7.01 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
# EoZ TwitterBot
# Programmed by: ZenOokami
# Http://EssenceOfZen.org ||
#
"""
A Twitter Bot written in Python utilizing Tweepy
The general design is to eventually have threads running in the background.
"""
import os
import csv
import tweepy
from time import gmtime, strftime
import time
from EoZAIkeys import *
import LogSnoot
# Notes =====================
# How searching can work
#
# We could have multiple search functions based off of parent functions
# One of these mechanics can be "FavTweet" "FollowUser" etc. -- depending on this function, we can run the proper
# search function and when the array is returned, we'll execute the action accordingly
#
# The function in question should check its results item with checked items,
# If the no match is found, run fine - and add the tweet to the checked list after.
#
# At the start of the process, we should always check the current date, then run the function that manages/clean the
# stored data for checked tweets.
#
# Set up a CSV sheet for followers, following, and
# ============================
# Global Variables ==========
version = "v00.01.00"
todays_date = 0
processes_ran = 0
up_time = 0
search_tag_flag = 1
search_mention_flag = 1
checked_mention_tweets = []
checked_result_tweets = []
checked_authors = []
# ===========================
# Threads ===================
# We should have a thread for every automatic functionality we have:
def searchingMentionsThread(): # Search For Mentions every x amount of time
global search_mention_flag
global checked_tweets
while(True):
while(search_mention_flag):
time.sleep(60 * 30) # sleep for 30 minutes
pass
def searchingEoZTagThread(): # Search for #EoZ tags and possibly others
global checked_result_tweets
while(True):
while(search_tag_flag):
time.sleep(60 * 60) # sleep for 30 minutes
pass
# def something
# ===========================
# Functions =================
def authenticate(): # Authenticate the Connection
authentication = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
authentication.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
twitter_api = tweepy.API(authentication)
return tweepy.API(authentication)
def SendTweet(tweet):
# Authenticate the connection
# authentication = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
# authentication.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
# twitter_api = tweepy.API(authentication)
# Sending the tweet
try:
twitter_api.update_status(tweet)
LOG.writeI("Attempting to update status with: " + tweet)
except tweepy.TweepError as error:
LOG.writeE(error)
LOG.space()
else:
LOG.writeI("System Tweeted: " + tweet)
LOG.space()
print("")
def search(input): # A genuine search function
try:
results = twitter_api.search(input)
except tweepy.TweepError as error:
print(error)
else:
return results
def setTodaysDate():
global todays_date
today_year = time.strftime("%Y")
today_month = time.strftime("%m")
today_day = time.strftime("%d")
todays_date = [today_year, today_month, today_day]
def getTodaysDate():
global todays_date
return todays_date
def checkDates(current_day, previous_date):
# Current day will be an array: [0]=year, [1]=month, [2]=day
# Check year
if (int(current_day[0] > previous_date.year)):
# A new year
# if statement
pass
else:
# Same year, check for month
if (int(current_day[1]) > previous_date.month):
# a new month
# if statement
pass
else:
# Same month, check day
if (int(current_day[2]) > previous_date.day):
# a new day
pass
else:
# same day, either check ID or check
pass
def followUser(tweet):
tweet.author.follow();
def favoriteTweet(tweet):
tweet.favorite()
def retweetTweet(tweet):
tweet.retweet();
def compareTweetID(index, id): # Allows us to see if a current id is equal to a list of previously checked
global checked_tweets
# We can return a bool that allows us to check if the item has been checked already.
if (checked_tweets[index] == id):
return True
else:
return False
def compareAuthorID(index, id): #
global checked_authors
if (checked_authors[index] == id):
return True
else:
return False
# Search functions should contain a system of dates to check and compare to see if the results have already been seen
def searchForTags(tag): # returns an array
try:
results = twitter_api.search('#' + tag)
LOG.writeI("Searching for Hashtag: " + tag)
except tweepy.TweepError as error:
print(error)
LOG.writeE(error)
LOG.space()
else:
LOG.writeI("Search Completed, for: " + tag)
LOG.space()
return results
def searchForUser(user):
try:
user_list = twitter_api.search_users(user)
print("Searching for user: " + user)
LOG.writeI("Searching for the user: ")
except tweepy.TweepError as error:
print(error)
LOG.writeE(error)
LOG.space()
else:
LOG.writeI("Search Completed for, " + user)
LOG.space()
return user_list
def searchForMentions(mention):
try:
pass
except tweepy.TweepError as error:
pass
else:
pass
def menu():
# Tweet, search for hashtag, grab latest tweet from user, run a custom protocol
# print("|" + "|".rjust(20,'='))
print("|".ljust(44,"=") + "|")
print("|- Tweet [t]".ljust(44) + "|")
print("|- Search Hashtag [sh]".ljust(44)+"|")
print("|- Latest Tweet From User [lt]".ljust(44) + "|")
print("|- Run Custom Protocol [rcp]".ljust(44) + "|")
print("|".ljust(44) + "|")
print("|- Exit [e]".ljust(44) + "|")
print("|".ljust(44,"=")+"|")
print("|- EoZTweetBot " + version.ljust(29) + "|")
print("|".ljust(44,"=")+"|")
def main():
system = 1
while system == 1:
menu()
# Get user input
user_input = input("Command: ")
# Check the command
if (user_input.lower() == "tweet") or (user_input.lower() == "t"):
user_input = input("Please input tweet: ")
SendTweet(user_input)
print("")
elif (user_input.lower() == "search hashtag"):
pass
elif (user_input.lower() == "latest tweet from user"):
pass
elif (user_input.lower() == "Run Custom Protocol"):
pass
elif (user_input.lower() == "exit"):
# Turn off the loop
system = 0
else:
print("Invalid input")
# System off
LOG.close() # stop our snooper
print("Shutting down AI unit...")
# ======================================
LOG = LogSnoot.Snoop() # Start our snooper
twitter_api = authenticate() # Set our API
main() # Main function runs our main function for user input