Skip to content
This repository has been archived by the owner on Oct 23, 2019. It is now read-only.

Add French-language weather support 🇫🇷 #323

Open
wants to merge 2 commits into
base: gonzobot
Choose a base branch
from

Conversation

mwscanlon
Copy link

This addresses #271

⚠️ I have not been able to test that the new URL for the Weather Underground API works.
Apparently they are ending support for the API and no longer providing API keys.
According to the documentation this should work though.

Since the Weather Underground API supports specifying a return language, the translation work locally is mostly swapping a few labels. While I like to think I know a little French, I relied entirely on Google Translate for this.

For the sake of completeness though, I also translated as many error messages as I could.

Also, at the prompting of my IDE, I added type information to doc-strings where it was missing.

Finally, the global location_cache was being kept as a list of key-value pairs and converted to a dict every time it was checked. Presumably there was a historical reason for this, but for now it seems more appropriate to just make it a dict.

This addresses snoonetIRC#271

The Weather Underground API supports specifying a return language,
so the translation work locally is mostly swapping a few labels.
While I like to think I know a little French,
I relied entirely on Google Translate for this.

For the sake of completeness though,
I also translated as many error messages as I could.

Also, at the prompting of my IDE, I added type information
to doc-strings where it was missing.

Finally, the global `location_cache` was being kept as a list of
key-value pairs and converted to a dict every time it was checked.
Presumably there was a historical reason for this,
but for now it seems more appropriate to just make it a dict.
2 × Unnecessary "elif" after "return"
return 'Unknown Error.'
if self._status == 'INVALID_REQUEST':
return 'Invalid Request.'
return repr(self._status)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't override __str__ on an exception subclass to set the text, use super().__init__("exception text") to do it. This is consistent with the rest of the exception API.

for row in db.execute(table.select()):
nick = row["nick"]
location = row["loc"]
location_cache.append((nick, location))
location_cache[nick] = location

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clear the cache before reloading it, as you could have old user data still there.

@@ -149,7 +178,7 @@ def weather(text, reply, db, nick, notice_doc):

forecast = response["forecast"]["simpleforecast"]["forecastday"]
if not forecast:
return "Unable to retrieve forecast data."
return 'Unable to retrieve forecast data.'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strings shown to a user should be enclosed in double-quotes.

# 'oui' is a pun, see https://github.com/snoonetIRC/CloudBot/issues/271
@hook.command('météo', 'meteo', 'oui', autohelp=False)
def meteo(text, reply, db, nick, notice_doc):
"""<lieu> - Quel temps fait-il à <lieu>?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional parameters should be enclosed in square-brackets [lieu]

return e.en_francais()
if not isinstance(weather_data, dict):
if weather_data == 'Unable to retrieve forecast data.':
weather_data = 'Impossible de récupérer les données météorologiques.'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not throw an error?

else:
location = location[0]
return location
class APIKeyMissing(Exception):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please group class declarations together above hook functions in the file.

@linuxdaemon
Copy link

Please address the relevant review comments

@linuxdaemon linuxdaemon added the blocked Pull request is blocked pending planned changes to application label Feb 6, 2019
@linuxdaemon
Copy link

This is also blocked for the time being, as the weather plugin will need to be rewritten entirely due to weather underground removing their API

@linuxdaemon linuxdaemon removed the blocked Pull request is blocked pending planned changes to application label Feb 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants