11
11
from bibtexparser .bwriter import BibTexWriter
12
12
13
13
14
- if __name__ == '__main__' :
14
+ try :
15
15
16
16
parser = argparse .ArgumentParser ()
17
17
parser .add_argument ("-b" , "--body" , help = "input issue body here" , type = str , default = "" )
102
102
if not req .status_code == 200 :
103
103
print (f'Request of { url } could not be processed, got status code { req .status_code } .' )
104
104
break
105
-
106
- data = req .json ()
107
105
108
- if len (data ['author' ]) > 1 :
109
- id = data ['author' ][0 ]['family' ] + 'EtAl' + str (data ['issued' ]['date-parts' ][0 ][0 ])
110
- else :
111
- id = data ['author' ][0 ]['family' ] + str (data ['issued' ]['date-parts' ][0 ][0 ])
106
+ with open ("request.txt" , "w" ) as f :
107
+ f .write (req .text )
108
+ try :
109
+ data = req .json ()
110
+ except :
111
+ # in case request did not provide the json data, retrieve it from the bib entry
112
+ data = {
113
+ e [0 ].strip (): e [1 ][1 :].split ("}" )[0 ]
114
+ for e in [e for e in [l .split (" = " ) for l in bib .splitlines ()] if len (e ) == 2 ]
115
+ }
116
+ data ["author" ] = [
117
+ {"family" : a .split (", " )[0 ], "given" : a .split (", " )[1 ]}
118
+ for a in data ["author" ].split (" and " )
119
+ ]
120
+ data ["issued" ] = {"date-parts" : [[data ["year" ]]]}
121
+
122
+ id = data ['author' ][0 ]['family' ] + 'EtAl' * (len (data ['author' ]) > 1 ) + str (data ['issued' ]['date-parts' ][0 ][0 ])
112
123
id = id .replace (" " , "_" )
113
124
114
125
d = db .get_entry_dict ()
162
173
line = re .sub (r'%}+' , '%' , line )
163
174
line = line .rstrip ('\r \n ' )
164
175
print (line )
176
+
177
+ except Exception as e :
178
+ print (f"ERROR : { e } \n " )
0 commit comments