push
This commit is contained in:
parent
976f106d43
commit
3e88ea16fa
3 changed files with 47 additions and 27 deletions
|
@ -3,6 +3,7 @@ import std/osproc
|
||||||
import std/re
|
import std/re
|
||||||
import strutils
|
import strutils
|
||||||
import i3bar_base
|
import i3bar_base
|
||||||
|
import std/math
|
||||||
|
|
||||||
const host: string = "web.wilde.cloud"
|
const host: string = "web.wilde.cloud"
|
||||||
const cmd: string = "ping -4 -c 1 " & host
|
const cmd: string = "ping -4 -c 1 " & host
|
||||||
|
@ -11,14 +12,15 @@ const time_secs: int = 4
|
||||||
let ping_re = re(r"time=[0-9.]+")
|
let ping_re = re(r"time=[0-9.]+")
|
||||||
|
|
||||||
proc get_ping(): float =
|
proc get_ping(): float =
|
||||||
|
var ping: float = -1
|
||||||
let cmdOut = execCmdEx(cmd)
|
let cmdOut = execCmdEx(cmd)
|
||||||
let lines = splitLines(cmdOut.output)
|
let lines = splitLines(cmdOut.output)
|
||||||
let ping_line = lines[1]
|
let ping_line = lines[1]
|
||||||
let bounds = findBounds(ping_line, ping_re)
|
let bounds = findBounds(ping_line, ping_re)
|
||||||
if bounds.first > 0:
|
if bounds.first > 0:
|
||||||
let ping = ping_line[bounds.first+5..bounds.last]
|
let png = ping_line[bounds.first+5..bounds.last]
|
||||||
return parseFloat(ping)
|
ping = parseFloat(png)
|
||||||
return -1
|
return round(ping,1)
|
||||||
|
|
||||||
proc getObject(ping: float): i3barData =
|
proc getObject(ping: float): i3barData =
|
||||||
var text = "🏓 " & $ping & " ms"
|
var text = "🏓 " & $ping & " ms"
|
||||||
|
|
|
@ -17,6 +17,7 @@ type
|
||||||
State: string
|
State: string
|
||||||
Time: string
|
Time: string
|
||||||
Height: string
|
Height: string
|
||||||
|
Tomorrow: bool
|
||||||
TideList = ref object
|
TideList = ref object
|
||||||
Tides: seq[Tide]
|
Tides: seq[Tide]
|
||||||
LastUpdated: DateTime
|
LastUpdated: DateTime
|
||||||
|
@ -26,7 +27,7 @@ proc sortTides(tides: seq[Tide]): seq[Tide] =
|
||||||
var reltides: seq[Tide]
|
var reltides: seq[Tide]
|
||||||
var count = 0
|
var count = 0
|
||||||
for tide in tides:
|
for tide in tides:
|
||||||
if timenow.format("HH:MM") <= tide.Time:
|
if timenow.format("HH:MM") <= tide.Time or tide.Tomorrow:
|
||||||
reltides.add(tide)
|
reltides.add(tide)
|
||||||
count += 1
|
count += 1
|
||||||
if count >= 2:
|
if count >= 2:
|
||||||
|
@ -35,15 +36,16 @@ proc sortTides(tides: seq[Tide]): seq[Tide] =
|
||||||
|
|
||||||
|
|
||||||
proc getTideData(gettomorrow: bool = false): seq[Tide] =
|
proc getTideData(gettomorrow: bool = false): seq[Tide] =
|
||||||
|
var tides: seq[Tide]
|
||||||
let fnd = re">((High|Low)|([0-9]+:[0-9]+)|([0-9]+\.[0-9]+m))"
|
let fnd = re">((High|Low)|([0-9]+:[0-9]+)|([0-9]+\.[0-9]+m))"
|
||||||
var client = newHttpClient()
|
var client = newHttpClient()
|
||||||
var link = replace(url,re"\%LOC",loc)
|
var link = replace(url,re"\%LOC",loc)
|
||||||
if gettomorrow:
|
if gettomorrow:
|
||||||
let tomdate = now() + initTimeInterval(days = 1)
|
let tomdate = now() + initTimeInterval(days = 1)
|
||||||
link &= "-" & tomdate.format("yyyymmdd")
|
link &= "-" & tomdate.format("yyyyMMdd")
|
||||||
|
try:
|
||||||
let data = client.getContent(link)
|
let data = client.getContent(link)
|
||||||
let times = findAll(data,fnd)
|
let times = findAll(data,fnd)
|
||||||
var tides: seq[Tide]
|
|
||||||
var tide: Tide
|
var tide: Tide
|
||||||
var count: int = 0
|
var count: int = 0
|
||||||
for time in times:
|
for time in times:
|
||||||
|
@ -59,7 +61,12 @@ proc getTideData(gettomorrow: bool = false): seq[Tide] =
|
||||||
tide.Time = time[1..l]
|
tide.Time = time[1..l]
|
||||||
elif count == 3:
|
elif count == 3:
|
||||||
tide.Height = time[1..l]
|
tide.Height = time[1..l]
|
||||||
|
if gettomorrow:
|
||||||
|
tide.Tomorrow = true
|
||||||
tides.add(tide)
|
tides.add(tide)
|
||||||
|
except:
|
||||||
|
sleep(5000)
|
||||||
|
return getTideData(false)
|
||||||
if not gettomorrow:
|
if not gettomorrow:
|
||||||
let tomtides = getTideData(true)
|
let tomtides = getTideData(true)
|
||||||
for tide in tomtides:
|
for tide in tomtides:
|
||||||
|
|
|
@ -5,7 +5,18 @@ import std/math
|
||||||
import i3bar_base
|
import i3bar_base
|
||||||
import std/threadpool
|
import std/threadpool
|
||||||
|
|
||||||
proc getDesign(vol: string): string =
|
proc get_current_volume(): string {.gcsafe.}
|
||||||
|
|
||||||
|
proc check_volume(volume: string): string =
|
||||||
|
var vol = volume
|
||||||
|
if strip(vol) == "Connection error":
|
||||||
|
discard execCmdEx("pulseaudio -k; sleep 5; pulseaudio -D")
|
||||||
|
vol = get_current_volume()
|
||||||
|
vol = check_volume(vol)
|
||||||
|
return vol
|
||||||
|
|
||||||
|
proc getDesign(volume: string): string =
|
||||||
|
let vol = check_volume(volume)
|
||||||
var icon = " "
|
var icon = " "
|
||||||
if vol == "muted":
|
if vol == "muted":
|
||||||
return icon & "muted"
|
return icon & "muted"
|
||||||
|
@ -21,7 +32,7 @@ proc getDesign(vol: string): string =
|
||||||
icon = " "
|
icon = " "
|
||||||
else:
|
else:
|
||||||
icon = " "
|
icon = " "
|
||||||
let text = icon & $pcnt & "%"
|
let text = "<span size=\"x-large\">" & icon & "</span>" & $pcnt & "%"
|
||||||
return text
|
return text
|
||||||
|
|
||||||
proc get_current_volume(): string =
|
proc get_current_volume(): string =
|
||||||
|
@ -35,7 +46,7 @@ proc get_volume(run_once: bool = false) =
|
||||||
var last_vol: string = ""
|
var last_vol: string = ""
|
||||||
while true:
|
while true:
|
||||||
let vol = get_current_volume()
|
let vol = get_current_volume()
|
||||||
if vol != last_vol:
|
if vol != last_vol or true:
|
||||||
let text = getDesign(vol)
|
let text = getDesign(vol)
|
||||||
let data = i3barData(
|
let data = i3barData(
|
||||||
full_text: text,
|
full_text: text,
|
||||||
|
|
Loading…
Reference in a new issue