From b0cd66f6c50e954b497cda752dc46ae509081223 Mon Sep 17 00:00:00 2001 From: emkael Date: Fri, 22 Oct 2021 03:04:30 +0200 Subject: Autocommit --- rozklady/get-tc-boards.py | 15 +++++++++++++ rozklady/scrape-boards.py | 54 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 rozklady/get-tc-boards.py create mode 100755 rozklady/scrape-boards.py (limited to 'rozklady') diff --git a/rozklady/get-tc-boards.py b/rozklady/get-tc-boards.py new file mode 100644 index 0000000..637a95c --- /dev/null +++ b/rozklady/get-tc-boards.py @@ -0,0 +1,15 @@ +import json, sys + +for fpath in sys.argv[1:]: + jsfile = json.load(open(fpath)) + print('[Board "%d"]' % (jsfile['ScoringGroups'][0]['Distribution']['_numberAsPlayed'])) + board = [] + for hand in ['N', 'E', 'S', 'W']: + board.append('%s.%s.%s.%s' % ( + jsfile['ScoringGroups'][0]['Distribution']['_handRecord']['Hand'+hand]['Spades'], + jsfile['ScoringGroups'][0]['Distribution']['_handRecord']['Hand'+hand]['Hearts'], + jsfile['ScoringGroups'][0]['Distribution']['_handRecord']['Hand'+hand]['Diamonds'], + jsfile['ScoringGroups'][0]['Distribution']['_handRecord']['Hand'+hand]['Clubs'] + )) + print('[Deal "N:%s"]' % (' '.join(board).replace('10', 'T'))) + print('') diff --git a/rozklady/scrape-boards.py b/rozklady/scrape-boards.py new file mode 100755 index 0000000..5f7ea7f --- /dev/null +++ b/rozklady/scrape-boards.py @@ -0,0 +1,54 @@ +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'): + sys.stderr.write(board_link['href'] + "\n") + 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].strip() + vulnerability = conditions[1].title() + if len(vulnerability) < 3: + vulnerability = vulnerability.upper() + card_cells = board.select('td.w') + sys.stderr.write(str(card_cells)) + sys.stderr.write("\n") + if len(card_cells) == 4: + cards = [ + [ + line.replace('10', 'T').replace(' ', '').strip() + for line in c + if type(line) == bs4.element.NavigableString and line != "\n" + ] 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 -- cgit v1.2.3