source: main/trunk/model-sites-dev/atea/collect/digital-nz/prepare/dnz-search-language-mi--python2.py@ 34460

Last change on this file since 34460 was 34460, checked in by davidb, 4 years ago

Tidy up of code and notes

  • Property svn:executable set to *
File size: 1.8 KB
Line 
1#!/usr/bin/env python2
2
3import dnz.api
4import pprint
5import json
6import sys
7import re
8
9# DNZ key
10DNZ = 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
17query_term={'language':['mi']}
18
19results = DNZ.search(_and=query_term, per_page=50)
20num_results=results.result_count
21print "Number of matching records: " + str(results.result_count)
22
23
24for 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
Note: See TracBrowser for help on using the repository browser.