Esempio n. 1
0
def save_courts_to_file():
    ''' Writes all courts to .json files in Playground data sources folder'''
    courts = [
        [
            'district_courts', 'https://www.mass.gov/orgs/district-court/locations'
        ],
        [
            'housing_courts', 'https://www.mass.gov/orgs/housing-court/locations'
        ],
        [
            'bmc', 'https://www.mass.gov/orgs/boston-municipal-court/locations'
        ],
        [
            'superior_courts', 'https://www.mass.gov/orgs/superior-court/locations'
        ],
        [
            'land_courts', 'https://www.mass.gov/orgs/land-court/locations'
        ],
        [
            'juvenile_courts', 'https://www.mass.gov/orgs/juvenile-court/locations'
        ],
        [
            'probate_and_family_courts', 'https://www.mass.gov/orgs/probate-and-family-court/locations'
        ] 
    ]

    try:
        for court in courts: 
            area = PlaygroundSection('sources').get_area()
            fpath = os.path.join(area.directory, court[0] + '.json')
            jdata = text_type(json.dumps(get_courts_from_massgov_url(court[1])))
            f = open(fpath, 'w')
            f.write(jdata)
            f.close()
            area.finalize()
    except:
        e = sys.exc_info()[0]
        return e
    else:
        return "Finished saving courts"
Esempio n. 2
0
 def __unicode__(self):
     return text_type(self.name)