mirror of
https://github.com/jlu5/SupyPlugins.git
synced 2025-04-26 21:11:14 -05:00
NuWeather: minor cleanup
This commit is contained in:
parent
753619c513
commit
3ca6f3c973
@ -27,11 +27,9 @@
|
|||||||
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
# POSSIBILITY OF SUCH DAMAGE.
|
# POSSIBILITY OF SUCH DAMAGE.
|
||||||
###
|
###
|
||||||
|
|
||||||
import re
|
|
||||||
import string
|
import string
|
||||||
|
|
||||||
from supybot import callbacks, conf, ircutils, log, utils
|
from supybot import ircutils, log
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import pendulum
|
import pendulum
|
||||||
|
@ -60,7 +60,7 @@ class NuWeather(callbacks.Plugin):
|
|||||||
self.db = accountsdb.AccountsDB("NuWeather", 'NuWeather.db', self.registryValue(accountsdb.CONFIG_OPTION_NAME))
|
self.db = accountsdb.AccountsDB("NuWeather", 'NuWeather.db', self.registryValue(accountsdb.CONFIG_OPTION_NAME))
|
||||||
geocode_db_filename = conf.supybot.directories.data.dirize("NuWeather-geocode.json")
|
geocode_db_filename = conf.supybot.directories.data.dirize("NuWeather-geocode.json")
|
||||||
if os.path.exists(geocode_db_filename):
|
if os.path.exists(geocode_db_filename):
|
||||||
with open(geocode_db_filename) as f:
|
with open(geocode_db_filename, encoding='utf-8') as f:
|
||||||
self.geocode_db = json.load(f)
|
self.geocode_db = json.load(f)
|
||||||
else:
|
else:
|
||||||
self.log.info("NuWeather: Creating new geocode DB")
|
self.log.info("NuWeather: Creating new geocode DB")
|
||||||
@ -72,7 +72,7 @@ class NuWeather(callbacks.Plugin):
|
|||||||
|
|
||||||
def _flush_geocode_db(self):
|
def _flush_geocode_db(self):
|
||||||
geocode_db_filename = conf.supybot.directories.data.dirize("NuWeather-geocode.json")
|
geocode_db_filename = conf.supybot.directories.data.dirize("NuWeather-geocode.json")
|
||||||
with open(geocode_db_filename, 'w') as f:
|
with open(geocode_db_filename, 'w', encoding='utf-8') as f:
|
||||||
json.dump(self.geocode_db, f)
|
json.dump(self.geocode_db, f)
|
||||||
|
|
||||||
def die(self):
|
def die(self):
|
||||||
@ -91,7 +91,7 @@ class NuWeather(callbacks.Plugin):
|
|||||||
try:
|
try:
|
||||||
f = utils.web.getUrl(url, headers=HEADERS).decode('utf-8')
|
f = utils.web.getUrl(url, headers=HEADERS).decode('utf-8')
|
||||||
data = json.loads(f)
|
data = json.loads(f)
|
||||||
except utils.web.Error as e:
|
except utils.web.Error:
|
||||||
log.debug('NuWeather: error searching for %r from Nominatim backend:', location, exc_info=True)
|
log.debug('NuWeather: error searching for %r from Nominatim backend:', location, exc_info=True)
|
||||||
data = None
|
data = None
|
||||||
if not data:
|
if not data:
|
||||||
|
@ -64,7 +64,6 @@ class NuWeatherTestCase(PluginTestCase):
|
|||||||
self.assertRegexp('weather Vancouver', 'Vancouver,')
|
self.assertRegexp('weather Vancouver', 'Vancouver,')
|
||||||
self.assertRegexp('weather LAX', 'Los Angeles')
|
self.assertRegexp('weather LAX', 'Los Angeles')
|
||||||
#self.assertRegexp('weather 76010', 'Arlington') # US ZIP codes not supported by Nominatim (default)
|
#self.assertRegexp('weather 76010', 'Arlington') # US ZIP codes not supported by Nominatim (default)
|
||||||
self.assertError('weather InvalidLocationTest')
|
|
||||||
|
|
||||||
@unittest.skipUnless(network, NO_NETWORK_REASON)
|
@unittest.skipUnless(network, NO_NETWORK_REASON)
|
||||||
def testSavedLocation(self):
|
def testSavedLocation(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user