def map_ip(response): ip = re.findall('(?:[0-9]{1,3}\.){3}[0-9]{1,3}', response.text)[0] logger.info('ip', ip) return { 'ip': ip, 'utc_datetime': unicode(datetime.utcnow()) }
def main(sys_args): weeks, = sys_args or [21] start_time = datetime.utcnow() from_date = (start_time - timedelta(int(weeks))).date() count = 0 filename = os.path.dirname(os.path.abspath(__file__)) + '/beers.json' if os.path.isfile(filename): with codecs.open(filename, 'r', 'utf-8') as file: logger.info('file', filename) headers = [ ("name_0", "Name"), ("name_1", "Name2"), ("price", "Price"), ("sale_start", "Sale start"), ("abv", "Alcohol"), ("supplier", "Supplier"), ("manufacturer", "Manufacturer") ] beers, ratings = _get_sales_start(file, from_date, headers), _get_ratings(file) _apply_ratings(beers, ratings) logger.info('data', json.dumps(beers, indent=2, ensure_ascii=False)) count += len(beers) else: logger.error('file', '{} does not exists'.format(filename)) logger.info('count', 'found {} since {:%Y-%m-%d %H:%M}'.format(count, from_date)) logger.info('duration', '{:.3f}s'.format((datetime.utcnow() - start_time).total_seconds())) return 0
def save(self): filename = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + "/beers.json" with codecs.open(filename, "w", "utf-8") as file: logger.info("write", "to " + filename) file.truncate() file.write(unicode(json.dumps(self.__items, indent=2, ensure_ascii=False)))