Пример #1
0
    def save_all_to_db(data):
        Logger.debug(str(data))
        try:

            location = Location.from_id(data['city']['id'])
        except KeyError:
            Logger.log(LOG_LEVELS['critical'],
                       'We seem to have some massive issue with something')
            return
        command = "INSERT OR REPLACE INTO forecast(forecast_id, location_id, time, temp, pressure, humidity, clouds, " \
                  "windspeed, winddirection, symbol) VALUES "
        for forecast in data['list']:
            forecast_time = forecast['dt']
            temp = forecast['main']['temp']
            pressure = forecast['main']['pressure']
            humidity = forecast['main']['humidity']
            clouds = forecast['clouds']['all']
            windspeed = forecast['wind']['speed']
            winddirection = forecast['wind']['deg']
            symbol = forecast['weather'][0]['id']
            command += Formatter().format(
                "((SELECT forecast_id FROM forecast WHERE location_id={location_id} AND time={time}),{location_id},{time},{temp},{pressure},{humidity},{clouds},{windspeed},{winddirection},{symbol}),",
                location_id=location.id,
                time=forecast_time,
                temp=temp,
                pressure=pressure,
                humidity=humidity,
                clouds=clouds,
                windspeed=windspeed,
                winddirection=winddirection,
                symbol=symbol)
        _db.execute(command[:-1])
Пример #2
0
 def log(self, message, level='info', tag='CoatiraneAdventures'):
     Logger.log({
         'info': 20,
         'warn': 30,
         'debug': 10,
         'error': 40
     }[level], f"{tag}: {message}")
Пример #3
0
 def do_job(self,callback):
     try:
         self.options=callback()
         self.job_state='finished'
     except:
         self.str_error=traceback.format_exc()
         self.job_state='error'
         Logger.log(self.str_error)
Пример #4
0
def require(version):
    '''Require can be used to check the minimum version required to run a Kivy
    application. For example, you can start your application code like this::

        import kivy
        kivy.require('1.0.1')

    If a user attempts to run your application with a version of Kivy that is
    older than the specified version, an Exception is raised.

    The Kivy version string is built like this::

        X.Y.Z[tag[tagrevision]]

        X is the major version
        Y is the minor version
        Z is the bugfixes revision

    The tag is optional, but may be one of '.dev', '.post', 'a', 'b', or 'rc'.
    The tagrevision is the revision number of the tag.

    .. warning::

        You must not ask for a version with a tag, except -dev. Asking for a
        'dev' version will just warn the user if the current Kivy
        version is not a -dev, but it will never raise an exception.
        You must not ask for a version with a tagrevision.

    '''

    # user version
    revision, tag, tagrev = parse_kivy_version(version)
    # current version
    sysrevision, systag, systagrev = parse_kivy_version(__version__)

    Logger.log(LOG_LEVELS.get('info'), f"Kivy: Using Kivy version {int(sysrevision[0])}.{int(sysrevision[1])}.{int(sysrevision[2])}.{systag}{systagrev}")

    if tag and not systag:
        Logger.warning('Application requested a dev version of Kivy. '
                       '(You have %s, but the application requires %s)' % (
                           __version__, version))
    # not tag rev (-alpha-1, -beta-x) allowed.
    if tagrev is not None:
        raise Exception('Revision format must not contain any tagrevision')

    # finally, checking revision
    if sysrevision < revision:
        raise Exception('The version of Kivy installed on this system '
                        'is too old. '
                        '(You have %s, but the application requires %s)' % (
                            __version__, version))
Пример #5
0
    def save_all_to_db(data):
        Logger.debug(str(data))
        try:

            location = Location.from_id(data['city']['id'])
        except KeyError:
            Logger.log(LOG_LEVELS['critical'], 'We seem to have some massive issue with something')
            return
        command = "INSERT OR REPLACE INTO forecast(forecast_id, location_id, time, temp, pressure, humidity, clouds, " \
                  "windspeed, winddirection, symbol) VALUES "
        for forecast in data['list']:
            forecast_time = forecast['dt']
            temp = forecast['main']['temp']
            pressure = forecast['main']['pressure']
            humidity = forecast['main']['humidity']
            clouds = forecast['clouds']['all']
            windspeed = forecast['wind']['speed']
            winddirection = forecast['wind']['deg']
            symbol = forecast['weather'][0]['id']
            command += Formatter().format(
                "((SELECT forecast_id FROM forecast WHERE location_id={location_id} AND time={time}),{location_id},{time},{temp},{pressure},{humidity},{clouds},{windspeed},{winddirection},{symbol}),",
                location_id = location.id, time=forecast_time, temp=temp, pressure=pressure, humidity=humidity, clouds=clouds, windspeed=windspeed, winddirection=winddirection, symbol=symbol)
        _db.execute(command[:-1])
Пример #6
0
 def log(self, lvl, msg, *args, **kwargs):
     msg = '%s: %s' % (self.name, msg)
     Logger.log(lvl, msg, *args, **kwargs)
Пример #7
0
 def emit(self, record):
     if KivyLogger.isEnabledFor(record.levelno):
         KivyLogger.log(
             record.levelno, 'Moa: {}'.format(self.format(record)))