-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathremove_all_with_error.py
More file actions
28 lines (22 loc) · 1000 Bytes
/
remove_all_with_error.py
File metadata and controls
28 lines (22 loc) · 1000 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import os
import json
from collections import defaultdict
from random import randint
BASE_DIR = os.path.join('.server_files', 'articles')
filenames_per_status = defaultdict(list)
filenames_with_pdf_read = list()
filenames_with_pdf_read_with_multiple_sections = list()
filenames_to_change_read = list()
for filename in [BASE_DIR + '/' + f for f in os.listdir(BASE_DIR) if f[-5:] == '.json']:
with open(filename) as filestream:
article_dict = json.load(filestream) or dict()
status = article_dict.get('read_status', str())
filenames_per_status[status].append(filename)
for status, filenames in filenames_per_status.items():
print('Status <' + status + '> filenames size: ' + str(len(filenames)))
if status == "Failed to read data from publisher":
for filename in filenames:
pdf_filename = filename.replace('.json', '.pdf')
if os.path.isfile(pdf_filename):
os.remove(pdf_filename)
os.remove(filename)