text stringlengths 0 93.6k |
|---|
try: |
resp = service.addLocation( location ) |
except Fault as err: |
print( f'Zeep error: addLocation: { err }' ) |
sys.exit( 1 ) |
print( '\naddLocation response:\n' ) |
print( resp,'\n' ) |
input( 'Press Enter to continue...' ) |
# Cleanup the objects we just created |
try: |
resp = service.removeLocation( name = 'testLocation') |
except Fault as err: |
print( f'Zeep error: removeLocation: { err }' ) |
sys.exit( 1 ) |
print( '\nremoveLocation response:' ) |
print( resp, '\n' ) |
# <FILESEP> |
import os |
import json |
from ebooklib import epub |
# 获取所有的 json 文件 |
json_files = [f for f in sorted(os.listdir('./temp')) if f.endswith('.json')] |
# 将文件分组,每 1000 个文件为一组, 按文件名排序,文件名 1.json, 2.json, 3.json ... |
# 按文件名排序 |
json_files.sort(key=lambda x: int(x.split('.')[0])) |
# 每 450万字符为 个文件为一组 |
# 用于存储分组后的文件 |
# read json file |
currentLength = 0 |
# group for store every group with files |
# 二维数组 group |
file_groups = [] |
currentGroupIndex = 0 |
for filename in json_files: |
with open(os.path.join('./temp', filename), 'r') as f: |
data = json.load(f) |
textLength = len(data['text']) |
currentLength += textLength |
# if group[currentGroupIndex] not exist, so create it |
if len(file_groups) <= currentGroupIndex: |
file_groups.append([]) |
file_groups[currentGroupIndex].append(filename) |
if currentLength > 4500000: |
print('yes ' + str(currentLength)) |
currentLength = 0 |
currentGroupIndex += 1 |
# file_groups = [json_files[x:x+3000] for x in range(0, len(json_files), 3000)] |
# 打印分组信息 |
print('共有 {} 组文件'.format(len(file_groups))) |
exit(0) |
# 为每一组文件创建一本电子书 |
for i, group in enumerate(file_groups): |
# 创建新的电子书 |
book = epub.EpubBook() |
# 设置元数据 |
book.set_identifier('id123456'+str(i)) |
book.set_title('Simple English Wikipedia ' + str(i)) |
book.set_language('en') |
book.add_author('Owen') |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.