forked from woct0rdho/pkuholebackup
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbatchsplit.py
More file actions
executable file
·32 lines (28 loc) · 1.2 KB
/
batchsplit.py
File metadata and controls
executable file
·32 lines (28 loc) · 1.2 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
#!/usr/bin/python3
import os
from datetime import date
from utils import my_log, post_dict_to_list, read_posts, write_posts
cdname = os.path.dirname(__file__)
filename = os.path.join(cdname, 'pkuhole.txt')
archive_dir = os.path.join(cdname, 'archivebak')
archive_basename = 'pkuhole'
archive_extname = '.txt'
if __name__ == '__main__':
post_list = read_posts(filename)
last_date = date.fromtimestamp(post_list[0]['timestamp'])
now_post_dict = {}
for post in post_list:
now_date = date.fromtimestamp(post['timestamp'])
if now_date < last_date:
archive_filename = os.path.join(
archive_dir, last_date.strftime('%Y%m'), archive_basename +
last_date.strftime('%Y%m%d') + archive_extname)
write_posts(archive_filename, post_dict_to_list(now_post_dict))
last_date = now_date
now_post_dict = {}
my_log(last_date.strftime('%Y%m%d'))
now_post_dict[post['pid']] = post
archive_filename = os.path.join(
archive_dir, last_date.strftime('%Y%m'),
archive_basename + last_date.strftime('%Y%m%d') + archive_extname)
write_posts(archive_filename, post_dict_to_list(now_post_dict))