-
Notifications
You must be signed in to change notification settings - Fork 0
/
match.py
55 lines (48 loc) · 1.22 KB
/
match.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
import requests
from bs4 import BeautifulSoup
from time import sleep
import sys
print('Live Cricket Matches:')
print('=====================')
url = "http://static.cricinfo.com/rss/livescores.xml"
r = requests.get(url)
soup = BeautifulSoup(r.text,'lxml')
i = 1
for item in soup.findAll('item'):
print(str(i) + '. ' + item.find('description').text)
print('------------------------------------------')
i = i + 1
links = []
for link in soup.findAll('item'):
links.append(link.find('guid').text)
print('Enter match number or enter 0 to exit:')
while True:
try:
userInput = int(input())
except NameError:
print('Invalid input. Try Again!')
continue
except SyntaxError:
print('Invalid input. Try Again!')
if userInput < 0 or userInput > 30:
print('Invalid input. Try Again!')
continue
elif userInput == 0:
sys.exit()
else:
break
url = links[userInput - 1]
r = requests.get(url)
soup = BeautifulSoup(r.text,'lxml')
while True:
matchUrl = links[userInput - 1]
r = requests.get(matchUrl)
soup = BeautifulSoup(r.text,'lxml')
score = soup.findAll('title')
try:
r.raise_for_status()
except Exception as exc:
print ('Connection Failure. Try again!')
continue
print(score[0].text + '\n')
sleep(20)