-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathentries_scraper.py
70 lines (60 loc) · 2.29 KB
/
entries_scraper.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
from bs4 import BeautifulSoup
import urllib2
import requests
import re
import pickle
import helpers
import comp_res_references
from mechanize import Browser
# loads in pickle file with competitor results
competitors = {}
competition = raw_input("Please enter event id as found on in the url of the entries list:")
pf_in = open("comp_res_2018Mar12.p", "rb")
print "loading pickle file"
competitors = pickle.load(pf_in)
print "done loading"
# determines if competitor has placed out based on current level points and points in 2 levels above
def check_eligibility_pts(name, level, style, dance):
def pt_lookup(level):
try:
return helpers.get_points(competitors, name, level, style, dance)
except KeyError:
# There is no record of eligible ycn placement history in pickle file
return 0
l_index = comp_res_references.level_list.index(level)
curr_lvl_pts = pt_lookup(level)
return (curr_lvl_pts < 7, curr_lvl_pts)
# post request to see all entries of an event
def entries_post(competition):
br = Browser()
br.open("https://entries.o2cm.com/?event=" + competition)
br.select_form(name="webfilter")
br.submit()
soup = BeautifulSoup(br.response().read(), "html.parser")
entries = soup.find_all('td', {"class":["h5b", "h5n"]})
return entries
event = ""
level = ""
dances = []
style = ""
# goes through entries line by line
for post in entries_post(competition):
# determines whether it is a event title or competitor entry
names = post.find_all('a')
if len(names) != 0:
for name in names:
name_concat = name.text.replace(" ", "")
for dance in dances:
elig_true = check_eligibility_pts(name_concat, level, style, dance)
if not elig_true[0]:
print name_concat + " has placed out of " + event + " with " + str(elig_true[1]) + " points in " + level + " " + dance
#else:
#print name_concat + " is ok to dance " + event + " with " + str(elig_true[1]) + " points in " + level + " " + dance
else:
# updates current event info
event = post.text
level = helpers.get_level(event)
sty_dan = helpers.get_style_dances(event)
style = sty_dan[0]
dances = sty_dan[1]
pf_in.close()