Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from munch import Munch, DefaultMunch
import copy
root = os.path.join(os.path.dirname(__file__), '..')
def load(url):
with urllib.request.urlopen(url) as f:
return json.loads(f.read().decode())
data = DefaultMunch.fromDict({
'zotero': load('https://api.zotero.org/schema'),
'jurism': load('https://raw.githubusercontent.com/Juris-M/zotero-schema/master/schema-jurism.json')
}, None)
print('Generating item field metadata...')
ValidFields = DefaultMunch(None, {})
ValidTypes = {}
Alias = {}
Itemfields = set()
for client in data.keys():
for spec in data[client].itemTypes:
if spec.itemType in ValidTypes:
ValidTypes[spec.itemType] = 'true'
else:
ValidTypes[spec.itemType] = client
if not ValidFields[spec.itemType]:
if spec.itemType == 'note':
ValidFields[spec.itemType] = DefaultMunch(None, {field: 'true' for field in 'itemType tags note id itemID dateAdded dateModified'.split(' ')})
elif spec.itemType == 'attachment':
ValidFields[spec.itemType] = DefaultMunch(None, {field: 'true' for field in 'itemType tags id itemID dateAdded dateModified'.split(' ')})
else:
print('Generating item field metadata...')
ValidFields = DefaultMunch(None, {})
ValidTypes = {}
Alias = {}
Itemfields = set()
for client in data.keys():
for spec in data[client].itemTypes:
if spec.itemType in ValidTypes:
ValidTypes[spec.itemType] = 'true'
else:
ValidTypes[spec.itemType] = client
if not ValidFields[spec.itemType]:
if spec.itemType == 'note':
ValidFields[spec.itemType] = DefaultMunch(None, {field: 'true' for field in 'itemType tags note id itemID dateAdded dateModified'.split(' ')})
elif spec.itemType == 'attachment':
ValidFields[spec.itemType] = DefaultMunch(None, {field: 'true' for field in 'itemType tags id itemID dateAdded dateModified'.split(' ')})
else:
ValidFields[spec.itemType] = DefaultMunch(None, {field: 'true' for field in 'itemType creators tags attachments notes seeAlso id itemID dateAdded dateModified multi'.split(' ')})
for field in spec.fields:
if field.baseField:
if not field.baseField in Alias: Alias[field.baseField] = Munch(zotero=set(), jurism=set())
Alias[field.baseField][client].add(field.field)
fieldName = field.baseField
else:
fieldName = field.field
if spec.itemType not in ['note', 'attachment']: Itemfields.add(fieldName)
Alias = {}
Itemfields = set()
for client in data.keys():
for spec in data[client].itemTypes:
if spec.itemType in ValidTypes:
ValidTypes[spec.itemType] = 'true'
else:
ValidTypes[spec.itemType] = client
if not ValidFields[spec.itemType]:
if spec.itemType == 'note':
ValidFields[spec.itemType] = DefaultMunch(None, {field: 'true' for field in 'itemType tags note id itemID dateAdded dateModified'.split(' ')})
elif spec.itemType == 'attachment':
ValidFields[spec.itemType] = DefaultMunch(None, {field: 'true' for field in 'itemType tags id itemID dateAdded dateModified'.split(' ')})
else:
ValidFields[spec.itemType] = DefaultMunch(None, {field: 'true' for field in 'itemType creators tags attachments notes seeAlso id itemID dateAdded dateModified multi'.split(' ')})
for field in spec.fields:
if field.baseField:
if not field.baseField in Alias: Alias[field.baseField] = Munch(zotero=set(), jurism=set())
Alias[field.baseField][client].add(field.field)
fieldName = field.baseField
else:
fieldName = field.field
if spec.itemType not in ['note', 'attachment']: Itemfields.add(fieldName)
if ValidFields[spec.itemType][fieldName]:
ValidFields[spec.itemType][fieldName] = 'true'
else:
ValidFields[spec.itemType][fieldName] = client