Commit b7786a8d authored by Melroy van den Berg's avatar Melroy van den Berg

add enum generation tool + category enum result so far

parent f0d2ec37
This diff is collapsed.
#!/usr/bin/env python3
"""
Convert HTML fields to enum list
"""
import argparse
parser = argparse.ArgumentParser(description="Convert HTML text: <li> list from marktplaats.nl, to python Enum. Using cat.txt as input file. Example:\n name_convert.py ANTIEK_KUNST 1")
parser.add_argument("prefix", help="Prefix name (eg. ANTIEK_KUNST)",
type=str)
parser.add_argument("prefix_number", help="Prefix ID (eg. 1)",
type=int)
args = parser.parse_args()
array = []
with open("cat.txt", "r") as ins:
for line in ins:
line = line.strip()
if line:
data = {}
line = line[line.find("data-val=\"") + len("data-val=\""):]
line = line.replace("</li>", "")
line = line.split("\">")
id = line[0]
name = line[1]
name = name.replace("'", "").replace("-", "_").replace(" | ", "_").replace(", ", "_").replace(" en ", "_").replace(" ", "_").replace("____", "_").replace("___", "_").replace("__", "_").upper()
data['id'] = id
data['name'] = name
array.append(data)
for line in array:
print(" " + args.prefix + "_" + line['name'] + " = \"" + str(args.prefix_number) + "/" + line['id'] + "\"")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment