Skip to content

Commit

Permalink
Updated scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
RodolfoFerro committed Jun 5, 2017
1 parent 4a46d83 commit b89411e
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 15 deletions.
20 changes: 16 additions & 4 deletions Full/book_bot.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,36 @@
import tweepy
import tweepy, re, time
from access import *
from random import randint
import re, time

# Setup API:
def twitter_setup():
# Authenticate and access using keys:
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_SECRET)

# Return API access:
api = tweepy.API(auth)
return api

# Function to extract status (will return status for post):
def extract_status(path=None):
# No path => return "No book opened!"
if not path:
return "No book opened!"

# Try to search a sentence in book:
try:
# Open and read textbook:
with open(path, 'r', encoding='ascii', errors='surrogateescape') as book:
text = book.read()
# If successfuly read, search sentence:
if text:
return search_sentence(text)
except:
# Book not found:
return "Book not found!"

# Function to search a sentence in book:
def search_sentence(text):
# Initialize status:
status = 200
Expand All @@ -30,11 +41,12 @@ def search_sentence(text):
index = randint(0,len(text))
# print(status)

#
# Set indices of sentence:
init_index = text[index:].find('.') + index + 2
last_index = text[init_index:].find('.') + init_index + 2
status = len(text[init_index:last_index])

# Replace breaks w/spaces:
sentence = re.sub("\n", " ", text[init_index:last_index])
return sentence

Expand All @@ -55,7 +67,7 @@ def search_sentence(text):
# Try to post status:
try:
bot.update_status(status)
print("Done")
print("Successfully posted.")
except tweepy.TweepError as e:
print(e.reason)

Expand Down
25 changes: 14 additions & 11 deletions Full/list_bot.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import tweepy
import tweepy, time
from access import *
from random import randint
import re, time

# Setup API:
def twitter_setup():
# Authenticate and access using keys:
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_SECRET)

# Return API access:
api = tweepy.API(auth)
return api

Expand All @@ -14,24 +17,24 @@ def twitter_setup():
bot = twitter_setup()

# Set waiting time:
segs = 3
secs = 3

# Set wait time:
tweetlist = ["This is a #Python test for my @pythondaymx workshop. \n#PythonDayMX17",
"This is anoter automated tweet with #Python for my @pythondaymx workshop. \n#PythonDayMX17",
"Final automated tweet test for my @pythondaymx workshop. \n#PythonDayMX17"]
# Set tweet list:
tweetlist = ["Test tweet using #Python in @FerroRodolfo's workshop at the @pythondaymx \n#PythonDayMX17",
"Look, I'm using #Python at the @pythondaymx w/@FerroRodolfo to post this! \n#PythonDayMX17",
" \n#PythonDayMX17"]

# Eternal posting:
# Tweet posting:
for tweet in tweetlist:
# Extract status:
# Print tweet:
print(tweet)

# Try to post tweet:
try:
bot.update_status(tweet)
print("Done")
print("Successfully posted.")
except tweepy.TweepError as e:
print(e.reason)

# Wait till next sentence extraction:
time.sleep(segs)
time.sleep(secs)
57 changes: 57 additions & 0 deletions book_bot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import tweepy, re, time
from access import *
from random import randint

# Setup API:
# TODO

# Function to extract status (will return status for post):
def extract_status(path=None):
# No path => return "No book opened!"
# TODO

# Try to search a sentence in book:
try:
# Open and read textbook:
# TODO

# If successfuly read, search sentence:
# TODO
except:
# Book not found:
# TODO

# Function to search a sentence in book:
def search_sentence(text):
# Initialize status:
# TODO

# While we have a long or very short status:
while not (5 < status < 125):
# Generate a random number:
# TODO

# Set indices of sentence:
# TODO

# Replace breaks w/spaces:
# TODO


if __name__ == '__main__':
# Setup Twitter API:
# TODO

# Set waiting time:
segs = 3

# Eternal posting:
while True:
# Extract status:
# TODO

# Try to post status:
# TODO

# Wait till next sentence extraction:
time.sleep(segs)
34 changes: 34 additions & 0 deletions list_bot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import tweepy, time
from access import *
from random import randint

# Setup API:
def twitter_setup():
# Authenticate and access using keys:
# TODO

# Return API access:
# TODO

if __name__ == '__main__':
# Setup Twitter API:
# TODO

# Set waiting time:
secs = 3

# Set tweet list:
tweetlist = ["Test tweet using #Python in @FerroRodolfo's workshop at the @pythondaymx \n#PythonDayMX17",
" \n#PythonDayMX17",
" \n#PythonDayMX17"]

# Tweet posting:
for tweet in tweetlist:
# Print tweet:
print(tweet)

# Try to post tweet:
# TODO

# Wait till next sentence extraction:
time.sleep(secs)

0 comments on commit b89411e

Please sign in to comment.