Exemple #1
0
class CEICInfoUpdater:
    def __init__(self, mongo=None, redis=None):
        if mongo is None:
            self._mongo = MonCollection(mongodb=MongoDB(),
                                        database='region',
                                        collection_name='CEIC')
        else:
            self._mongo = mongo

        if redis is None:
            self._redis = Redis()
        else:
            self._redis = redis

    def __call__(self):
        ceic_period = sorted(self._mongo.distinct('year'))
        ceic_variable = sorted(self._mongo.distinct('variable'))
        ceic_acode = sorted(self._mongo.distinct('acode'))
        ceic_region = [
            self._mongo.collection.find_one({'acode': acode},
                                            projection={
                                                '_id': False,
                                                'region': True
                                            })['region']
            for acode in ceic_acode
        ]

        #update
        self._redis.set('ceic_acode', ceic_acode)
        self._redis.set('ceic_period', ceic_period)
        self._redis.set('ceic_variable', ceic_variable)
        self._redis.set('ceic_region', ceic_region)
Exemple #2
0
class AirQualityUpdater:
    def __init__(self, mongo=None, redis=None):
        if mongo is None:
            self._mongo = MonCollection(mongodb=MongoDB(),
                                        database='scraperdata',
                                        collection_name='airqualityfromMin')
        else:
            self._mongo = mongo

        if redis is None:
            self._redis = Redis()
        else:
            self._redis = redis

    def __call__(self):
        airquality_citycode = sorted(self._mongo.distinct('CITYCODE'))
        airquality_city = [
            self._mongo.collection.find_one({'CITYCODE': ccode},
                                            projection={
                                                '_id': False,
                                                'CITY': True
                                            })['CITY']
            for ccode in airquality_citycode
        ]
        airquality_date = ([
            date.strftime("%y-%m-%d")
            for date in sorted(self._mongo.distinct('OPER_DATE'))
        ])

        # update
        self._redis.set('airquality_city', airquality_city)
        self._redis.set('airquality_citycode', airquality_citycode)
        self._redis.set('airquality_date', airquality_date)