Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys, time, tweepy
- auth = tweepy.OAuthHandler('YOUR CONSUMER KEY', 'YOUR CONSUMER SECRET')
- auth.set_access_token('YOUR ACCESS TOKEN', 'YOUR ACCESS TOKEN SECRET')
- api = tweepy.API(auth, retry_count=10, timeout=120, wait_on_rate_limit=True)
- def getFollowerCoordinates():
- print('\n---------- Get Coordinates of Followers ----------\n')
- while True:
- targetUser = input('Target User Handle or [R]eturn: @')
- if targetUser == 'Return' or targetUser == 'return' or targetUser == 'R' or targetUser == 'r':
- return None
- try:
- targetUser = api.get_user(targetUser)
- break
- except:
- print('User not found.')
- outputFileName = input('Output File Name: ')
- outputFile = open(outputFileName + '.txt', 'w', encoding='utf-8')
- outputFile.close()
- print()
- followerPageCount = 0
- for followerPage in tweepy.Cursor(api.followers, screen_name=targetUser.screen_name).pages():
- followerPageCount += 1
- #print('Currently on Follower Page ' + str(followerPageCount) + ' of ' + str(int(targetUser.followers_count / 20)) + ' for ' + targetUser.name + ' (@' + targetUser.screen_name + ').')
- for follower in followerPage:
- if follower.geo_enabled == True and follower.protected == False:
- tweetPageCount = 0
- hadCoords = False
- for tweetPage in tweepy.Cursor(api.user_timeline, screen_name=follower.screen_name, count=200).pages():
- tweetPageCount += 1
- #print('Currently on Tweet Page ' + str(tweetPageCount) + ' of ' + str(int(follower.statuses_count / 200)) + ' for ' + follower.name + ' (@' + follower.screen_name + ').')
- for tweet in tweetPage:
- if tweet.geo != None:
- if hadCoords == False:
- hadCoords = True
- outputFile = open(outputFileName + '.txt', 'at', encoding='utf-8')
- outputFile.write('-------------------------------------------------- ' + follower.name + '\'s (@' + follower.screen_name + ') Coordinates --------------------------------------------------\n')
- if follower.description != '':
- outputFile.write('Bio: ' + follower.description + '\n')
- if follower.location != '':
- outputFile.write('Location: ' + follower.location + '\n')
- if follower.url != None:
- outputFile.write('Website: ' + follower.url + '\n')
- outputFile.close()
- print('-------------------------------------------------- ' + follower.name + '\'s (@' + follower.screen_name + ') Coordinates --------------------------------------------------')
- if follower.description != '':
- print('Bio: ' + follower.description)
- if follower.location != '':
- print('Location: ' + follower.location)
- if follower.url != None:
- print('Website: ' + follower.url)
- coordString = tweet.geo
- outputFile = open(outputFileName + '.txt', 'at', encoding='utf-8')
- outputFile.write(str(coordString['coordinates']) + ' as of ' + str(tweet.created_at) + '\nReference: https://twitter.com/' + follower.screen_name + '/status/' + tweet.id_str + '\n')
- outputFile.close()
- print(str(coordString['coordinates']) + ' as of ' + str(tweet.created_at) + '\nReference: https://twitter.com/' + follower.screen_name + '/status/' + tweet.id_str)
- time.sleep(26)
- time.sleep(122)
- def getFollowingCoordinates():
- print('\n---------- Get Coordinates of Friends (Following) ----------\n')
- while True:
- targetUser = input('Target User Handle or [R]eturn: @')
- if targetUser == 'Return' or targetUser == 'return' or targetUser == 'R' or targetUser == 'r':
- return None
- try:
- targetUser = api.get_user(targetUser)
- break
- except:
- print('User not found.')
- outputFileName = input('Output File Name: ')
- outputFile = open(outputFileName + '.txt', 'w', encoding='utf-8')
- outputFile.close()
- print()
- friendPageCount = 0
- for friendsPage in tweepy.Cursor(api.friends, screen_name=targetUser.screen_name).pages():
- friendPageCount += 1
- #print('Currently on Following Page ' + str(friendsPageCount) + ' of ' + str(int(targetUser.friends_count / 20)) + ' for ' + targetUser.name + ' (@' + targetUser.screen_name + ').')
- for friend in friendsPage:
- if friend.geo_enabled == True and friend.protected == False:
- tweetPageCount = 0
- hadCoords = False
- for tweetPage in tweepy.Cursor(api.user_timeline, screen_name=friend.screen_name, count=200).pages():
- tweetPageCount += 1
- #print('Currently on Tweet Page ' + str(tweetPageCount) + ' of ' + str(int(friend.statuses_count / 200)) + ' for ' + friend.name + ' (@' + targetUser.screen_name + ').')
- for tweet in tweetPage:
- if tweet.geo != None:
- if hadCoords == False:
- hadCoords = True
- outputFile = open(outputFileName + '.txt', 'at', encoding='utf-8')
- outputFile.write('-------------------------------------------------- ' + friend.name + '\'s (@' + friend.screen_name + ') Coordinates --------------------------------------------------\n')
- if friend.description != '':
- outputFile.write('Bio: ' + friend.description)
- if friend.location != '':
- outputFile.write('Location: ' + friend.location)
- if friend.url != None:
- outputFile.write('Website: ' + friend.url)
- outputFile.close()
- print('-------------------------------------------------- ' + friend.name + '\'s (@' + friend.screen_name + ') Coordinates --------------------------------------------------')
- if friend.description != '':
- print('Bio: ' + friend.description)
- if friend.location != '':
- print('Location: ' + friend.location)
- if friend.url != None:
- print('Website: ' + friend.url)
- coordString = tweet.geo
- outputFile = open(outputFileName + '.txt', 'at', encoding='utf-8')
- outputFile.write(str(coordString['coordinates']) + ' as of ' + str(tweet.created_at) + '\nReference: https://twitter.com/' + friend.screen_name + '/status/' + tweet.id_str + '\n')
- outputFile.close()
- print(str(coordString['coordinates']) + ' as of ' + str(tweet.created_at) + '\nReference: https://twitter.com/' + friend.screen_name + '/status/' + tweet.id_str)
- time.sleep(26)
- time.sleep(122)
- while True:
- print('---------- Nuance\'s Twitter Menu ----------\n')
- print('1) Get Coordinates of Followers')
- print('2) Get Coordinates of Friends (Following)')
- print('3) Exit\n')
- menuChoice = input('> ')
- if menuChoice == '1':
- getFollowerCoordinates()
- print('\n')
- elif menuChoice == '2':
- getFollowingCoordinates()
- print('\n')
- elif menuChoice == '3':
- sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment