-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmanage_plugins.py
82 lines (72 loc) · 2.76 KB
/
manage_plugins.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
"""
Plugins of Management System
"""
import json
from datetime import datetime
from manage_base import ManagePluginBase
from bangumi import get_default_dict
from database import get_all_anime
class Add(ManagePluginBase):
"""
Add entries to database.
The function generates an empty JSON file containing default value. Fill
it. Then, invoke aad add file_path to add enties to database.
"""
description = 'Generate a standard empty JSON file.'
@classmethod
def func(cls):
"""
Generate a JSON file containing num empty enties
user input:
num Number of enties
"""
num = int(input('Number of anime you want to add: '))
default_dict = get_default_dict()
default_arr = [default_dict for _ in range(num)]
json_str = json.dumps(default_arr, indent=4, separators=(',', ':'))
generate_file = open('new_bangumi_'
+ datetime.now().strftime('%Y-%m-%d-%H%M%S')
+ '.json', 'w')
generate_file.write(json_str)
generate_file.close()
print('File has been generated.')
class Change(ManagePluginBase):
"""
Change entries in database.
The function generates a JSON file compatable with change rule based on
designated entries.
"""
description = 'Generate a standard file containing entries you intent to change'
@classmethod
def func(cls):
anime = get_all_anime()
for key, entry in enumerate(anime):
print('Number', key)
print(entry)
print('')
user_input = input(
'Input numbers of anime you want to change(Seperate by space): ')
if user_input == 'all':
change_list = anime
else:
choices = user_input.split(' ')
choices = [int(i) for i in choices]
change_list = [anime[choice] for choice in choices]
new_change_list = []
for entry in change_list:
new_entry = {'name': entry['name']}
for key, value in entry.items():
new_entry['new_' + key] = value
new_entry['new_start_date'] = new_entry[
'new_start_date'].strftime('%Y-%m-%d')
if 'folder' not in entry:
new_entry['new_folder'] = ''
new_change_list.append(new_entry)
generate_file = open('change_anime_'
+ datetime.now().strftime('%Y-%m-%d-%H%M%S')
+ '.json', 'wb')
json_str = json.dumps(new_change_list, generate_file,
indent=4, separators=(',', ':'), ensure_ascii=False).encode('utf-8')
generate_file.write(json_str)
generate_file.close()
print('File has been generated.')