Skip to content
Merged
Changes from all commits
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
28 changes: 21 additions & 7 deletions bin/issue_to_bibtex.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from bibtexparser.bwriter import BibTexWriter


if __name__ == '__main__':
try:

parser = argparse.ArgumentParser()
parser.add_argument("-b", "--body", help="input issue body here", type=str, default="")
Expand Down Expand Up @@ -102,13 +102,24 @@
if not req.status_code == 200:
print(f'Request of {url} could not be processed, got status code {req.status_code}.')
break

data = req.json()

if len(data['author']) > 1:
id = data['author'][0]['family'] + 'EtAl' + str(data['issued']['date-parts'][0][0])
else:
id = data['author'][0]['family'] + str(data['issued']['date-parts'][0][0])
with open("request.txt", "w") as f:
f.write(req.text)
try:
data = req.json()
except:
# in case request did not provide the json data, retrieve it from the bib entry
data = {
e[0].strip(): e[1][1:].split("}")[0]
for e in [e for e in [l.split(" = ") for l in bib.splitlines()] if len(e) == 2]
}
data["author"] = [
{"family": a.split(", ")[0], "given": a.split(", ")[1]}
for a in data["author"].split(" and ")
]
data["issued"] = {"date-parts": [[data["year"]]]}

id = data['author'][0]['family'] + 'EtAl'*(len(data['author']) > 1) + str(data['issued']['date-parts'][0][0])
id = id.replace(" ", "_")

d = db.get_entry_dict()
Expand Down Expand Up @@ -162,3 +173,6 @@
line = re.sub(r'%}+', '%', line)
line = line.rstrip('\r\n')
print(line)

except Exception as e:
print(f"ERROR : {e}\n")
Loading