-
-
Save Galunid/fe82c95b035e94a6373b0b0309b7adb0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
def generate_entry(item, special=False): | |
if not special: | |
return f"""str_in_list(field('tags'), ",", '{item}', '{item}',""" | |
return f"""test({item},{item},""" | |
def generate_joint_entry(item, special=False): | |
if not special: | |
return f"""strcat(str_in_list(field('tags'),",", '{item}', strcat('{item}/',""" | |
return f"""strcat(test({item}, strcat({item},'/',""" | |
hierarchy = { | |
"Magazine": { | |
"%series%": [] | |
}, | |
"Chess": { | |
"%series%": [] | |
}, | |
"IT": { | |
"Programming": { | |
"Application Design": [], | |
"Python": [], | |
"JavaScript": [], | |
"Java": [], | |
"C": [], | |
"C++": [], | |
"Algorithms": [] | |
}, | |
"Operating Systems": [], | |
"Algorithms": [], | |
"Networking": [], | |
"Project Management": [], | |
"Data Science": [], | |
"Machine Learning": [], | |
"InfoSec": [], | |
"Databases": [], | |
"VCS": [] | |
}, | |
"LightNovel": { | |
"%series%": [], | |
}, | |
"WebNovel": { | |
"%series%": [], | |
}, | |
"Fiction": { | |
"%series%": [], | |
}, | |
"Science": [], | |
"Psychology": [], | |
"Philosophy": [], | |
"Business": [], | |
"Life Style": [], | |
"Mathematics": [], | |
"Classics": [], | |
"Research Paper": [] | |
} | |
def gen(item_hierarchy): | |
def t(item_hierarchy): | |
s = "" | |
missing_brackets = 0 | |
for k, v in item_hierarchy.items(): | |
special = False | |
if re.search(r'^\%(\D+)\%$', k): | |
k = f"field('{k[1:-1]}')" | |
special = True | |
if type(v) is dict: | |
s += generate_joint_entry(k, special=special) | |
special = False | |
missing_brackets += 2 | |
s += t(v) | |
s += ")," | |
else: | |
s += generate_entry(k, special=special) | |
missing_brackets += 1 | |
special = False | |
s += "'Other'" | |
s += ')' * missing_brackets | |
return s | |
return "program: strcat(" + t(item_hierarchy) + ", '/', field('title'))" | |
print(gen(hierarchy)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment