Twitterbot

Written on October 25, 2015

Simple Twitterbot used to quote Faulker.

Tweet.py

#import twitter
import random
import re
import linecache
	
def rewind_line():
	global random_line
	global offset
	
def find_cap(strg):
	if re.findall ("[A-Z]", strg):
		print "fart"
	
def find_period(strg):
	if '.' in strg:
		return True

def find_comma(strg):
	if ',' in strg:
		return True
		
def find_excla(strg):
	if '!' in strg:
		return True
		
def find_question(strg):
	if '?' in strg:
		return True
		
def find_mr(strg):
	if 'Mr.' in strg:
		return True
		
def find_mrs(strg):
	if 'Mrs.' in strg:
		return True
		
def find_dr(strg):
	if 'Dr.' in strg:
		return True

# create the first line of content

filesize = 43309                 #size of the really big file
offset = random.randrange(filesize)

text = open('text.txt')
random_line = linecache.getline("text.txt",offset)

print offset

while len(random_line) < 140:
        offset = offset + 1
        print offset
        random_line = random_line + linecache.getline("text.txt",offset)


# determine if there's punctuation in the new line

if find_period(random_line):
	print "Found period."
else:
	print "No period found."
	
tweet = random_line
print tweet

Tweet2.py

import twitter
import random 

# create two random numbers between -100/100

filesize = 43309                 #size of the really big file
offset = random.randrange(filesize)

text = open('text.txt')
text.seek(offset)                  #go to random position
text.readline()                    # discard - bound to be partial line
random_line = text.readline()      # bingo!

#print random_line
print offset

while len(random_line) < 140:
        offset = offset + 1
        print offset
        new_line = text.readline(offset)
        #print new_line
        random_line = new_line + random_line
        #print combination
        #print len(combination)


# format the Tweet nicely with spaces
tweet = random_line
print tweet

try:
	api = twitter.Api(
	consumer_key = 'xxx',
	consumer_secret = 'xxx',
	access_token_key = 'xxx',
	access_token_secret = 'xxx')
 
	status = api.PostUpdate(tweet)
	print '  post successful!'
 
except twitter.TwitterError:
	print 'error posting!'

Tweet3.py

#import twitter
import random
import re

offset = 0

def find_line():
	global random_line
	global offset
	if offset == 0:
		filesize = 43309
		offset = random.randrange(filesize)
		text = open('text.txt')
		text.seek(offset)                  # go to random position
		text.readline()                    # read from random position
		random_line = text.readline()      # place line into value
	else:
		text = open('text.txt')
		offset = offset - 1
		text.seek(offset)
		text.readline()
		random_line = text.readline()
	return random_line
	
def rewind_line():
	global random_line
	global offset
	
def find_cap(strg):
	if re.findall ("[A-Z]", strg):
		print "fart"
	
def find_period(strg):
	if '.' in strg:
		return True

def find_comma(strg):
	if ',' in strg:
		return True
		
def find_excla(strg):
	if '!' in strg:
		return True
		
def find_question(strg):
	if '?' in strg:
		return True
		
def find_mr(strg):
	if 'Mr.' in strg:
		return True
		
def find_mrs(strg):
	if 'Mrs.' in strg:
		return True
		
def find_dr(strg):
	if 'Dr.' in strg:
		return True

# create the first line of content
find_line()
new_line = random_line
if new_line < 140:
	while new_line < 140:
		find_line()
		new_line = new_line + random_line

# determine if there's punctuation in the new line

if find_period(new_line):
	print "Found period."
else:
	print "No period found."
	
# create the second line of content

#find_line()
#second_line = random_line

print new_line
#print second_line

#while len(random_line) < 140:
#        offset =+ offset + 1
#        random_line =+ text.readline(offset)

#tweet = first_line
#print tweet

#try:
#	api = twitter.Api(
#	consumer_key = 'xxx',
#	consumer_secret = 'xxx',
#	access_token_key = 'xxx',
#	access_token_secret = 'xxx')
 
#	status = api.PostUpdate(tweet)
#	print '  post successful!'
 
#except twitter.TwitterError:
#	print 'error posting!'

Take me home.

Check out the archive.