3
3
'''
4
4
5
5
import os
6
- import bs4
6
+ import pathlib
7
7
import re
8
- import django
9
- import os
10
8
import sys
11
- import pathlib
12
- from torcms .model .category_model import MCategory
13
- from torcms .model .post_model import MPost
14
- from torcms .handlers .post_handler import update_category
15
- from torcms .model .wiki_model import MWiki
16
9
10
+ import bs4
11
+ import django
17
12
from faker import Faker
18
13
19
14
from config import post_cfg
20
15
from torcms .core .tools import get_uu4d , get_uuid
16
+ from torcms .handlers .post_handler import update_category
17
+ from torcms .model .category_model import MCategory
18
+ from torcms .model .post_model import MPost
19
+ from torcms .model .wiki_model import MWiki
21
20
22
21
os .environ .setdefault ("DJANGO_SETTINGS_MODULE" , "administor.settings" )
23
22
django .setup ()
37
36
rest_regs = [
38
37
'\<img.+?\/\>' ,
39
38
]
39
+
40
+
40
41
def update_label (post_id , post_data ):
41
42
'''
42
43
Update the label when updating.
@@ -69,18 +70,23 @@ def update_label(post_id, post_data):
69
70
else :
70
71
MPost2Label .remove_relation (post_id , cur_info .tag_id )
71
72
73
+
72
74
def gen_post (tag_uid ):
73
75
dt = datetime .now ()
74
76
post_uid = f'{ key } { get_uu4d ()} '
75
77
extinfo = {}
76
78
# 增加地图缺少的信息
77
79
if key == 'm' :
78
80
extinfo = {
79
- 'ext_lon' :fak .pyfloat (left_digits = 3 , right_digits = 3 ,min_value = 0 ,max_value = 180 ),
80
- 'ext_lat' :fak .pyfloat (left_digits = 2 , right_digits = 3 ,min_value = 0 ,max_value = 90 ),
81
- 'ext_zoom_current' :'4' ,
82
- 'ext_zoom_max' :'7' ,
83
- 'ext_zoom_min' :'1' ,
81
+ 'ext_lon' : fak .pyfloat (
82
+ left_digits = 3 , right_digits = 3 , min_value = 0 , max_value = 180
83
+ ),
84
+ 'ext_lat' : fak .pyfloat (
85
+ left_digits = 2 , right_digits = 3 , min_value = 0 , max_value = 90
86
+ ),
87
+ 'ext_zoom_current' : '4' ,
88
+ 'ext_zoom_max' : '7' ,
89
+ 'ext_zoom_min' : '1' ,
84
90
}
85
91
dict_info = {
86
92
'uid' : post_uid ,
@@ -91,13 +97,19 @@ def gen_post(tag_uid):
91
97
'time_create' : dt .timestamp (),
92
98
'time_update' : dt .timestamp (),
93
99
'kind' : key ,
94
- 'extinfo' :extinfo
100
+ 'extinfo' : extinfo ,
95
101
}
96
102
uu = TabPost .objects .get_or_create (uid = post_uid , defaults = dict_info )
97
103
return post_uid
98
- def gen_label (post_uid ,kind ):
99
- post_data = {'tags' : '{},{}' .format (fak .text (max_nb_chars = 5 ), fak .text (max_nb_chars = 5 ))}
104
+
105
+
106
+ def gen_label (post_uid , kind ):
107
+ post_data = {
108
+ 'tags' : '{},{}' .format (fak .text (max_nb_chars = 5 ), fak .text (max_nb_chars = 5 ))
109
+ }
100
110
update_label (post_uid , post_data )
111
+
112
+
101
113
pwd = os .getcwd ()
102
114
103
115
@@ -133,7 +145,7 @@ def filter_reg_text(inws, out_reg_arr):
133
145
img_path = pathlib .Path (inws )
134
146
for wfile in img_path .rglob ('*' ):
135
147
if img == wfile .name :
136
- img = str (wfile .resolve ())[len (pwd ):]
148
+ img = str (wfile .resolve ())[len (pwd ) :]
137
149
tt .append ('src="{}"' .format (img ))
138
150
else :
139
151
tt .append (bb )
@@ -142,8 +154,6 @@ def filter_reg_text(inws, out_reg_arr):
142
154
return outarr
143
155
144
156
145
-
146
-
147
157
def do_for_chapter (cat_id , ch_path ):
148
158
file_path = []
149
159
idx = 1
@@ -174,7 +184,6 @@ def do_for_chapter(cat_id, ch_path):
174
184
175
185
def do_for_page (cat_id , ch_path , filename , idx ):
176
186
for x in ch_path .rglob ('*.html' ):
177
-
178
187
if x .name .startswith (filename ):
179
188
pass
180
189
else :
@@ -188,7 +197,6 @@ def do_for_page(cat_id, ch_path, filename, idx):
188
197
189
198
190
199
def get_page_meta (catid , the_file , idx ):
191
-
192
200
print (the_file .name )
193
201
File = open (str (the_file .resolve ()))
194
202
Soup = bs4 .BeautifulSoup (File .read (), features = "html.parser" )
@@ -208,7 +216,6 @@ def get_page_meta(catid, the_file, idx):
208
216
209
217
210
218
def get_meta (catid , sig , the_file , idx ):
211
-
212
219
File = open (str (the_file .resolve ()))
213
220
Soup = bs4 .BeautifulSoup (File .read (), features = "html.parser" )
214
221
title = Soup .select ('h1' )[0 ].getText ()
@@ -219,7 +226,6 @@ def get_meta(catid, sig, the_file, idx):
219
226
result [1 ::2 ] = vv
220
227
content = ' ' .join (result )
221
228
222
-
223
229
pp_data = {}
224
230
pp_data ['uid' ] = sig
225
231
pp_data ['title' ] = str (title )[:- 1 ]
@@ -240,7 +246,6 @@ def get_meta(catid, sig, the_file, idx):
240
246
241
247
def get_catname (ch_path , filename ):
242
248
for x in ch_path .rglob ('*.html' ):
243
-
244
249
if x .name .startswith (filename ):
245
250
pass
246
251
else :
@@ -271,7 +276,6 @@ def bianli(inws):
271
276
idx = max_order + 1
272
277
273
278
for wdir in wdirs :
274
-
275
279
if wdir .startswith ('ch' ) and len (wdir .split ('_' )) > 2 :
276
280
pass
277
281
else :
@@ -298,41 +302,29 @@ def bianli(inws):
298
302
else :
299
303
cat_name = cat_slug
300
304
301
- post_data = {'name' : cat_name ,
302
- 'slug' : cat_slug .lower (),
303
- 'order' : idx ,
304
- 'kind' : 'k' ,
305
- 'pid' : pid }
305
+ post_data = {
306
+ 'name' : cat_name ,
307
+ 'slug' : cat_slug .lower (),
308
+ 'order' : idx ,
309
+ 'kind' : 'k' ,
310
+ 'pid' : pid ,
311
+ }
306
312
307
313
try :
308
314
MCategory .add_or_update (cat_id , post_data )
309
315
except Exception :
310
316
pass
311
317
312
- do_for_chapter (
313
- cat_id ,
314
- pathlib .Path (os .path .join (wroot , wdir ))
315
- )
318
+ do_for_chapter (cat_id , pathlib .Path (os .path .join (wroot , wdir )))
316
319
317
320
# 将 chapter.html 内容存入数据库, page/catid 形式访问
318
- do_for_page (
319
- cat_id ,
320
- pathlib .Path (os .path .join (wroot , wdir )),
321
- 'chapter' ,
322
- idx
323
- )
321
+ do_for_page (cat_id , pathlib .Path (os .path .join (wroot , wdir )), 'chapter' , idx )
324
322
# 将 index.html 内容存入数据库, page/catid 形式访问
325
- do_for_page (
326
- pid ,
327
- pathlib .Path (os .path .join (wroot )),
328
- 'index' ,
329
- idx
330
- )
323
+ do_for_page (pid , pathlib .Path (os .path .join (wroot )), 'index' , idx )
331
324
332
325
idx = idx + 1
333
326
334
327
335
-
336
328
if __name__ == '__main__' :
337
329
# gen()
338
330
@@ -354,10 +346,12 @@ def bianli(inws):
354
346
else :
355
347
tag_recs = TabTag .objects .filter (kind = key ).all ()
356
348
for tag_rec in tag_recs :
349
+ if tag_rec .uid .endswith ('00' ):
350
+ continue
357
351
for ii in range (10 ):
358
352
post_uid = gen_post (tag_rec .uid )
359
353
print (post_uid )
360
- gen_label (post_uid ,key )
354
+ gen_label (post_uid , key )
361
355
post2tag = TabPost2Tag (
362
356
uid = get_uuid (),
363
357
par_id = f'{ tag_rec .uid [:2 ]} 00' ,
@@ -367,7 +361,6 @@ def bianli(inws):
367
361
)
368
362
post2tag .save ()
369
363
370
-
371
364
#
372
365
# recs = TabPost.objects.filter().all()
373
366
# for rec in recs:
0 commit comments