mirror of
https://github.com/MathiasDPX/grainParisArt.git
synced 2025-07-03 20:36:07 +00:00
Compare commits
No commits in common. "f6c60b41dd7055c04f9844386c59f9a4edf97748" and "06d7ab80e91c211acb9ef944ca626ac65ecd1c75" have entirely different histories.
f6c60b41dd
...
06d7ab80e9
5 changed files with 18 additions and 42 deletions
12
app.py
12
app.py
|
@ -3,14 +3,13 @@ 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.api import *
|
from modules.Classes 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"]]
|
||||||
|
@ -56,6 +55,7 @@ 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,16 +87,12 @@ 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': useragent,
|
'useragent': request.headers.get('User-Agent'),
|
||||||
'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):
|
||||||
|
|
|
@ -1,20 +0,0 @@
|
||||||
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)
|
|
|
@ -1,11 +1,11 @@
|
||||||
import time
|
|
||||||
import logging
|
|
||||||
import psycopg2
|
import psycopg2
|
||||||
from os import getenv
|
|
||||||
from dotenv import load_dotenv
|
|
||||||
from typing import Optional, Any
|
|
||||||
from psycopg2 import OperationalError
|
from psycopg2 import OperationalError
|
||||||
from ua_parser import parse_os, parse_user_agent
|
import time
|
||||||
|
from typing import Optional, Any
|
||||||
|
import logging
|
||||||
|
from os import getenv
|
||||||
|
import httpagentparser
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
|
|
||||||
|
@ -153,11 +153,12 @@ if isInit:
|
||||||
|
|
||||||
def log(ip:str, useragent:str, day:int) -> bool:
|
def log(ip:str, useragent:str, day:int) -> bool:
|
||||||
if not isInit: return True
|
if not isInit: return True
|
||||||
os = parse_os(useragent)
|
ua_data = httpagentparser.detect(useragent)
|
||||||
browser = parse_user_agent(useragent)
|
os = ua_data.get('os', {}).get("name", "unknown")
|
||||||
|
browser = ua_data.get('browser', {}).get("name", "unknown")
|
||||||
|
success = db.execute_query(f"INSERT INTO cinema_queries (ip, time, browser, os, day) VALUES (\'{ip}\', current_timestamp, \'{browser}\', \'{os}\', {day});")
|
||||||
|
return success
|
||||||
|
|
||||||
os_family = os.family if os != None else "unknown"
|
if __name__ == "__main__":
|
||||||
browser_family = browser.family if browser != None else "unknown"
|
ua ="Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:133.0) Gecko/20100101 Firefox/133.0"
|
||||||
|
print(httpagentparser.detect(ua))
|
||||||
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
|
|
|
@ -2,4 +2,3 @@ Flask
|
||||||
psycopg2
|
psycopg2
|
||||||
requests
|
requests
|
||||||
python-dotenv
|
python-dotenv
|
||||||
ua-parser[regex]
|
|
Loading…
Add table
Add a link
Reference in a new issue