Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to make bib parser #272

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions tools/precommit-bib.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import json
#TODO do not split {} by ,. We need a more deeper parser!
bib_list = {}
with open("qmlcourseRU/_bibliography/references.bib", "r") as bibfile:
bibtex = bibfile.readlines()
entry_type=None
entry=None
for line in bibtex:
# print(line)
line = line.strip() #remove spaces and tabs at start/end of line (trimm string)
# print(line)
if line.startswith("@"):
if entry_type is not None:
bib_list[entry_label] = {
#TODO: all variants
"entry_type":entry_type,
"entry_label":entry_label,
"entry":entry,
}

entry_type, entry = line.split("{")
entry_label, entry = entry.split(",")
# entry = "{" + entry attepmt to use json.loads()
else:
entry+=line
print(bib_list)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

давай для такого лучше https://github.com/Delgan/loguru использовать если сильно нужно, долой print

with open("qmlcourseRU/_bibliography/references2.bib", "w") as bibfile:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

тут создается новый bib-файл, но как на него будет смотреть jb, не особо понял этот случай?

for k, v in bib_list.items():
bibfile.writelines(v["entry_type"]+"{"+v["entry_label"]+",\n")
split_entry_lines = v["entry"].split("},")
for i in split_entry_lines[:-1]:
bibfile.writelines(i+"},\n")
bibfile.writelines(split_entry_lines[-1]+"\n")