From c5bc686aca3779d428e8d36f1b71ccaeb95bcb11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9=20=D0=90=D0=B1?= =?UTF-8?q?=D0=B4=D1=80=D0=B0=D1=85=D0=BC=D0=B0=D0=BD=D0=BE=D0=B2?= <565963@gmail.com> Date: Thu, 17 Oct 2024 19:45:27 +0300 Subject: [PATCH] add: parser, new metrics --- configs/conky.conf | 22 +++++++++++++--------- services/conkyconf.service | 3 ++- src/parser.py | 18 ++++++++++++++++++ src/weather.py | 4 ++-- 4 files changed, 35 insertions(+), 12 deletions(-) create mode 100644 src/parser.py diff --git a/configs/conky.conf b/configs/conky.conf index f11f6c6..cb2dede 100644 --- a/configs/conky.conf +++ b/configs/conky.conf @@ -18,18 +18,18 @@ conky.config = { cpu_avg_samples = 2, default_color = 'white', default_outline_color = 'white', - default_shade_color = 'white', + default_shade_color = 'black', double_buffer = true, draw_borders = false, draw_graph_borders = false, draw_outline = false, - draw_shades = false, + draw_shades = yes, extra_newline = false, - font = 'DejaVu Serif:size=18', - gap_x = 15, + font = 'Nimbus Mono PS:size=20', + gap_x = 8, gap_y = 15, minimum_height = 5, - minimum_width = 5, + minimum_width = 650, net_avg_samples = 2, no_buffers = true, out_to_console = false, @@ -41,7 +41,7 @@ conky.config = { own_window_class = 'Conky', own_window_hints = 'undecorated,sticky,below,skip_taskbar,skip_pager', own_window_type = 'desktop', - own_window_argb_value = 112, + own_window_argb_value = 0, show_graph_range = false, show_graph_scale = false, stippled_borders = 0, @@ -52,7 +52,11 @@ conky.config = { } conky.text = [[ -${alignc}${color orange}Weather -${alignc}${voffset 15}${color grey}Current -${color grey}${exec cat /home/citrullux/example} +${font Nimbus Mono PS:size=32}${time %A}${font} +${voffset 10}${font Nimbus Mono PS:size=32}${time %B %d}${font}${font Nimbus Mono PS:style=bold:size=80}${voffset -48}${alignr}${time %H:%M}${font} +$hr +${color DDFFFF}${font Nimbus Mono PS:size=32}Weather${color}${font} +${voffset 15}${color DDFFFF}Current: ${color grey}${exec cat /home/citrullux/example} +${voffset 15}${color DDFFFF}Today: ${color grey}${exec cat /home/citrullux/example} +${voffset 15}${color DDFFFF}This week: ${color grey}${exec cat /home/citrullux/example} ]] \ No newline at end of file diff --git a/services/conkyconf.service b/services/conkyconf.service index 3f8b931..d9aab28 100644 --- a/services/conkyconf.service +++ b/services/conkyconf.service @@ -3,11 +3,12 @@ Description=Service for conky configuration After=conky.service [Service] -Type=oneshot +Type=simple WorkingDirectory=/home/citrullux/ModernOSLabs/src ExecStart=/usr/bin/python3 /home/citrullux/ModernOSLabs/src/main.py -f Restart=on-failure RestartSec=30 +ExecStartPre=/usr/bin/sleep 5 [Install] WantedBy=default.target \ No newline at end of file diff --git a/src/parser.py b/src/parser.py new file mode 100644 index 0000000..5f103a6 --- /dev/null +++ b/src/parser.py @@ -0,0 +1,18 @@ +import json +import urllib.request + + +def parse_weather() -> None: + current = {} + forecast = {} + data = {} + response = urllib.request.urlopen("http://127.0.0.1:7841", timeout=10).read() + data = json.loads(response) + for params in data["current"]: + value = data["current"][params] + unit = data["current_units"][params] + current[params] = str(value) + " " + str(unit) + print(current) + + +parse_weather() diff --git a/src/weather.py b/src/weather.py index 8b2391e..51b18f4 100644 --- a/src/weather.py +++ b/src/weather.py @@ -8,9 +8,9 @@ def weather_handler(date: str) -> dict: # Request variables api_link = "https://api.open-meteo.com/v1/forecast?" coordinates = [48.712, 44.514] - weather_values = "temperature_2m,relative_humidity_2m,rain,snowfall,weather_code,wind_speed_10m,wind_direction_10m" + weather_values = "temperature_2m,precipitation_probability,relative_humidity_2m,rain,snowfall,weather_code,wind_speed_10m,wind_direction_10m" timezone = "Europe/Moscow" - days = "3" + days = "7" url = ( api_link + "latitude="