def load_courts_from_file(self,
                              json_path,
                              data_path='docassemble.MACourts:data/sources/'):
        """Add the list of courts at the specified JSON file into the current list"""

        path = path_and_mimetype(os.path.join(data_path,
                                              json_path + '.json'))[0]

        with open(path) as courts_json:
            courts = json.load(courts_json)

        for item in courts:
            # translate the dictionary data into an MACourtList

            court = self.appendObject()
            court.name = item['name']
            court.phone = item['phone']
            court.fax = item['fax']
            court.location.latitude = item['location']['latitude']
            court.location.longitude = item['location']['longitude']
            court.has_po_box = item.get('has_po_box')
            court.description = item.get('description')

            court.address.address = item['address']['address']
            court.address.city = item['address']['city']
            court.address.state = item['address']['state']
            court.address.zip = item['address']['zip']
            court.address.county = item['address']['county']
            court.address.orig_address = item['address'].get('orig_address')
 def load_boston_wards_from_file(
         self, json_path, data_path='docassemble.MACourts:data/sources/'):
     """load geojson file for boston wards"""
     path = path_and_mimetype(
         os.path.join(data_path, json_path + '.geojson'))[0]
     wards = gpd.read_file(path)
     return wards
Example #3
0
def load_courts_from_file(json_path):
    new_courts = []

    (path, mimetype) = path_and_mimetype(json_path)

    with open(path) as courts_json:
        courts = json.load(courts_json)

    for item in courts:
        # translate the JSON data into a DA Address types
        address = Address()
        address.address = item['address']['address']
        address.city = item['address']['city']
        address.state = item['address']['state']
        address.zip = item['address']['zip']
        address.county = item['address']['county']

        court = MACourt()
        court.name = item['name']
        court.phone = item['phone']
        court.fax = item['fax']
        court.address = address
        court.lat = item['lat']
        court.lng = item['lng']

        new_courts.append(court)

    return new_courts
Example #4
0
def load_program_data():
    (path, mimetype
     ) = path_and_mimetype('docassemble.lscrefer:data/sources/Programs.json')
    with open(path, 'rU', encoding='utf-8') as fp:
        program_list = json.load(fp)
    lsc_programs.clear()
    for program_dict in program_list:
        program = dict()
        lsc_programs[program_dict["Serv_Area_ID"]] = program
        program['name'] = program_dict["R_Legalname"].strip()
        program['phone_number'] = program_dict["Local_800"].strip()
        program['url'] = program_dict["Web_URL"].strip()
    lsc_programs_by_rin.clear()
    lsc_programs_by_serv_a.clear()
    area_data = service_areas()
    if 'features' not in area_data:
        sys.stderr.write("area data is empty\n")
    else:
        for item in area_data['features']:
            attribs = item['attributes']
            if attribs['ServArea'] == 'MA-4':
                attribs['ServArea'] = 'MA04'
                attribs['ServArea_1'] = 'MA-4'
                attribs['servA'] = 'MA04'
            service_area = attribs['ServArea_1'].strip()
            if service_area in lsc_programs:
                lsc_programs_by_rin[
                    attribs['RIN']] = lsc_programs[service_area]
                lsc_programs_by_serv_a[
                    attribs['servA']] = lsc_programs[service_area]
                lsc_programs[service_area]['rin'] = attribs['RIN']
                lsc_programs[service_area]['serv_a'] = attribs['servA']
            else:
                sys.stderr.write("Could not find {} in program info.\n".format(
                    service_area))
def load_from_csv(relative_path):
    """ Return a list containing a dictionary for each line of the CSV file at relative_path. Uses Docassemble path_and_mimetype to locate the path."""
    (path, mimetype) = path_and_mimetype(relative_path)
    reader = csv.DictReader(open(path, 'r'))
    myList = []
    for line in reader:
        myList.append(line)
    del reader
    return myList
Example #6
0
 def _load_data(self)->pd.DataFrame:
   """
   Return dataframe of the whole file's contents.
   """
   if "/" in self.filename:
     to_load = path_and_mimetype(self.filename)[0]
   else:
     to_load = path_and_mimetype(os.path.join("data/sources", self.filename))[0]
   
   if self.filename.lower().endswith('.xlsx'):
     df = pd.read_excel(to_load)
   elif self.filename.lower().endswith('.csv'):
     df = pd.read_csv(to_load)
   elif self.filename.lower().endswith('.json'):
     # TODO: we may need to normalize a JSON file
     df = pd.read_json(to_load)
   else:
     raise Exception('The datafile must be a CSV, XLSX, or JSON file. Unknown file type: ' + to_load)
   return df
Example #7
0
def read_data(filename):
    the_xlsx_file, mimetype = path_and_mimetype(filename)
    df = pandas.read_excel(the_xlsx_file)
    for indexno in df.index:
        if not df['Name'][indexno]:
            continue
        fruit_names.append(df['Name'][indexno])
        fruit_info_by_name[df['Name'][indexno]] = {
            "color": df['Color'][indexno],
            "seeds": df['Seeds'][indexno]
        }
Example #8
0
    def load_courts_from_file(self,
                              court_name,
                              data_path='docassemble.MACourts:data/sources/'):
        """Add the list of courts at the specified JSON file into the current list"""

        json_path = court_name

        # 'housing_courts','bmc','district_courts','superior_courts'
        if court_name == 'housing_courts':
            court_department = 'Housing Court'
        elif court_name == 'bmc':
            court_department = 'Boston Municipal Court'
        elif court_name == 'district_courts':
            court_department = 'District Court'
        elif court_name == 'superior_courts':
            court_department = 'Superior Court'
        elif court_name == 'juvenile_courts':
            court_department = 'Juvenile Court'
        elif court_name in ['land_courts', 'land_court']:
            court_department = 'Land Court'
        elif court_name == 'probate_and_family_courts':
            court_department = 'Probate and Family Court'

        path = path_and_mimetype(os.path.join(data_path,
                                              json_path + '.json'))[0]

        with open(path) as courts_json:
            courts = json.load(courts_json)

        for item in courts:
            # translate the dictionary data into an MACourtList
            court = self.appendObject()
            court.name = item['name']
            court.department = court_department
            court.division = parse_division_from_name(item['name'])
            court.phone = item['phone']
            court.fax = item['fax']
            court.location.latitude = item['location']['latitude']
            court.location.longitude = item['location']['longitude']
            court.has_po_box = item.get('has_po_box')
            court.description = item.get('description')

            court.address.address = item['address']['address']
            court.address.city = item['address']['city']
            court.address.state = item['address']['state']
            court.address.zip = item['address']['zip']
            court.address.county = item['address']['county']
            court.address.orig_address = item['address'].get('orig_address')
Example #9
0
import csv
import re
import json
import requests
import io
import docx
import textract
import tempfile
from docassemble.base.util import path_and_mimetype, ocr_file, DAObject, DAFile

(filename, mimetype) = path_and_mimetype('data/static/obce.json')


def najitObec(obec, kraj):
    with open(filename, encoding='utf-8') as d:
        data = json.load(d)
    for polozka in data["municipalities"]:
        if obec.lower() == polozka["hezkyNazev"].lower() and re.sub(
                '(k|K)raj', '', kraj).strip().lower() == re.sub(
                    '(k|K)raj', '',
                    polozka["adresaUradu"]["kraj"]).strip().lower():
            return (polozka)
    return (False)


def vyhlaskyObce(idds):
    with requests.Session() as s:
        r = s.get(
            'https://sbirkapp.gov.cz/vyhledavani/vysledek?typ=ozv&ovm=' +
            idds +
            '&kod_vusc=&ucinnost_od=&ucinnost_do=&oblast=&zmocneni=&nazev=&znacka=&format_exportu=csv'
import csv
from docassemble.base.util import path_and_mimetype

(filename, mimetype) = path_and_mimetype('data/static/obyvatele_full.csv')

__all__ = ['pocetObyvatel']


def pocetObyvatel(obec):
    vysledek = []
    with open(filename, newline='', encoding='utf-8') as csvfile:
        reader = csv.reader(csvfile, delimiter=';')
        for row in reader:
            if row[1] == obec:
                vysledek.append(row)

    return (vysledek)
Example #11
0
 def test_path(self):
     (path, mimetype) = path_and_mimetype('lithuania.svg')
     self.assertTrue(
         path.endswith(
             'site-packages/docassemble/demo/data/static/lithuania.svg'))
     self.assertEqual(mimetype, 'image/svg+xml')
Example #12
0
 def __load_yaml(self, yaml_file_name, default=[]):
     path = path_and_mimetype(self.path + yaml_file_name)[0]
     #try:
     with open(path, encoding="utf-8") as file:
         results = yaml.safe_load(file)
         return results or default