-
Notifications
You must be signed in to change notification settings - Fork 0
/
raceHorse.py
executable file
·51 lines (29 loc) · 918 Bytes
/
raceHorse.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
#!/usr/bin/python
"""
Grab the name of a racehorse.
"""
import string
import urllib
from random import choice # to choose a random item from a list
from bs4 import BeautifulSoup
import re
from config import debug
class raceHorse ( object ) :
def __init__ (self) :
True
def getName ( self ) :
url_base = 'http://www.horses-and-horse-information.com/horsenames/'
alpha = list ( string.ascii_lowercase )
letter = choice ( alpha )
#letter= 'b'
url = url_base + letter + '.shtml'
#print '<!--',url,'-->'
#print 'url',url
socket = urllib.urlopen ( url )
HTMLSource = socket.read ( )
socket.close ( )
raceHorseHTML = BeautifulSoup ( HTMLSource, "lxml" )
names = raceHorseHTML.find_all('td',class_='text11black',text=re.compile(letter + "*"))
random_name = choice ( names )
# FIXME: make sure this returns something!
return random_name.text