-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathclient.py
More file actions
1229 lines (910 loc) · 35 KB
/
client.py
File metadata and controls
1229 lines (910 loc) · 35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# coding: utf-8
import os
import json
import logging
import time
import socket
from datetime import datetime
from collections import namedtuple
import requests
import thriftpy2
from thriftpy2.rpc import make_client, client_context
from thriftpy2.transport import TTransportException
from xylose.scielodocument import Article, Journal, Issue
# URLJOIN Python 3 and 2 import compatibilities
try:
from urllib.parse import urljoin
except:
from urlparse import urljoin
LIMIT = 1000
DEFAULT_FROM_DATE = '1996-01-01'
logger = logging.getLogger(__name__)
EVENTS_STRUCT = namedtuple('event', 'code collection event date')
class ArticleMetaExceptions(Exception):
pass
class UnauthorizedAccess(ArticleMetaExceptions):
pass
class ServerError(ArticleMetaExceptions):
pass
def dates_pagination(from_date, until_date):
"""
Essa função tem como responsabilidade criar páginas por ano, portanto ao
realizar uma consulta indicando ou não um período este será dividido,
entre os anos e o deslocamento.
"""
from_date = datetime.strptime(from_date, '%Y-%m-%d')
until_date = datetime.strptime(until_date, '%Y-%m-%d')
for year in range(from_date.year, until_date.year+1):
dtbg = '%d-01-01' % year
dtnd = '%d-12-31' % year
if from_date.year == until_date.year:
yield (from_date.isoformat()[:10], until_date.isoformat()[:10])
continue
if year == from_date.year:
yield (from_date.isoformat()[:10], dtnd)
continue
if year == until_date.year:
yield (dtbg, until_date.isoformat()[:10])
continue
yield (dtbg, dtnd)
class RestfulClient(object):
ARTICLEMETA_URL = 'http://articlemeta.scielo.org'
JOURNAL_ENDPOINT = '/api/v1/journal'
ARTICLE_ENDPOINT = '/api/v1/article'
ARTICLES_ENDPOINT = '/api/v1/articles'
ISSUE_ENDPOINT = '/api/v1/issue'
ISSUES_ENDPOINT = '/api/v1/issues'
COLLECTION_ENDPOINT = '/api/v1/collection'
ATTEMPTS = 10
_timeout = 3
def __init__(self, domain=None, timeout=3):
if domain:
self.ARTICLEMETA_URL = domain
self._timeout = timeout
def _do_request(self, url, params=None, method='GET'):
request = requests.get
params = params if params else {}
if method == 'POST':
request = requests.post
if method == 'DELETE':
request = requests.delete
result = None
for attempt in range(self.ATTEMPTS):
# Throttling requests to the API. Our servers will throttle accesses to the API from the same IP in 3 per second.
# So, to not receive a "too many connections error (249 HTTP ERROR)", do not change this line.
time.sleep(0.4)
try:
result = request(url, params=params, timeout=self._timeout)
if result.status_code == 401:
logger.error('Unautorized Access for (%s)', url)
logger.exception(UnauthorizedAccess())
break
except requests.RequestException as e:
logger.error('fail retrieving data from (%s) attempt(%d/%d)', url, attempt+1, self.ATTEMPTS)
logger.exception(e)
continue
if not result:
return
try:
return result.json()
except:
return result.text
def journal(self, code, collection):
url = urljoin(self.ARTICLEMETA_URL, self.JOURNAL_ENDPOINT)
params = {
'issn': code,
'collection': collection
}
result = self._do_request(url, params)
if not result:
return None
if len(result) != 1:
return None
xresult = Journal(result[0])
return xresult
def journals(self, collection=None, issn=None, only_identifiers=False):
params = {
'limit': LIMIT
}
if collection:
params['collection'] = collection
if issn:
params['code'] = issn
params['offset'] = 0
while True:
url = urljoin(self.ARTICLEMETA_URL, self.JOURNAL_ENDPOINT + '/identifiers')
identifiers = self._do_request(url, params=params).get('objects', [])
if len(identifiers) == 0:
return
for identifier in identifiers:
if only_identifiers is True:
yield identifier
continue
journal = self.journal(
identifier['code'],
identifier['collection']
)
if journal and journal.data:
yield journal
params['offset'] += LIMIT
def journals_history(self, collection=None, event=None, code=None,
from_date=None, until_date=None,
only_identifiers=False):
params = {
'limit': LIMIT
}
if collection:
params['collection'] = collection
if code:
params['code'] = code
if event:
params['event'] = event
fdate = from_date or DEFAULT_FROM_DATE
udate = until_date or datetime.today().isoformat()[:10]
for from_date, until_date in dates_pagination(fdate, udate):
params['offset'] = 0
if from_date:
params['from_date'] = from_date
if until_date:
params['until_date'] = until_date
while True:
url = urljoin(self.ARTICLEMETA_URL, self.JOURNAL_ENDPOINT + '/history')
identifiers = self._do_request(url, params=params).get('objects', [])
if len(identifiers) == 0:
break
for identifier in identifiers:
if only_identifiers is True:
yield (EVENTS_STRUCT(**identifier), None)
continue
if identifier['event'] == 'delete':
yield (EVENTS_STRUCT(**identifier), None)
continue
journal = self.journal(
identifier['code'],
identifier['collection']
)
if journal and journal.data:
yield (EVENTS_STRUCT(**identifier), journal)
params['offset'] += LIMIT
def exists_journal(self, code, collection):
url = urljoin(self.ARTICLEMETA_URL, self.JOURNAL_ENDPOINT + '/exists')
params = {
'collection': collection,
'code': code
}
result = self._do_request(url, params=params).json()
if result is True:
return True
return False
def exists_issue(self, code, collection):
url = urljoin(self.ARTICLEMETA_URL, self.ISSUE_ENDPOINT + '/exists')
params = {
'collection': collection,
'code': code
}
result = self._do_request(url, params=params).json()
if result is True:
return True
return False
def exists_article(self, code, collection):
url = urljoin(self.ARTICLEMETA_URL, self.ARTICLE_ENDPOINT + '/exists')
params = {
'collection': collection,
'code': code
}
result = self._do_request(url, params=params).json()
if result is True:
return True
return False
def issue(self, code, collection):
url = urljoin(self.ARTICLEMETA_URL, self.ISSUE_ENDPOINT)
params = {
'collection': collection,
'code': code
}
result = self._do_request(url, params)
if not result:
return None
xresult = Issue(result)
return xresult
def issues(
self, collection=None, issn=None, from_date=None,
until_date=None
):
params = {
'limit': 100
}
if collection:
params['collection'] = collection
if issn:
params['issn'] = issn
fdate = from_date or DEFAULT_FROM_DATE
udate = until_date or datetime.today().isoformat()[:10]
for from_date, until_date in dates_pagination(fdate, udate):
params['from'] = from_date
params['until'] = until_date
params['offset'] = 0
while True:
url = urljoin(self.ARTICLEMETA_URL, self.ISSUES_ENDPOINT)
issues = self._do_request(url, params=params)
if issues is None:
break
issues = issues.get('objects', [])
if len(issues) == 0:
break
for issue in issues:
yield Issue(issue)
params['offset'] += 100
def issues_by_identifiers(self, collection=None, issn=None, from_date=None,
until_date=None, only_identifiers=False):
params = {
'limit': LIMIT
}
if collection:
params['collection'] = collection
if issn:
params['issn'] = issn
fdate = from_date or DEFAULT_FROM_DATE
udate = until_date or datetime.today().isoformat()[:10]
for from_date, until_date in dates_pagination(fdate, udate):
params['from'] = from_date
params['until'] = until_date
params['offset'] = 0
while True:
url = urljoin(self.ARTICLEMETA_URL, self.ISSUE_ENDPOINT + '/identifiers')
identifiers = self._do_request(url, params=params).get('objects', [])
if len(identifiers) == 0:
break
for identifier in identifiers:
if only_identifiers is True:
yield identifier
continue
issue = self.issue(
identifier['code'],
identifier['collection']
)
if issue and issue.data:
yield issue
params['offset'] += LIMIT
def issues_history(self, collection=None, issn=None, from_date=None, until_date=None, only_identifiers=False):
params = {
'limit': LIMIT
}
if collection:
params['collection'] = collection
if issn:
params['issn'] = issn
fdate = from_date or DEFAULT_FROM_DATE
udate = until_date or datetime.today().isoformat()[:10]
for from_date, until_date in dates_pagination(fdate, udate):
params['from'] = from_date
params['until'] = until_date
params['offset'] = 0
while True:
url = urljoin(self.ARTICLEMETA_URL, self.ISSUE_ENDPOINT + '/history')
identifiers = self._do_request(url, params=params).get('objects', [])
if len(identifiers) == 0:
break
for identifier in identifiers:
if only_identifiers is True:
yield (EVENTS_STRUCT(**identifier), None)
continue
if identifier['event'] == 'delete':
yield (EVENTS_STRUCT(**identifier), None)
continue
issue = self.issue(
identifier['code'],
identifier['collection']
)
if issue and issue.data:
yield (EVENTS_STRUCT(**identifier), issue)
params['offset'] += LIMIT
def document(self, code, collection, fmt='xylose', body=False):
url = urljoin(self.ARTICLEMETA_URL, self.ARTICLE_ENDPOINT)
params = {
'collection': collection,
'code': code,
'format': fmt,
'body': str(body).lower()
}
result = self._do_request(url, params, )
if not result:
return None
if fmt == 'xylose':
return Article(result)
return result
def documents(
self, collection=None, issn=None, from_date=None,
until_date=None, fmt='xylose', body=False
):
params = {
'limit': 100,
'fmt': fmt,
'body': str(body).lower()
}
if collection:
params['collection'] = collection
if issn:
params['issn'] = issn
fdate = from_date or DEFAULT_FROM_DATE
udate = until_date or datetime.today().isoformat()[:10]
for from_date, until_date in dates_pagination(fdate, udate):
params['from'] = from_date
params['until'] = until_date
params['offset'] = 0
while True:
url = urljoin(self.ARTICLEMETA_URL, self.ARTICLES_ENDPOINT)
articles = self._do_request(url, params=params)
if articles is None:
break
articles = articles.get('objects', [])
if len(articles) == 0:
break
for article in articles:
yield Article(article)
params['offset'] += 100
def documents_by_identifiers(
self, collection=None, issn=None, from_date=None,
until_date=None, fmt='xylose', body=False, only_identifiers=False
):
params = {
'limit': LIMIT
}
if collection:
params['collection'] = collection
if issn:
params['issn'] = issn
fdate = from_date or DEFAULT_FROM_DATE
udate = until_date or datetime.today().isoformat()[:10]
for from_date, until_date in dates_pagination(fdate, udate):
params['from'] = from_date
params['until'] = until_date
params['offset'] = 0
while True:
url = urljoin(self.ARTICLEMETA_URL, self.ARTICLE_ENDPOINT + '/identifiers')
identifiers = self._do_request(url, params=params).get('objects', [])
if len(identifiers) == 0:
break
for identifier in identifiers:
if only_identifiers is True:
yield identifier
continue
document = self.document(
identifier['code'],
identifier['collection'],
fmt=fmt,
body=body
)
if fmt == 'xylose' and document and document.data:
yield document
continue
if fmt != 'xylose' and document:
yield document
params['offset'] += LIMIT
def documents_history(self, collection=None, issn=None, from_date=None,
until_date=None, fmt='xylose', only_identifiers=False, body=False):
params = {
'limit': LIMIT
}
if collection:
params['collection'] = collection
if issn:
params['issn'] = issn
fdate = from_date or DEFAULT_FROM_DATE
udate = until_date or datetime.today().isoformat()[:10]
for from_date, until_date in dates_pagination(fdate, udate):
params['from'] = from_date
params['until'] = until_date
params['offset'] = 0
while True:
url = urljoin(self.ARTICLEMETA_URL, self.ARTICLE_ENDPOINT + '/history')
identifiers = self._do_request(url, params=params).get('objects', [])
if len(identifiers) == 0:
break
for identifier in identifiers:
if only_identifiers is True:
yield (EVENTS_STRUCT(**identifier), None)
continue
if identifier['event'] == 'delete':
yield (EVENTS_STRUCT(**identifier), None)
continue
document = self.document(
identifier['code'],
identifier['collection'],
fmt=fmt,
body=body
)
if fmt == 'xylose' and document and document.data:
yield (EVENTS_STRUCT(**identifier), document)
continue
if fmt != 'xylose' and document:
yield (EVENTS_STRUCT(**identifier), document)
params['offset'] += LIMIT
def collection(self, code):
"""
Retrieve the collection ids according to the given 3 letters acronym
"""
url = urljoin(self.ARTICLEMETA_URL, self.COLLECTION_ENDPOINT)
params = {'code': code}
result = self._do_request(url, params=params)
if not result:
return None
return result
def collections(self):
url = urljoin(self.ARTICLEMETA_URL, self.COLLECTION_ENDPOINT + '/identifiers')
result = self._do_request(url)
if not result:
return []
return result
class ThriftClient(object):
ATTEMPTS = 10
ARTICLEMETA_THRIFT = thriftpy2.load(
os.path.join(os.path.dirname(__file__))+'/thrift/articlemeta.thrift')
def __init__(self, domain=None, admintoken=None, timeout=5000):
"""
Cliente thrift para o Articlemeta.
"""
self.domain = domain or 'articlemeta.scielo.org:11621'
self._set_address()
self._admintoken = admintoken
self._timeout = timeout
def _set_address(self):
address = self.domain.split(':')
self._address = address[0]
try:
self._port = int(address[1])
except ValueError:
self._port = 11620
@property
def client(self):
return make_client(
self.ARTICLEMETA_THRIFT.ArticleMeta,
self._address,
self._port,
timeout=self._timeout
)
def client_cntxt(self):
return client_context(
self.ARTICLEMETA_THRIFT.ArticleMeta,
self._address,
self._port,
socket_timeout=self._timeout,
connect_timeout=self._timeout
)
def dispatcher(self, *args, **kwargs):
for attempt in range(self.ATTEMPTS):
try:
func = args[0]
with self.client_cntxt() as cl:
response = getattr(cl, func)(*args[1:], **kwargs)
return response
except (TTransportException, self.ARTICLEMETA_THRIFT.ServerError,
socket.timeout) as e:
msg = 'Error requesting articlemeta: %s args: %s kwargs: %s message: %s' % (
str(func), str(args[1:]), str(kwargs), str(e)
)
logger.info("Request Retry (%d,%d): %s", attempt+1, self.ATTEMPTS, msg)
time.sleep(self.ATTEMPTS*2)
except self.ARTICLEMETA_THRIFT.Unauthorized as e:
msg = 'Unautorized access to articlemeta: %s args: %s kwargs: %s message: %s' % (
str(func), str(args[1:]), str(kwargs), str(e)
)
raise UnauthorizedAccess(msg)
except self.ARTICLEMETA_THRIFT.ValueError as e:
msg = 'Error requesting articlemeta: %s args: %s kwargs: %s message: %s' % (
str(func), str(args[1:]), str(kwargs), str(e)
)
raise ValueError(msg)
raise ServerError(msg)
def getInterfaceVersion(self):
"""
This method retrieve the version of the thrift interface.
data: legacy SciELO Documents JSON Type 3.
"""
version = self.dispatcher(
'getInterfaceVersion'
)
return version
def add_journal(self, data):
"""
This method include new journals to the ArticleMeta.
data: legacy SciELO Documents JSON Type 3.
"""
journal = self.dispatcher(
'add_journal',
data,
self._admintoken
)
return json.loads(journal)
def add_issue(self, data):
"""
This method include new issues to the ArticleMeta.
data: legacy SciELO Documents JSON Type 3.
"""
issue = self.dispatcher(
'add_issue',
data,
self._admintoken
)
return json.loads(issue)
def add_document(self, data):
"""
This method include new issues to the ArticleMeta.
data: legacy SciELO Documents JSON Type 3.
"""
document = self.dispatcher(
'add_article',
data,
self._admintoken
)
return json.loads(document)
def journal(self, code, collection=None):
journal = self.dispatcher(
'get_journal',
code,
collection
)
if not journal:
logger.info('Journal not found for: %s_%s', collection, code)
return None
jjournal = None
try:
jjournal = json.loads(journal)
except:
msg = 'Fail to load JSON when retrienving journal: %s_%s' % (
collection, code
)
raise ValueError(msg)
xjournal = Journal(jjournal)
logger.info('Journal loaded: %s_%s', collection, code)
return xjournal
def journals(self, collection=None, issn=None, only_identifiers=False, limit=LIMIT):
offset = 0
while True:
identifiers = self.dispatcher(
'get_journal_identifiers',
collection=collection, issn=issn, limit=limit,
offset=offset
)
if len(identifiers) == 0:
return
for identifier in identifiers:
identifier.code = identifier.code
if only_identifiers is True:
yield identifier
continue
journal = self.journal(
identifier.code,
identifier.collection
)
if journal and journal.data:
yield journal
offset += limit
def journals_history(self, collection=None, event=None, code=None,
from_date=None, until_date=None,
only_identifiers=False, limit=LIMIT):
fdate = from_date or DEFAULT_FROM_DATE
udate = until_date or datetime.today().isoformat()[:10]
for from_date, until_date in dates_pagination(fdate, udate):
offset = 0
while True:
identifiers = self.dispatcher(
'journal_history_changes',
collection=collection, event=event, code=code,
from_date=from_date, until_date=until_date,
limit=limit, offset=offset
)
if len(identifiers) == 0:
break
for identifier in identifiers:
identifier.code = identifier.code
if only_identifiers is True:
yield (identifier, None)
continue
if identifier.event == 'delete':
yield (identifier, None)
continue
journal = self.journal(
identifier.code,
identifier.collection
)
if journal and journal.data:
yield (identifier, journal)
offset += limit
def exists_journal(self, code, collection):
return self.dispatcher(
'exists_journal',
code,
collection
)
def exists_issue(self, code, collection):
return self.dispatcher(
'exists_issue',
code,
collection
)
def exists_document(self, code, collection):
return self.dispatcher(
'exists_article',
code,
collection
)
def set_aid(self, code, collection, aid):
self.dispatcher(
'set_aid',
code,
collection,
aid,
self._admintoken
)
def set_doaj_id(self, code, collection, doaj_id):
self.dispatcher(
'set_doaj_id',
code, collection,
doaj_id,
self._admintoken
)
def issue(self, code, collection, replace_journal_metadata=True):
issue = self.dispatcher(
'get_issue',
code=code,
collection=collection,
replace_journal_metadata=True
)
if not issue:
logger.info('Issue not found for: %s_%s', collection, code)
return None
jissue = None
try:
jissue = json.loads(issue)
except:
msg = 'Fail to load JSON when retrienving document: %s_%s' % (collection, code)
raise ValueError(msg)
xissue = Issue(jissue)
logger.info('Issue loaded: %s_%s' % (collection, code))
return xissue
def issues_bulk(
self, collection=None, issn=None, from_date=None,
until_date=None, extra_filter=None, limit=LIMIT
):
fdate = from_date or DEFAULT_FROM_DATE
udate = until_date or datetime.today().isoformat()[:10]
for from_date, until_date in dates_pagination(fdate, udate):
offset = 0
while True:
issues = self.dispatcher(
'get_issues',
collection=collection, issn=issn, from_date=from_date,
until_date=until_date, limit=limit, offset=offset,
extra_filter=extra_filter
)
if issues is None:
break
issues = json.loads(issues).get('objects', [])
if len(issues) == 0:
break
for issue in issues:
yield Issue(issue)
offset += limit
def issues(
self, collection=None, issn=None, from_date=None,
until_date=None, extra_filter=None, only_identifiers=False, limit=LIMIT
):
fdate = from_date or DEFAULT_FROM_DATE
udate = until_date or datetime.today().isoformat()[:10]
for from_date, until_date in dates_pagination(fdate, udate):
offset = 0
while True:
identifiers = self.dispatcher(
'get_issue_identifiers',
collection=collection, issn=issn, from_date=from_date,
until_date=until_date, limit=limit, offset=offset,
extra_filter=extra_filter
)
if len(identifiers) == 0:
break
for identifier in identifiers:
if only_identifiers is True:
yield identifier
continue
issue = self.issue(
identifier.code,
identifier.collection,
replace_journal_metadata=True
)
if issue and issue.data:
yield (identifier, issue)
offset += limit
def issues_history(
self, collection=None, event=None, code=None,
from_date=None, until_date=None, only_identifiers=False, limit=LIMIT
):
fdate = from_date or DEFAULT_FROM_DATE
udate = until_date or datetime.today().isoformat()[:10]
for from_date, until_date in dates_pagination(fdate, udate):
offset = 0
while True:
identifiers = self.dispatcher(
'issue_history_changes',
collection=collection, event=event, code=code,
from_date=from_date, until_date=until_date,
limit=limit, offset=offset
)
if len(identifiers) == 0:
break
for identifier in identifiers: