@NateTanner/

Twitter Scraper

Python

No description

fork
loading
Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import tweepy
import random
from time import sleep

conkey = "UX8VgZDIZbFhi3naYxyjrAvoz"
consec = "GbnlDR9XVfIriIplZWk4us0upLBw9dJPYQPTuhiEfi8hzuOcAk"
tokkey = "1087532499310399495-zyHIQURzNCq8mbsgR3yy0DWddKaxSR"
toksec = "Jdeys1oDWEIlOXW72kFGVaDhqhgpwEiGefWXLrKbOhBXj"
users = []
user = "BAHSTigers"
i = 0 
branchOut = False
foll = False
keywords = ["senior", "sarah"]
auth = tweepy.OAuthHandler(conkey, consec)  # Consumer Key, Consumer Secret
auth.set_access_token(tokkey, toksec)  # Token key, Token Secret
api = tweepy.API(auth)  # logs into @Natebot01
user = api.get_user(user)


print("Loading all needed items.")
sleep(random.randrange(1,5))
print("Loaded")
sleep(random.randrange(1, 3))
table = ", ".join(keywords)
print(f"Running command -search {table} with @BAHSTigers")
sleep(random.randrange(1, 3))
print(user)

def check(desc):
	for word in keywords:
		if word in desc:
			return True



while 1:
	try:
		lastFollower = False
		for follower in api.followers(user.id):
			i += 1 
			print(f"Checking user {follower.screen_name}")
			foll = follower
			if check(str.lower(follower.description)):
				print(f"Adding user to list {follower.name}")
				users.append((follower.screen_name, follower.id))
				user = follower
				branchOut = True
			ranNum = random.randrange(1,4)
			if ranNum == 3 and not follower.protected:
				lastFollower = follower
		if not lastFollower:
			user = foll
		else:
			user = lastFollower
		print(str(users))
		print(f"Searched {str(i)} users.")
		sleep(1)
		print(f"Running command -search senior with @{user.screen_name}")
	except tweepy.RateLimitError:
		print("Rate limit exceeded. Waiting 60 seconds before trying again.")
		sleep(60)