def trips(): if request.method == 'POST': id = uuid.uuid4() username = session['username'] origin = request.form['origin'] originLat = request.form['originLat'] originLng = request.form['originLng'] destination = request.form['destination'] destinationLat = request.form['destinationLat'] destinationLng = request.form['destinationLng'] seats = request.form['seats'] fare = request.form['fare'] date = request.form['date'] time = request.form['time'] database.execute( 'INSERT INTO trips VALUES ("{}", "{}", "{}", "{}", "{}", "{}", "{}", "{}", "{}", "{}", "{}", "{}");' .format(id, username, origin, originLat, originLng, destination, destinationLat, destinationLng, seats, fare, date, time)) return redirect(url_for('trip', id=id)) all_trips = database.fetchall( 'SELECT * FROM trips WHERE date >= date("now");') trips = list(map(get_trip_obj, all_trips)) passenger_count = dict( database.fetchall('SELECT id, COUNT(*) FROM carpools GROUP BY id;')) radius = request.args.get('radius', 10) originLat = request.args.get('originLat', None) originLng = request.args.get('originLng', None) destinationLat = request.args.get('destinationLat', None) destinationLng = request.args.get('destinationLng', None) if originLat and originLng: trips = [ trip for trip in trips if distance(trip['originLat'], trip['originLng'], float(originLat), float(originLng)) <= float(radius) ] if destinationLat and destinationLng: trips = [ trip for trip in trips if distance( trip['destinationLat'], trip['destinationLng'], float(destinationLat), float(destinationLng)) <= float(radius) ] return render_template('trip_list.html', trips=trips, passenger_count=passenger_count, filter=request.args)
async def history(msg: types.Message): global status all_screenshot = database.fetchall(msg.from_user.id) all_names = [i['name'] for i in all_screenshot] status = True await msg.answer("Выберите скриншоты которые хотите посмотреть:", reply_markup=get_button_list(all_names))
async def save_name_and_url(msg: types.Message, state: FSMContext): if msg.text in [i['name'] for i in database.fetchall(msg.from_user.id)]: await msg.answer(f"Имя {msg.text} занято придумайте другое") await SiteStates.write_name.set() # FSM.py else: await state.update_data({"name": msg.text}) screenshot_detail = await state.get_data() await state.finish() await msg.answer( "Отлично! Вот данные, которые вы ввели:\n\n" f"Имя: {screenshot_detail['name']}\n\n" f"Url: {screenshot_detail['url']}\n", reply_markup=ReplyKeyboardRemove()) await msg.answer("Подождите делаем скриншот!") url, name = screenshot_detail['url'], screenshot_detail['name'] user = msg.from_user.id database.insert({'name': name, 'url': url, 'user': user}) logger.info(msg.chat.id) browser = Browser(url, name) try: browser.get_sreenshot() except InvalidArgumentException: await msg.answer("Упс похоже Вы ввели неправильный адресс!", reply_markup=next_button) else: await msg.answer("Ваш скриншот готов:\n") await send_image(msg, screenshot_detail['name']) await msg.answer("Выберите:", reply_markup=next_button)
def get(self): query = '''SELECT * FROM APICOUNT''' rows = fetchall(query) if rows: for row in rows: return [row[0]], 200 else: return [-100], 200 #Should never actually reach here. If it reaches here, database tables not set up properly.
def my_trips(): username = session['username'] driver_trips = database.fetchall( 'SELECT * FROM trips WHERE username="******";'.format(username)) driver_trips = list(map(get_trip_obj, driver_trips)) rider_trip_ids = database.fetchall( 'SELECT id FROM carpools WHERE username="******";'.format(username)) rider_trip_ids = [t[0] for t in rider_trip_ids] rider_trips = database.fetchall( 'SELECT * FROM trips WHERE id IN ({})'.format( '"' + '","'.join(rider_trip_ids) + '"')) rider_trips = list(map(get_trip_obj, rider_trips)) passenger_count = dict( database.fetchall('SELECT id, COUNT(*) FROM carpools GROUP BY id;')) return render_template('my_trip_list.html', driver_trips=driver_trips, rider_trips=rider_trips, passenger_count=passenger_count)
def trip(id=None): trip = database.fetchone('SELECT * FROM trips WHERE id="{}";'.format(id)) if not trip: return render_template('trips.html', error='Invalid trip ID') trip = get_trip_obj(trip) if request.method == 'POST': username = session['username'] database.execute('INSERT INTO carpools VALUES ("{}", "{}");'.format( id, username)) passengers = database.fetchall( 'SELECT username FROM carpools WHERE id="{}";'.format(id)) passengers = [p[0] for p in passengers] return render_template('trip.html', trip=trip, passengers=passengers, success='Trip joined successfully') passengers = database.fetchall( 'SELECT username FROM carpools WHERE id="{}"'.format(id)) passengers = [p[0] for p in passengers] return render_template('trip.html', trip=trip, passengers=passengers)
def wall(username, other_username=None): other_username = other_username or auth_helper.get_username_from_session() if not other_username: return redirect(url_for('index')) other_username = escape_sql(other_username) if not auth_helper.is_valid_username(other_username): return render_template('no_wall.html', username=other_username) db_posts = database.fetchall("SELECT post FROM posts WHERE username='******';".format(other_username)) posts = [ post[0] for post in db_posts ] avatar, age = get_user_info(other_username) return render_template('wall.html', username=username, other_username=other_username, posts=posts, avatar=avatar, age=age)
def db_read(table, columns, condition=None): if columns: select_query = ''' SELECT ''' + ','.join(columns) + ''' FROM ''' + table + ''' ''' + ('WHERE ' + ' AND '.join( map(lambda x, y: x + '=' + repr(y), condition.keys(), condition.values())) if condition else '') rows = fetchall(select_query) res = [] if rows: for row in rows: res.append({columns[i]: row[i] for i in range(len(columns))}) return res, 200 return {}, 400
def post(self): args = request.get_json() table = args['table'] if 'columns' in args: columns = args['columns'] select_query = ''' SELECT ''' + ','.join(columns) + ''' FROM ''' + table + ''' ''' + ('WHERE ' + ' AND '.join(map(lambda x, y: x + '=' + repr(y), args['condition'].keys(), args['condition'].values())) if 'condition' in args else '') rows = fetchall(select_query) res = [] if rows: for row in rows: res.append({columns[i]: row[i] for i in range(len(columns))}) return res, 200 return {}, 400
def _get_all_categories() -> dict: """Return all categories from DB""" categories = database.fetchall("Categories", "id", "name_ua") return categories
def get(self): query = '''SELECT COUNT(*) FROM RIDES''' rows = fetchall(query) if rows: for row in rows: return [row[0]], 200
def unregistered_dataset(): database.execute("SELECT email, codename FROM users WHERE registered = 0;") return database.fetchall()