-
Notifications
You must be signed in to change notification settings - Fork 0
/
movies_edit.py
39 lines (34 loc) · 1.14 KB
/
movies_edit.py
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
28
29
30
31
32
33
34
35
36
37
38
39
import jsonlines
import json
file = open('E:\\movies.json', 'r', encoding='utf-8')
file2 = jsonlines.open('E:\\movies2.json', 'a')
for line in file.readlines():
dic = json.loads(line)
# 评论得分处理 存在没评论的情况
if len(dic['reviews']) >= 1:
t = 0
for item in dic['reviews']:
t += float(item['score'])
average = round(t / len(dic['reviews']), 1)
print(average)
dic['ReviewPoint'] = average
else:
dic['ReviewPoint'] = 0
# 时间处理
dic_split = str(dic['Date First Available']).replace(' ', ',').split(',')
if len(dic_split) != 3 and len(dic['reviews']) >= 1: # 取评论
print(dic['reviews'][0]['date'])
new_str = str(dic['reviews'][0]['date']).replace(' ', ',').split(',')[-4:]
del new_str[2]
print(new_str)
dic['Date First Available'] = new_str
file2.write(dic)
continue
print(dic['Date First Available'])
date = str(dic['Date First Available']).replace(',', '').split(' ')
print(date)
dic['Date First Available'] = date
file2.write(dic)
file.close()
file2.close()
# 日期转换