Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import tweepy
def listgenfriends(friends, un,ul):
for friend in friends:
f2.write(un+','+friend.screen_name+'\n')
if friend.screen_name in ul:
f3.write(un+','+friend.screen_name+'\n')
else:
f4.write(un+','+friend.screen_name+'\n')
return True
def listgenfollowers(followers, un,ul):
for follower in followers:
f5.write(follower.screen_name+','+un+'\n')
if follower.screen_name in ul:
f6.write(follower.screen_name+','+un+'\n')
else:
f7.write(follower.screen_name+','+un+'\n')
return True
#[i for i in L1 if i in L2]
auth = tweepy.BasicAuthHandler("?????", "?????")
api = tweepy.API(auth)
f =open('hashtaggersIDs.txt')
f2=open('taggersfriends1.csv','w')
f3=open('taggersinnerfriends1.csv','w')
f4=open('taggersouterfriends1.csv','w')
f5=open('taggersfollowers1.csv','w')
f6=open('taggersinnerfollowers1.csv','w')
f7=open('taggersouterfollowers1.csv','w')
ul=[]
ul2=[]
fo2=[]
fr2=[]
for uid in f:
#print uid,
#user=api.get_user(uid)
#un=user.screen_name
#ul.append(un)
#uid=uid.strip()
ul.append(uid)
ul2.append(uid.strip())
for un in ul:
print un,
#user = tweepy.api.get_user(uid)
try:
for friend in api.friends_ids(un):
un=un.strip()
sfriend=str(friend)
f2.write(un+','+sfriend+'\n')
if sfriend in ul2:
f3.write(un+','+sfriend+'\n')
else:
f4.write(un+','+sfriend+'\n')
except tweepy.error.TweepError:
fr2.append(un)
print 'oops-friend '+un+'\n'
try:
for follower in api.followers_ids(un):
un=un.strip()
sfollower=str(follower)
f5.write(sfollower+','+un+'\n')
if sfollower in ul2:
f6.write(sfollower+','+un+'\n')
else:
f7.write(sfollower+','+un+'\n')
except tweepy.error.TweepError:
print 'oops-follow '+un+'\n'
fo2.append(un)
print "done pass 1\n"
print 'trying fails...\n'
for un in fr2:
print un,
#user = tweepy.api.get_user(uid)
try:
for friend in api.friends_ids(un):
un=un.strip()
sfriend=str(friend)
f2.write(un+','+sfriend+'\n')
if sfriend in ul2:
f3.write(un+','+sfriend+'\n')
else:
f4.write(un+','+sfriend+'\n')
except tweepy.error.TweepError:
fr.append(un)
print 'still oops-friend '+un+'\n'
for un in fo2:
print un,
#user = tweepy.api.get_user(uid)
try:
for follower in api.followers_ids(un):
un=un.strip()
sfollower=str(follower)
f5.write(sfollower+','+un+'\n')
if sfollower in ul2:
f6.write(sfollower+','+un+'\n')
else:
f7.write(sfollower+','+un+'\n')
except tweepy.error.TweepError:
print 'still oops-follow '+un+'\n'
f2.close()
f.close()
f3.close()
f4.close()
f5.close()
f6.close()
f7.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.