-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathname_checker.py
75 lines (70 loc) · 2.52 KB
/
name_checker.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
'''
File: name_checker.py
Author: Adam Pah
Description:
Checks name input against
'''
#Standard path imports
from __future__ import division, print_function
import argparse
from time import sleep
#Non-standard imports
from google import search
import pandas as pd
#Global directories and variables
def main(args):
#open the files
cfile = open('correct_names.csv', 'a')
ifile = open('incorrect_names.csv', 'a')
ufile = open('url_failures.csv', 'a')
#Trackers
tot_correct = 0
url_failure = 0
correct_names, incorrect_names = [], []
#Read in teh dataframe
df = pd.read_csv(args.infile)
#Iterate through faculty names
for name, email in df.loc[:, [args.name_column, args.email_column]].values:
correct = False
try:
#Try the name first
for url in search(name, stop = 5):
#Check to see if the check url is in one of the other urls
if args.check_url in url:
correct = True
break
#Do the email search if it isn't true yet
if correct != True:
sleep(3)
for url in search(email, stop = 5):
if args.check_url in url:
correct = True
break
#Do the addition if the check is true
if correct == True:
tot_correct += 1
print('%s,%s' % (name, email), file=cfile)
else:
print('%s,%s' % (name, email), file=ifile)
except:
url_failure += 1
print('%s,%s' % (name, email), file=ufile)
pass
#sleep it out
sleep(3)
#close all the files
cfile.close()
ifile.close()
ufile.close()
#Print it out
print('Total correct ', tot_correct)
print('number timed out ', url_failure)
print('Perc. correct ', tot_correct / df[args.email_column].count())
if __name__ == '__main__':
parser = argparse.ArgumentParser(description="")
parser.add_argument('infile', help = 'input result file')
parser.add_argument('check_url', help = 'edu url for the appropriate url')
parser.add_argument('-name_column', default = 'list_of_faculty_names_and_emails', help="column name of found faculty name")
parser.add_argument('-email_column', default = 'Email', help="column name of found faculty name")
args = parser.parse_args()
main(args)