weather module added in slstatus

This commit is contained in:
wt committed 2024-08-06 17:11:35 +07:00
1 parent 7addaf17b8
commit 68997bd9d0
36 files changed
+66 -4

No files matched your search

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+21
View File
@@ -0,0 +1,21 @@
#include <stdio.h>
#include <string.h>
#include "../slstatus.h"
#include "../util.h"
#define WTTR_TEMP "/tmp/wttr"
const char *weather()
{
FILE *wttr = fopen(WTTR_TEMP, "r");
char temp[10];
memset(&temp, '\0', 10);
fgets(temp, 10, wttr);
fclose(wttr);
temp[strlen(temp)-1] = '\0';
return bprintf("%s", temp);
}
Binary file not shown.
Binary file not shown.
+28
View File
@@ -0,0 +1,28 @@
#!/bin/bash
# This function checks if wttr.in is available before the weather info is fetched
ck_curl() {
curl -sf ru.wttr.in > /dev/null
}
ck_curl
if [ $? -eq 0 ] # $? means "output of the last command"
then
curl -s v2.wttr.in/tomsk?format="%t\n" > /tmp/wttr
wttr_net=1
else # Non-zero output would appear both when the site \
for (( cntr = 0; cntr < 3; cntr++ )) # is down and when you're physically offline
do
echo "Probing. " > /tmp/wttr
sleep 0.5
echo "Probing.. " > /tmp/wttr
sleep 0.5
echo "Probing..." > /tmp/wttr
sleep 0.5 # A wee bit of animation
done
ck_curl # Online check is rerun only once, if the first check fails.
fi # In case you're using wifi, and the cron job runs before \
# it authenticates
if ! [ $wttr_net ]
then echo "Offline fr :'( " > /tmp/wttr
fi