Changeset 34863
- Timestamp:
- 2021-02-15T21:29:06+13:00 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/model-sites-dev/eurovision-lod/collect/eurovision/prepare/voting-excel/xlsx-to-jsonmetadata.py
r34861 r34863 1 1 #!/usr/bin/env python 2 3 from __future__ import print_function 2 4 3 5 import os 4 6 import re 5 7 import sys 8 import json 9 6 10 import argparse 7 8 11 import openpyxl 9 12 10 13 import xlsxutil 11 14 12 15 def eprint(*args, **kwargs): 16 print(*args, file=sys.stderr, **kwargs) 17 13 18 def fileset_voting_for_esc_country_in_year(data_hashmap): 14 19 … … 86 91 # { "FileSet": 87 92 # [ 88 # { "FileName": "France1991 .id" },93 # { "FileName": "France1991\.nul" }, 89 94 # { "Description": 90 95 # { … … 104 109 metadata_array = [] 105 110 111 jury_metadata_vals = [] 112 tele_metadata_vals = [] 113 106 114 for to_country_year_vote in to_country_year_votes: 107 115 to_country = to_country_year_vote.get('To country') … … 115 123 metadata_array.append(voting_rec) 116 124 125 if (vote_type == "J"): 126 jury_metadata_vals.append(from_country+"-J") 127 elif (vote_type == "T"): 128 tele_metadata_vals.append(from_country+"-T") 129 else: 130 eprint("Warning: Unrecognized voting type: " + vote_type) 131 132 if (len(jury_metadata_vals)>0): 133 metadata_array.append({ "name": "JuryVotesJSON", "content": json.dumps(jury_metadata_vals) }) 134 if (len(tele_metadata_vals)>0): 135 metadata_array.append({ "name": "TeleVotesJSON", "content": json.dumps(tele_metadata_vals) }) 136 117 137 id_to_country = to_country_year_votes[0].get('To country') 118 138 id_to_country = re.sub(r'\s+', '', id_to_country) 119 139 id_year = to_country_year_votes[0].get('Year'); 120 140 id = id_to_country + str(id_year); 121 filename_id = id + " .id"141 filename_id = id + "\\.nul" 122 142 123 143 fileset = { … … 151 171 data_hashmap_array = xlsxutil.convert_worksheet_to_hashmaps(worksheet) 152 172 153 print "Number of data rows: ", len(data_hashmap_array)173 print("Number of data rows: " + str(len(data_hashmap_array))) 154 174 155 175 … … 167 187 # { "FileSet": 168 188 # [ 169 # { "FileName": "France1991 .id" },189 # { "FileName": "France1991\.nul" }, 170 190 # { "Description": 171 191 # { … … 185 205 directory_metadata = [] 186 206 187 ### TODO 188 189 ## provide metadata value that lists the countries-year-type to voted 190 191 print "Creating Greenstone JSON voting metadata for:" 207 print("Creating Greenstone JSON voting metadata for:") 192 208 for to_country_year_votes in to_country_year_voting_groups: 193 209 … … 197 213 filename_id = fileset.get('FileSet')[0].get('FileName') 198 214 num_countries_voting_data = len(fileset.get('FileSet')[1].get('Description').get('Metadata')) 199 # print fileset.get('FileSet')[1].get('Description') 200 201 print " " + filename_id.ljust(28) + ": " + str(num_countries_voting_data) + " votes" 202 203 greenstone_metadata_json = { "DirectoryMetadta": directory_metadata } 204 205 215 216 print(" " + filename_id.ljust(28) + ": " + str(num_countries_voting_data) + " votes") 217 218 greenstone_metadata_json = { "DirectoryMetadata": directory_metadata } 219 220 221 with open(json_output_filename, 'w') as outfile: 222 json.dump(greenstone_metadata_json, outfile, indent=2)
Note:
See TracChangeset
for help on using the changeset viewer.