From 42019ce85f1789b7340dd97b2dc324efb7541298 Mon Sep 17 00:00:00 2001 From: JoeLametta Date: Wed, 6 Nov 2019 15:17:15 +0000 Subject: [PATCH] Port (misc) offsets script to Python 3 I've also changed the output format a bit. Signed-off-by: JoeLametta --- misc/offsets.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/misc/offsets.py b/misc/offsets.py index 626f925..5dac793 100644 --- a/misc/offsets.py +++ b/misc/offsets.py @@ -6,13 +6,12 @@ import sys -import BeautifulSoup +from bs4 import BeautifulSoup -handle = open(sys.argv[1]) +with open(sys.argv[1]) as f: + doc = f.read() -doc = handle.read() - -soup = BeautifulSoup.BeautifulSoup(doc) +soup = BeautifulSoup(doc) offsets = {} # offset -> total count @@ -50,18 +49,17 @@ for count, offset in counts: # now format it for code inclusion lines = [] -line = 'OFFSETS = "' +line = 'OFFSETS = ("' for offset in offsets: line += offset + ", " if len(line) > 60: - line += "\" + \\" lines.append(line) - line = ' "' + line = ' "' # get last line too, trimming the comma and adding the quote if len(line) > 11: - line = line[:-2] + '"' + line = line[:-2] + '")' lines.append(line) print("\n".join(lines))