-
Notifications
You must be signed in to change notification settings - Fork 0
/
bball_class.py
87 lines (68 loc) · 2.18 KB
/
bball_class.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
from csv import reader
from bs4 import BeautifulSoup
import requests
class BasketballIndex():
def __init__(self, link):
self.link = link
def page_parser(self, url):
link = self.link + ''.join(url)
page = requests.get(link)
soup = BeautifulSoup(page.text, "html.parser")
return soup
def make_list(self, file):
player_list = []
with open(file) as f:
csv_reader = reader(f)
for row in csv_reader:
player_list.append(row)
return player_list
def player_college_team(self, url):
soup = self.page_parser(url)
item_type = soup.find(itemtype="https://schema.org/Person")
a_tags = []
for p in item_type.find_all("a"):
if 'colleges' in p['href']:
a_tags.append(p.get_text())
if len(a_tags) > 1:
return ' & the '.join(a_tags)
elif len(a_tags) == 0:
return "did not go to college"
else:
return ''.join(a_tags)
def player_nba_team(self, url):
soup = self.page_parser(url)
item_type = soup.find(itemtype="https://schema.org/Person")
a_tags = []
for p in item_type.find_all("a"):
if 'teams' in p['href']:
a_tags.append(p.get_text())
if len(a_tags) > 1:
return ' & the '.join(a_tags)
elif len(a_tags) == 0:
return "no team currently"
else:
return ''.join(a_tags)
def player_height(self, url):
soup = self.page_parser(url)
item_type = soup.find(itemtype="https://schema.org/Person")
height_class = item_type.find("span", {"itemprop": "height"})
height = height_class.get_text()
return height
def player_number(self, url):
soup = self.page_parser(url)
item_type = soup.find(class_="uni_holder bbr")
number_class = item_type.find("text", {"x": "9", "y": "39", "fill": "#ffffff"})
if number_class == None:
number_class = item_type.find("text", {"x": "15", "y": "39", "fill": "#ffffff"})
player_num = number_class.get_text()
return player_num
def player_position(self, url):
soup = self.page_parser(url)
item_type = soup.find(itemtype="https://schema.org/Person")
player_position = ""
player_team = ""
sep = '▪'
for p in item_type.find_all("p"):
if 'position' in str(p).lower():
player_position += str(p.text)
return ' '.join(player_position.split()).split(sep, 1)[0].replace('Position: ', '')