Created
February 21, 2013 19:10
-
-
Save pavgup/5007234 to your computer and use it in GitHub Desktop.
This is a simple tool that uses two twitter accounts to tweet to each other about something interesting. The data provided must meet certain characteristics (ask me if you have questions) and you need to fill in the appropriate key details, but it should work quite simply.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import twitter | |
| import csv | |
| import string | |
| import time | |
| import random | |
| import sys | |
| pavan = twitter.Api(consumer_key='<REMOVED>',consumer_secret='<REMOVED>',access_token_key='<REMOVED>',access_token_secret='<REMOVED>') | |
| fark = twitter.Api(consumer_key='<REMOVED>',consumer_secret='<REMOVED>',access_token_key='<REMOVED>',access_token_secret='<REMOVED>') | |
| #fark.PostUpdate("I'm an automated robot! Hi @pav_gup!") | |
| #pavan.PostUpdate("Hello, @FurrukhMemon!") | |
| with open('tweetsActing','r') as source: | |
| data = [ (random.random(), line) for line in source ] | |
| data.sort() | |
| with open('tweetsActing','w') as target: | |
| for _, line in data: | |
| target.write( line ) | |
| rawData = csv.reader(open('tweetsActing','rb'),delimiter='|') | |
| with open('tweetsActing','r') as source: | |
| data = source.readlines() | |
| skipTime = 2 | |
| for row in rawData: | |
| if row[0] == "fromFarks": | |
| test = string.strip(row[1]) | |
| print test | |
| #print "skipping" | |
| try: | |
| fark.PostUpdate(string.strip(row[1])) | |
| except Exception, e: | |
| print e | |
| with open('tweetsActingSkipped','a') as target: | |
| target.write(data[0]) | |
| print "caught a twitter error in the fromFarks block; dropping in exception queue; skipTime is ",skipTime | |
| skipTime = skipTime*2 | |
| if skipTime > 240: | |
| skipTime = 240; | |
| pass | |
| else: | |
| with open('tweetsActingComplete','a') as target: | |
| target.write(data[0]) | |
| skipTime = 2; | |
| data.pop(0) | |
| with open('tweetsActing','w') as target: | |
| for item in data: | |
| target.write("%s" % item) | |
| time.sleep(skipTime) | |
| elif row[0] == "fromPavan": | |
| test = string.strip(row[1]) | |
| print test | |
| #print "skipping" | |
| try: | |
| pavan.PostUpdate(string.strip(row[1])) | |
| except Exception, e: | |
| print e | |
| with open('tweetsActingSkipped','a') as target: | |
| target.write(data[0]) | |
| print "caught a twitter error in the fromPavan block; dropping in exception queue; skipTime is ",skipTime | |
| skipTime = skipTime*2 | |
| if skipTime > 240: | |
| skipTime = 240; | |
| pass | |
| else: | |
| with open('tweetsActingComplete','a') as target: | |
| target.write(data[0]) | |
| skipTime = 2 | |
| data.pop(0) | |
| with open('tweetsActing','w') as target: | |
| for item in data: | |
| target.write("%s" % item) | |
| time.sleep(skipTime) | |
| else: | |
| print "Skipped a line of data and wrote", data[0] | |
| with open('tweetsActingSkipped','a') as target: | |
| target.write(data[0]) | |
| data.pop(0) | |
| with open('tweetsActing','w') as target: | |
| for item in data: | |
| target.write("%s" % item) | |
| sys.stdout.flush() |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Oh. One more thing. This hammers twitter. You should really try to use this very carefully.