add: parser, new metrics

This commit is contained in:
Дмитрий Абдрахманов 2024-10-17 19:45:27 +03:00
parent aa2bd4b5f8
commit c5bc686aca
4 changed files with 35 additions and 12 deletions

View File

@ -18,18 +18,18 @@ conky.config = {
cpu_avg_samples = 2, cpu_avg_samples = 2,
default_color = 'white', default_color = 'white',
default_outline_color = 'white', default_outline_color = 'white',
default_shade_color = 'white', default_shade_color = 'black',
double_buffer = true, double_buffer = true,
draw_borders = false, draw_borders = false,
draw_graph_borders = false, draw_graph_borders = false,
draw_outline = false, draw_outline = false,
draw_shades = false, draw_shades = yes,
extra_newline = false, extra_newline = false,
font = 'DejaVu Serif:size=18', font = 'Nimbus Mono PS:size=20',
gap_x = 15, gap_x = 8,
gap_y = 15, gap_y = 15,
minimum_height = 5, minimum_height = 5,
minimum_width = 5, minimum_width = 650,
net_avg_samples = 2, net_avg_samples = 2,
no_buffers = true, no_buffers = true,
out_to_console = false, out_to_console = false,
@ -41,7 +41,7 @@ conky.config = {
own_window_class = 'Conky', own_window_class = 'Conky',
own_window_hints = 'undecorated,sticky,below,skip_taskbar,skip_pager', own_window_hints = 'undecorated,sticky,below,skip_taskbar,skip_pager',
own_window_type = 'desktop', own_window_type = 'desktop',
own_window_argb_value = 112, own_window_argb_value = 0,
show_graph_range = false, show_graph_range = false,
show_graph_scale = false, show_graph_scale = false,
stippled_borders = 0, stippled_borders = 0,
@ -52,7 +52,11 @@ conky.config = {
} }
conky.text = [[ conky.text = [[
${alignc}${color orange}Weather ${font Nimbus Mono PS:size=32}${time %A}${font}
${alignc}${voffset 15}${color grey}Current ${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}
${color grey}${exec cat /home/citrullux/example} $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}
]] ]]

View File

@ -3,11 +3,12 @@ Description=Service for conky configuration
After=conky.service After=conky.service
[Service] [Service]
Type=oneshot Type=simple
WorkingDirectory=/home/citrullux/ModernOSLabs/src WorkingDirectory=/home/citrullux/ModernOSLabs/src
ExecStart=/usr/bin/python3 /home/citrullux/ModernOSLabs/src/main.py -f ExecStart=/usr/bin/python3 /home/citrullux/ModernOSLabs/src/main.py -f
Restart=on-failure Restart=on-failure
RestartSec=30 RestartSec=30
ExecStartPre=/usr/bin/sleep 5
[Install] [Install]
WantedBy=default.target WantedBy=default.target

18
src/parser.py Normal file
View File

@ -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()

View File

@ -8,9 +8,9 @@ def weather_handler(date: str) -> dict:
# Request variables # Request variables
api_link = "https://api.open-meteo.com/v1/forecast?" api_link = "https://api.open-meteo.com/v1/forecast?"
coordinates = [48.712, 44.514] 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" timezone = "Europe/Moscow"
days = "3" days = "7"
url = ( url = (
api_link api_link
+ "latitude=" + "latitude="