-
Notifications
You must be signed in to change notification settings - Fork 3
/
USStaffMama.py
216 lines (175 loc) · 7.45 KB
/
USStaffMama.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#!/usr/bin/python3
class color:
yellow = '\033[95m'
blue = '\033[94m'
green = '\033[92m'
red = '\033[91m'
end = '\033[0m'
import sys
import re
import requests
import json
import argparse, textwrap
import configparser
from bs4 import BeautifulSoup
""" Setup Argument Parameters """
parser = argparse.ArgumentParser(description='[INFO] Example: python3 USStaffMana.py -c telsa -e telsa.com -n 0', formatter_class=argparse.RawTextHelpFormatter)
requiredNamed = parser.add_argument_group('required named arguments')
requiredNamed.add_argument('-c', '--company', help='Company Name', required=True)
requiredNamed.add_argument('-e', '--email', help='Company Email Domain', required=True)
requiredNamed.add_argument('-n', '--naming', help= textwrap.dedent('''\
User Name Format:
\t[0] Auto (Hunter.io)
\t[1] FirstLast
\t[2] FirstMiddleLast
\t[3] FLast
\t[4] FirstL
\t[5] First.Last
\t[6] Last.First'''), required=True)
args = parser.parse_args()
""" API-KEY """
config = configparser.RawConfigParser()
config.read("USStaffMama.cfg")
api_key = config.get('API_KEYS', 'hunter_api')
def error():
print("[ERROR] Something went wrong!")
sys.exit()
def banner():
print
print(" __ ____________ __ __________ ___ ")
print(" / / / / ___/ ___// /_____ _/ __/ __/ |/ /___ _____ ___ ____ _ ")
print(" / / / /\__ \\\\__ \/ __/ __ `/ /_/ /_/ /|_/ / __ `/ __ `__ \/ __ `/ ")
print("/ /_/ /___/ /__/ / /_/ /_/ / __/ __/ / / / /_/ / / / / / / /_/ / ")
print("\____//____/____/\__/\__,_/_/ /_/ /_/ /_/\__,_/_/ /_/ /_/\__,_/ ")
print(" [bigb0ss] ")
print
print
# US Staff Search
def search(company, email, prefix):
csv = []
url = "https://bearsofficialsstore.com/company/%s/page1" % company
r = requests.get(url)
if r.status_code != 200:
print("[ERROR] 404 Error! The company name needs to be verified. Go to https://bearsofficialsstore.com/ and find the EXACT company name (e.g., t-mobile != t_mobile)")
sys.exit()
content = (r.text)
contentSoup = BeautifulSoup(content, 'html.parser')
# Finding the last page
for i in contentSoup.find_all('a'):
page = i.get('href')
match = re.search('page([0-9]*)', page)
if match == None:
lastPage = 1
lastPageNum = 2
print("[INFO] Total Pages: %s" % lastPage)
else:
lastPage = match.group()[4:]
lastPage = int(lastPage)
lastPageNum = lastPage + 1 # you know what python does for numbering
print("[INFO] Total Pages: %s" % lastPage)
for page in range(1, lastPageNum):
url = "https://bearsofficialsstore.com/company/%s/page%s" % (company, page)
print("[INFO] Fetching usernames: %s" % url)
r = requests.get(url)
content = (r.text)
contentSoup = BeautifulSoup(content, 'html.parser')
for j in contentSoup.find_all("img"):
if 'id="imgCompanyLogo"' in str(j):
# The Logo img tag is alt="" which breaks forloop
continue
else:
raw = j.get('alt').lower().split()
firstName = raw[0]
lastName = raw[1:]
name = firstName + " " + lastName[0]
fname = ""
mname = ""
lname = ""
if len(lastName) == 1:
fname = firstName
mname = '?'
lname = lastName[0]
elif len(lastName) == 2:
fname = firstName
mname = lastName[0]
lname = lastName[1]
elif len(lastName) >= 3:
fname = firstName
lname = lastName[0]
else:
fname = firstName
lname = '?'
fname = re.sub('[^A-Za-z]+', '', fname)
mname = re.sub('[^A-Za-z]+', '', mname)
lname = re.sub('[^A-Za-z]+', '', lname)
#print(fname, mname, lname)
if len(fname) == 0 or len(lname) == 0:
continue
# Username Scheme Generator
# [0] Auto (hunter.io)
# [1] FirstLast
if prefix == "1" or prefix == 'firstlast':
user = '{}{}'.format(fname, lname)
# [2] FirstMiddleLast
if prefix == "2" or prefix == 'fistmlast':
if len(mname) == 0:
user = '{}{}{}'.format(fname, mname, lname)
else:
user = '{}{}{}'.format(fname, mname[0], lname)
# [3] FLast
if prefix == "3" or prefix == 'flast':
user = '{}{}'.format(fname[0], lname)
# [4] FirstL
if prefix == "4" or prefix == 'firstl':
user = '{}{}'.format(fname, lname[0])
# [5] First.Last
if prefix == "5" or prefix == 'first.last':
user = '{}.{}'.format(fname, lname)
# [6] Last.First
if prefix == "6" or prefix == 'lastfirst':
user = '{}.{}'.format(lname, fname)
if prefix == 'fmlast':
if len(mname) == 0:
user = '{}{}{}'.format(fname[0], mname, lname)
else:
user = '{}{}{}'.format(fname[0], mname[0], lname)
# CSV
csv.append('"%s","%s","%s","%s"' % (fname, lname, name, user + "@" + email))
f = open('{}.csv'.format(company), 'w')
f.writelines('\n'.join(csv))
f.close()
if __name__ == '__main__':
banner()
company = args.company
company = company.lower()
email = args.email
email = email.lower()
if "." not in email:
print(color.red + "[ERROR] Incorrect Email Format." + color.end)
sys.exit()
prefix = args.naming
prefix = prefix.lower()
if prefix == "0":
# Hunter.io
print("[INFO] Hunter.io search...")
url_hunter = "https://api.hunter.io/v2/domain-search?domain=%s&api_key=%s" % (email, api_key)
r = requests.get(url_hunter)
if r.status_code != 200:
print("[ERROR] Something is wrong accessing Hunter.io")
sys.exit()
content = json.loads(r.text)
prefix = content['data']['pattern']
print("[INFO] %s" % prefix)
if prefix:
prefix = prefix.replace("{","").replace("}", "")
if prefix == "firstlast" or prefix == "firstmlast" or prefix == "flast" or prefix == "firstl" or prefix =="first" or prefix == "first.last" or prefix == "fmlast" or prefix == "lastfirst":
print("[INFO] Found %s Naming Scheme" % prefix)
else:
print(color.red + "[ERROR] Auto-search Failed. Select the user name format from the option." + color.end)
sys.exit()
else:
print(color.red + "[ERROR] Auto-search Failed. Select the user name format from the option." + color.end)
sys.exit()
# Scraping
search(company, email, prefix)
print("[INFO] US Staff Scrapping Done!")