mirror of
https://github.com/gensokyo-zone/infrastructure.git
synced 2026-02-10 04:49:19 -08:00
The comma is a lie.
This commit is contained in:
parent
e6b215cefd
commit
2c6230dd63
14 changed files with 58 additions and 38 deletions
|
|
@ -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 =
|
||||
|
|
|
|||
16
pkgs/kat-weather/default.nix
Normal file
16
pkgs/kat-weather/default.nix
Normal 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
|
||||
'';
|
||||
}
|
||||
48
pkgs/kat-weather/weather.py
Normal file
48
pkgs/kat-weather/weather.py
Normal 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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue