diff --git a/app.py b/app.py index 5aba11b..93f7521 100644 --- a/app.py +++ b/app.py @@ -220,7 +220,7 @@ def start_pool(): def sitemap(): conn = pool.acquire() cur = conn.cursor() - cur.execute('select distinct trunc(pg/40000)+1 nm from mv_pages'); + cur.execute('select distinct trunc(pg/40000)+1 nm from mv_pages') nm = cur.fetchall() return render_template('sitemap.xml', site=site, siten=nm) @@ -332,7 +332,9 @@ def detail_vin(vin): user_ip = get_ip(request) ## определение ip клиента try: returnVal = cur.callfunc("checkip", int, [user_ip, request.headers.get("CF-IPCountry", 'None'), get_addr(user_ip), 0, 0, 1]) - except: + if returnVal == 1: + return redirect('/rate_limit.html', 301) + except Exception as e: print(request) logger.error(traceback.format_exc()) @@ -376,7 +378,8 @@ def search(): conn = pool.acquire() cur = conn.cursor() returnVal = cur.callfunc("checkip", int, [user_ip, request.headers.get("CF-IPCountry", 'None'), get_addr(user_ip), 0, 1, 0]) - + if returnVal == 1: + return redirect('/rate_limit.html', 301) cur.execute("""select 'None', COALESCE((select value from m_JSONS_FROM_NHTSA v3 where v3.svin =s.svin and v3.variableid ='26'),(select val from vind2 where svin = substr(s.vin, 1, 8) || '*' || substr(s.vin, 10, 2) and varb = 'Make'),'UNKNOWN') make, COALESCE((select value from m_JSONS_FROM_NHTSA v3 where v3.svin =s.svin and v3.variableid ='28'),(select val from vind2 where svin = substr(s.vin, 1, 8) || '*' || substr(s.vin, 10, 2) and varb = 'Model'),'UNKNOWN') model, COALESCE((select value from m_JSONS_FROM_NHTSA v3 where v3.svin =s.svin and v3.variableid ='29'),(select val from vind2 where svin = substr(s.vin, 1, 8) || '*' || substr(s.vin, 10, 2) and varb = 'Model Year'),'UNKNOWN') year, @@ -398,6 +401,10 @@ def search(): logger.error(traceback.format_exc()) return 'bad request!', 500 +@app.route("/rate_limit.html") +def rate_limit_html(): + return render_template('rate_limit.html', site=site) + ## API @app.route("/api/search") def api_search(): diff --git a/static/qr_telegram.png b/static/qr_telegram.png new file mode 100644 index 0000000..62ae8b9 Binary files /dev/null and b/static/qr_telegram.png differ diff --git a/static/qr_telegram2.png b/static/qr_telegram2.png new file mode 100644 index 0000000..14d0636 Binary files /dev/null and b/static/qr_telegram2.png differ diff --git a/telegram_bot.py b/telegram_bot.py deleted file mode 100644 index 4194269..0000000 --- a/telegram_bot.py +++ /dev/null @@ -1,40 +0,0 @@ -import os -import requests -from flask import Flask -from telegram import Update, Bot -from telegram.ext import CommandHandler, CallbackContext, ApplicationBuilder - -app = Flask(__name__) -TOKEN = 'YOUR_TELEGRAM_BOT_TOKEN' # Замените на ваш токен - -async def start(update: Update, context: CallbackContext) -> None: - await update.message.reply_text('Привет! Используйте /decode для декодирования VIN или /check для проверки VIN.') - -def decode_vin(update: Update, context: CallbackContext) -> None: - vin = context.args[0] if context.args else None - if vin: - response = requests.get(f'http://localhost:5000/search?vin={vin}') - update.message.reply_text(response.text) - else: - update.message.reply_text('Пожалуйста, укажите VIN.') - -def check_vin(update: Update, context: CallbackContext) -> None: - vin = context.args[0] if context.args else None - if vin: - response = requests.get(f'http://localhost:5000/detail/{vin}.html') - update.message.reply_text(response.text) - else: - update.message.reply_text('Пожалуйста, укажите VIN.') - -def main() -> None: - application = ApplicationBuilder().token(TOKEN).build() - dispatcher = application.dispatcher - - dispatcher.add_handler(CommandHandler("start", start)) - dispatcher.add_handler(CommandHandler("decode", decode_vin)) - dispatcher.add_handler(CommandHandler("check", check_vin)) - - application.run_polling() - -if __name__ == '__main__': - main() diff --git a/templates/rate_limit.html b/templates/rate_limit.html index d2b949a..b5e7cb2 100644 --- a/templates/rate_limit.html +++ b/templates/rate_limit.html @@ -12,10 +12,10 @@ We've noticed that you're using our service very frequently. Such frequent checks are typically associated with business usage, which contradicts our principles of providing free vehicle history checks for individual users.

- Please try again later or contact us if you need a business solution. + Please try again later or use our Telegram bot.

-