Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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