def read_downloads(self):
downloads_path = os.path.join(self.project_path, DOWNLOADS_DIR)
json_path = os.path.join(downloads_path, 'json', '*.json')
raw_path = os.path.join(downloads_path, 'raw')
downloads = dict()
for file_path in glob.glob(json_path):
download_id = int(get_fn(file_path, 0))
downloads[download_id] = dict()
with open(file_path) as json_text:
downloads[download_id]['json'] = json.loads(json_text.read())
for download_id in os.listdir(raw_path):
downloads[int(download_id)]['raw'] = list()
for file_path in glob.glob(os.path.join(raw_path, str(download_id),
'*.*')):
file_name = get_fn(file_path)
ext = get_fn(file_path, 1)
try:
content_type = mimetypes.types_map[ext]
except KeyError:
content_type = 'multipart/form-data'
with open(file_path, 'rb') as raw_file:
downloads[int(download_id)]['raw'].append(dict(
name=file_name,
raw=raw_file.read(),
content_type=content_type
))
return collections.OrderedDict(sorted(downloads.items()))
评论列表
文章目录