コード例 #1
0
ファイル: functions.py プロジェクト: wpbdry/Doerffelbot
def wetter(bot, update):

    gotten_chat = bot.get_chat(chat_id=update.message.chat.id)

    # query weather data for "Weida, Germany"
    yweather = YahooWeather(704463, UNIT_C)
    print("Wetterdaten wurden empfangen")

    if yweather.updateWeather():
        bot.send_message(
            chat_id=update.message.chat_id,
            text="Wetter f�r Weida, TH, Germany:" + "\nBeschreibung: " +
            str(yweather.Forecast[0]['text']) + "\nAktuelle Temperatur: " +
            emojize(" :arrow_right:", use_aliases=True) + " " +
            str(yweather.Now['temp']) + " �C" +
            emojize(" :arrow_left:", use_aliases=True) +
            "\nH�chsttemperatur: " + emojize(" :arrow_up:", use_aliases=True) +
            " " + str(yweather.Forecast[0]['high']) + " �C" +
            emojize(" :arrow_up:", use_aliases=True) +
            "\nNiedrigsttemperatur: " +
            emojize(" :arrow_down:", use_aliases=True) + " " +
            str(yweather.Forecast[0]['low']) + " �C" +
            emojize(" :arrow_down:", use_aliases=True) + "\nSonnenaufgang: " +
            str(yweather.Astronomy['sunrise']) +
            emojize(" :arrow_heading_up:", use_aliases=True) +
            "\nSonnenuntergang: " + str(yweather.Astronomy['sunset']) +
            emojize(" :arrow_heading_down:",
                    use_aliases=True))  # schickt aktuelle Wetterdaten
        print("und zu " + gotten_chat.first_name + " geschickt\n")
    else:
        bot.send_message(
            chat_id=update.message.chat_id,
            text="Konnte yahoo-Wetterdaten nicht empfangen!")  # Fehlermeldung
        print("und konnten nicht zu " + gotten_chat.first_name +
              " geschickt werden\n")  # Statusmeldung: Fehler bei Wetterdaten
コード例 #2
0
def predictWeather(woeid):
	logging.basicConfig(level=logging.WARNING)

	yweather = YahooWeather(woeid, UNIT_C)
	if yweather.updateWeather():
		print("RawData: %s" % str(yweather.RawData))
		print("Units: %s" % str(yweather.Units))
		print("Now: %s" % str(yweather.Now))
		print("Forecast: %s" % str(yweather.Forecast))
		print("Wind: %s" % str(yweather.Wind))
		print("Atmosphere: %s" % str(yweather.Atmosphere))
		print("Astronomy: %s" % str(yweather.Astronomy))
		return yweather.Now,yweather.Forecast,yweather.Wind,yweather.Atmosphere,yweather.Astronomy
	else:
		print("Can't read data from yahoo!")
コード例 #3
0
 def test_empty(self):
     status, response, chart_data = YahooWeather(
         sqlite_object=self.sqlite_object).fetch_forecast("")
     self.assertEqual(status, False)
     self.assertNotEqual(type(response), dict)
     self.assertEqual(response, "Empty text")
     self.assertEqual(chart_data, None)
コード例 #4
0
 def test_invalid(self):
     status, response, chart_data = YahooWeather(
         sqlite_object=self.sqlite_object).fetch_forecast("versgehi")
     self.assertEqual(status, False)
     self.assertNotEqual(type(response), dict)
     self.assertEqual(response, "Invalid City Name")
     self.assertEqual(chart_data, None)
コード例 #5
0
 def test_save_data(self):
     status, response, chart_data = YahooWeather(
         sqlite_object=self.sqlite_object).fetch_forecast("delhi")
     row_count = self.sqlite_object.fetch_one(
         "Select Count(*) From forecast;")[0]
     self.assertEqual(
         row_count,
         len(response["query"]["results"]["channel"]["item"]["forecast"]))
コード例 #6
0
ファイル: weather.py プロジェクト: pkrolkgp/home-assistant
class YahooWeatherData:
    """Handle the Yahoo! API object and limit updates."""
    def __init__(self, woeid, temp_unit):
        """Initialize the data object."""
        self._yahoo = YahooWeather(woeid, temp_unit)

    @property
    def yahoo(self):
        """Return Yahoo! API object."""
        return self._yahoo

    def update(self):
        """Get the latest data from Yahoo!."""
        return self._yahoo.updateWeather()
コード例 #7
0
ファイル: sensor.py プロジェクト: fabiandevia/home
class YahooWeatherData:
    """Handle Yahoo! API object and limit updates."""
    def __init__(self, woeid, temp_unit):
        """Initialize the data object."""
        from yahooweather import YahooWeather
        self._yahoo = YahooWeather(woeid, temp_unit)

    @property
    def yahoo(self):
        """Return Yahoo! API object."""
        return self._yahoo

    @Throttle(MIN_TIME_BETWEEN_UPDATES)
    def update(self):
        """Get the latest data from Yahoo!."""
        return self._yahoo.updateWeather()
コード例 #8
0
class YahooWeatherData:
    """Handle the Yahoo! API object and limit updates."""

    def __init__(self, woeid, temp_unit):
        """Initialize the data object."""
        from yahooweather import YahooWeather
        self._yahoo = YahooWeather(woeid, temp_unit)

    @property
    def yahoo(self):
        """Return Yahoo! API object."""
        return self._yahoo

    def update(self):
        """Get the latest data from Yahoo!."""
        return self._yahoo.updateWeather()
コード例 #9
0
ファイル: yweather.py プロジェクト: compvter/home-assistant
class YahooWeatherData(object):
    """Handle yahoo api object and limit updates."""

    def __init__(self, woeid, temp_unit):
        """Initialize the data object."""
        from yahooweather import YahooWeather

        # init yahoo api object
        self._yahoo = YahooWeather(woeid, temp_unit)

    @property
    def yahoo(self):
        """Return yahoo api object."""
        return self._yahoo

    @Throttle(MIN_TIME_BETWEEN_UPDATES)
    def update(self):
        """Get the latest data from yahoo. True is success."""
        return self._yahoo.updateWeather()
コード例 #10
0
ファイル: sensor.py プロジェクト: fabiandevia/home
 def __init__(self, woeid, temp_unit):
     """Initialize the data object."""
     from yahooweather import YahooWeather
     self._yahoo = YahooWeather(woeid, temp_unit)
コード例 #11
0
ファイル: yweather.py プロジェクト: compvter/home-assistant
    def __init__(self, woeid, temp_unit):
        """Initialize the data object."""
        from yahooweather import YahooWeather

        # init yahoo api object
        self._yahoo = YahooWeather(woeid, temp_unit)
コード例 #12
0
ファイル: sensor.py プロジェクト: pkrolkgp/home-assistant
 def __init__(self, woeid, temp_unit):
     """Initialize the data object."""
     self._yahoo = YahooWeather(woeid, temp_unit)
コード例 #13
0
ファイル: test.py プロジェクト: qbss/yahooweather
import logging
from yahooweather import YahooWeather, get_woeid, UNIT_C

logging.basicConfig(level=logging.DEBUG)

yweather = YahooWeather(91543049, UNIT_C)
if yweather.updateWeather():
    print("RawData: %s" % str(yweather.RawData))
    print("Units: %s" % str(yweather.Units))
    print("Now: %s" % str(yweather.Now))
    print("Forecast: %s" % str(yweather.Forecast))
    print("Wind: %s" % str(yweather.Wind))
    print("Atmosphere: %s" % str(yweather.Atmosphere))
    print("Astronomy: %s" % str(yweather.Astronomy))

    data = yweather.Now
    print("Weather image from current: %s" %
          yweather.getWeatherImage(data["code"]))

    print("The woeid from Gstaad is: %s" % get_woeid(46.475661, 7.283469))

else:
    print("Can't read data from yahoo!")
コード例 #14
0
ファイル: eva(1).py プロジェクト: deep8302/basicIoTprogram
        elif opt3==4:
            print('please wait ........')
            time.sleep(1)
            send_url = "http://api.ipstack.com/check?access_key=80944066d86f6370d9b7ffa056255ad9"
            geo_req = requests.get(send_url)
            geo_json = json.loads(geo_req.text)
            latitude = geo_json['latitude']
            longitude = geo_json['longitude']
            city = geo_json['city']
            print(latitude,longitude)
            print(city)
            

            logging.basicConfig(level=logging.WARNING)

            yweather = YahooWeather(91543049, UNIT_C)
            if yweather.updateWeather():
                a=("RawData: %s" % str(yweather.RawData))
                b=("Units: %s" % str(yweather.Units))
                c=("Now: %s" % str(yweather.Now))
                d=("Forecast: %s" % str(yweather.Forecast))
                e=("Wind: %s" % str(yweather.Wind))
                f=("Atmosphere: %s" % str(yweather.Atmosphere))
                g=("Astronomy: %s" % str(yweather.Astronomy))

                data = yweather.Now
                print(c)
                print(e)
                print(f)
                print(d)
            else:
コード例 #15
0
 def test_valid(self):
     status, response, chart_data = YahooWeather(
         sqlite_object=self.sqlite_object).fetch_forecast("delhi")
     self.assertEqual(status, True)
     self.assertEqual(type(response), dict)
     self.assertNotEqual(chart_data, None)
コード例 #16
0
 def _get_data_(self):
     city_name = self.city_name_search.get_text()
     status, response, chart_data = YahooWeather().fetch_forecast(city_name)
     self._hide_data_()
     if status:
         self.show_data(response["query"]["results"]["channel"], chart_data)