Package: wetter
wetterThis repository provides an Python application for checking the current
weather conditions at your favourite location. Additionally, it allows querying
historical data to run analysis on past measurements.UsageThe tool provides thewettercommand line tool with several subcommands:commandDescriptionwetter latestReturn latest measurement for your favourite citywetter updateUpdate datastore with latest measurementswetter update --historicalUpdate datastore with measurements from last yearwetter compare --last-weekCompare current weather w/ last weekwetter compare --last-monthCompare current weather w/ last monthwetter compare --last-yearCompare current weather w/ last yearwetter compare --monthAnalyse specific month (average temperature & hottest days)Entering nothing but thewettercommand will return the latest measurement
of the location similar towetter latest.Getting startedThere are several ways to installwetter. The easiest method would be to use pypi, download releases from GitHub or clone the repository and use e.g.poetryto install it. If you don't want to install library immediately you could first trywetterby spinning up its docker image.Install using pypipipinstallwetter# the more courageous can add a --pre flagInstall by (1) downloading the.whlfrom our releases and (2) install usingpippython3-mpipinstallwetter-0.3.0-py3-none-any.whlInstall from source by cloning the repository and usingpoetrygitclonehttps://github.com/ucyo/wetter-py.git# clone the repocdwetter-py/wetter# change to librarypoetryinstallGet started using dockerdockerrun-itucyo/wetter:latestbash# ucyo/wetter:testing for pre-releasesChecking if everything is working appropriately can be done usingwetter latest. It should return something like the following:>wetterlatest
Currentlyitis🌡️12.7°Candwindspeed🌬️13.0km/h.
Latestmeasurementon📅2023-01-01@01:00AM.Now that we know everything is working as expected. Go ahead and update the database by executingwetter update.Your mileage might vary on getting the exact same output. The timestamp of the above command adjusts to the local time zone and might be different on yours.ConfigurationI don't know why, but you might be interested in measurements from a different location. You can do this by adjusting thewetter.tomlfile. The location of thewetter.tomldepends on your operating system. Additionally, you can find the locations of the measurement data itself i.e.wetter.jsonand logs i.e.wetter.log.LocationOperating System/home/<username>/.config/wetter/Linux :penguin: (config)/home/<username>/.local/share/wetter/Linux :penguin: (data)/home/<username>/.local/state/wetter/log/wetter.logLinux :penguin: (log)/Users/<username>/Library/Application Support/wetter/macOS :apple: (config & data)/Users/<username>/Library/Logs/wetter/macOS :apple: (logs)C:\Users\<username>\AppData\Local\ucyo\wetterWindows :window: (config & data)C:\Users\<username>\AppData\Local\ucyo\wetter\logsWindows :window: (logs)If you have problems finding the proper location there is a gimmick that got you covered.
The path to the configuration file is returned bywetter configure --config.
The logging level can be set by theWETTER_LOGenvironmental variable.Sample configuration[location]lat=49lon=8.41The configuration file is very basic. Simply type in the lat/lon position :earth_africa: of
your favourite location.
You might use an online service to look up the coordinates of a certain city like aLatLongFinder.Sample database{"lat":49,"lon":8.41,"version":1,"data":{"index":["temperature","wind"],"columns":["2023-01-01T00:00:00.000000+0000","2023-01-01T01:00:00.000000+0000"],"data":[[7.7,12.7],[6.8,13.0]],},}The json database stores only the data for a single position. Those are included
in the database with thelatandlontags.
This information aligned on system start with the configuration file.
Should they not match within 1 degree (in the above case for latitude48 <= lat <= 50),
then a reset will be triggered.Note: The update to the new location happens without user interaction.
The tool assumes the user changed the settings knowingly and will update the
the database on the next execution.Setup background daemonThere are several ways to enable a background process on Unix systems (incl. macOS).
The easiest and most supported is to setup usingcron.
Another scheduling daemon issystemd.
In the following are the instructions for both systems.Spoiler alert! Usecron.CrontabExecute the following command:(crontab-l;echo"5 * * * * wetter update")2>/dev/null|sort-u|crontab-Checkcrontab gurufor details on the scheduling syntax.SystemdGo back :point_up: Just usecron. All that glistens is not gold :eyes:tl;drIn user space:wetterconfigure--systemd>wetter.service# generate service filewetterconfigure--systemdtimer>wetter.timer# generate schedule fileAs privileged user:ln-s$(whichwetter)/usr/bin/wetter# get binary out of homemvwetter.service/etc/systemd/system/wetter.service# move service filemvwetter.timer/etc/systemd/system/wetter.timer# move schedule servicesystemctlenablewetter.service# enable servicesystemctlstartwetter.service# start serviceDetailedFirst you need to create the necessary files for a systemd service.
This involves two files:
First, the service file which defines the background process inwetter.service.
Afterwards, the scheduler file which defines when the background process needs to be run i.e.wetter.timer.wetterconfigure--systemd>wetter.service# generate service filewetterconfigure--systemdtimer>wetter.timer# generate schedule fileNote: Timers are not mandatory to run services on a certain schedule. One could use the thesystemd-runcommand to schedule calls to services without a timer configuration. Seesystemd-run manpageon ArchLinux for details.Now that have the necessary files set up, need to make them available
for systemd. The most common location of systemd files is/etc/systemd/system/.
Therefore you need to move the files to that location.mvwetter.service/etc/systemd/system/wetter.service# move service filemvwetter.timer/etc/systemd/system/wetter.timer# schedule serviceNote: Fedora/RedHat/CentOS users might need to adjust the above mentioned location.Before you can enable and start the service you must address a caveat of systemd.
The systemd daemon is not allowed to access binaries in home directories of users.
That's why you need to create a symbolic link in/usr/binto allow
the service to execute updates on the database. That can be done using
the following command:ln-s$(whichwetter)/usr/bin/wetterThis concludes the setup process. Now the service can be enabled and started
using thesystemctlcommand.Enabling the systemd servicesystemctl enable wetter.serviceStarting the systemd servicesystemctl start wetter.serviceResourcesThe measurement data is being gathered using the archive and forecast API
fromOpen-Meteo.com:heart: