Исправлено форматирование SQL-запроса в функции sitemap, добавлена обработка исключений в функциях detail_vin и search для ограничения частоты запросов. Добавлен новый маршрут для отображения страницы ограничения частоты запросов. Обновлен шаблон rate_limit.html с добавлением QR-кода для Telegram-бота.
This commit is contained in:
parent
e169ad65a0
commit
5d80db3b47
13
app.py
13
app.py
@ -220,7 +220,7 @@ def start_pool():
|
|||||||
def sitemap():
|
def sitemap():
|
||||||
conn = pool.acquire()
|
conn = pool.acquire()
|
||||||
cur = conn.cursor()
|
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()
|
nm = cur.fetchall()
|
||||||
return render_template('sitemap.xml', site=site, siten=nm)
|
return render_template('sitemap.xml', site=site, siten=nm)
|
||||||
|
|
||||||
@ -332,7 +332,9 @@ def detail_vin(vin):
|
|||||||
user_ip = get_ip(request) ## определение ip клиента
|
user_ip = get_ip(request) ## определение ip клиента
|
||||||
try:
|
try:
|
||||||
returnVal = cur.callfunc("checkip", int, [user_ip, request.headers.get("CF-IPCountry", 'None'), get_addr(user_ip), 0, 0, 1])
|
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)
|
print(request)
|
||||||
logger.error(traceback.format_exc())
|
logger.error(traceback.format_exc())
|
||||||
|
|
||||||
@ -376,7 +378,8 @@ def search():
|
|||||||
conn = pool.acquire()
|
conn = pool.acquire()
|
||||||
cur = conn.cursor()
|
cur = conn.cursor()
|
||||||
returnVal = cur.callfunc("checkip", int, [user_ip, request.headers.get("CF-IPCountry", 'None'), get_addr(user_ip), 0, 1, 0])
|
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,
|
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 ='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,
|
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())
|
logger.error(traceback.format_exc())
|
||||||
return 'bad request!', 500
|
return 'bad request!', 500
|
||||||
|
|
||||||
|
@app.route("/rate_limit.html")
|
||||||
|
def rate_limit_html():
|
||||||
|
return render_template('rate_limit.html', site=site)
|
||||||
|
|
||||||
## API
|
## API
|
||||||
@app.route("/api/search")
|
@app.route("/api/search")
|
||||||
def api_search():
|
def api_search():
|
||||||
|
|||||||
BIN
static/qr_telegram.png
Normal file
BIN
static/qr_telegram.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.1 MiB |
BIN
static/qr_telegram2.png
Normal file
BIN
static/qr_telegram2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 385 KiB |
@ -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> для декодирования VIN или /check <vin> для проверки 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()
|
|
||||||
@ -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.
|
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.
|
||||||
</p>
|
</p>
|
||||||
<p class="lead">
|
<p class="lead">
|
||||||
Please try again later or contact us if you need a business solution.
|
Please try again later or use our Telegram bot.
|
||||||
</p>
|
</p>
|
||||||
<div class="mt-4">
|
<div class="text-center mt-3 mb-3">
|
||||||
<a href="/" class="btn btn-primary">Return to Homepage</a>
|
<img src="/static/qr_telegram2.png" class="img-fluid" alt="Telegram Bot QR Code" style="max-width: 400px;">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user