Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions tweepy-bot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import logging
import time
from config import create_api

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger()


# making GET request to github API
def make_req():
def make_req(): # makes get request for issues and returns it
response = requests.get("https://api.github.com/search/issues?q=label:"
"hacktoberfest+is:issue+is:open&"
"sort=updated&order=desc")
Expand All @@ -19,44 +19,44 @@ def make_req():
prev_issues = []

# because I need to index a blank list later
for i in range(0, 30):
for i in range(0, 30): # add 30 blank indexes to previous issues
prev_issues.append("")


def humanize_url(url):
h_url = url[:8]+"github.com/"+url[29:]
def humanize_url(url): # reformat url
h_url = url[:8] + "github.com/" + url[29:]
return h_url


def tweet(api):
print("next call")
new_issues = make_req().json()['items']
new_issues = make_req().json()['items'] # stores new issues array into variable
current_issues = []
match = False
for i in range(0, len(new_issues)):
url = humanize_url(new_issues[i]["url"])
for j in range(0, len(prev_issues)):
for i in range(0, len(new_issues)): # checks for issues previously included within the last set
url = humanize_url(new_issues[i]["url"]) # gets usable url
for j in range(0, len(prev_issues)): # compares previous issues with the new issue using url
if prev_issues[j] == url:
match = True
# print("match is found for " + url + "in prev_issues array "
# "at position "+str(j))
if not match:
twt = new_issues[i]["title"] + "\n" + url
if not match: # if issue was not previously included, then tweet the new issue.
twt = new_issues[i]["title"] + "\n" + url # stores issue into string 'twt'
try:
api.update_status(status=twt)
except tweepy.TweepError as error:
if error.api_code == 187:
api.update_status(status=twt) # sends the tweet with variable 'twt'
except tweepy.TweepError as error: # catch error when tweeting
if error.api_code == 187: # assume error as duplicate message, then prints
# Do something special
print('duplicate message')
else:
raise error
print(i+1)
print(i + 1)
print(twt)
print("\n")

current_issues.append(url)
current_issues.append(url) # add the issue into current issues

for i in range(0, len(current_issues)):
for i in range(0, len(current_issues)): # replace previous issues with current issues
prev_issues[i] = current_issues[i]

# print("previous issues array")
Expand All @@ -66,14 +66,14 @@ def tweet(api):

def main():
api = create_api()
while True:
while True: # run tweet loop, runs every 30 seconds, indefinitely
tweet(api)
logger.info("Waiting...")
time.sleep(60)


if __name__ == "__main__":
main()
main() # run main method

# update the status
# api.update_status(status ="Happy hacktober Everyone!")