diff options
author | emkael <emkael@tlen.pl> | 2017-11-22 14:09:17 +0100 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2017-11-22 14:09:17 +0100 |
commit | 3e9bdf760c812f7e2a539144ebbe39a5d4bc730f (patch) | |
tree | 142ebfd95fc46fa1f60a3554c44b68d62ff59c26 /scrape-boards.py |
Initial commit.
Board scraper:
* takes traveller file
* complete produces PBN for all boards in segment
Scores scraper:
* takes board file, round, segment and board number (1..n, not physical board number)
* produces SQL that UPDATES scores table (so scores needs to have rows)
* does not support ARB/Axx scores
* probably won't support wrong lines
Diffstat (limited to 'scrape-boards.py')
-rw-r--r-- | scrape-boards.py | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/scrape-boards.py b/scrape-boards.py new file mode 100644 index 0000000..f9e02cd --- /dev/null +++ b/scrape-boards.py @@ -0,0 +1,51 @@ +from bs4 import BeautifulSoup as bs +import bs4 +import os +import sys + +traveller_file = file(sys.argv[1]) +traveller = bs(traveller_file, 'lxml') + +print '% PBN 1.0' +print '[Generator "JFRTeamy-restorerer"]' +print '[Event "%s"]' % (traveller_file.name) + +board_links = traveller.select('td.bdcc a.zb') +for board_link in board_links: + if board_link.has_attr('href'): + board_number = board_link.text.strip() + board_file = open( + os.path.join( + os.path.dirname(traveller_file.name), + board_link['href'] + ) + ) + board = bs(board_file, 'lxml') + conditions = [ + c for c in + board.select('td[valign="top"] h4')[0].contents + if type(c) == bs4.element.NavigableString + ] + dealer = conditions[0] + vulnerability = conditions[1].title() + if len(vulnerability) < 3: + vulnerability = vulnerability.upper() + card_cells = board.select('td.w') + if len(card_cells) == 4: + cards = [ + [ + line.replace('10', 'T').replace(' ', '').strip() + for line in c + if type(line) == bs4.element.NavigableString + ][1::2] for c in card_cells + ] + print '[Board "%s"]' % board_number + print '[Dealer "%s"]' % dealer + print '[Vulnerable "%s"]' % vulnerability + print '[Deal "N:%s %s %s %s"]' % ( + '.'.join(cards[0]), + '.'.join(cards[2]), + '.'.join(cards[3]), + '.'.join(cards[1]) + ) + print |