-
Notifications
You must be signed in to change notification settings - Fork 0
/
extensioncount.py
39 lines (32 loc) · 1022 Bytes
/
extensioncount.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
#!/usr/bin/env python
from __future__ import division
import optparse
import os
import sys
import dwca
import json
import pprint
parser = optparse.OptionParser()
parser.add_option("-f", "--file", help="DWC-a file to read")
parser.add_option("-q", "--quiet",
action="store_false", dest="verbose", default=True,
help="don't print status messages to stdout")
(options, args) = parser.parse_args()
ids = {}
if options.file == None:
parser.print_help()
sys.exit(1)
else:
dwcaobj = dwca.Dwca(options.file)
for record in dwcaobj.core:
ids[record["id"]] = 0
#print(json.dumps(record,separators=(',',':')))
for dwcrf in dwcaobj.extensions:
for record in dwcrf:
ids[record["coreid"]] += 1
#print(json.dumps(record,separators=(',',':')))
#print(json.dumps(dwcaobj.metadata,separators=(',',':')))
for k in ids.keys():
if ids[k] == 0:
del ids[k]
pprint.pprint(ids)