Ejemplo n.º 1
0
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
Ejemplo n.º 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!")
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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"]))
Ejemplo n.º 6
0
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()
Ejemplo n.º 7
0
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()
Ejemplo n.º 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()
Ejemplo n.º 9
0
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()
Ejemplo n.º 10
0
 def __init__(self, woeid, temp_unit):
     """Initialize the data object."""
     from yahooweather import YahooWeather
     self._yahoo = YahooWeather(woeid, temp_unit)
Ejemplo n.º 11
0
    def __init__(self, woeid, temp_unit):
        """Initialize the data object."""
        from yahooweather import YahooWeather

        # init yahoo api object
        self._yahoo = YahooWeather(woeid, temp_unit)
Ejemplo n.º 12
0
 def __init__(self, woeid, temp_unit):
     """Initialize the data object."""
     self._yahoo = YahooWeather(woeid, temp_unit)
Ejemplo n.º 13
0
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!")
Ejemplo n.º 14
0
        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:
Ejemplo n.º 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)
Ejemplo n.º 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)