Changeset 34977


Ignore:
Timestamp:
2021-03-26T17:51:23+13:00 (3 years ago)
Author:
davidb
Message:

mini code tidy-up

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/model-sites-dev/eurovision-lod/collect/eurovision/prepare/errata-categories/esc-wikipedia-download-and-process-votes.py

    r34976 r34977  
    5252    return header_to_vals
    5353
    54 def convert_cols_to_country_recs(header_to_vals,year):
    55 
    56     country_recs = {}
    57 
     54def convert_cols_to_country_year_recs(header_to_vals,year):
     55
     56    country_year_recs = {}
     57
     58    a_href_re = re.compile(r"^.*" + str(year) + r"$")
     59   
    5860    for country_tag in header_to_vals.get("Country"):
    5961        # print("@@@@@ td = " + repr(country_tag));
    6062       
    61         country = country_tag.find("a",href=re.compile(r"^.*" + str(year) + r"$")).string
     63        #country = country_tag.find("a",href=re.compile(r"^.*" + str(year) + r"$")).string
     64        country = country_tag.find("a",href=a_href_re).string
    6265        # print("**** country = " + country)
    63        
    64         country_recs[country] = {}
     66        country_year = country+str(year)
     67       
     68        country_year_recs[country_year] = {}
    6569                   
    6670    for key in header_to_vals.keys():
     
    7377            country_tag = header_to_vals.get("Country")[l]
    7478            country_flag_img = country_tag.find("img")
    75             country = country_tag.find("a",href=re.compile(r"^.*" + str(year) + r"$")).string
     79            #country = country_tag.find("a",href=re.compile(r"^.*" + str(year) + r"$")).string
     80            country = country_tag.find("a",href=a_href_re).string
     81            country_year = country+str(year)
    7682           
    7783            val = vals[l]
    78             print("@@@ val = " + repr(val))
    7984           
    8085            if key == "Artist":
     
    106111            #print("*** storing: " + country + "[" + key + "] = " + val)
    107112           
    108             country_recs[country][key] = val
    109 
    110     return country_recs
    111 
    112 def output_country_recs(country_recs):
    113 
    114     for country_name in country_recs.keys():
    115         country_rec = country_recs.get(country_name)
     113            country_year_recs[country_year][key] = val
     114
     115    return country_year_recs
     116
     117def output_country_year_recs(country_year_recs):
     118
     119    for country_name in country_year_recs.keys():
     120        country_rec = country_year_recs.get(country_name)
    116121
    117122        print("[" + country_name + "]")
     
    164169    header_to_vals = html_tablerows_to_hashmap(table_rows)
    165170
    166     country_recs = convert_cols_to_country_recs(header_to_vals,year)
     171    country_year_recs = convert_cols_to_country_year_recs(header_to_vals,year)
    167172
    168173    print()
    169174    print("==========")
    170175
    171     output_country_recs(country_recs)
     176    output_country_year_recs(country_year_recs)
    172177   
    173178   
Note: See TracChangeset for help on using the changeset viewer.