本文整理匯總了Python中FileManager.FileManager.read_json方法的典型用法代碼示例。如果您正苦於以下問題:Python FileManager.read_json方法的具體用法?Python FileManager.read_json怎麽用?Python FileManager.read_json使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類FileManager.FileManager
的用法示例。
在下文中一共展示了FileManager.read_json方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: main
# 需要導入模塊: from FileManager import FileManager [as 別名]
# 或者: from FileManager.FileManager import read_json [as 別名]
def main():
last_date = datetime.now() - timedelta(days=2)
captor = FlickrCaptor(logger)
file_manager = FileManager()
try:
try:
woe_ids = file_manager.get_locations(source)
except IOError:
raise InitError("File %s is missing"% file_manager.get_locations_path(source))
except ValueError:
raise InitError("The %s file does not contain any correct JSON object"% file_manager.get_locations_path(source))
min_date_file_path = file_manager.get_path(source, None, min_date_file)
try:
min_date_json = file_manager.read_json(source, min_date_file)
min_date = datetime.strptime(min_date_json['min_date'], min_date_format)
except IOError:
raise InitError("File %s is missing. You should create this file and set {'min_date':YYYY-MM-DD} in it."% min_date_file_path)
except (ValueError, KeyError):
raise InitError("You need to set {\"min_date\":\"YYYY-MM-DD\"} in file %s"% min_date_file_path)
zero_day = timedelta(days=0)
one_day = timedelta(days=1)
if (last_date - min_date) < zero_day:
raise InitError("The date set as min_date in %s is after 2 days ago."% min_date_file_path)
while (last_date - min_date) >= zero_day:
logger.warning("---- Capting for %s" % min_date.strftime('%y-%m-%d'))
for city, woe_id in woe_ids.iteritems():
max_date = min_date + one_day
logger.warning("Capting for %s" % city)
loaded_json = captor.get_data(min_date, max_date, woe_id)
try:
file_manager.write_json(loaded_json, source, city, min_date.strftime('%y-%m-%d'))
except IOError:
raise InitError("Folder %s is missing"% file_manager.get_folder_path(source, city))
logger.warning("New JSON written for %s " % city)
min_date = max_date
f = open(min_date_file_path, 'w+')
json.dump({'min_date':min_date.strftime(min_date_format)}, f)
f.close()
logger.warning("... Sleeping for 5 s")
sleep(5)
return 0
except InitError as e:
logger.critical("%s: %s"% (type(e).__name__, e))
return 1
except requests.exceptions.RequestException as e:
logger.critical("%s: %s"% (type(e).__name__, e))
return 2
except FlickrCaptor.FlickrApiError as e:
logger.critical("%s: %s"% (type(e).__name__, e))
return 3
except Exception as e:
logger.critical(e, exc_info=True)
return 4