Пример #1
0
    def check_sinoptik(self):
        """Check and process weather data from sinoptik.ua."""
        date = datetime.strftime(datetime.now(), "%Y-%m-%d")
        last_update = UpdateDay.objects.all().filter(id=1).first()
        if (last_update is None) or (last_update.day != date):
            weather = Sinoptik()
            if weather.load():
                weather.get_weather()

                weather_db = Weather.objects.all().filter(id=1).first()
                if weather_db is None:
                    weather_db = Weather(
                        today=weather.today_str(),
                        days=weather.days_str(),
                        water=weather.water_str(),
                        infoDaylight=weather.infoDaylight_str(),
                        warnings=weather.warnings,
                        description=weather.description)
                else:
                    weather_db.today = weather.today_str()
                    weather_db.days = weather.days_str()
                    weather_db.water = weather.water_str()
                    weather_db.infoDaylight = weather.infoDaylight_str()
                    weather_db.warnings = weather.warnings
                    weather_db.description = weather.description
                weather_db.save()

                if last_update is None:
                    last_update = UpdateDay(day=date)
                else:
                    last_update.day = date
                last_update.save()