The comma is a lie.

This commit is contained in:
kat witch 2021-03-07 00:56:51 +00:00
parent e6b215cefd
commit 2c6230dd63
No known key found for this signature in database
GPG key ID: 1B477797DCA5EC72
14 changed files with 58 additions and 38 deletions

View file

@ -1,13 +1,14 @@
{ config ? { }, sources, system ? builtins.currentSystem, ... }@args:
let
pkgs = import sources.nixpkgs args;
pkgs = import sources.nixpkgs { inherit config; };
overlay = self: super: rec {
dino = super.callPackage "${sources.qyliss-nixlib}/overlays/patches/dino" {
inherit (super) dino;
};
discord = super.discord.override { nss = self.nss_latest; };
discord = unstable.discord.override { nss = self.nss_latest; };
arc = import sources.arc-nixexprs { pkgs = super; };
unstable = import sources.nixpkgs-unstable { inherit (self) config; };
@ -18,6 +19,8 @@ let
screenstub = unstable.callPackage ./screenstub { };
kat-weather = super.callPackage ./kat-weather { };
linuxPackagesFor = kernel:
(super.linuxPackagesFor kernel).extend (_: ksuper: {
vendor-reset =

View file

@ -0,0 +1,16 @@
{ lib, stdenv, fetchurl, python36, pythonPackages, installShellFiles }:
stdenv.mkDerivation {
name = "kat-weather";
buildInputs = [
(python36.withPackages (pythonPackages: with pythonPackages; [
requests
]))
];
unpackPhase = "true";
installPhase = ''
mkdir -p $out/bin
cp ${./weather.py} $out/bin/kat-weather
chmod +x $out/bin/kat-weather
'';
}

View file

@ -0,0 +1,48 @@
#!/usr/bin/env python3
import requests
import json
import sys
city = sys.argv[1]
api_key = sys.argv[2]
url = f"https://api.openweathermap.org/data/2.5/weather?q={city}&appid={api_key}&units=metric"
weather_icons = {
"Thunderstorm": "",
"Clouds": "",
"Drizzle": "",
"Rain": "",
"Snow": "",
"Clear": "",
"Mist": "",
"Smoke": "",
"Haze": "",
"Dust": "",
"Fog": "",
"Sand": "",
"Ash": "",
"Squall": "",
"Tornado": ""
}
#def degrees_to_cardinal(d):
# dirs = ["N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE",
# "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW"]
# ix = int((d + 11.25)/22.5)
# return dirs[ix % 16]
response = requests.get(url)
data = json.loads(response.text)
#print(data)
condition = data["weather"][0]["main"]
weather_icon = weather_icons[condition]
temperature = f"{round(data['main']['temp'])}°C"
feels_like_temperature = f"{round(data['main']['feels_like'])}°C"
humidity = f"{data['main']['humidity']}%"
wind = f"{round(data['wind']['speed'])}m/s" # {degrees_to_cardinal(data['wind']['deg'])}"
end_string = f"{weather_icon} {temperature} {feels_like_temperature} {humidity} {wind}"
print(end_string)