Skip to content

Commit 76b4ddc

Browse files
committed
chang all
1 parent eb87290 commit 76b4ddc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+80
-278460
lines changed

Makefile

Lines changed: 0 additions & 177 deletions
This file was deleted.
File renamed without changes.
File renamed without changes.

basic/myos/read_write.py

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@
44
Topic: sample
55
Desc :
66
"""
7+
import re
8+
import os
9+
from os.path import join
10+
import logging
11+
12+
logging.basicConfig(level=logging.INFO,
13+
format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s',
14+
datefmt='%Y-%m-%d %H:%M:%S',
15+
handlers=[logging.FileHandler('d:/logs/cookbook.log', 'w', 'utf-8')])
16+
_log = logging.getLogger('app.' + __name__)
717

818

919
def read_demo():
@@ -15,5 +25,54 @@ def read_demo():
1525
pass
1626

1727

28+
def read_plus(txt_file, init_c, base_dir):
29+
"""演示一下seek方法"""
30+
chapter = init_c - 1 # 章
31+
paper = 0 # 节
32+
write_file = None # 接下来要写入的文件
33+
temp_lines = [] # 临时存放章或节内容
34+
with open(txt_file, mode='r', encoding='utf-8') as f:
35+
for line in f:
36+
if re.match('^CHAPTER \d+$', line.strip()):
37+
chapter += 1
38+
# 开始新的一章了
39+
_log.info('开始新的一章了,第{}章!'.format(chapter))
40+
# 前面的给写入文件中
41+
if temp_lines:
42+
with open(write_file, mode='w', encoding='utf-8') as wf:
43+
wf.writelines(temp_lines)
44+
temp_lines.clear()
45+
# 首先创建一个章节源码目录
46+
c_dir = join(base_dir, 'cookbook', 'c{:02d}'.format(chapter))
47+
if not os.path.exists(c_dir):
48+
os.makedirs(c_dir)
49+
# 找到章节文件
50+
chapters_dir = join(c_dir, 'source', 'chapters')
51+
onlyfiles = [join(chapters_dir, f) for f in os.listdir(chapters_dir)
52+
if os.path.isfile(join(chapters_dir, f))]
53+
write_file = next(f for f in onlyfiles if f.startswith('p{:02d}'.format(chapter)))
54+
elif re.match('^{}.{}. '.format(chapter, paper + 1), line.strip()):
55+
f.seek(1, 1) # 往前进一行
56+
if f.readline().strip() == 'Problem':
57+
# 说明是新的一节开始了
58+
paper += 1
59+
f.seek(-1, 1) # 退一行
60+
_log.info('开始新的一节了,第{}章,第{}节!'.format(chapter, paper))
61+
# 前面的给写入文件中
62+
if temp_lines:
63+
with open(write_file, mode='w', encoding='utf-8') as wf:
64+
wf.writelines(temp_lines)
65+
temp_lines.clear()
66+
# 定义接下来要写入的节文件
67+
paper_dir = join(base_dir, 'source', 'c{:02d}'.format(chapter))
68+
pfs = [join(paper_dir, f) for f in os.listdir(paper_dir)
69+
if os.path.isfile(join(paper_dir, f))]
70+
write_file = next(f for f in pfs if f.startswith('p{:02d}'.format(chapter)))
71+
else:
72+
f.seek(-1, 1)
73+
else:
74+
temp_lines.append(line)
75+
76+
1877
if __name__ == '__main__':
19-
read_demo()
78+
print('{:02d}'.format(11))

basic/myutils/__init__.py

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python
22
# -*- encoding: utf-8 -*-
33
"""
4-
Topic: sample
4+
Topic: 实用代码集锦
55
Desc :
66
"""
77

basic/myutils/constants.py renamed to basic/samples/constants.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44
Topic: sample
55
Desc :
66
"""
7-
import sys, os
8-
from . import consttype as const
7+
import sys
8+
import os
9+
10+
from basic.samples import consttype as const
11+
912
__author__ = 'Xiong Neng'
1013

1114
const.ROOT_PATH = os.path.dirname(sys.path[0])
File renamed without changes.
File renamed without changes.

basic/myutils/excel/excel_mysql.py renamed to basic/samples/excel/excel_mysql.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def xlsx_to_table(xlsx_name):
222222

223223

224224
if __name__ == '__main__':
225-
excel = r'D:\download\20150505\gdc2.xlsx'
225+
excel = r'D:\download\20150505\gdc.xlsx'
226226
_init_table()
227227
conn = _connect()
228228
xlsx_to_table(excel)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

basic/myutils/pdf/perfect_lines.py renamed to basic/samples/pdf/cookbook_source.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,19 @@
66
"""
77
import re
88

9+
910
def beauty(txt_file):
1011
with open(txt_file, mode='r+', encoding='utf-8') as f:
1112
lines = f.readlines()
1213
f.seek(0)
1314
for line in lines:
1415
if line.startswith('www.it-ebooks.info'):
15-
f.seek(f.tell() - 1)
16+
f.seek(f.tell() - 1, 1)
1617
if f.readline().startswith('Chapter '):
1718
# 回退7位
18-
f.seek(f.tell() - 7)
19+
f.seek(f.tell() - 7, 1)
1920
else:
20-
f.seek(f.tell() - 5)
21+
f.seek(f.tell() - 5, 1)
2122
else:
2223
f.write(line)
2324
f.truncate()
@@ -47,5 +48,13 @@ def beauty2(pre_txt, after_txt):
4748
f.writelines(result_lines)
4849

4950

51+
def generate_chapter():
52+
"""
53+
解析文本文件,生成最终的待翻译文件
54+
"""
55+
56+
57+
5058
if __name__ == '__main__':
51-
beauty2('pc_pre.txt', 'pc_after')
59+
# beauty2('pc_pre.txt', 'pc_after')
60+
pass
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

configs/common.yml

Whitespace-only changes.

configs/test.html

Lines changed: 0 additions & 13 deletions
This file was deleted.

exts/chinese_search.py

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)