mirror of
https://github.com/MathiasDPX/grainParisArt.git
synced 2025-01-09 00:26:38 +00:00
Handle curl
This commit is contained in:
parent
215b5cf275
commit
f6c60b41dd
4 changed files with 28 additions and 6 deletions
12
app.py
12
app.py
|
@ -3,13 +3,14 @@ from datetime import timedelta
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
from os import getenv
|
from os import getenv
|
||||||
import monitoring
|
|
||||||
import html
|
import html
|
||||||
|
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
|
|
||||||
# IMPORT DES MODULES
|
# IMPORT DES MODULES
|
||||||
from modules.Classes import *
|
from modules.api import *
|
||||||
|
from modules.curl import *
|
||||||
|
import modules.monitoring as monitoring
|
||||||
|
|
||||||
theaters = [Theater(data["node"]) for data in
|
theaters = [Theater(data["node"]) for data in
|
||||||
requests.get("https://www.allocine.fr/_/localization_city/Brest").json()["values"]["theaters"]]
|
requests.get("https://www.allocine.fr/_/localization_city/Brest").json()["values"]["theaters"]]
|
||||||
|
@ -55,7 +56,6 @@ def getShowtimes(date):
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
showtimes = []
|
showtimes = []
|
||||||
for i in range(0, 7):
|
for i in range(0, 7):
|
||||||
day_showtimes = getShowtimes(datetime.today() + timedelta(days=i))
|
day_showtimes = getShowtimes(datetime.today() + timedelta(days=i))
|
||||||
|
@ -87,12 +87,16 @@ def home():
|
||||||
if delta > 6: delta = 6
|
if delta > 6: delta = 6
|
||||||
if delta < 0: delta = 0
|
if delta < 0: delta = 0
|
||||||
|
|
||||||
|
useragent = request.headers.get('User-Agent')
|
||||||
Thread(target=monitoring.log, kwargs={
|
Thread(target=monitoring.log, kwargs={
|
||||||
'ip': request.environ.get("HTTP_X_FORWARDED_FOR", request.remote_addr),
|
'ip': request.environ.get("HTTP_X_FORWARDED_FOR", request.remote_addr),
|
||||||
'useragent': request.headers.get('User-Agent'),
|
'useragent': useragent,
|
||||||
'day': delta
|
'day': delta
|
||||||
}).start()
|
}).start()
|
||||||
|
|
||||||
|
if useragent.startswith("curl/"):
|
||||||
|
return handle_curl(showtimes[delta])
|
||||||
|
|
||||||
dates = []
|
dates = []
|
||||||
|
|
||||||
for i in range(0, 7):
|
for i in range(0, 7):
|
||||||
|
|
20
modules/curl.py
Normal file
20
modules/curl.py
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
border_top = "╔" + "═" * 58 + "╗"
|
||||||
|
border_bottom = "╚" + "═" * 58 + "╝"
|
||||||
|
separator = "╠" + "═" * 58 + "╣"
|
||||||
|
|
||||||
|
def handle_curl(movies):
|
||||||
|
table = [border_top, "║{:^58}║".format("CinéBrest"), separator]
|
||||||
|
|
||||||
|
for film in movies:
|
||||||
|
title_line = f"║ {film['title']:<57}║"
|
||||||
|
table.append(title_line)
|
||||||
|
|
||||||
|
for cinema, seances in film['seances'].items():
|
||||||
|
cinema_line = f"║ ├─ {cinema:<54}║"
|
||||||
|
seances_line = f"║ │ └─ : {', '.join(seances):<43}║"
|
||||||
|
table.extend([cinema_line, seances_line])
|
||||||
|
|
||||||
|
table.append(separator)
|
||||||
|
|
||||||
|
table[-1] = border_bottom
|
||||||
|
return "\n".join(table)
|
|
@ -159,7 +159,5 @@ def log(ip:str, useragent:str, day:int) -> bool:
|
||||||
os_family = os.family if os != None else "unknown"
|
os_family = os.family if os != None else "unknown"
|
||||||
browser_family = browser.family if browser != None else "unknown"
|
browser_family = browser.family if browser != None else "unknown"
|
||||||
|
|
||||||
print(os_family, browser_family)
|
|
||||||
|
|
||||||
success = db.execute_query(f"INSERT INTO cinema_queries (ip, time, browser, os, day) VALUES (\'{ip}\', current_timestamp, \'{browser_family}\', \'{os_family}\', {day});")
|
success = db.execute_query(f"INSERT INTO cinema_queries (ip, time, browser, os, day) VALUES (\'{ip}\', current_timestamp, \'{browser_family}\', \'{os_family}\', {day});")
|
||||||
return success
|
return success
|
Loading…
Reference in a new issue