-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimeStamp.py
More file actions
57 lines (47 loc) · 1.12 KB
/
Copy pathTimeStamp.py
File metadata and controls
57 lines (47 loc) · 1.12 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import pandas as pd
import json
import numpy as np
from collections import defaultdict
from datetime import datetime
huge_json_file= "RS_2021-05"
d = defaultdict(list)
print(d)
with open(huge_json_file, "r") as f:
#print(f.readline())
#for i in range(2):
one_block = f.readline()
res = json.loads(one_block)
#print (res)
count=0
while one_block:
one_block = f.readline()
if one_block=="":
break
res = json.loads(one_block)
if res['media']==None:
continue
YouTube_Check = res.get('media', {}).get('oembed', {}).get('provider_name',"")
if YouTube_Check== "YouTube":
author=res['author']
url=res['url']
time_unix=int(res['created_utc'])
time_real=datetime.utcfromtimestamp(time_unix).strftime('%Y-%m-%d %H:%M:%S')
packet=[]
packet.append(url)
packet.append(time_real)
#print(packet)
temp=1
for items in d[author]:
if url==items[0]:
temp=0
break
else:
continue
if temp==1:
d[author].append(packet)
count=count+1
print(count)
else:
continue
with open('data-2021-05.txt', 'a') as convert_file:
convert_file.write(json.dumps(d))