Created
October 9, 2022 03:13
-
-
Save CSUwangj/871e54f227499ea73782bcb660750e55 to your computer and use it in GitHub Desktop.
generate_metadata.py
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
meta = { | |
"formatVersion": 1, | |
"appVersion": "0.54.2", | |
"files": [] | |
} | |
year_meta = { | |
"isClone": False, | |
"title": "2022", | |
"notePosition": 10, | |
"isExpanded": False, | |
"type": "text", | |
"mime": "text/html", | |
"attributes": [ | |
{ | |
"type": "relation", | |
"name": "child:child:template", | |
"value": "TKP4y9X9Spwr", | |
"isInheritable": False, | |
"position": 50 | |
}, | |
{ | |
"type": "relation", | |
"name": "template", | |
"value": "m6lAK2HYo3u4", | |
"isInheritable": False, | |
"position": 60 | |
}, | |
{ | |
"type": "relation", | |
"name": "child:template", | |
"value": "wWm0HmMurCyh", | |
"isInheritable": False, | |
"position": 70 | |
}, | |
{ | |
"type": "label", | |
"name": "yearNote", | |
"value": "2022", | |
"isInheritable": False, | |
"position": 71 | |
}, | |
{ | |
"type": "label", | |
"name": "sorted", | |
"value": "", | |
"isInheritable": False, | |
"position": 72 | |
} | |
], | |
"format": "markdown", | |
"dataFileName": "2022.md", | |
"dirFileName": "2022", | |
"children": [] | |
} | |
month_meta = { | |
"isClone": False, | |
"title": "", | |
"notePosition": 10, | |
"isExpanded": False, | |
"type": "text", | |
"mime": "text/html", | |
"attributes": [ | |
{ | |
"type": "relation", | |
"name": "child:template", | |
"value": "TKP4y9X9Spwr", | |
"isInheritable": False, | |
"position": 50 | |
}, | |
{ | |
"type": "relation", | |
"name": "template", | |
"value": "wWm0HmMurCyh", | |
"isInheritable": False, | |
"position": 70 | |
}, | |
{ | |
"type": "label", | |
"name": "monthNote", | |
"value": "", | |
"isInheritable": False, | |
"position": 71 | |
}, | |
{ | |
"type": "label", | |
"name": "sorted", | |
"value": "", | |
"isInheritable": False, | |
"position": 72 | |
} | |
], | |
"format": "markdown", | |
"dirFileName": "", | |
"children": [] | |
} | |
day_meta = { | |
"isClone": False, | |
"title": "2022-10-06 总结", | |
"notePosition": 10, | |
"isExpanded": False, | |
"type": "text", | |
"mime": "text/html", | |
"attributes": [ | |
{ | |
"type": "relation", | |
"name": "template", | |
"value": "TKP4y9X9Spwr", | |
"isInheritable": False, | |
"position": 10 | |
}, | |
{ | |
"type": "label", | |
"name": "dateNote", | |
"value": "", | |
"isInheritable": False, | |
"position": 20 | |
} | |
], | |
"format": "markdown", | |
"dataFileName": "2022-10-06 总结.md" | |
} | |
import calendar | |
import copy | |
for year in years: | |
ym = copy.deepcopy(year_meta) | |
ym['title'] = year | |
ym['attributes'][3]['value'] = year | |
ym['dataFileName'] = '{}.md'.format(year) | |
ym['dirFileName'] = year | |
for month in months: | |
mm = copy.deepcopy(month_meta) | |
mm['title'] = month | |
mm['attributes'][2]['value'] = '{}-{}'.format(year, month[:2]) | |
mm['dataFileName'] = '{}.md'.format(month) | |
mm['dirFileName'] = month | |
for day in range(1, calendar.monthrange(int(year), int(month[:2]))[1]): | |
dm = copy.deepcopy(day_meta) | |
dm['title'] = '{}-{}-{:02d} 总结'.format(year, month[:2], day) | |
dm['attributes'][1]['value'] = '{}-{}-{:02d}'.format(year, month[:2], day) | |
dm['dataFileName'] = '{}-{}-{:02d} 总结.md'.format(year, month[:2], day) | |
mm['children'].append(dm) | |
ym['children'].append(mm) | |
meta['files'].append(ym) | |
with open('./!!!meta.json', 'w') as f: | |
f.write(json.dumps(meta, ensure_ascii=False)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment