1 | #!/usr/bin/env python2
|
---|
2 |
|
---|
3 | import dnz.api
|
---|
4 | import pprint
|
---|
5 | import json
|
---|
6 | import sys
|
---|
7 | import re
|
---|
8 |
|
---|
9 | # DNZ key
|
---|
10 | DNZ = dnz.api.Dnz('<CHANGEME>')
|
---|
11 |
|
---|
12 |
|
---|
13 | #result = dnz.search('kiwi tui')
|
---|
14 | #result = dnz.search('kiwi tui', per_page=50, page=10, fields=['id', 'title', 'collection', 'content_partner'])
|
---|
15 | #result = dnz.search(_or={'category':['Videos', 'Images']}, _and={'content_partner':['Ministry for Culture and Heritage']})
|
---|
16 |
|
---|
17 | query_term={'language':['mi']}
|
---|
18 |
|
---|
19 | results = DNZ.search(_and=query_term, per_page=50)
|
---|
20 | num_results=results.result_count
|
---|
21 | print "Number of matching records: " + str(results.result_count)
|
---|
22 |
|
---|
23 |
|
---|
24 | for i in range(0,num_results,50):
|
---|
25 | page = i / 50
|
---|
26 | results = DNZ.search(_and=query_term, page=page, per_page=50)
|
---|
27 |
|
---|
28 | for rec in results.records:
|
---|
29 | # pprint.pprint(rec)
|
---|
30 | landing_url = rec["landing_url"]
|
---|
31 | print "Landing URL: " + rec["landing_url"]
|
---|
32 |
|
---|
33 | landing_url = unicode(landing_url).encode('utf8')
|
---|
34 | json_landing_filename = re.sub('[:/.]', '-', landing_url) + ".json"
|
---|
35 | full_json_landing_filename = "downloads/" + json_landing_filename
|
---|
36 |
|
---|
37 | dc_identifiers = rec["dc_identifier"]
|
---|
38 |
|
---|
39 | #json.dump(rec, sys.stdout)
|
---|
40 |
|
---|
41 | if (len(dc_identifiers)>0):
|
---|
42 |
|
---|
43 | full_id = unicode(dc_identifiers[0]).encode('utf8')
|
---|
44 | print " ID: " + full_id
|
---|
45 |
|
---|
46 | # tail_id = full_id.replace('http://hdl.handle.net/','')
|
---|
47 |
|
---|
48 | # json_filename = re.sub('[:/.]', '-', tail_id) + ".json"
|
---|
49 | # print json_filename
|
---|
50 | else:
|
---|
51 | print "**** No ID specified"
|
---|
52 |
|
---|
53 |
|
---|
54 | with open(full_json_landing_filename, 'w') as outfile:
|
---|
55 | json.dump(rec, outfile)
|
---|
56 |
|
---|
57 | print ""
|
---|
58 |
|
---|
59 | # with open(json_filename, 'w') as outfile:
|
---|
60 | # json.dump(data, outfile)
|
---|
61 |
|
---|
62 | #pprint.pprint(result.records)
|
---|
63 |
|
---|
64 |
|
---|
65 | #with open('data.json', 'w') as outfile:
|
---|
66 | # json.dump(data, outfile)
|
---|
67 |
|
---|
68 |
|
---|