Changeset 34863


Ignore:
Timestamp:
2021-02-15T21:29:06+13:00 (3 years ago)
Author:
davidb
Message:

Voting metadata added in

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  
    11#!/usr/bin/env python
     2
     3from __future__ import print_function
    24
    35import os
    46import re
    57import sys
     8import json
     9
    610import argparse
    7 
    811import openpyxl
    912
    1013import xlsxutil
    1114
    12 
     15def eprint(*args, **kwargs):
     16    print(*args, file=sys.stderr, **kwargs)
     17   
    1318def fileset_voting_for_esc_country_in_year(data_hashmap):
    1419
     
    8691    # { "FileSet":
    8792    #   [
    88     #     { "FileName": "France1991.id" },
     93    #     { "FileName": "France1991\.nul" },
    8994    #     { "Description":
    9095    #       {
     
    104109    metadata_array = []
    105110
     111    jury_metadata_vals = []
     112    tele_metadata_vals = []
     113   
    106114    for to_country_year_vote in to_country_year_votes:
    107115        to_country   = to_country_year_vote.get('To country')
     
    115123        metadata_array.append(voting_rec)
    116124
     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                         
    117137    id_to_country = to_country_year_votes[0].get('To country')
    118138    id_to_country = re.sub(r'\s+', '', id_to_country)   
    119139    id_year = to_country_year_votes[0].get('Year');
    120140    id = id_to_country + str(id_year);
    121     filename_id = id + ".id"
     141    filename_id = id + "\\.nul"
    122142
    123143    fileset = {
     
    151171    data_hashmap_array = xlsxutil.convert_worksheet_to_hashmaps(worksheet)
    152172
    153     print "Number of data rows: ", len(data_hashmap_array)
     173    print("Number of data rows: " + str(len(data_hashmap_array)))
    154174
    155175   
     
    167187    #     { "FileSet":
    168188    #       [
    169     #         { "FileName": "France1991.id" },
     189    #         { "FileName": "France1991\.nul" },
    170190    #         { "Description":
    171191    #           {
     
    185205    directory_metadata = []
    186206       
    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:")
    192208    for to_country_year_votes in to_country_year_voting_groups:
    193209       
     
    197213        filename_id = fileset.get('FileSet')[0].get('FileName')
    198214        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.