Browse Source

Add temp_precision option to darksky plugin

This gives the darksky plugin a temp_precision option, which allows
users to set the precision with which temperatures are read.  It
defaults to 0, not the old hard-coded value of 1, because I decided that
it's not usually useful to hear that much information.
Clara Hobbs 6 years ago
parent
commit
a14358df2b
1 changed files with 9 additions and 1 deletions
  1. 9
    1
      kayleevc/plugins/darksky.py

+ 9
- 1
kayleevc/plugins/darksky.py View File

@@ -19,6 +19,9 @@ Weather information is cached for up to ``cache_max_age`` seconds
19 19
 (default 1800, half an hour).  To conserve API calls, the cache is not
20 20
 updated until the first time the user requests weather information
21 21
 after the cache becomes stale.
22
+
23
+Temperatures are read to the nearest ``temp_precision`` decimal places
24
+(default 0).
22 25
 """
23 26
 
24 27
 import json
@@ -47,6 +50,10 @@ class Plugin(PluginBase):
47 50
             self._cache_max_age = self.options['cache_max_age']
48 51
         except KeyError:
49 52
             self._cache_max_age = 1800
53
+        try:
54
+            self._temp_precision = self.options['temp_precision']
55
+        except KeyError:
56
+            self._temp_precision = 0
50 57
 
51 58
         self.commands = {
52 59
             'whats the temperature': self._temperature,
@@ -63,7 +70,8 @@ class Plugin(PluginBase):
63 70
 
64 71
     def _format_temperature(self, temperature, unit='Fahrenheit'):
65 72
         """Format a temperature for the TTS system"""
66
-        return '{:.1f} degrees {}'.format(temperature, unit)
73
+        return '{:.{prec}f} degrees {}'.format(temperature, unit,
74
+                prec=self._temp_precision)
67 75
 
68 76
     def _temperature(self):
69 77
         return self._format_temperature(self.cache['currently']['temperature'])

Loading…
Cancel
Save