main_website/print_stats.py

53 lines
2.1 KiB
Python
Raw Normal View History

2021-11-19 17:09:24 +01:00
#!/usr/bin/python3
import os
import traceback
import logging
2021-11-19 17:09:24 +01:00
from time import sleep
from dotenv import load_dotenv
from seleniumwire import webdriver
from seleniumwire.webdriver import FirefoxOptions
try:
2021-11-19 22:51:34 +01:00
os.chdir(os.path.dirname(os.path.abspath(__file__)))
load_dotenv()
2021-11-19 17:09:24 +01:00
2021-11-19 22:51:34 +01:00
opts = FirefoxOptions()
opts.add_argument("--headless")
browser = webdriver.Firefox(options=opts,executable_path="/usr/local/bin/geckodriver")
2021-11-19 17:09:24 +01:00
2021-11-19 22:51:34 +01:00
def interceptor(request):
request.headers['Authorization'] = 'Basic '+os.environ["ES_TOKEN"]
browser.request_interceptor = interceptor
2021-11-19 17:09:24 +01:00
browser.set_window_size(3000, 285)
browser.get("https://mon.gnous.fr/app/dashboards#/view/813e0b00-8544-11ec-876e-0f6254f8a3d0?embed=true&_g=(filters%3A!()%2CrefreshInterval%3A(pause%3A!t%2Cvalue%3A0)%2Ctime%3A(from%3Anow-15m%2Cto%3Anow))&hide-filter-bar=true")
sleep(60)
browser.get_screenshot_as_file("html/ressources/stats/mmsyn.png")
browser.set_window_size(3000, 930)
2021-11-19 22:51:34 +01:00
for duration in ["24h", "7d", "1M", "1y"]:
browser.get("https://mon.gnous.fr/app/dashboards#/view/562f3400-88f2-11ec-876e-0f6254f8a3d0?embed=true&_g=(filters%3A!()%2CrefreshInterval%3A(pause%3A!t%2Cvalue%3A0)%2Ctime%3A(from%3Anow-"+duration+"%2Cto%3Anow))&hide-filter-bar=true")
2021-11-21 01:42:47 +01:00
sleep(60)
2021-11-19 22:51:34 +01:00
browser.get_screenshot_as_file("html/ressources/stats/mm"+duration+".png")
2021-11-19 17:09:24 +01:00
browser.set_window_size(3000, 285)
browser.get("https://mon.gnous.fr/app/dashboards#/view/e4e742a0-88fc-11ec-876e-0f6254f8a3d0?embed=true&_g=(filters%3A!()%2CrefreshInterval%3A(pause%3A!t%2Cvalue%3A0)%2Ctime%3A(from%3Anow-15m%2Cto%3Anow))&hide-filter-bar=true")
sleep(60)
browser.get_screenshot_as_file("html/ressources/stats/ncsyn.png")
browser.set_window_size(3000, 930)
2021-11-19 22:51:34 +01:00
for duration in ["24h", "7d", "1M", "1y"]:
browser.get("https://mon.gnous.fr/app/dashboards#/view/14d78520-8a78-11ec-876e-0f6254f8a3d0?embed=true&_g=(filters%3A!()%2CrefreshInterval%3A(pause%3A!t%2Cvalue%3A0)%2Ctime%3A(from%3Anow-"+duration+"%2Cto%3Anow))&hide-filter-bar=true")
2021-11-21 01:42:47 +01:00
sleep(60)
2021-11-19 22:51:34 +01:00
browser.get_screenshot_as_file("html/ressources/stats/nc"+duration+".png")
2021-11-21 01:42:47 +01:00
browser.quit()
except Exception as e:
2021-11-19 22:51:34 +01:00
logging.error(traceback.format_exc())