mirror of
https://github.com/MathiasDPX/grainParisArt.git
synced 2025-05-09 23:23:05 +00:00
Compare commits
3 commits
06d7ab80e9
...
f6c60b41dd
Author | SHA1 | Date | |
---|---|---|---|
f6c60b41dd | |||
215b5cf275 | |||
6aef5ed35e |
5 changed files with 40 additions and 16 deletions
12
app.py
12
app.py
|
@ -3,13 +3,14 @@ from datetime import timedelta
|
|||
from dotenv import load_dotenv
|
||||
from threading import Thread
|
||||
from os import getenv
|
||||
import monitoring
|
||||
import html
|
||||
|
||||
load_dotenv()
|
||||
|
||||
# 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
|
||||
requests.get("https://www.allocine.fr/_/localization_city/Brest").json()["values"]["theaters"]]
|
||||
|
@ -55,7 +56,6 @@ def getShowtimes(date):
|
|||
|
||||
return data
|
||||
|
||||
|
||||
showtimes = []
|
||||
for i in range(0, 7):
|
||||
day_showtimes = getShowtimes(datetime.today() + timedelta(days=i))
|
||||
|
@ -87,12 +87,16 @@ def home():
|
|||
if delta > 6: delta = 6
|
||||
if delta < 0: delta = 0
|
||||
|
||||
useragent = request.headers.get('User-Agent')
|
||||
Thread(target=monitoring.log, kwargs={
|
||||
'ip': request.environ.get("HTTP_X_FORWARDED_FOR", request.remote_addr),
|
||||
'useragent': request.headers.get('User-Agent'),
|
||||
'useragent': useragent,
|
||||
'day': delta
|
||||
}).start()
|
||||
|
||||
if useragent.startswith("curl/"):
|
||||
return handle_curl(showtimes[delta])
|
||||
|
||||
dates = []
|
||||
|
||||
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)
|
|
@ -1,11 +1,11 @@
|
|||
import psycopg2
|
||||
from psycopg2 import OperationalError
|
||||
import time
|
||||
from typing import Optional, Any
|
||||
import logging
|
||||
import psycopg2
|
||||
from os import getenv
|
||||
import httpagentparser
|
||||
from dotenv import load_dotenv
|
||||
from typing import Optional, Any
|
||||
from psycopg2 import OperationalError
|
||||
from ua_parser import parse_os, parse_user_agent
|
||||
|
||||
load_dotenv()
|
||||
|
||||
|
@ -153,12 +153,11 @@ if isInit:
|
|||
|
||||
def log(ip:str, useragent:str, day:int) -> bool:
|
||||
if not isInit: return True
|
||||
ua_data = httpagentparser.detect(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 = parse_os(useragent)
|
||||
browser = parse_user_agent(useragent)
|
||||
|
||||
if __name__ == "__main__":
|
||||
ua ="Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:133.0) Gecko/20100101 Firefox/133.0"
|
||||
print(httpagentparser.detect(ua))
|
||||
os_family = os.family if os != None else "unknown"
|
||||
browser_family = browser.family if browser != None else "unknown"
|
||||
|
||||
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,3 +2,4 @@ Flask
|
|||
psycopg2
|
||||
requests
|
||||
python-dotenv
|
||||
ua-parser[regex]
|
Loading…
Add table
Add a link
Reference in a new issue