@@ -268,18 +268,23 @@ def ingest_publication(
268
268
return
269
269
270
270
if not ignore_ads :
271
- use_ads = check_ads_token ()
272
- if not use_ads and (not reference and (not doi or not bibcode )):
273
- logger .error (
274
- "An ADS_TOKEN environment variable must be set"
275
- "in order to auto-populate the fields.\n "
276
- "Without an ADS_TOKEN, name and bibcode or DOI must be set explicity."
277
- )
278
- return
279
- else :
280
- use_ads = False
271
+ ads_token = check_ads_token ()
281
272
282
- logger .debug (f"Use ADS set to { use_ads } " )
273
+ if not ads_token :
274
+ logger .warning (
275
+ "An ADS_TOKEN environment variable is not set.\n "
276
+ "setting ignore_ads=True." )
277
+ ignore_ads = True
278
+
279
+ if (not reference and (not doi or not bibcode )):
280
+ logger .error (
281
+ "An ADS_TOKEN environment variable must be set"
282
+ "in order to auto-populate the fields.\n "
283
+ "Without an ADS_TOKEN, name and bibcode or DOI must be set explicity."
284
+ )
285
+ return
286
+
287
+ logger .debug (f"ignore_ads set to { ignore_ads } " )
283
288
284
289
if bibcode :
285
290
if "arXiv" in bibcode :
@@ -291,40 +296,15 @@ def ingest_publication(
291
296
arxiv_id = None
292
297
293
298
name_add , bibcode_add , doi_add = "" , "" , ""
294
- # Search ADS uing a provided arxiv id
295
- if arxiv_id and use_ads :
296
- arxiv_matches = ads .SearchQuery (
297
- q = arxiv_id , fl = ["id" , "bibcode" , "title" , "first_author" , "year" , "doi" ]
298
- )
299
- arxiv_matches_list = list (arxiv_matches )
300
- if len (arxiv_matches_list ) != 1 :
301
- logger .error ("should only be one matching arxiv id" )
302
- return
303
-
304
- if len (arxiv_matches_list ) == 1 :
305
- logger .debug (f"Publication found in ADS using arxiv id: , { arxiv_id } " )
306
- article = arxiv_matches_list [0 ]
307
- logger .debug (
308
- f"{ article .first_author } , { article .year } , { article .bibcode } , { article .title } "
309
- )
310
- if not reference : # generate the name if it was not provided
311
- name_stub = article .first_author .replace ("," , "" ).replace (" " , "" )
312
- name_add = name_stub [0 :4 ] + article .year [- 2 :]
313
- else :
314
- name_add = reference
315
- description = article .title [0 ]
316
- bibcode_add = article .bibcode
317
- doi_add = article .doi [0 ]
299
+ using = f"ref: { name_add } , bibcode: { bibcode_add } , doi: { doi_add } "
318
300
319
- using = f"ref: { name_add } , bibcode: { bibcode_add } , doi: { doi_add } "
320
- elif arxiv_id :
321
- name_add = reference
322
- bibcode_add = arxiv_id
323
- doi_add = doi
324
- using = f"ref: { name_add } , bibcode: { bibcode_add } , doi: { doi_add } "
301
+ # Search ADS uing a provided arxiv id
302
+ if arxiv_id :
303
+ name_add , bibcode_add , doi_add , description = find_pub_using_arxiv_id (arxiv_id , reference , doi , ignore_ads )
304
+ using = f"ref: { name_add } , bibcode: { bibcode_add } , doi: { doi_add } "
325
305
326
306
# Search ADS using a provided DOI
327
- if doi and use_ads :
307
+ if doi and not ignore_ads :
328
308
doi_matches = ads .SearchQuery (
329
309
doi = doi , fl = ["id" , "bibcode" , "title" , "first_author" , "year" , "doi" ]
330
310
)
@@ -335,7 +315,6 @@ def ingest_publication(
335
315
336
316
if len (doi_matches_list ) == 1 :
337
317
logger .debug (f"Publication found in ADS using DOI: { doi } " )
338
- using = doi
339
318
article = doi_matches_list [0 ]
340
319
logger .debug (
341
320
f"{ article .first_author } , { article .year } ,"
@@ -349,12 +328,14 @@ def ingest_publication(
349
328
description = article .title [0 ]
350
329
bibcode_add = article .bibcode
351
330
doi_add = article .doi [0 ]
331
+ using = f"ref: { name_add } , bibcode: { bibcode_add } , doi: { doi_add } "
352
332
elif doi :
353
333
name_add = reference
354
334
bibcode_add = bibcode
355
335
doi_add = doi
336
+ using = f"ref: { name_add } , bibcode: { bibcode_add } , doi: { doi_add } "
356
337
357
- if bibcode and use_ads :
338
+ if bibcode and not ignore_ads :
358
339
bibcode_matches = ads .SearchQuery (
359
340
bibcode = bibcode ,
360
341
fl = ["id" , "bibcode" , "title" , "first_author" , "year" , "doi" ],
@@ -370,7 +351,6 @@ def ingest_publication(
370
351
371
352
elif len (bibcode_matches_list ) == 1 :
372
353
logger .debug (f"Publication found in ADS using bibcode: { bibcode } " )
373
- using = str (bibcode )
374
354
article = bibcode_matches_list [0 ]
375
355
logger .debug (
376
356
f"{ article .first_author } , { article .year } , "
@@ -387,6 +367,7 @@ def ingest_publication(
387
367
doi_add = None
388
368
else :
389
369
doi_add = article .doi [0 ]
370
+ using = f"ref: { name_add } , bibcode: { bibcode_add } , doi: { doi_add } "
390
371
elif bibcode :
391
372
name_add = reference
392
373
bibcode_add = bibcode
@@ -395,7 +376,7 @@ def ingest_publication(
395
376
396
377
if reference and not bibcode and not doi :
397
378
name_add = reference
398
- using = "user input"
379
+ using = "ref: {reference} user input. No bibcode or doi provided. "
399
380
400
381
new_ref = [
401
382
{
@@ -438,3 +419,36 @@ def check_ads_token():
438
419
439
420
return use_ads
440
421
422
+
423
+ def find_pub_using_arxiv_id (arxiv_id , reference , doi , ignore_ads ):
424
+ if not ignore_ads :
425
+ arxiv_matches = ads .SearchQuery (
426
+ q = arxiv_id , fl = ["id" , "bibcode" , "title" , "first_author" , "year" , "doi" ]
427
+ )
428
+ arxiv_matches_list = list (arxiv_matches )
429
+ if len (arxiv_matches_list ) != 1 :
430
+ logger .error ("should only be one matching arxiv id" )
431
+ return
432
+
433
+ if len (arxiv_matches_list ) == 1 :
434
+ logger .debug (f"Publication found in ADS using arxiv id: , { arxiv_id } " )
435
+ article = arxiv_matches_list [0 ]
436
+ logger .debug (
437
+ f"{ article .first_author } , { article .year } , { article .bibcode } , { article .title } "
438
+ )
439
+ if not reference : # generate the name if it was not provided
440
+ name_stub = article .first_author .replace ("," , "" ).replace (" " , "" )
441
+ name_add = name_stub [0 :4 ] + article .year [- 2 :]
442
+ else :
443
+ name_add = reference
444
+ description = article .title [0 ]
445
+ bibcode_add = article .bibcode
446
+ doi_add = article .doi [0 ]
447
+
448
+ else :
449
+ name_add = reference
450
+ bibcode_add = arxiv_id
451
+ doi_add = doi
452
+ description = None
453
+
454
+ return name_add , bibcode_add , doi_add , description
0 commit comments