Exemplo n.º 1
0
def get_fixed():
    valid_fields = [
        'id', 'title', 'description', 'state', 'date', 'pollution_category',
        'pollution_rating', 'budget', 'comments', 'location', 'photos'
    ]

    fields = request.args.get('fields', None)
    if fields:
        fields = [i for i in fields.split(',') if i in valid_fields]
    else:
        fields = valid_fields

    fixed_issues = IssueWrapper().fixed_issues_info(fields)
    response = json.dumps(fixed_issues)
    return response
Exemplo n.º 2
0
def issue_info(id):
    valid_fields = [
        'id', 'title', 'description', 'state', 'date', 'creator', 'approver',
        'pollution_category', 'pollution_rating', 'budget', 'comments',
        'location', 'photos'
    ]

    fields = request.args.get('fields', None)
    if fields:
        fields = [i for i in fields.split(',') if i in valid_fields]
    else:
        fields = valid_fields

    issue = IssueWrapper().info(id, fields)
    response = json.dumps(issue)

    return response
Exemplo n.º 3
0
def issue_get_comments(id):
    valid_fields = ['id', 'text', 'datetime', 'author', 'origin', 'rating']

    offset = int(request.args.get('offset', 0))
    offset = max(offset, 0)
    limit = int(request.args.get('limit', 25))
    limit = min(25, limit)

    fields = request.args.get('fields', None)
    if fields:
        fields = [i for i in fields.split(',') if i in valid_fields]
    else:
        fields = valid_fields

    comments = IssueWrapper().comments(id, fields, offset, limit)

    response = json.dumps(comments)
    return response
Exemplo n.º 4
0
                'title': i.title,
                'type': i.pollution_category.category,
                'date': str(i.date),
                'rating': i.pollution_rating,
                'text': i.description,
                'state': i.state.state,
                'lon': (point := wkb.loads(bytes(i.location.data))).x,
                'lat': point.y
            }
            for i in iter(issues)
        },
        separators=(',', ':'))


if __name__ == '__main__':
    connstring = os.getenv('POSTGRES_URL')
    if connstring is None:
        print('Setup the POSTGRES_URL variable')
        exit(1)

    db = sa.create_engine(connstring, echo=True)
    Session = sessionmaker(bind=db)
    Base.metadata.create_all(db)

    IssueWrapper(Session)
    EventWrapper(Session)
    UserWrapper(Session)
    MapWrapper(Session)

    app.run()