-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathris2web_api
executable file
·1061 lines (980 loc) · 57.3 KB
/
ris2web_api
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
#!/usr/bin/env python3
"""
pip install pyzotero
# zotero.Zotero.items returns a data list as follows:
{
"data": {
"DOI": "10.7202/027620ar",
"ISSN": "0034-379X, 1703-8138",
"abstractNote": "",
"accessDate": "2016-11-24T22:09:56Z",
"archive": "",
"archiveLocation": "",
"callNumber": "",
"collections": [
"GAZFJMGC"
],
"creators": [
{
"creatorType": "author",
"firstName": "John H. G.",
"lastName": "Crispo"
}
],
"date": "1965",
"dateAdded": "2016-11-24T22:09:56Z",
"dateModified": "2016-11-24T22:10:18Z",
"extra": "",
"issue": "4",
"itemType": "journalArticle",
"journalAbbreviation": "",
"key": "RWDBFFEU",
"language": "en",
"libraryCatalog": "CrossRef",
"pages": "700-706",
"publicationTitle": "Relations industrielles",
"relations": {},
"rights": "",
"series": "",
"seriesText": "",
"seriesTitle": "",
"shortTitle": "Looking Back and Looking Forward",
"tags": [],
"title": "Looking Back and Looking Forward : Can Organized Labour Stand the Test of Time?",
"url": "http://id.erudit.org/iderudit/027620ar",
"version": 14527,
"volume": "20"
},
"key": "RWDBFFEU",
"library": {
"id": 290262,
"links": {
"alternate": {
"href": "https://www.zotero.org/groups/canadian_labour_studies_bibliography",
"type": "text/html"
}
},
"name": "Canadian Labour Studies Bibliography",
"type": "group"
},
"links": {
"alternate": {
"href": "https://www.zotero.org/groups/canadian_labour_studies_bibliography/items/RWDBFFEU",
"type": "text/html"
},
"self": {
"href": "https://api.zotero.org/groups/290262/items/RWDBFFEU",
"type": "application/json"
}
},
"meta": {
"createdByUser": {
"id": 3393813,
"links": {
"alternate": {
"href": "https://www.zotero.org/erinvader",
"type": "text/html"
}
},
"name": "",
"username": "ErinVader"
},
"creatorSummary": "Crispo",
"numChildren": 0,
"parsedDate": "1965"
},
"version": 14527
}
"""
from pyzotero import zotero
import datetime
import json
import psycopg2
import configparser
from os.path import abspath, dirname
class ZoteroParser:
"""Read a Zotero item and parse it into its unique fields
Currently suffers a bit too much from its RIS background
"""
# We expect each of these fields to appear only once for a given citation
core_map = {
"abstractNote": "abstract",
"accessDate": "access_date",
"callNumber": "call_number",
"date": "pub_date",
#'date': 'pub_year',
"DOI": "doi",
"edition": "edition",
"endPage": "end_page", # we get this from parsing
"ISBN": "isbn_issn",
"ISSN": "isbn_issn",
"issue": "issue_number",
"itemType": "doc_type", # type of the cited document
"journalAbbreviation": "alternate_title", # often abbrev. journal or book title
"key": "zotero_key",
"language": "language",
"libraryCatalog": "pub_database",
"pages": "start_page",
"numPages": "start_page",
"place": "pub_place", # book
"publicationTitle": "pub_title",
"publisher": "publisher", # book
"rights": "rights",
"seriesNumber": "id_number",
"series": "series",
#'series': 'title2',
#'series': 'title3',
"shortTitle": "short_title", # often abbrev. journal or book title
"thesisType": "work_type",
"title": "title",
#'url': 'local_url',
"university": "publisher",
"url": "url",
"volume": "volume",
}
# multiple authors / editors per citation
# see http://refdb.sourceforge.net/manual/ch07.html#sect1-ris-format
# but Zotero exports "series_editor" as A2 and "editor" as A3, argh
author_map = {
"AU": "author",
"A3": "editor",
"A2": "series_editor",
"A4": "translator",
"A5": "contributor",
}
def __init__(self, item, config, notes):
"Parse it up"
self.add_date = datetime.datetime.strptime(
item["data"]["dateAdded"], "%Y-%m-%dT%H:%M:%SZ"
)
self.notes = notes
self.cite = {}
self.authors = []
self.keywords = []
self.config = config
self.get_db()
if item["data"]["itemType"] == "attachment":
return
if item["data"]["itemType"] == "note":
self.parse_notes(item)
return
for zot, ris in ZoteroParser.core_map.items():
if zot in item["data"]:
z = item["data"][zot]
if z == "" and ris not in self.cite:
self.cite[ris] = None
else:
self.cite[ris] = z
elif ris not in self.cite:
self.cite[ris] = None
if "creators" in item["data"]:
self.authorship(item)
if "tags" in item["data"]:
self.parse_tags(item)
self.map_doc_type()
self.map_pages()
# print(json.dumps(self.cite, sort_keys=True, indent=4))
self.cite["source"] = json.dumps(item["data"])
# print(json.dumps(self.authors))
def map_doc_type(self):
"Map Zotero doc types to RIS doc types"
z_to_r = {
"journalArticle": "JOUR",
"book": "BOOK",
"bookSection": "CHAP",
"thesis": "THES",
"report": "RPRT",
"webpage": "ELEC",
"magazineArticle": "MGZN",
"newspaperArticle": "JOUR",
"film": "MPCT",
"videoRecording": "VIDEO",
"map": "MAP",
"blogPost": "ELEC",
"encyclopediaArticle": "JOUR",
"conferencePaper": "JOUR",
}
if self.cite["doc_type"] in z_to_r:
self.cite["doc_type"] = z_to_r[self.cite["doc_type"]]
def map_pages(self):
"Map start/end pages"
if self.cite["start_page"] is not None and "-" in self.cite["start_page"]:
self.cite["start_page"], self.cite["end_page"] = self.cite[
"start_page"
].split("-", maxsplit=1)
# emdashes - really
if self.cite["start_page"] is not None and "–" in self.cite["start_page"]:
self.cite["start_page"], self.cite["end_page"] = self.cite[
"start_page"
].split("–", maxsplit=1)
def parse_tags(self, item):
"Parse out keywords for the item"
for t in item["data"]["tags"]:
self.keywords.append(t["tag"])
def parse_notes(self, item):
"Parse out notes for the item"
self.notes.append({item["data"]["key"]: item["data"]["note"]})
def authorship(self, item):
"Parse out different types of authors"
for a in item["data"]["creators"]:
# print("\t%s" % (json.dumps(a)))
if "firstName" in a:
self.authors.append(
{
"creator": a["creatorType"],
"name": "%s, %s" % (a["lastName"], a["firstName"]),
"first_name": a["firstName"],
"last_name": a["lastName"],
}
)
else:
self.authors.append({"creator": a["creatorType"], "name": a["name"]})
def insert_citation(self):
cur = self.conn.cursor()
cur.execute(
"""
INSERT INTO citations(abstract, access_date, alternate_title, call_number, doc_type, doi, edition, end_page, id_number, isbn_issn, issue_number, language, pub_database, pub_date, publisher, pub_place, pub_title, short_title, start_page, title, series, url, volume, work_type, zotero_key, source)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s);""",
(
self.cite["abstract"],
self.cite["access_date"],
self.cite["alternate_title"],
self.cite["call_number"],
self.cite["doc_type"],
self.cite["doi"],
self.cite["edition"],
self.cite["end_page"],
self.cite["id_number"],
self.cite["isbn_issn"],
self.cite["issue_number"],
self.cite["language"],
self.cite["pub_database"],
self.cite["pub_date"],
self.cite["publisher"],
self.cite["pub_place"],
self.cite["pub_title"],
self.cite["short_title"],
self.cite["start_page"],
self.cite["title"],
self.cite["series"],
self.cite["url"],
self.cite["volume"],
self.cite["work_type"],
self.cite["zotero_key"],
self.cite["source"],
),
)
self.conn.commit()
cur.close()
def update_citation(self):
if "title" not in self.cite or self.cite["title"] is None:
print(self.cite["zotero_key"])
return False
cur = self.conn.cursor()
# Start with checking for the Zotero key
if self.cite["zotero_key"] is not None:
cur.execute(
"SELECT id FROM citations WHERE zotero_key = %s",
(self.cite["zotero_key"],),
)
res = cur.fetchone()
if cur.rowcount != 1:
cur.execute(
r"""
SELECT id FROM citations WHERE (lower(translate(title, '[]:. ', '')) = %s OR regexp_replace(title, E' // Review', E'') = %s) AND doc_type = %s AND (start_page = %s OR start_page IS NULL) AND zotero_key IS NULL
""",
(
self.cite["title"]
.translate(str.maketrans("", "", "[]:. "))
.lower(),
self.cite["title"],
self.cite["doc_type"],
self.cite["start_page"],
),
)
res = cur.fetchone()
# If two match, then we'll be picking the first one
if cur.rowcount > 2 or res is None:
cur.close()
return False
cur.execute(
"UPDATE citations SET abstract= %s, access_date= %s, alternate_title= %s, call_number= %s, doc_type= %s, doi= %s, edition= %s, end_page = %s, id_number= %s, isbn_issn= %s, issue_number= %s, language= %s, pub_database= %s, pub_date= %s, pub_title= %s, publisher= %s, pub_place= %s, short_title= %s, start_page= %s, title= %s, series= %s, url= %s, volume= %s, work_type= %s, zotero_key= %s, source = %s WHERE id = %s",
(
self.cite["abstract"],
self.cite["access_date"],
self.cite["alternate_title"],
self.cite["call_number"],
self.cite["doc_type"],
self.cite["doi"],
self.cite["edition"],
self.cite["end_page"],
self.cite["id_number"],
self.cite["isbn_issn"],
self.cite["issue_number"],
self.cite["language"],
self.cite["pub_database"],
self.cite["pub_date"],
self.cite["pub_title"],
self.cite["publisher"],
self.cite["pub_place"],
self.cite["short_title"],
self.cite["start_page"],
self.cite["title"],
self.cite["series"],
self.cite["url"],
self.cite["volume"],
self.cite["work_type"],
self.cite["zotero_key"],
self.cite["source"],
res[0],
),
)
self.conn.commit()
cur.close()
return True
def insert_authors(self):
cur = self.conn.cursor()
for author in self.authors:
if "last_name" in author:
cur.execute(
"INSERT INTO zotero_cites_to_authors(zotero_key, author_type, name, last_name, first_name) VALUES (%s, %s, %s, %s, %s)",
(
self.cite["zotero_key"],
author["creator"],
author["name"],
author["last_name"],
author["first_name"],
),
)
else:
cur.execute(
"INSERT INTO zotero_cites_to_authors(zotero_key, author_type, name) VALUES (%s, %s, %s)",
(self.cite["zotero_key"], author["creator"], author["name"]),
)
self.conn.commit()
cur.close()
def insert_keywords(self):
cur = self.conn.cursor()
for kw in self.keywords:
cur.execute(
"INSERT INTO zotero_keywords(zotero_key, keywords) VALUES (%s, %s)",
(self.cite["zotero_key"], kw),
)
self.conn.commit()
cur.close()
def get_db(self):
"""
Get a database connection
With a host attribute in the mix, you could connect to a remote
database, but then you would have to set up .pgpass or add a
password parameter, so let's keep it simple.
"""
try:
self.conn = psycopg2.connect(
database=self.config["database"]["dbname"],
user=self.config["database"]["dbuser"],
)
except Exception as e:
print(e)
def get_db(config):
"""
Get a database connection
With a host attribute in the mix, you could connect to a remote
database, but then you would have to set up .pgpass or add a
password parameter, so let's keep it simple.
"""
try:
conn = psycopg2.connect(
database=config["database"]["dbname"], user=config["database"]["dbuser"]
)
except Exception as e:
print(e)
return conn
def prep_db(config):
"Extend the database to support richer Zotero API data"
# We're going to start tracking the citations by their zotero key:
stmts = [
"ALTER TABLE citations ADD COLUMN zotero_key TEXT;",
"ALTER TABLE citations ADD COLUMN source JSONB;",
"CREATE INDEX ON citations(zotero_key);",
r"UPDATE citations SET title = regexp_replace(title, E'^(.*?) (ed\\. )?by .*? \\(review\\)$', E'\\1') WHERE title ~ E' by .*? \\(review\\)$';",
r"UPDATE citations SET zotero_key = 'MNR2E9G7' WHERE title = 'Comprendre le comportement de l''individu au travail: un schema d''integration // Review';",
r"UPDATE citations SET zotero_key = 'HKPVMMVR' WHERE title = '[Au-dela de l''emploi: transformations du travail & devenir du droit du travail en Europe]' AND pub_date ~ '1999';",
r"UPDATE citations SET zotero_key = '8IZT5G6M' WHERE title = 'Critique du droit du travail // Review' AND pub_date ~ '1995';",
r"UPDATE citations SET zotero_key = 'RPKWMA9Z' WHERE title = '[Droits en synergie sur le travail: elements de droits international & compare du travail]' AND pub_date ~ '1998';",
r"UPDATE citations SET zotero_key = '7BTUBT86' WHERE title = 'Le droit des salaries a la negociation collective: principe general du droit // Review' AND pub_date ~ '1995';",
r"UPDATE citations SET zotero_key = 'IMURBAPS' WHERE title = 'Les dilemmes de l''ANACT: ambiguite ou complementarite? [L''accord nord-americain de cooperation dans le domaine du travail]' AND pub_date ~ '1999';",
r"UPDATE citations SET zotero_key = 'XCVR3HWC' WHERE title = 'L''État, l''autonomie collective et le travailleur - Étude comparée du droit italien et du droit français de la représentativité syndicale' AND pub_date ~ '1997';",
r"UPDATE citations SET zotero_key = 'HPH22NAD' WHERE title = '[Libertad sindical]' AND pub_date ~ '2000';",
r"UPDATE citations SET zotero_key = '98X42ZCX' WHERE title = 'Syndicats et droit syndical: Le droit syndical dans l''entreprise' AND pub_date ~ '1985';",
r"UPDATE citations SET zotero_key = 'JKVT5E4T' WHERE title = '[The rise & development of collective labor law]' AND pub_date ~ '2001';",
r"UPDATE citations SET zotero_key = 'SEK2ZV7H' WHERE title = 'Transformation de l''entreprise et representation syndicale' AND pub_date ~ '1993';",
r"UPDATE citations SET zotero_key = 'WSBUS4M2' WHERE title = 'La Planification strategique des ressources humaines // Review' AND pub_date ~ '1992';",
r"UPDATE citations SET zotero_key = 'C4K92P5M' WHERE title = 'Sayer, Derek. Capitalism And Modernity: An Excursus On Marx And Weber // Review' AND pub_date ~ '1991';",
r"UPDATE citations SET zotero_key = 'GBFI9W6E' WHERE title = 'Esping-Andersen, Gosta. The Three Worlds Of Welfare Capitalism // Review' AND pub_date ~ '1992';",
r"UPDATE citations SET zotero_key = '2T8TQAV3' WHERE title = 'Comparative Industrial Relations. Ideologies, Institutions, Practices and Problems under Social Systems with Special Reference to Socialist Planned Economies' AND pub_date ~ '1985';",
r"UPDATE citations SET zotero_key = 'A2K78SKR' WHERE title = 'Mitarbeiter beteiligung. Grundlagen - Befunde - Modelle';",
r"UPDATE citations SET zotero_key = '535SASAC' WHERE title = 'New Forms of Work Organization and thier Social and Economic Development';",
r"UPDATE citations SET zotero_key = 'WMRCN7DN' WHERE title = 'Trade Unions : The logic of Collective Action' AND pub_date ~ '1984';",
r"UPDATE citations SET zotero_key = '6H6S3ANE' WHERE title = 'Workplace Innovation in Canada. Reflections on the Past Prospects for the Future. A Study prepared for the Economic Council of Canada, Ottawa, Minister of Supply and Services Canada';",
r"UPDATE citations SET zotero_key = '5FQCJMJH' WHERE title = 'Book notes' AND pub_date ~ '1989';",
r"UPDATE citations SET zotero_key = 'FJQ743X2' WHERE title = 'Comparative Labour History: Australia and Canada' AND pub_date ~ '1996';",
r"UPDATE citations SET zotero_key = 'B69TWSH8' WHERE title = 'Editor''s Note' AND pub_date ~ '1988' AND pub_date ~ 'Spring';",
r"UPDATE citations SET zotero_key = '3TBZN432' WHERE title = 'Enjeux actuels de la formation professionnelle // Review' AND pub_date ~ '1994';",
r"UPDATE citations SET zotero_key = 'JHKHUMZE' WHERE title = 'Lane, Christel. Management And Labour In Europe // Review' AND pub_date ~ '1991';",
r"UPDATE citations SET zotero_key = '46AJPUFF' WHERE title = 'La sociologie des entreprises // Review' AND pub_date ~ '1996';",
r"UPDATE citations SET zotero_key = 'CCENH72Z' WHERE title = 'Les apprentissages du changement dans l''entreprise // Review' AND pub_date ~ '1996';",
r"UPDATE citations SET zotero_key = 'NJV89249' WHERE title = 'Modern capitalism: privatization, employee ownership & industrial democracy // Review' AND pub_date ~ '1996';",
r"UPDATE citations SET zotero_key = 'T3ZU5PT6' WHERE title = 'Occupational subcultures in the workplace // Review' AND pub_date ~ '1995';",
r"UPDATE citations SET zotero_key = 'BVI45GH5' WHERE title = 'On strong foundations: the BWIU & industrial relations in the Australian construction industry, 1942-1992 // Review' AND pub_date ~ '1996';",
r"UPDATE citations SET zotero_key = 'MZNVG26X' WHERE title = 'Profit sharing: does it make a difference? // Review' AND pub_date ~ '1994';",
r"UPDATE citations SET zotero_key = '4KJ4HQ5X' WHERE title = 'Projecting capitalism: a history of the internationalization of the construction industry // Review' AND pub_date ~ '1995';",
r"UPDATE citations SET zotero_key = '2N7APD6K' WHERE title = 'Shadows of the mind: a search for the missing science of consciousness // Review' AND pub_date ~ '1995';",
r"UPDATE citations SET zotero_key = 'QCZZ95UE' WHERE title = 'Understanding industrial organizations: theoretical perspectives in industrial sociology // Review' AND pub_date ~ '1994';",
r"UPDATE citations SET zotero_key = 'VXSPD67B' WHERE id = 2227 AND title ~* 'in case you hadn''t noticed';",
r"UPDATE citations SET zotero_key = 'XFDSE58P' WHERE id = 2228 AND title ~* 'in case you hadn''t noticed';",
r"UPDATE citations SET zotero_key = '777WN9HU' WHERE id = 204 AND title ~* 'Alberta''s Construction Labour Relations';",
r"DELETE FROM citations WHERE id = 205 AND title ~* 'Alberta''s Construction Labour Relations';",
r"UPDATE citations SET zotero_key = 'WTC627ZQ' WHERE id = 463 AND title ~* 'beyond Simulation, A Touch of Reality';",
r"DELETE FROM citations WHERE id = 464 AND title ~* 'beyond Simulation, A Touch of Reality';",
r"UPDATE citations SET zotero_key = 'SREMJFJ4' WHERE id = 467 AND title ~* 'Bargaining Units and Bargaining Power';",
r"DELETE FROM citations WHERE id IN (468, 469) AND title ~* 'Bargaining Units and Bargaining Power';",
r"UPDATE citations SET zotero_key = 'JSC4JQNT' WHERE id = 535 AND title ~* 'Recent Publications in Canadian Labour History';",
r"UPDATE citations SET zotero_key = 'T8WCZ9G9' WHERE id = 532 AND title ~* 'Recent Publications in Canadian Labour History';",
r"UPDATE citations SET zotero_key = 'JC9W3X3B' WHERE id = 533 AND title ~* 'Recent Publications in Canadian Labour History';",
r"UPDATE citations SET zotero_key = 'EC4XV7JF' WHERE id = 524 AND title ~* 'Recent Publications in Canadian Labour History';",
r"UPDATE citations SET zotero_key = 'V9G62UU9' WHERE id = 610 AND title ~* 'Book notes / Reférénces bibliographiques';",
r"DELETE FROM citations WHERE id = 609 AND title ~* 'Book notes/ Reférénces bibliographiques';",
r"UPDATE citations SET zotero_key = 'EUCSUJNP' WHERE title = 'Canadian Labour History Bibliography';",
r"DELETE FROM citations WHERE id IN (199, 285, 1384, 1473, 1485, 1993, 2126, 3073, 4007, 4471, 4495, 4638, 4821, 5023, 6276);",
r"UPDATE citations SET zotero_key = 'WBQJXC9H' WHERE id = 16;",
r"UPDATE citations SET zotero_key = 'XQQ445WB' WHERE id = 19;",
r"UPDATE citations SET zotero_key = '6HKBPUEA' WHERE id = 27;",
r"UPDATE citations SET zotero_key = 'Z3RVX5Q7' WHERE id = 25;",
r"UPDATE citations SET zotero_key = 'VBQUG42W' WHERE id = 28;",
r"UPDATE citations SET zotero_key = 'HDJHVBWN' WHERE id = 23;",
r"UPDATE citations SET zotero_key = '6VZRG53J' WHERE id = 26;",
r"UPDATE citations SET zotero_key = 'CBEQTU7S' WHERE id = 30;",
r"UPDATE citations SET zotero_key = '77INUJID' WHERE id = 29;",
r"UPDATE citations SET zotero_key = 'JK7QQ2RF' WHERE id = 24;",
r"UPDATE citations SET zotero_key = '8DHPRTGV' WHERE id = 22;",
r"UPDATE citations SET zotero_key = 'XDNE5VCR' WHERE id = 49;",
r"UPDATE citations SET zotero_key = 'CUEZJXXP' WHERE id = 50;",
r"UPDATE citations SET zotero_key = 'IHEWH5V8' WHERE id = 51;",
r"UPDATE citations SET zotero_key = 'W38DF65T' WHERE id = 149;",
r"UPDATE citations SET zotero_key = 'SRKMAIE6' WHERE id = 161;",
r"UPDATE citations SET zotero_key = 'XTNSBAMU' WHERE id = 193;",
r"UPDATE citations SET zotero_key = '3D3T26DZ' WHERE id = 201;",
r"UPDATE citations SET zotero_key = 'TMWHTBIZ' WHERE id = 264;",
r"UPDATE citations SET zotero_key = '28CG266F' WHERE id = 289;",
r"UPDATE citations SET zotero_key = '7G8M5QI6' WHERE id = 315;",
r"UPDATE citations SET zotero_key = 'SEK7N36I' WHERE id = 323;",
r"UPDATE citations SET zotero_key = '59E6JVGR' WHERE id = 367;",
r"UPDATE citations SET zotero_key = '947DIIH9' WHERE id = 393;",
r"UPDATE citations SET zotero_key = 'S4M95ZZD' WHERE id = 401;",
r"UPDATE citations SET zotero_key = 'WPX6Q6JT' WHERE id = 406;",
r"UPDATE citations SET zotero_key = 'H4MPEDZM' WHERE id = 427;",
r"UPDATE citations SET zotero_key = '96QAAGUF' WHERE id = 450;",
r"UPDATE citations SET zotero_key = 'E3F7V9KA' WHERE id = 549;",
r"UPDATE citations SET zotero_key = 'SGZZ3K3I' WHERE id = 551;",
r"UPDATE citations SET zotero_key = '4JH7BVTN' WHERE id = 562;",
r"UPDATE citations SET zotero_key = 'M98VH7KX' WHERE id = 614;",
r"UPDATE citations SET zotero_key = '2NAZ3AMB' WHERE id = 674;",
r"UPDATE citations SET zotero_key = 'W5GDWF99' WHERE id = 701;",
r"UPDATE citations SET zotero_key = '6E4J4QD8' WHERE id = 708;",
r"UPDATE citations SET zotero_key = 'C5FRF5EA' WHERE id = 722;",
r"UPDATE citations SET zotero_key = '9SW46SEQ' WHERE id = 799;",
r"UPDATE citations SET zotero_key = 'I2HDKKV2' WHERE id = 849;",
r"UPDATE citations SET zotero_key = 'JJJBXRUI' WHERE id = 847;",
r"UPDATE citations SET zotero_key = 'XW5HVEAP' WHERE id = 875;",
r"UPDATE citations SET zotero_key = 'PB638ZDJ' WHERE id = 911;",
r"UPDATE citations SET zotero_key = 'H4GFS4UF' WHERE id = 941;",
r"UPDATE citations SET zotero_key = 'RV8UJM8S' WHERE id = 993;",
r"UPDATE citations SET zotero_key = 'E3F7V9KA' WHERE id = 1077;",
r"UPDATE citations SET zotero_key = '67VE657D' WHERE id = 1104;",
r"UPDATE citations SET zotero_key = 'NG6UXHK2' WHERE id = 1132;",
r"UPDATE citations SET zotero_key = 'K73N932B' WHERE id = 1139;",
r"UPDATE citations SET zotero_key = '24XHRMND' WHERE id = 1202;",
r"UPDATE citations SET zotero_key = 'QUXX87X7' WHERE id = 1203;",
r"UPDATE citations SET zotero_key = '5S3C4DGJ' WHERE id = 1220;",
r"UPDATE citations SET zotero_key = 'R4DSUXFB' WHERE id = 1280;",
r"UPDATE citations SET zotero_key = 'TEPBXU9N' WHERE id = 1301;",
r"UPDATE citations SET zotero_key = '63ID5ZV3' WHERE id = 1352;",
r"UPDATE citations SET zotero_key = 'ZEZH64EX' WHERE id = 1392;",
r"UPDATE citations SET zotero_key = '4RXCEH28' WHERE id = 1400;",
r"UPDATE citations SET zotero_key = '4UUXAFGM' WHERE id = 1417;",
r"UPDATE citations SET zotero_key = 'HRC8EC3A' WHERE id = 1436;",
r"UPDATE citations SET zotero_key = '5ENDSVCH' WHERE id = 1435;",
r"UPDATE citations SET zotero_key = '2E3RZ9P2' WHERE id = 1437;",
r"UPDATE citations SET zotero_key = 'PQR3PEUB' WHERE id = 1447;",
r"UPDATE citations SET zotero_key = 'WBUZNAR6' WHERE id = 1446;",
r"UPDATE citations SET zotero_key = 'K7FZDEGP' WHERE id = 1450;",
r"UPDATE citations SET zotero_key = 'HPET8QP9' WHERE id = 1453;",
r"UPDATE citations SET zotero_key = '94EQH9JR' WHERE id = 1452;",
r"UPDATE citations SET zotero_key = 'ZSTK6RD3' WHERE id = 1451;",
r"UPDATE citations SET zotero_key = 'I4RBUTRK' WHERE id = 1448;",
r"UPDATE citations SET zotero_key = 'SGTPNN95' WHERE id = 1454;",
r"UPDATE citations SET zotero_key = 'NIDXH2J6' WHERE id = 1462;",
r"UPDATE citations SET zotero_key = 'FI3STXU6' WHERE id = 1466;",
r"UPDATE citations SET zotero_key = '3XNA7PRH' WHERE id = 1464;",
r"UPDATE citations SET zotero_key = '2DWQEZ63' WHERE id = 1460;",
r"UPDATE citations SET zotero_key = 'CI4WC368' WHERE id = 1465;",
r"UPDATE citations SET zotero_key = '9D23G8UZ' WHERE id = 1461;",
r"UPDATE citations SET zotero_key = 'U4GTIWTG' WHERE id = 1469;",
r"UPDATE citations SET zotero_key = '27F4E374' WHERE id = 1470;",
r"UPDATE citations SET zotero_key = 'WBUZNAR6' WHERE id = 1467;",
r"UPDATE citations SET zotero_key = 'PQR3PEUB' WHERE id = 1468;",
r"UPDATE citations SET zotero_key = 'VQZ74DFB' WHERE id = 1496;",
r"UPDATE citations SET zotero_key = 'TMUDECDM' WHERE id = 1501;",
r"UPDATE citations SET zotero_key = 'UK5M2SN7' WHERE id = 1522;",
r"UPDATE citations SET zotero_key = 'EWZWXIKU' WHERE id = 1578;",
r"UPDATE citations SET zotero_key = '7DH2GQHW' WHERE id = 1589;",
r"UPDATE citations SET zotero_key = 'NJG3UNE2' WHERE id = 1624;",
r"UPDATE citations SET zotero_key = 'QC8ZXDCZ' WHERE id = 1628;",
r"UPDATE citations SET zotero_key = '6GJIWW6P' WHERE id = 1632;",
r"UPDATE citations SET zotero_key = 'CDP4I93D' WHERE id = 1646;",
r"UPDATE citations SET zotero_key = 'PK3WWDXP' WHERE id = 1727;",
r"UPDATE citations SET zotero_key = 'FHPIXE5T' WHERE id = 1734;",
r"UPDATE citations SET zotero_key = 'WFQ6QHUC' WHERE id = 1750;",
r"UPDATE citations SET zotero_key = 'I5KF5RRS' WHERE id = 1791;",
r"UPDATE citations SET zotero_key = 'KPF8BTN4' WHERE id = 1908;",
r"UPDATE citations SET zotero_key = 'PQUURNXT' WHERE id = 1910;",
r"UPDATE citations SET zotero_key = 'CIA8XDEA' WHERE id = 1913;",
r"UPDATE citations SET zotero_key = 'WU3PDHK3' WHERE id = 1914;",
r"UPDATE citations SET zotero_key = '2H2PPG2M' WHERE id = 1915;",
r"UPDATE citations SET zotero_key = 'GV6DPTQZ' WHERE id = 1932;",
r"UPDATE citations SET zotero_key = 'U8349XXQ' WHERE id = 2019;",
r"UPDATE citations SET zotero_key = '3AVHGMK8' WHERE id = 2045;",
r"UPDATE citations SET zotero_key = '3P4XPGZX' WHERE id = 2068;",
r"UPDATE citations SET zotero_key = '3PWCF9E5' WHERE id = 2123;",
r"UPDATE citations SET zotero_key = '66NEJ7DH' WHERE id = 2125;",
r"UPDATE citations SET zotero_key = '8R7XKX5S' WHERE id = 2154;",
r"UPDATE citations SET zotero_key = 'W7PWFG7E' WHERE id = 2168;",
r"UPDATE citations SET zotero_key = 'XAWJW35U' WHERE id = 2169;",
r"UPDATE citations SET zotero_key = 'H8J3NC9D' WHERE id = 2187;",
r"UPDATE citations SET zotero_key = 'HXJGDQMG' WHERE id = 2265;",
r"UPDATE citations SET zotero_key = '5I7QIXV4' WHERE id = 2313;",
r"UPDATE citations SET zotero_key = 'PTKZI2U5' WHERE id = 2324;",
r"UPDATE citations SET zotero_key = 'E64IDBCM' WHERE id = 2369;",
r"UPDATE citations SET zotero_key = 'G3I8I2WR' WHERE id = 2461;",
r"UPDATE citations SET zotero_key = 'GSUNIMZ2' WHERE id = 2467;",
r"UPDATE citations SET zotero_key = 'RSRWKQCA' WHERE id = 2477;",
r"UPDATE citations SET zotero_key = 'NAXCQS78' WHERE id = 2488;",
r"UPDATE citations SET zotero_key = '2HATBVZB' WHERE id = 2494;",
r"UPDATE citations SET zotero_key = '68FMC37Q' WHERE id = 2502;",
r"UPDATE citations SET zotero_key = '7UFQ4349' WHERE id = 2511;",
r"UPDATE citations SET zotero_key = '42RPREGM' WHERE id = 2521;",
r"UPDATE citations SET zotero_key = 'VGMCX78U' WHERE id = 2522;",
r"UPDATE citations SET zotero_key = '2T6DZR8G' WHERE id = 2525;",
r"UPDATE citations SET zotero_key = 'KTGMT5BH' WHERE id = 2588;",
r"UPDATE citations SET zotero_key = 'EEUVD8J5' WHERE id = 2597;",
r"UPDATE citations SET zotero_key = '9N3QTQEX' WHERE id = 2615;",
r"UPDATE citations SET zotero_key = '94DBIAR5' WHERE id = 2636;",
r"UPDATE citations SET zotero_key = 'G4QQURXJ' WHERE id = 2643;",
r"UPDATE citations SET zotero_key = 'A6KAX2BA' WHERE id = 2648;",
r"UPDATE citations SET zotero_key = 'QMJN9BZR' WHERE id = 2659;",
r"UPDATE citations SET zotero_key = 'PC54IWWH' WHERE id = 2666;",
r"UPDATE citations SET zotero_key = 'U2U94TCE' WHERE id = 2676;",
r"UPDATE citations SET zotero_key = 'SGCWEF39' WHERE id = 2703;",
r"UPDATE citations SET zotero_key = '63PCHISE' WHERE id = 2704;",
r"UPDATE citations SET zotero_key = '3XH78WID' WHERE id = 2709;",
r"UPDATE citations SET zotero_key = '33Z42FSF' WHERE id = 2724;",
r"UPDATE citations SET zotero_key = 'THE2SWTV' WHERE id = 2735;",
r"UPDATE citations SET zotero_key = 'K55IZQ93' WHERE id = 2736;",
r"UPDATE citations SET zotero_key = 'VH7UKMT4' WHERE id = 2770;",
r"UPDATE citations SET zotero_key = 'QUI4I9KN' WHERE id = 2784;",
r"UPDATE citations SET zotero_key = '32SBUXEW' WHERE id = 2788;",
r"UPDATE citations SET zotero_key = 'GRAR96RR' WHERE id = 2799;",
r"UPDATE citations SET zotero_key = '8KSWZM9G' WHERE id = 2803;",
r"UPDATE citations SET zotero_key = '85N7DVBW' WHERE id = 2810;",
r"UPDATE citations SET zotero_key = '443I5782' WHERE id = 2819;",
r"UPDATE citations SET zotero_key = 'VJZ57CIZ' WHERE id = 2844;",
r"UPDATE citations SET zotero_key = '2G85V5CV' WHERE id = 2858;",
r"UPDATE citations SET zotero_key = '93QMCJZR' WHERE id = 2876;",
r"UPDATE citations SET zotero_key = 'VZUQ5F7H' WHERE id = 2904;",
r"UPDATE citations SET zotero_key = 'S8AMJCMG' WHERE id = 2914;",
r"UPDATE citations SET zotero_key = 'IWS4UWHJ' WHERE id = 2915;",
r"UPDATE citations SET zotero_key = '89AH4J5I' WHERE id = 2916;",
r"UPDATE citations SET zotero_key = 'U22PMZF7' WHERE id = 2927;",
r"UPDATE citations SET zotero_key = 'PSBP4QF9' WHERE id = 2933;",
r"UPDATE citations SET zotero_key = 'IA3KAEB9' WHERE id = 2940;",
r"UPDATE citations SET zotero_key = 'XCXPDZMP' WHERE id = 2946;",
r"UPDATE citations SET zotero_key = 'SNAKTX27' WHERE id = 2979;",
r"UPDATE citations SET zotero_key = 'U8WGM6F4' WHERE id = 2997;",
r"UPDATE citations SET zotero_key = 'BFVSP3VE' WHERE id = 2999;",
r"UPDATE citations SET zotero_key = 'ITPNP4WM' WHERE id = 3018;",
r"UPDATE citations SET zotero_key = 'QGDEN6ES' WHERE id = 3022;",
r"UPDATE citations SET zotero_key = '299NNICT' WHERE id = 3029;",
r"UPDATE citations SET zotero_key = 'H58JADJ7' WHERE id = 3037;",
r"UPDATE citations SET zotero_key = 'Q4NJN5CH' WHERE id = 3041;",
r"UPDATE citations SET zotero_key = '2CNWPT4R' WHERE id = 3046;",
r"UPDATE citations SET zotero_key = 'MTPMMR3B' WHERE id = 3050;",
r"UPDATE citations SET zotero_key = 'QCRGIPEW' WHERE id = 3052;",
r"UPDATE citations SET zotero_key = 'IDJEUE29' WHERE id = 3053;",
r"UPDATE citations SET zotero_key = 'XPVQAUBB' WHERE id = 3067;",
r"UPDATE citations SET zotero_key = '29PR4K93' WHERE id = 3083;",
r"UPDATE citations SET zotero_key = '57NMKF4F' WHERE id = 3095;",
r"UPDATE citations SET zotero_key = 'NUAZFM4V' WHERE id = 3097;",
r"UPDATE citations SET zotero_key = 'IGK2I5ZV' WHERE id = 3103;",
r"UPDATE citations SET zotero_key = 'KU9F6S72' WHERE id = 3109;",
r"UPDATE citations SET zotero_key = 'GM2STCE4' WHERE id = 3113;",
r"UPDATE citations SET zotero_key = 'QKCTB3K3' WHERE id = 3115;",
r"UPDATE citations SET zotero_key = '8UDPUID3' WHERE id = 3133;",
r"UPDATE citations SET zotero_key = 'RH5KNGJI' WHERE id = 3141;",
r"UPDATE citations SET zotero_key = 'JN2B7SIP' WHERE id = 3150;",
r"UPDATE citations SET zotero_key = 'XCVR3HWC' WHERE id = 3151;",
r"UPDATE citations SET zotero_key = 'FRSS4P3D' WHERE id = 3160;",
r"UPDATE citations SET zotero_key = '5NW4A32F' WHERE id = 3162;",
r"UPDATE citations SET zotero_key = 'B4PS53I4' WHERE id = 3165;",
r"UPDATE citations SET zotero_key = 'XSI52RZN' WHERE id = 3172;",
r"UPDATE citations SET zotero_key = 'TUE5XJ6M' WHERE id = 3179;",
r"UPDATE citations SET zotero_key = '5SRCUPQ6' WHERE id = 3187;",
r"UPDATE citations SET zotero_key = '39RDA9RE' WHERE id = 3215;",
r"UPDATE citations SET zotero_key = 'RDXC8PDC' WHERE id = 3221;",
r"UPDATE citations SET zotero_key = 'QT5ZEXGB' WHERE id = 3223;",
r"UPDATE citations SET zotero_key = 'SJB37ZJ2' WHERE id = 3236;",
r"UPDATE citations SET zotero_key = 'Q5UIPEFA' WHERE id = 3238;",
r"UPDATE citations SET zotero_key = 'UI7BMJVH' WHERE id = 3239;",
r"UPDATE citations SET zotero_key = '9QJQENXE' WHERE id = 3246;",
r"UPDATE citations SET zotero_key = 'V7ZI8CQE' WHERE id = 3274;",
r"UPDATE citations SET zotero_key = 'XQGQQ8BK' WHERE id = 3258;",
r"UPDATE citations SET zotero_key = '58IU3ERH' WHERE id = 3279;",
r"UPDATE citations SET zotero_key = 'RCT5Q965' WHERE id = 3261;",
r"UPDATE citations SET zotero_key = 'J5AZNZ5I' WHERE id = 3280;",
r"UPDATE citations SET zotero_key = 'M6UDZDUB' WHERE id = 3270;",
r"UPDATE citations SET zotero_key = 'PK23C2WK' WHERE id = 3259;",
r"UPDATE citations SET zotero_key = 'TRQI7E8Q' WHERE id = 3263;",
r"UPDATE citations SET zotero_key = 'RU8XJG7T' WHERE id = 3265;",
r"UPDATE citations SET zotero_key = 'DXDC9BKV' WHERE id = 3260;",
r"UPDATE citations SET zotero_key = 'RB6WUBPB' WHERE id = 3275;",
r"UPDATE citations SET zotero_key = 'EA5IXD4H' WHERE id = 3272;",
r"UPDATE citations SET zotero_key = 'CZP45QGH' WHERE id = 3278;",
r"UPDATE citations SET zotero_key = 'CX4QGEA6' WHERE id = 3276;",
r"UPDATE citations SET zotero_key = 'ITZNUHCB' WHERE id = 3273;",
r"UPDATE citations SET zotero_key = 'XT9SKN6U' WHERE id = 3271;",
r"UPDATE citations SET zotero_key = 'A7TFAK2H' WHERE id = 3277;",
r"UPDATE citations SET zotero_key = 'P96P3UVK' WHERE id = 3264;",
r"UPDATE citations SET zotero_key = 'F3PVPQ9S' WHERE id = 3296;",
r"UPDATE citations SET zotero_key = 'UDP89A5T' WHERE id = 3297;",
r"UPDATE citations SET zotero_key = 'VXAJ6PAC' WHERE id = 3303;",
r"UPDATE citations SET zotero_key = 'ATXBI8JW' WHERE id = 3322;",
r"UPDATE citations SET zotero_key = 'NQH5T8QB' WHERE id = 3373;",
r"UPDATE citations SET zotero_key = 'ZED93AXB' WHERE id = 3375;",
r"UPDATE citations SET zotero_key = '6MNET3PR' WHERE id = 3430;",
r"UPDATE citations SET zotero_key = 'RDCHR2KV' WHERE id = 3431;",
r"UPDATE citations SET zotero_key = '8QZEKB6K' WHERE id = 3457;",
r"UPDATE citations SET zotero_key = 'HWMSKRDN' WHERE id = 3483;",
r"UPDATE citations SET zotero_key = 'RUSZM4CQ' WHERE id = 3489;",
r"UPDATE citations SET zotero_key = 'EA7RXWZA' WHERE id = 3511;",
r"UPDATE citations SET zotero_key = '8DN4BJGW' WHERE id = 3544;",
r"UPDATE citations SET zotero_key = 'PVDSJDBJ' WHERE id = 3571;",
r"UPDATE citations SET zotero_key = 'B8KRN2U9' WHERE id = 3572;",
r"UPDATE citations SET zotero_key = 'SMFPJ828' WHERE id = 3573;",
r"UPDATE citations SET zotero_key = '3AAV3ZSA' WHERE id = 3696;",
r"UPDATE citations SET zotero_key = '5CHVMG75' WHERE id = 3708;",
r"UPDATE citations SET zotero_key = 'AV92K3MJ' WHERE id = 3703;",
r"UPDATE citations SET zotero_key = 'F2ISI7P5' WHERE id = 3704;",
r"UPDATE citations SET zotero_key = '27F4E374' WHERE id = 3707;",
r"UPDATE citations SET zotero_key = '7N2DDTA2' WHERE id = 3712;",
r"UPDATE citations SET zotero_key = 'RFTZSMEH' WHERE id = 3727;",
r"UPDATE citations SET zotero_key = 'WKHEC99F' WHERE id = 3775;",
r"UPDATE citations SET zotero_key = '3WD33CZE' WHERE id = 3780;",
r"UPDATE citations SET zotero_key = 'FJ6CKEVB' WHERE id = 3783;",
r"UPDATE citations SET zotero_key = 'IMKQVHR4' WHERE id = 3796;",
r"UPDATE citations SET zotero_key = 'PJMDVVKX' WHERE id = 3813;",
r"UPDATE citations SET zotero_key = 'GV3FGJ9I' WHERE id = 3863;",
r"UPDATE citations SET zotero_key = 'GU5S4RB9' WHERE id = 3896;",
r"UPDATE citations SET zotero_key = 'KNKS5A4V' WHERE id = 3908;",
r"UPDATE citations SET zotero_key = 'Q35DKNFM' WHERE id = 3924;",
r"UPDATE citations SET zotero_key = '78GGGR98' WHERE id = 3941;",
r"UPDATE citations SET zotero_key = '5QZVE7XR' WHERE id = 3993;",
r"UPDATE citations SET zotero_key = 'TS7RRHZH' WHERE id = 4027;",
r"UPDATE citations SET zotero_key = '4HGFTEWD' WHERE id = 4035;",
r"UPDATE citations SET zotero_key = 'ZU94X98B' WHERE id = 4150;",
r"UPDATE citations SET zotero_key = 'BCQAUZSA' WHERE id = 4160;",
r"UPDATE citations SET zotero_key = '3PG7853C' WHERE id = 4141;",
r"UPDATE citations SET zotero_key = 'V48SDNPH' WHERE id = 4136;",
r"UPDATE citations SET zotero_key = 'DFG3RMJD' WHERE id = 4137;",
r"UPDATE citations SET zotero_key = '2W7GAQ7B' WHERE id = 4151;",
r"UPDATE citations SET zotero_key = 'MM8SN2S3' WHERE id = 4158;",
r"UPDATE citations SET zotero_key = 'NMBXRHGR' WHERE id = 4139;",
r"UPDATE citations SET zotero_key = 'GQMRTUS6' WHERE id = 4142;",
r"UPDATE citations SET zotero_key = 'QC4B3TZ9' WHERE id = 4143;",
r"UPDATE citations SET zotero_key = '8V2D9WB7' WHERE id = 4157;",
r"UPDATE citations SET zotero_key = '7N2AZDKX' WHERE id = 4152;",
r"UPDATE citations SET zotero_key = 'FXSPNH7X' WHERE id = 4155;",
r"UPDATE citations SET zotero_key = 'H3AQQVG4' WHERE id = 4154;",
r"UPDATE citations SET zotero_key = 'CJ7DH32A' WHERE id = 4159;",
r"UPDATE citations SET zotero_key = '8644GJCV' WHERE id = 4138;",
r"UPDATE citations SET zotero_key = 'F4IFMXT6' WHERE id = 4156;",
r"UPDATE citations SET zotero_key = '7Q5QKP9D' WHERE id = 4153;",
r"UPDATE citations SET zotero_key = 'DIDQ7PAE' WHERE id = 4175;",
r"UPDATE citations SET zotero_key = '3AAWK2UW' WHERE id = 4193;",
r"UPDATE citations SET zotero_key = 'QT5KRTSH' WHERE id = 4208;",
r"UPDATE citations SET zotero_key = 'Q624U7AP' WHERE id = 4215;",
r"UPDATE citations SET zotero_key = 'JDTEGZJG' WHERE id = 4237;",
r"UPDATE citations SET zotero_key = 'SNAKTX27' WHERE id = 4277;",
r"UPDATE citations SET zotero_key = 'RIRBT4HG' WHERE id = 4290;",
r"UPDATE citations SET zotero_key = 'KRGX3A6C' WHERE id = 4303;",
r"UPDATE citations SET zotero_key = '7E5N9NGF' WHERE id = 4319;",
r"UPDATE citations SET zotero_key = 'W5BQPG6C' WHERE id = 4325;",
r"UPDATE citations SET zotero_key = 'BKXKXQXG' WHERE id = 4326;",
r"UPDATE citations SET zotero_key = '7XZ2D6DZ' WHERE id = 4345;",
r"UPDATE citations SET zotero_key = 'UIZ56E8X' WHERE id = 4347;",
r"UPDATE citations SET zotero_key = 'SWETPUHV' WHERE id = 4355;",
r"UPDATE citations SET zotero_key = '5TH95JAA' WHERE id = 4357;",
r"UPDATE citations SET zotero_key = 'BHN78KCR' WHERE id = 4361;",
r"UPDATE citations SET zotero_key = 'HGGVVQK3' WHERE id = 4400;",
r"UPDATE citations SET zotero_key = 'WFKT8ZT3' WHERE id = 4450;",
r"UPDATE citations SET zotero_key = '4AMAB8EU' WHERE id = 4452;",
r"UPDATE citations SET zotero_key = 'KFVMZQZE' WHERE id = 4539;",
r"UPDATE citations SET zotero_key = 'QM7WBVWF' WHERE id = 4545;",
r"UPDATE citations SET zotero_key = '358RJW83' WHERE id = 4549;",
r"UPDATE citations SET zotero_key = '7RIKSWWW' WHERE id = 4569;",
r"UPDATE citations SET zotero_key = '8WS73VKR' WHERE id = 4590;",
r"UPDATE citations SET zotero_key = '7H3CMDHE' WHERE id = 4615;",
r"UPDATE citations SET zotero_key = 'MR5FGBMV' WHERE id = 4645;",
r"UPDATE citations SET zotero_key = '7EDNAA82' WHERE id = 4650;",
r"UPDATE citations SET zotero_key = 'QKCTB3K3' WHERE id = 4659;",
r"UPDATE citations SET zotero_key = 'PPZ4JV7D' WHERE id = 4691;",
r"UPDATE citations SET zotero_key = 'FEU5QPMI' WHERE id = 4694;",
r"UPDATE citations SET zotero_key = '6GRRREX3' WHERE id = 4695;",
r"UPDATE citations SET zotero_key = '8279D8QV' WHERE id = 4759;",
r"UPDATE citations SET zotero_key = 'BAQ9VSG2' WHERE id = 4793;",
r"UPDATE citations SET zotero_key = 'KDK9UKD2' WHERE id = 4847;",
r"UPDATE citations SET zotero_key = 'TX7S9ZMJ' WHERE id = 4910;",
r"UPDATE citations SET zotero_key = 'HPTW2SKQ' WHERE id = 5022;",
r"UPDATE citations SET zotero_key = 'XTSUB4NQ' WHERE id = 5059;",
r"UPDATE citations SET zotero_key = 'PXABGMT8' WHERE id = 5080;",
r"UPDATE citations SET zotero_key = 'C2VFT48X' WHERE id = 5142;",
r"UPDATE citations SET zotero_key = 'Q8GRRPMQ' WHERE id = 5172;",
r"UPDATE citations SET zotero_key = 'CZKEANUF' WHERE id = 5190;",
r"UPDATE citations SET zotero_key = 'JHA3GSPG' WHERE id = 5229;",
r"UPDATE citations SET zotero_key = '9ETW49DK' WHERE id = 5231;",
r"UPDATE citations SET zotero_key = '8GPZNBP9' WHERE id = 5285;",
r"UPDATE citations SET zotero_key = 'M4WEXRBS' WHERE id = 5352;",
r"UPDATE citations SET zotero_key = 'CXBRB63R' WHERE id = 5400;",
r"UPDATE citations SET zotero_key = '2KTX4N5E' WHERE id = 5465;",
r"UPDATE citations SET zotero_key = 'ANSS6QF4' WHERE id = 5493;",
r"UPDATE citations SET zotero_key = '473PRJPA' WHERE id = 5505;",
r"UPDATE citations SET zotero_key = '8FKGWCCJ' WHERE id = 5596;",
r"UPDATE citations SET zotero_key = 'DKW5EMT5' WHERE id = 5626;",
r"UPDATE citations SET zotero_key = 'AXUGN7KT' WHERE id = 5640;",
r"UPDATE citations SET zotero_key = '22ERE4S5' WHERE id = 5643;",
r"UPDATE citations SET zotero_key = 'XPWRZCWB' WHERE id = 5711;",
r"UPDATE citations SET zotero_key = 'B4B2WSBD' WHERE id = 5781;",
r"UPDATE citations SET zotero_key = 'X4S4QJ96' WHERE id = 5839;",
r"UPDATE citations SET zotero_key = 'AXJZWBV6' WHERE id = 5846;",
r"UPDATE citations SET zotero_key = '2IKX57VI' WHERE id = 5860;",
r"UPDATE citations SET zotero_key = 'NJD2JWFD' WHERE id = 5874;",
r"UPDATE citations SET zotero_key = 'C3Q22DCI' WHERE id = 5896;",
r"UPDATE citations SET zotero_key = 'DF6R7THG' WHERE id = 5917;",
r"UPDATE citations SET zotero_key = '4ISA5SK7' WHERE id = 5940;",
r"UPDATE citations SET zotero_key = 'BJ5HZ6PQ' WHERE id = 5955;",
r"UPDATE citations SET zotero_key = 'CRJ8GZ87' WHERE id = 5986;",
r"UPDATE citations SET zotero_key = '82AK589W' WHERE id = 6057;",
r"UPDATE citations SET zotero_key = 'EMRU3I8G' WHERE id = 6126;",
r"UPDATE citations SET zotero_key = '3HERXVSN' WHERE id = 6140;",
r"UPDATE citations SET zotero_key = '5H7W73HH' WHERE id = 6153;",
r"UPDATE citations SET zotero_key = 'AGGQV6UA' WHERE id = 6227;",
r"UPDATE citations SET zotero_key = 'U3STKGXZ' WHERE id = 6262;",
r"UPDATE citations SET zotero_key = 'HEQXAJ2S' WHERE id = 6266;",
r"UPDATE citations SET zotero_key = 'PND5UTN6' WHERE id = 6270;",
r"UPDATE citations SET zotero_key = 'MEPGETEA' WHERE id = 6314;",
r"UPDATE citations SET zotero_key = 'DSIDSE7A' WHERE id = 6340;",
r"UPDATE citations SET zotero_key = 'VITKARH4' WHERE id = 6527;",
r"UPDATE citations SET zotero_key = 'M4X9EZNQ' WHERE id = 6528;",
]
# This will enable us to insert the new citations, as well as a new
# zotero_cites_to_authors table:
stmts.append(
"CREATE TABLE zotero_cites_to_authors (zotero_key TEXT, author_type TEXT, name TEXT, first_name TEXT, last_name TEXT, author_id INT);"
)
# Then we'll be able to normalize the authors with the existing authors table
# (updating author_id), then map the authors to citations by ID in the
# cites_to_author table.
# We also want to automatically assign IDs for the new citations (6533 is the latest):
stmts.append("CREATE SEQUENCE citations_id_seq;")
stmts.append("SELECT SETVAL('citations_id_seq', MAX(id) + 1) FROM citations;")
stmts.append(
"ALTER TABLE citations ALTER COLUMN id SET DEFAULT nextval('citations_id_seq');"
)
# Prevent duplicate author/citation rows from new citations
stmts.append(
"ALTER TABLE cites_to_authors ADD CONSTRAINT unique_cites_to_authors UNIQUE (citation, author_type, author);"
)
# Store our keywords
stmts.append("CREATE TABLE zotero_keywords(zotero_key TEXT, keywords TEXT)")
conn = get_db(config)
cur = conn.cursor()
for stmt in stmts:
cur.execute(stmt)
conn.commit()
cur.close()
def post_process(config, notes):
stmts = [
r"""UPDATE citations
SET url = regexp_replace(url, '\.librweb.laurentian.ca', '')
WHERE url ~ 'librweb';""",
r"UPDATE citations SET isbn_issn = regexp_replace(isbn_issn, E'^(\\d{4})(\\d{4})$', '\1-\2') WHERE isbn_issn ~ E'^\\d{8}$';",
r"UPDATE citations SET isbn_issn = regexp_replace(isbn_issn, E'^(\\d{4})(\\d{3}X)$', '\1-\2') WHERE isbn_issn ~ E'^\\d{7}X$';",
"UPDATE citations SET title2 = pub_title WHERE doc_type = 'JOUR' AND title2 IS NULL AND pub_title IS NOT NULL;",
"UPDATE zotero_cites_to_authors SET author_id = a.id FROM authors a WHERE a.author_name = name;",
"INSERT INTO authors (author_name) SELECT DISTINCT name FROM zotero_cites_to_authors WHERE author_id IS NULL;",
"UPDATE zotero_cites_to_authors SET author_id = a.id FROM authors a WHERE a.author_name = name AND author_id IS NULL;",
"INSERT INTO cites_to_authors (citation, author_type, author) SELECT DISTINCT c.id, z.author_type, z.author_id FROM zotero_cites_to_authors z INNER JOIN citations c ON c.zotero_key = z.zotero_key WHERE c.zotero_key IS NOT NULL AND NOT EXISTS (SELECT citation, author_type, author FROM cites_to_authors WHERE citation = c.id AND author_type = z.author_type AND author = z.author_id);",
r"""UPDATE citations
SET title2 = 'Relations Industrielles / Industrial Relations'
WHERE title2 ~* 'Relations Industrielles';""",
r"""UPDATE citations
SET title2 = 'Labour / Le Travail'
WHERE title2 IN ('Labour/Le Travail');""",
r"""UPDATE citations
SET title2 = 'Socialist Studies / Études socialistes'
WHERE title2 IN ('Socialist Studies/Études socialistes');""",
r"""UPDATE citations SET language = 'English'
WHERE language IN ('eng', 'en', 'en_ca', 'en-GB', 'en-US', 'EN', 'en-CA');""",
r"""UPDATE citations SET language = 'English'
WHERE language IS NULL;""",
r"""UPDATE citations SET language = 'French'
WHERE language IN ('fr', 'fre');""",
r"""UPDATE citations SET language = 'Spanish'
WHERE language IN ('sp');""",
r"""UPDATE citations SET language = 'English, French'
WHERE language IN ('en fr', 'eng; fre');""",
r"""UPDATE citations SET language = 'French, English'
WHERE language IN ('fr en');""",
r"""UPDATE citations SET language = 'French, English, Spanish'
WHERE language IN ('fr en sp');""",
r"""UPDATE citations SET language = 'Italian'
WHERE language IN ('It');""",
r"""UPDATE citations
SET publisher = 'Canadian Committee on Labour History'
WHERE publisher = 'Committee on Canadian Labour History';""",
r"""UPDATE citations SET series = title2
WHERE doc_type IN ('BOOK', 'RPRT');""",
r"""UPDATE citations SET series = title3
WHERE doc_type IN ('CHAP');""",
r"""UPDATE citations SET pub_title = title2
WHERE doc_type IN ('JOUR', 'CHAP', 'NEWS', 'MGZN', 'ELEC');""",
r"""UPDATE citations SET pub_title = title
WHERE doc_type IN ('BOOK');""",
r"""UPDATE citations SET kw_tsv = setweight(to_tsvector('english', title), 'A')
|| setweight(to_tsvector('english', COALESCE(abstract, '')), 'C');""",
r"""UPDATE citations SET kw_tsv = kw_tsv || setweight(to_tsvector('english', COALESCE(
(SELECT STRING_AGG(notes, ' ') FROM citation_notes WHERE citation = citations.id), '')), 'C');""",
r"""UPDATE citations SET kw_tsv = kw_tsv || setweight(to_tsvector('english', COALESCE(
(SELECT STRING_AGG(keywords, ' ') FROM citation_keywords WHERE citation = citations.id), '')), 'B');""",
r"""UPDATE citations SET kw_tsv = kw_tsv || setweight(to_tsvector('english', COALESCE(
(SELECT STRING_AGG(author_name, ' ') FROM authored_v WHERE citation = citations.id), '')), 'B');""",
r"UPDATE citations SET pub_date = regexp_replace(pub_date, E'^(\\D+) (\\d{4})', E'\\2\/\/\/\\1') WHERE pub_date ~ E'^\\D';",
r"UPDATE citations SET pub_date = regexp_replace(pub_date, E'^.*? (\\d+).*? (\\d{4})', E'\\2/01/\\1') WHERE pub_date ~* E'^Jan';",
r"UPDATE citations SET pub_date = regexp_replace(pub_date, E'^.*? (\\d+).*? (\\d{4})', E'\\2/02/\\1') WHERE pub_date ~* E'^Feb';",
r"UPDATE citations SET pub_date = regexp_replace(pub_date, E'^.*? (\\d+).*? (\\d{4})', E'\\2/03/\\1') WHERE pub_date ~* E'^Mar';",
r"UPDATE citations SET pub_date = regexp_replace(pub_date, E'^.*? (\\d+).*? (\\d{4})', E'\\2/04/\\1') WHERE pub_date ~* E'^Apr';",
r"UPDATE citations SET pub_date = regexp_replace(pub_date, E'^.*? (\\d+).*? (\\d{4})', E'\\2/05/\\1') WHERE pub_date ~* E'^May';",
r"UPDATE citations SET pub_date = regexp_replace(pub_date, E'^.*? (\\d+).*? (\\d{4})', E'\\2/06/\\1') WHERE pub_date ~* E'^Jun';",
r"UPDATE citations SET pub_date = regexp_replace(pub_date, E'^.*? (\\d+).*? (\\d{4})', E'\\2/07/\\1') WHERE pub_date ~* E'^Jul';",
r"UPDATE citations SET pub_date = regexp_replace(pub_date, E'^.*? (\\d+).*? (\\d{4})', E'\\2/08/\\1') WHERE pub_date ~* E'^Aug';",
r"UPDATE citations SET pub_date = regexp_replace(pub_date, E'^.*? (\\d+).*? (\\d{4})', E'\\2/09/\\1') WHERE pub_date ~* E'^Sep';",
r"UPDATE citations SET pub_date = regexp_replace(pub_date, E'^.*? (\\d+).*? (\\d{4})', E'\\2/10/\\1') WHERE pub_date ~* E'^Oct';",
r"UPDATE citations SET pub_date = regexp_replace(pub_date, E'^.*? (\\d+).*? (\\d{4})', E'\\2/11/\\1') WHERE pub_date ~* E'^Nov';",
r"UPDATE citations SET pub_date = regexp_replace(pub_date, E'^.*? (\\d+).*? (\\d{4})', E'\\2/12/\\1') WHERE pub_date ~* E'^Dec';",
r"UPDATE citations SET pub_date = regexp_replace(pub_date, E'^(\\d{2})\/(\\d{2})\/(\\d{4})', E'\\3\/\\2\/\\1') WHERE pub_date ~ E'^\\d{2}\/\\d{2}\/\\d{4}';",
r"UPDATE citations SET pub_date = regexp_replace(pub_date, E'^(\\d+) March (\\d{4})', E'\\2/03/\\1') WHERE pub_date ~* E'March';",
r"UPDATE citations SET pub_date = regexp_replace(pub_date, E'^(\\d+) April (\\d{4})', E'\\2/04/\\1') WHERE pub_date ~* E'April';",
r"UPDATE citations SET pub_date = regexp_replace(pub_date, E'^(\\d+) May (\\d{4})', E'\\2/05/\\1') WHERE pub_date ~* E'May';",
r"UPDATE citations SET pub_date = regexp_replace(pub_date, E'^(\\d+) July (\\d{4})', E'\\2/07/\\1') WHERE pub_date ~* E'July';",
r"UPDATE citations SET pub_date = regexp_replace(pub_date, E'^(\\d+) October (\\d{4})', E'\\2/10/\\1') WHERE pub_date ~* E'October';",
r"UPDATE citations SET pub_date = regexp_replace(pub_date, E'^(\\d{2})\/(\\d{4})', E'\\2/\\1') WHERE pub_date ~ E'^\\d{2}\/\\d{4}';",
]
try:
conn = get_db(config)
cur = conn.cursor()
for stmt in stmts:
cur.execute(stmt)
conn.commit()
for note in notes:
cur.execute(
"INSERT INTO citation_notes(citation, notes) VALUES (%s, %s)",
(note[0], note[1]),
)
conn.commit()
cur.close()
except Exception as e:
print(e)
def main():
"Integrate the latest updates to the database"
write_updates = True
read_updates = False
notes = []
config = configparser.ConfigParser()
config.read(abspath(dirname(__file__)) + "/config.ini")
if write_updates:
f = open("updates.json", "w")
try:
prep_db(config)
except Exception as e:
print(e)
stop_date = datetime.datetime.strptime(config["zotero"]["stop_date"], "%Y-%m-%d")
# Access our group
zot = zotero.Zotero(config["zotero"]["group"], "group", config["zotero"]["key"])
# list_collections(zot)
if read_updates and not write_updates:
f = open("updates.json", "r")
items = json.load(f)
else:
items = zot.items(sort="dateModified", direction="desc", limit=100)
# items = [zot.item('JC94RN9H')]
# import requests