-
Notifications
You must be signed in to change notification settings - Fork 0
/
cricscores_old.py
executable file
·71 lines (60 loc) · 2.17 KB
/
cricscores_old.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
#!/usr/bin/env python3
import urllib.request
from bs4 import BeautifulSoup
from terminaltables import AsciiTable
import textwrap
global URL
def set_url():
global URL
URL = "http://www.espncricinfo.com/ci/engine/match/index.html?view=live"
def get_html():
with urllib.request.urlopen(URL) as response:
return response.read();
def get_matches(html_doc):
soup = BeautifulSoup(html_doc, 'lxml')
match_info_soup=soup.find_all('div', class_='match-info')
innings_info_1_soup=soup.find_all('div', class_='innings-info-1')
innings_info_2_soup=soup.find_all('div', class_='innings-info-2')
match_status_soup=soup.find_all('div', class_='match-status')
dates = []
stadiums = []
team1s = []
score1s = []
team2s = []
score2s = []
match_statuses = []
for x in match_info_soup:
dates.append(x.find('span', class_='bold').string.strip())
stadiums.append(x.find('span', class_='match-no').a.string.strip())
for x in innings_info_1_soup:
team1s.append(x.find(text=True).strip())
if str(x.span.string).strip() != 'None':
score1s.append(str(x.span.string).strip())
else:
score1s.append("")
for x in innings_info_2_soup:
team2s.append(x.find(text=True).strip())
if str(x.span.string).strip() != 'None':
score2s.append(str(x.span.string).strip())
else:
score2s.append("")
#wrapped=textwrap.fill(x,50)
for x in match_status_soup:
match_statuses.append(str(x.span.string).strip())
matches = zip(dates, stadiums, team1s, score1s, team2s, score2s, match_statuses)
return matches
def print_matches(matches):
matches_arr = []
for match in matches:
#match_arr = [str(match[2]), str(match[3]), str(match[4]), str(match[5]), str(match[1])]
match_arr = [str(match[2]), str(match[3]), str(match[4]), str(match[5])]
matches_arr.append(match_arr)
#print (matches_array)
table = AsciiTable(matches_arr)
table.inner_heading_row_border = False
table.inner_row_border = True
print (table.table)
set_url()
html_doc = get_html()
matches = get_matches(html_doc)
print_matches(matches)