source: TI01-discovery/branches/ingestion-MEDIN/ingestAutomation-upgrade/OAIBatch/testISO.py @ 6363

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI01-discovery/branches/ingestion-MEDIN/ingestAutomation-upgrade/OAIBatch/testISO.py@6363
Revision 6363, 3.0 KB checked in by sdonegan, 12 years ago (diff)

added method to return start and end dates - useful if multiple date elements used

Line 
1from ExtractISO import ExtractISO
2import logging,os,pdb,datetime
3
4def accessIsoDataModel(struct,name):
5        cnt=0
6
7        #are we dealing with a list or dictionary?
8        if type(struct) is dict:
9                for j in struct.keys():
10                        print name + "(" + str(cnt) + "): " + j + " = " + str(struct[j])
11                        cnt = cnt + 1
12                       
13        if type(struct) is list:       
14                for i in struct:
15                        if type(i) is dict:
16                                for j in i.keys():             
17                                        print name + "(" + str(cnt) + "): " + j + " = " + str(i[j])
18                        if type(i) is list:
19                                for j in i:
20                                        print name + "(" + str(cnt) + "): " + j
21               
22                        if len(struct) > 1:
23                                print "-------------------------------"
24                       
25                        cnt = cnt + 1
26
27logging.basicConfig(level=logging.DEBUG,format='%(asctime)s %(filename)s:%(lineno)d %(levelname)s %(message)s')
28
29#test dif2stubIso xml file - converted from dif via xquery
30dif2stubIso_file = 'data/NEODC/stub_iso/neodc.nerc.ac.uk__stubISO__dataent_11658383444211836_DIF_multiDate.xml'
31#dif2stubIso_file = 'data/NEODC/stub_iso/neodc.nerc.ac.uk__stubISO__dataent_11658383444211836_DIF_multiCoord.xml'
32#dif2stubIso_file = 'data/NEODC/stub_iso/neodc.nerc.ac.uk__stubISO__dataent_11658383444211836_DIF.xml'
33
34isoData = ExtractISO(dif2stubIso_file,'dif2stubIso')
35
36if isoData.createISOdataStructure() is True:
37        logging.info("ISO extractor worked fine! (here are the variables...)")
38elif isoData.createISOdataStructure() is True:
39        logging.info ("Something wrong with ISO extractor... (ExtractISO returned False: xml access problem?)")
40        sys.exit()
41else:
42        logging.info( "Something SERIOUSELY wrong with extractor (couldnt get at ExtractISO class)")
43        sys.exit()
44
45print "\nTesting for bounding dates (list of dictionaries) ..."
46name = "boundingDates"
47accessIsoDataModel(isoData.boundingDates, name)
48
49print "\nTesting for extracting start and end dates (dictionary)"
50name = "boundingDatesRange"
51
52accessIsoDataModel(isoData.boundingDatesRange,name)
53
54
55
56print "\nTesting for datasetID (List)..."
57name = "datasetID"
58accessIsoDataModel(isoData.datasetID, name)
59
60print "\nTesting for keywords (List)..."
61name = "keywords"
62accessIsoDataModel(isoData.keywords, name)
63
64print "\nTesting for revision date (List)..."
65name = "revisionDate"
66accessIsoDataModel(isoData.revisionDate, name)
67
68print "\nTesting for creation date (List) ..."
69name = "createDate"
70accessIsoDataModel(isoData.createDate, name)
71       
72print "\nTesting for dataset name (List) ..."
73name = "datasetName"
74accessIsoDataModel(isoData.datasetName, name)
75               
76print "\nTesting for original format (List) ..."
77name = "originalFormat"
78accessIsoDataModel(isoData.originalFormat, name)
79       
80print "\nTesting for authors (List) ..."
81name = "authors"
82accessIsoDataModel(isoData.authors, name)
83               
84print "\nTesting for data centre name (List) ..."
85name = "datacentreName"
86accessIsoDataModel(isoData.datacentreName, name)
87       
88print "\nTesting for parameters (List) ..."
89name = "parameters"
90accessIsoDataModel(isoData.parameters, name)
91       
92print "\nTesting for data centre name (list of dictionaries) ..."
93name = "boundingBoxCoordinates"
94accessIsoDataModel(isoData.boundingBoxCoordinates, name)
Note: See TracBrowser for help on using the repository browser.