def cache(cls): city_list_from_thinkpage_filename = \ common.get_file_from_current_dir(__file__, 'city_list_from_thinkpage.json') if not os.path.exists(city_list_from_thinkpage_filename): logger.error('Missing file \'city_list_from_thinkpage.json\'') return try: city_list_from_thinkpage_file = open(city_list_from_thinkpage_filename, 'r') city_list_from_thinkpage_content = city_list_from_thinkpage_file.read() cls.city_list_from_thinkpage = json.loads(city_list_from_thinkpage_content) if cls.city_list_from_thinkpage is None: raise Exception('city_list_from_thinkpage is None') except Exception, e: logger.error('Failed to read the file (city_list_from_thinkpage.json), error: %s' % e)
except Exception, e: logger.error('Failed to read the file (city_list_from_thinkpage.json), error: %s' % e) finally: if city_list_from_thinkpage_file is not None: city_list_from_thinkpage_file.close() for _ in cls.city_list_from_thinkpage[::-1]: id_ = _.get('id') if id_ is not None and id_.startswith('CH'): name = _.get('name') if name is not None: cls.city_name_list.append(name) # img code img_code_map_filename = \ common.get_file_from_current_dir(__file__, 'img_code_map.json') if not os.path.exists(img_code_map_filename): logger.error('Missing file \'img_code_map.json\'') return try: img_code_map_file = open(img_code_map_filename, 'r') img_code_map_content = img_code_map_file.read() img_code_map = json.loads(img_code_map_content) if img_code_map is None: raise Exception('img_code_map is None') cls.img_code_map = img_code_map except Exception, e: logger.error('Failed to read the file (img_code_map.json), error: %s' % e) finally: if img_code_map_file is not None: img_code_map_file.close()