From ef35e34ad56e896e7f9e57c383702a8b2541809f Mon Sep 17 00:00:00 2001 From: James Lu Date: Sat, 9 Mar 2019 11:28:27 -0800 Subject: [PATCH] Add a DB migration script from Weather to NuWeather --- NuWeather/README.md | 40 ++++++++++++++++++++++++++++++++++-- NuWeather/weather-migrate.py | 25 ++++++++++++++++++++++ Weather/README.md | 4 +++- 3 files changed, 66 insertions(+), 3 deletions(-) create mode 100755 NuWeather/weather-migrate.py diff --git a/NuWeather/README.md b/NuWeather/README.md index a2c4fc3..48f410a 100644 --- a/NuWeather/README.md +++ b/NuWeather/README.md @@ -1,4 +1,4 @@ -## NuWeather +# NuWeather A weather plugin for Limnoria. It supports multiple backends: @@ -7,7 +7,7 @@ A weather plugin for Limnoria. It supports multiple backends: For the Dark Sky backend, [OpenStreetMap Nominatim](https://nominatim.openstreetmap.org/) is used to translate locations into latitude/longitude pairs. -### Quick start +## Quick start 1) Pick your preferred backend: `config help plugins.nuweather.defaultbackend` @@ -18,3 +18,39 @@ For the Dark Sky backend, [OpenStreetMap Nominatim](https://nominatim.openstreet 5) Set your default weather location: `setweather ` 6) Obtain weather: `weather []` + +## Migrating from the Weather plugin + +This plugin includes a script to migrate from the [Weather](../Weather) plugin's SQLite DB to NuWeather's binary format. + +``` +$ ./weather-migrate.py -h +usage: weather-migrate [-h] infile outfile + +Migrates user locations from the Weather plugin to NuWeather. + +positional arguments: + infile input filename (BOT_DATA_DIR/Weather.db) + outfile output filename (e.g. BOT_DATA_DIR/NuWeather.db) + +optional arguments: + -h, --help show this help message and exit +``` + +### Migration instructions + +1) If you have not loaded NuWeather previously, **load** the plugin for the first time so that config entries are populated. + +2) Then, **unload** the plugin before running the migration script. You may also wish to make a backup of your current `NuWeather.db` if it is of any use. + +3) Run the script on the right files: `./weather-migrate.py BOT_DATA_DIR/Weather.db BOT_DATA_DIR/NuWeather.db` + +4) After performing the migration, set the **`plugins.NuWeather.DBAddressingMode` option to `nicks`** (since the previous database tracks locations by nick): + +``` +config plugins.NuWeather.DBAddressingMode nicks +``` + +5) Load the plugin again for these changes to take effect. + +(If you're comfortable with re-creating your database from scratch, the other options tell NuWeather to save location by Supybot account (the default) or ident@host.) diff --git a/NuWeather/weather-migrate.py b/NuWeather/weather-migrate.py new file mode 100755 index 0000000..69d01ff --- /dev/null +++ b/NuWeather/weather-migrate.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 +""" +Migrates user locations from the Weather plugin to NuWeather. +""" + +import argparse +import sqlite3 +import pickle + +parser = argparse.ArgumentParser(prog='weather-migrate', description=__doc__) +parser.add_argument('infile', type=str, help='input filename (BOT_DATA_DIR/Weather.db)') +parser.add_argument('outfile', type=str, help='output filename (e.g. BOT_DATA_DIR/NuWeather.db)') +args = parser.parse_args() + +conn = sqlite3.connect(args.infile) +c = conn.cursor() +# We only care about nick and location +c.execute('SELECT nick, location from users') +out = dict(c.fetchall()) +print("OK read %d entries from %s" % (len(out), args.infile)) +c.close() # No need to commit since we only read + +with open(args.outfile, 'wb') as outf: + pickle.dump(out, outf) + print("OK wrote output to %s" % args.outfile) diff --git a/Weather/README.md b/Weather/README.md index 12aedc2..3891fcb 100644 --- a/Weather/README.md +++ b/Weather/README.md @@ -1,4 +1,6 @@ -# Limnoria plugin for Weather Underground +# [DEPRECATED] Limnoria plugin for Weather Underground + +Update 201903: Weather Underground has shut down free weather access, so this plugin will no longer be maintained. See the [NuWeather](../NuWeather) plugin for an alternative using other backends. ## Installation