scrapers/scrape_matrix.py
def check_expected(abbr, date, data):
    """
    Verify that canton `abbr` has expected numbers presents.
    If not, return a non-empty list of expectation violations back to the caller.
    """
    expected_extras = matrix[abbr]
    violated_expectations = []
    warnings = []

    for k in expected_extras:
        if k not in allowed_extras:
            text = f'Unknown extra {k} present (typo?) in expectation matrix[{abbr}]'
            print(f'WARNING: {text}', file=sys.stderr)
            warnings.append(text)

    cross = {
        'Confirmed cases': data.get('ncumul_conf'),
        'Deaths': data.get('ncumul_deceased'),
        'Hospitalized': data.get('current_hosp'),
        'ICU': data.get('current_icu'),
        'Vent': data.get('current_vent'),
        'Released': data.get('ncumul_released'),
        'Isolated': data.get('current_isolated'),
        'Quarantined': data.get('current_quarantined'),
    }

    # Check for fields that should be there, but aren't
    for k, v in cross.items():
        if v is None and k in expected_extras:
            violated_expectations.append(f'Expected {k} to be present for {abbr}')

    # Check for new fields, that are there, but we didn't expect them
    # for k, v in cross.items():
    #     if v is not None and k not in expected_extras:
    #         text = f'Not expected {k} to be present for {abbr}. Update scrape_matrix.py file.'
    #         print(f'WARNING: {text}', file=sys.stderr)
    #         warnings.append(text)

    assert date and "T" in date, f'Date is invalid: {date}'
    date_time = date.split("T", 1)
    assert len(date_time[0]) == 10
    if abbr in matrix_time:
        if len(date_time[1]) != 5:
            violated_expectations.append(f'Expected time of a day to be present for {abbr}. Found none.')
    else:
        if len(date_time[1]) != 0:
            text = f'Not expected time of a day to be present for {abbr}. Found "{date_time[1]}". Update scrape_matrix.py file?'
            print(f'WARNING: {text}', file=sys.stderr)
            warnings.append(text)

    return (violated_expectations, warnings)

    Verify that canton `abbr` has expected numbers presents.
    If not, return a non-empty list of expectation violations back to the caller.
    
Verify that canton `abbr` has expected numbers presents.
If not, return a non-empty list of expectation violations back to the caller.
Verify that canton ` abbr ` has expected numbers presents . If not return a non - empty list of expectation violations back to the caller .
def check_expected(abbr, date, data):
    expected_extras = matrix[abbr]
    violated_expectations = []
    warnings = []
    for k in expected_extras:
        if k not in allowed_extras:
            text = f'Unknown extra {k} present (typo?) in expectation matrix[{abbr}]'
            print(f'WARNING: {text}', file=sys.stderr)
            warnings.append(text)
    cross = {
        'Confirmed cases': data.get('ncumul_conf'),
        'Deaths': data.get('ncumul_deceased'),
        'Hospitalized': data.get('current_hosp'),
        'ICU': data.get('current_icu'),
        'Vent': data.get('current_vent'),
        'Released': data.get('ncumul_released'),
        'Isolated': data.get('current_isolated'),
        'Quarantined': data.get('current_quarantined'),
    }
    for k, v in cross.items():
        if v is None and k in expected_extras:
            violated_expectations.append(f'Expected {k} to be present for {abbr}')
    assert date and "T" in date, f'Date is invalid: {date}'
    date_time = date.split("T", 1)
    assert len(date_time[0]) == 10
    if abbr in matrix_time:
        if len(date_time[1]) != 5:
            violated_expectations.append(f'Expected time of a day to be present for {abbr}. Found none.')
    else:
        if len(date_time[1]) != 0:
            text = f'Not expected time of a day to be present for {abbr}. Found "{date_time[1]}". Update scrape_matrix.py file?'
            print(f'WARNING: {text}', file=sys.stderr)
            warnings.append(text)
    return (violated_expectations, warnings)
def check_expected ( abbr , date , data ) : expected_extras = matrix [ abbr ] violated_expectations = [ ] warnings = [ ] for k in expected_extras : if k not in allowed_extras : text = f'Unknown extra {k} present (typo?) in expectation matrix[{abbr}]' print ( f'WARNING: {text}' , file = sys . stderr ) warnings . append ( text ) cross = { 'Confirmed cases' : data . get ( 'ncumul_conf' ) , 'Deaths' : data . get ( 'ncumul_deceased' ) , 'Hospitalized' : data . get ( 'current_hosp' ) , 'ICU' : data . get ( 'current_icu' ) , 'Vent' : data . get ( 'current_vent' ) , 'Released' : data . get ( 'ncumul_released' ) , 'Isolated' : data . get ( 'current_isolated' ) , 'Quarantined' : data . get ( 'current_quarantined' ) , } for k , v in cross . items ( ) : if v is None and k in expected_extras : violated_expectations . append ( f'Expected {k} to be present for {abbr}' ) assert date and "T" in date , f'Date is invalid: {date}' date_time = date . split ( "T" , 1 ) assert len ( date_time [ 0 ] ) == 10 if abbr in matrix_time : if len ( date_time [ 1 ] ) != 5 : violated_expectations . append ( f'Expected time of a day to be present for {abbr}. Found none.' ) else : if len ( date_time [ 1 ] ) != 0 : text = f'Not expected time of a day to be present for {abbr}. Found "{date_time[1]}". Update scrape_matrix.py file?' print ( f'WARNING: {text}' , file = sys . stderr ) warnings . append ( text ) return ( violated_expectations , warnings )
Verify that canton `abbr` has expected numbers presents.
Verify that canton ` abbr ` has expected numbers presents .
"""
    Verify that canton `abbr` has expected numbers presents.
    If not, return a non-empty list of expectation violations back to the caller.
    """ # Check for fields that should be there, but aren't # Check for new fields, that are there, but we didn't expect them # for k, v in cross.items(): #     if v is not None and k not in expected_extras: #         text = f'Not expected {k} to be present for {abbr}. Update scrape_matrix.py file.' #         print(f'WARNING: {text}', file=sys.stderr) #         warnings.append(text)
abbr
date
data