Beispiel #1
0
    def load_scrum(self, _date=None):
        self.date = get_date(_date)

        scrums = utils.read_file(os.path.join(self.name, 'scrums'),
                                 formatted_date(self.date))

        self.scrum_data = scrums.split('\n') if scrums else []
Beispiel #2
0
    def weather(self, params=None, **kwargs):
        """Display current weather report (ex: .w [set] [<location>])"""
        if params:
            location = params
            if location.startswith("set "):
                location = location[4:]
                utils.write_file(self.name, self.irc.source, location)
                self.irc.reply("Location information saved")
        else:
            location = utils.read_file(self.name, self.irc.source)
            if not location:
                self.irc.reply(self.weather.__doc__)
                return

        try:
            w = pywapi.get_weather_from_google(location)
        except Exception:
            self.irc.reply("Unable to fetch weather data")
            return

        if w["current_conditions"]:
            city = w["forecast_information"]["city"]
            temp_f = w["current_conditions"]["temp_f"]
            temp_c = w["current_conditions"]["temp_c"]
            humidity = w["current_conditions"]["humidity"]
            wind = w["current_conditions"]["wind_condition"]
            condition = w["current_conditions"]["condition"]

            result = "%s: %sF/%sC   %s   %s   %s" % (city, temp_f, temp_c,
                    humidity, wind, condition)
            self.irc.reply(result)
        else:
            self.irc.reply("Location not found: '%s'" % location)
Beispiel #3
0
 def load_teatime(self):
     try:
         self.teatime_election = json.loads(utils.read_file(self.name, 'teatime'))
     except (TypeError, ValueError), e:
         self.teatime_election = {'started': False,
                                  'locations': {}}
         utils.write_file(self.name, 'teatime',
                          json.dumps(self.teatime_election))
Beispiel #4
0
    def weather(self, params=None, **kwargs):
        """Display current weather report (ex: .w [set] [<location>])"""
        wunderground = utils.get_config("Wunderground")
        api_key = wunderground.get("key")

        if params:
            location = params
            if location.startswith("set "):
                location = location[4:]
                utils.write_file(self.name, self.irc.source, location)
                self.irc.reply("Location information saved")
        else:
            location = utils.read_file(self.name, self.irc.source)
            if not location:
                self.irc.reply(self.weather.__doc__)
                return

        try:
            w = pywunderground.request(api_key, ["conditions"], location)
        except Exception:
            self.irc.reply("Unable to fetch weather data")
            return

        if w.get("current_observation"):
            w = w["current_observation"]

            city = w["display_location"]["full"]
            zip_code = w["display_location"]["zip"]
            temp = w["temperature_string"]
            heat_index = "%s F (%s C)" % (w["heat_index_f"], w["heat_index_c"])
            humidity = w["relative_humidity"]
            wind = w["wind_string"]
            condition = w["weather"]

            zip_code = "" if zip_code == "00000" else " %s" % zip_code
            humidity = "N/A%" if len(humidity) > 3 else humidity

            result = ("%s%s: [%s / Feels Like: %s]   Humidity: %s   "
                    "Wind: %s   %s") % (city, zip_code, temp, heat_index,
                    humidity, wind, condition)

            self.irc.reply(result)
        else:
            self.irc.reply("Location not found: '%s'" % location)
Beispiel #5
0
 def load_clusters(self):
     res = utils.read_file(self.name, 'clusters')
     res = json.loads(res) if res else {}
     return res
Beispiel #6
0
 def load_spaces(self):
     spaces = utils.read_file(self.name, 'space.db')
     spaces = "" if spaces is None else spaces
     spaces = spaces.split('\n%')
     return spaces
Beispiel #7
0
 def load_facts(self):
     facts = utils.read_file(self.name, 'facts.db')
     facts = "" if facts is None else facts
     facts = facts.split('\n%')
     return facts
Beispiel #8
0
 def load_jokes(self):
     jokes = utils.read_file(self.name, 'jokes.db')
     jokes = "" if jokes is None else jokes
     jokes = jokes.split('\n%')
     return jokes
Beispiel #9
0
 def test_read_file(self):
     self.assertEquals(utils.read_file("tests", "pyhole_test_file"), "foo")
Beispiel #10
0
 def test_read_file(self):
     self.assertEquals(utils.read_file("tests", "pyhole_test_file"), "foo")
Beispiel #11
0
 def _read_cache(self):
     """Read RSS cache data."""
     rss_cache = utils.read_file(self.name, "rss_cache")
     return json.loads(rss_cache)