-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimulateStream.py
62 lines (51 loc) · 1.96 KB
/
simulateStream.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# -*- coding:utf-8 -*-
import time
import pymongo
import shutil
import datetime
# get the date between them
def get_every_day(begin_date, end_date):
date_list = []
begin_date = datetime.datetime.strptime(begin_date, "%Y-%m-%d")
end_date = datetime.datetime.strptime(end_date, "%Y-%m-%d")
while begin_date <= end_date:
date_str = begin_date.strftime("%Y-%m-%d")
date_list.append(date_str)
begin_date += datetime.timedelta(days=1)
return date_list
if __name__ == '__main__':
client = pymongo.MongoClient("mongodb://localhost:27017/")
db = client.bilibili
col = db.videosAhead
col2=db.videos
dateDuration = get_every_day('2018-12-20', '2018-12-31')
result = 0
for oneDate in dateDuration:
fileName = oneDate+ "&" + str(time.time())
filePath = r'tmp/' + str(fileName) + '.log'
with open(filePath, 'w',errors='ignore',encoding='utf-8') as f:
queryAns = col.find({'time': {"$regex": oneDate}})
for doc in queryAns:
list=doc['key']
for item in list:
f.write(item)
f.write('\n')
result+=1
print(result)
destination = shutil.move(filePath, r'log/' + str(fileName) + '.log')
time.sleep(0.5)
dateDuration2=get_every_day('2019-01-01','2019-04-01')
for oneDate in dateDuration2:
fileName = oneDate+ "&" + str(time.time())
filePath = r'tmp/' + str(fileName) + '.log'
with open(filePath, 'w',errors='ignore',encoding='utf-8') as g:
queryAns = col2.find({'time': {"$regex": oneDate}})
for doc in queryAns:
list=doc['key']
for item in list:
g.write(item)
g.write('\n')
result+=1
print(result)
destination = shutil.move(filePath, r'log/' + str(fileName) + '.log')
time.sleep(1)