1
0
mirror of https://github.com/bitcoinbook/bitcoinbook synced 2024-11-15 12:39:01 +00:00
bitcoinbook/code/bip-table.py

44 lines
1.3 KiB
Python
Raw Normal View History

2017-04-23 11:07:48 +00:00
# Convert mediawiki list of BIPs to asciidoc table for book appendix
# Gnarly hack of regex with no error checking - it worked once
import re
regex_num = re.compile("\\|.\\[\\[bip-\\d+.mediawiki\\|(\\d+)\\]\\]")
regex_altnum = re.compile("\\D+(\\d+)\\D+")
bips = []
f = open('README.mediawiki.txt', 'r')
line = f.readline()
while (line[0] != "|"):
line = f.readline()
while (line[1] == '-'):
2017-08-24 16:14:02 +00:00
line_num = f.readline()
line_layer = f.readline()[2:-1]
line_title = f.readline()[2:-1]
line_owner = f.readline()[2:-1]
line_type = f.readline()[2:-1]
2017-04-23 11:07:48 +00:00
line_status = f.readline()[2:-1]
2017-08-24 16:14:02 +00:00
line = f.readline()
2017-04-23 11:07:48 +00:00
while (line[0] != "|"):
2017-08-24 16:14:02 +00:00
line = f.readline()
2017-04-23 11:07:48 +00:00
num = regex_num.match(line_num)
alt_num = regex_altnum.match(line_num)
if num:
bip_num = num.group(1)
elif alt_num:
bip_num = alt_num.group(1)
2017-08-24 16:14:02 +00:00
print("|[[bip-{0}]]https://github.com/bitcoin/bips/blob/master/bip-{0:04d}"
".mediawiki[BIP-{0}] |{1} |{2} |{3} |{4} ".format(int(bip_num),
line_title,
line_owner,
line_type,
line_status))
2017-04-23 11:07:48 +00:00
f.close()