-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfields.py
410 lines (393 loc) · 5.98 KB
/
fields.py
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
#!/usr/bin/env python3
import csv
from datetime import datetime
import json
import time
yyyymdNow = datetime.now().strftime("%y%m%d")
yymmdd = time.strftime("%y%m%d")
fractionalNow = datetime.now().strftime("%Y%m%d%H%M%S.%f")[:-4]
class DataField:
def __init__(
self,
tag,
ind1='\\',
ind2='\\'
):
self.tag = tag
self.ind1 = ind1
self.ind2 = ind2
self.subfields = []
class Subfield:
def __init__(self,subfieldCharacter,value):
self.subfieldCharacter = subfieldCharacter
self.value = value
class Leader:
def __init__(self,ItemBytes):
self.ItemBytes = ItemBytes
self.data = (
"{}"
"{}"
"{}"
"{}"
"{}"
"{}"
"{}"
"{}"
"{}"
"{}"
"{}"
"{}"
"{}"
"{}"
"{}"
"{}".format(
"00000", # Record length (??)
self.ItemBytes.Recstat,
self.ItemBytes.Type,
self.ItemBytes.BLvl,
self.ItemBytes.Ctrl,
"a", # character coding scheme (UTF-8)
"2", # indicator count
"2", # subfield count
"00000", # Base Address of Data (system supplied???)
self.ItemBytes.ELvl,
self.ItemBytes.Desc,
"\\",
"4", # Length of the length-of-field portion
"5", # Length of the starting-character-position portion
"0", # Length of the implementation-defined portion
"0" # Undefined
)
)
class OhOhSeven:
def __init__(self,
a="\\",
b="\\",
c="||", # annoyingly, $c doesn't exist in 007 but you still have to leave an empty space for where it would go
d="\\",
e="\\",
f="\\",
g="\\",
h="\\",
i="\\",
j="\\",
k="\\",
l="\\",
m="\\",
n="\\",
o="\\",
p="\\",
q="\\",
r="\\\\\\\\"
):
# I think 007 only has up to 'r' subfields...
self.a = a
self.b = b
self.c = c
self.d = d
self.e = e
self.f = f
self.g = g
self.h = h
self.i = i
self.j = j
self.k = k
self.l = l
self.m = m
self.n = n
self.o = o
self.p = p
self.q = q
self.r = r
self.data = (
"{}"
"{}"
"{}"
"{}"
"{}"
"{}"
"{}"
"{}"
"{}"
"{}"
"{}"
"{}"
"{}"
"{}".format(
self.a,
self.b,
self.c,
self.d,
self.e,
self.f,
self.g,
self.h,
self.i,
self.j,
self.k,
self.l,
self.m,
self.n
)
)
class OhOhEight:
def __init__(self,ItemBytes):
self.ItemBytes = ItemBytes
self.data = (
"{}"
"{}"
"{}"
"{}"
"{}"
"{}"
"{}"
"{}"
"{}".format(
self.ItemBytes.Entered,
self.ItemBytes.DtSt,
self.ItemBytes.Dates[:4], # Date 1
self.ItemBytes.Dates[4:], # Date 2
self.ItemBytes.Ctry,
self.ItemBytes.set_008_bytes(),
self.ItemBytes.Lang,
self.ItemBytes.MRec,
self.ItemBytes.Srce
)
)
class OhOhSix:
def __init__(self):
pass
class ItemBytes:
"""
Manifestation-specific codes used in Leader/008/006
format must be one of: BKS, CNR, COM, MAP, MIX, REC, SCO, VIS
formatCode is the more specific MARC "type code"
"""
def __init__(
self,
format,
AccM="\\\\\\\\\\\\",
Alph="\\",
Audn="\\",
Biog="\\",
BLvl="\\",
Comp="\\\\",
Conf="\\",
Cont="\\\\\\\\",
CrTp="a",
Ctrl="\\",
Ctry="\\\\\\",
Dates="\\\\\\\\\\\\\\\\",
Desc="\\",
DtSt="\\",
ELvl="\\",
Entered=yyyymdNow,
EntW="\\",
Fest="\\",
File="u",
FMus="n",
Form="\\",
Freq="\\",
GPub="\\",
Ills="\\\\\\\\",
Indx="\\",
Lang="\\\\\\",
LitF="u",
LTxt="\\\\",
MRec="\\",
OCLC=None,
Orig="\\",
Part="n",
Proj="\\\\",
Recstat="n",
Regl="\\",
Relf="\\\\\\\\",
Replaced="\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\",
SpFm="\\\\",
Srce="d",
SrTp="\\",
SL="0",
Tech="n",
Time="\\\\\\",
TMat="\\",
TrAr="n",
Type="\\"
):
self.format = format
self.AccM=AccM
self.Alph=Alph
self.Audn=Audn
self.Biog=Biog
self.BLvl=BLvl
self.Comp=Comp
self.Conf=Conf
self.Cont=Cont
self.CrTp=CrTp
self.Ctrl=Ctrl
self.Ctry=Ctry
self.Dates=Dates
self.Desc=Desc
self.DtSt=DtSt
self.ELvl=ELvl
self.Entered=Entered
self.EntW=EntW
self.Fest=Fest
self.File=File
self.FMus=FMus
self.Form=Form
self.Freq=Freq
self.GPub=GPub
self.Ills=Ills
self.Indx=Indx
self.Lang=Lang
self.LitF=LitF
self.LTxt=LTxt
self.MRec=MRec
self.OCLC=OCLC
self.Orig=Orig
self.Part=Part
self.Proj=Proj
self.Recstat=Recstat
self.Regl=Regl
self.Relf=Relf
self.Replaced=Replaced
self.SpFm=SpFm
self.Srce=Srce
self.SrTp=SrTp
self.SL=SL
self.Tech=Tech
self.Time=Time
self.TMat=TMat
self.TrAr=TrAr
self.Type=Type
def set_008_bytes(self):
"""
Set the 008 format-specific 17 character byte string (positions 18-34)
"""
if self.format == "BKS":
bytes = (
"{}"
"{}"
"{}"
"{}"
"{}"
"{}"
"{}"
"{}"
"{}"
"{}"
"{}".format(
self.Ills,
self.Audn,
self.Form,
self.Cont,
self.GPub,
self.Conf,
self.Fest,
self.Indx,
"\\",
self.LitF,
self.Biog
)
)
elif self.format == "REC":
bytes = (
"{}"
"{}"
"{}"
"{}"
"{}"
"{}"
"{}"
"{}"
"{}"
"{}".format(
self.Comp,
self.FMus,
self.Part,
self.Audn,
self.Form,
self.AccM,
self.LTxt,
"\\",
self.TrAr,
"\\"
)
)
elif self.format == "VIS":
bytes = (
"{}"
"{}"
"{}"
"{}"
"{}"
"{}"
"{}"
"{}"
"{}"
"{}"
"{}"
"{}"
"{}"
"{}"
"{}".format(
self.Time,
"\\",
self.Audn,
"\\",
"\\",
"\\",
"\\",
"\\",
self.GPub,
self.Form,
"\\",
"\\",
"\\",
self.TMat,
self.Tech
)
)
elif self.format == "COM":
bytes = (
"{}"
"{}"
"{}"
"{}"
"{}"
"{}"
"{}"
"{}"
"{}"
"{}"
"{}"
"{}"
"{}"
"{}"
"{}"
"{}"
"{}".format(
"\\",
"\\",
"\\",
"\\",
self.Audn,
self.Form,
"\\",
"\\",
self.File,
"\\",
self.GPub,
"\\",
"\\",
"\\",
"\\",
"\\",
"\\"
)
)
# print(len(bytes))
if len(bytes) == 17:
return bytes
else:
return False