def agg_months(station_id): diapason = request.args.get('diapason') if diapason is None or diapason not in [ 'months', 'weeks', 'days', 'hours12', 'hours6' ]: return {}, 400 d_begin = request.args.get('begin') d_end = request.args.get('end') if d_begin is None or d_end is None: query = sql.text(f'SELECT web.{diapason}_json(:id);') return simple_get_set_values(db, query, id=station_id) else: try: if datetime.strptime(d_end, '%Y%m%d') <= datetime.strptime( d_begin, '%Y%m%d'): return jsonify(message='Некорректный диапозон дат!'), 400 query = sql.text( f'SELECT web.{diapason}_json_diapason(:id, :begin, :end);') return simple_get_set_values(db, query, id=station_id, begin=d_begin, end=d_end) except ValueError: print(sys.exc_info()) return jsonify(message='Некорректный диапозон дат!'), 400
def get_registration(station_id): if request.method == 'GET': d_begin = request.args.get('begin') d_end = request.args.get('end') data_type = request.args.get('type', 'json') if d_begin is None or d_end is None: if data_type == 'json': query = sql.text('SELECT web.registration_json(:id);') return simple_get_set_values(db, query, id=station_id) else: return {}, 400 else: try: if datetime.strptime(d_end, '%Y%m%d') <= datetime.strptime( d_begin, '%Y%m%d'): return jsonify(message='Некорректный диапозон дат!'), 400 if data_type == 'json': query = sql.text( 'SELECT web.registration_diapason_json(:id, :begin, :end);' ) return simple_get_set_values(db, query, id=station_id, begin=d_begin, end=d_end) else: return {}, 400 except ValueError: print(sys.exc_info()) return jsonify(message='Некорректный диапозон дат!'), 400
def all_regions(country_id): if request.method == 'POST': struct = request.get_json() query = sql.text('CALL web.insert_region_json(:json, :id)') if simple_import_values(db, query, json=json.dumps(struct), id=country_id): return {}, 201 return jsonify(message='exception!'), 400 elif request.method == 'GET': query = sql.text('SELECT web.region_json()') return simple_get_set_values(db, query, id=country_id)
def get_cloudiness(): query = sql.text('SELECT web.get_wind_direction_json()') return simple_get_set_values(db, query)
def get_all_stations(): if request.method == 'GET': query = sql.text('SELECT web.station_json()') return simple_get_set_values(db, query)
def get_all_locality(region_id): if request.method == 'GET': query = sql.text('SELECT web.locality_json()') return simple_get_set_values(db, query, id=region_id)