-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbio_search.py
90 lines (74 loc) · 3.36 KB
/
bio_search.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import tweepy
import secrets
import os
import string
import re
import fnmatch
auth = tweepy.OAuthHandler(secrets.consumer_key, secrets.consumer_secret)
auth.set_access_token(secrets.access_token, secrets.access_token_secret)
twitter_api = tweepy.API(auth)
# get the status from the stream, and get the user bio
# if the user bio has a social media account, grab that
# write that account to a file
class MyStreamListener(tweepy.StreamListener):
def on_status(self, status):
if status.user.description:
# print(status.user.description)
# f.write(no_emoji(status.user.description) + '\n')
find_social_accounts(no_emoji(status.user.description))
def on_error(self, status_code):
print(status_code)
def no_emoji(tweet):
tweet = list(filter(lambda x: x in string.printable, tweet))
new_string = ''.join(tweet)
return new_string.strip()
def get_filter():
topic = str(input("Topic to stream data from: "))
return topic
def find_social_accounts(bio):
with open('accounts.txt', 'a') as account_file:
words = bio.split(' ')
for word in words:
if fnmatch.fnmatch(str(word), 'ig?'):
print("Wrote an Instagram username to the file")
the_index = int(words.index(word))
if the_index + 1 < len(words):
# need a better way to handle cases with values found at the end of bio
if len(words[the_index + 1]) > 0:
account_file.write(
'Instagram account - ' + words[the_index + 1] + '\n')
if fnmatch.fnmatch(str(word), 'insta?'):
print("Wrote an Instagram username to the file")
the_index = int(words.index(word))
if the_index + 1 < len(words):
# need a better way to handle cases with values found at the end of bio
if len(words[the_index + 1]) > 0:
account_file.write(
'Instagram account - ' + words[the_index + 1] + '\n')
if fnmatch.fnmatch(str(word), 'sc?'):
print("Wrote a snapchat username to the file")
the_index = int(words.index(word))
if the_index + 1 < len(words):
# need a better way to handle cases with values found at the end of bio
if len(words[the_index + 1]) > 0:
account_file.write(
'Snapchat account - ' + words[the_index + 1] + '\n')
if fnmatch.fnmatch(str(word), 'snap?'):
print("Wrote a snapchat username to the file")
the_index = int(words.index(word))
if the_index + 1 < len(words):
# need a better way to handle cases with values found at the end of bio
if len(words[the_index + 1]) > 0:
account_file.write(
'Snapchat account - ' + words[the_index + 1] + '\n')
else:
continue
def main():
if os.path.isfile('accounts.txt'):
os.remove('accounts.txt')
myStreamListener = MyStreamListener()
myStream = tweepy.Stream(auth=twitter_api.auth, listener=myStreamListener)
myStream.filter(track=[get_filter()])
filter_bios()
if __name__ == '__main__':
main()