예제 #1
0
파일: __init__.py 프로젝트: izaxon/py2ng
def sch_to_intrf(name, schema, conv_camel=False):
    name = name.replace('Schema', '') + 'Interface'
    fields = []
    indent = ' ' * 4

    for k, v in schema._declared_fields.items():
        ts_type = TYPE_MAP.get(type(v), 'any')
        fields.append(
            f'{indent}{k if not conv_camel else to_camel(k)}: {ts_type};')
    fields = '\n'.join(fields)
    CONTENT = f'''export interface {name} {{
{fields}
}}
    '''
    print(CONTENT)
예제 #2
0
    def fix_zip_codes(self, data):
        # The source file has some weird ZIP codes like "15025-CLAR"
        # which appears to be a convention of appending an abbrevation
        # for the township to distinguish between multiple neighborhoods
        # and townships in the same ZIP code.

        # Other oddballs: "15-71"
        fields = ['incident.zip']
        if 'decedent.zip' in data:
            fields.append(['decedent.zip'])
        for field in fields:
            if data[field] in ['NA']:
                data[field] = None
            elif len(data[field]) > 5:
                data[field] = data[field][:5]  # This is a simple truncation
예제 #3
0
        def resolve_selectors(s):
            fields = []
            sub_field_selectors = {}
            # TODO: Handle dot-separated fields
            for k, v in s._update_fields().items():
                fields.extend(v.metadata.get('backing_attrs', []))

                field_name = v.attribute or v.name or k
                nested_schema = _schema_for_field(v)
                if not nested_schema:
                    fields.append(field_name)
                else:
                    schema_view = v.schema_view
                    if schema_view:
                        nested_schema.schema_view = schema_view
                    sub_field_selectors[field_name] = resolve_selectors(nested_schema)
            return selectors.FieldSelectors(*fields, **sub_field_selectors)
예제 #4
0
 def find_form_fields(self):
     fields = []
     forms = BeautifulSoup(self.html, features="lxml").find_all('form')
     inputs = forms[0].find_all('input')
     for input in inputs:
         fields.append(input['name'])