re-common 10.0.39__py3-none-any.whl → 10.0.40__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- re_common/baselibrary/__init__.py +4 -4
- re_common/baselibrary/baseabs/__init__.py +6 -6
- re_common/baselibrary/baseabs/baseabs.py +26 -26
- re_common/baselibrary/database/mbuilder.py +132 -132
- re_common/baselibrary/database/moudle.py +93 -93
- re_common/baselibrary/database/msqlite3.py +194 -194
- re_common/baselibrary/database/mysql.py +169 -169
- re_common/baselibrary/database/sql_factory.py +26 -26
- re_common/baselibrary/mthread/MThreadingRun.py +486 -486
- re_common/baselibrary/mthread/MThreadingRunEvent.py +349 -349
- re_common/baselibrary/mthread/__init__.py +2 -2
- re_common/baselibrary/mthread/mythreading.py +695 -695
- re_common/baselibrary/pakge_other/socks.py +404 -404
- re_common/baselibrary/readconfig/config_factory.py +18 -18
- re_common/baselibrary/readconfig/ini_config.py +317 -317
- re_common/baselibrary/readconfig/toml_config.py +49 -49
- re_common/baselibrary/temporary/envdata.py +36 -36
- re_common/baselibrary/tools/all_requests/aiohttp_request.py +118 -118
- re_common/baselibrary/tools/all_requests/httpx_requet.py +102 -102
- re_common/baselibrary/tools/all_requests/mrequest.py +412 -412
- re_common/baselibrary/tools/all_requests/requests_request.py +81 -81
- re_common/baselibrary/tools/batch_compre/bijiao_batch.py +31 -31
- re_common/baselibrary/tools/contrast_db3.py +123 -123
- re_common/baselibrary/tools/copy_file.py +39 -39
- re_common/baselibrary/tools/db3_2_sizedb3.py +102 -102
- re_common/baselibrary/tools/foreachgz.py +39 -39
- re_common/baselibrary/tools/get_attr.py +10 -10
- re_common/baselibrary/tools/image_to_pdf.py +61 -61
- re_common/baselibrary/tools/java_code_deal.py +139 -139
- re_common/baselibrary/tools/javacode.py +79 -79
- re_common/baselibrary/tools/mdb_db3.py +48 -48
- re_common/baselibrary/tools/merge_file.py +171 -171
- re_common/baselibrary/tools/merge_gz_file.py +165 -165
- re_common/baselibrary/tools/mhdfstools/down_hdfs_files.py +42 -42
- re_common/baselibrary/tools/mhdfstools/hdfst.py +42 -42
- re_common/baselibrary/tools/mhdfstools/up_hdfs_files.py +38 -38
- re_common/baselibrary/tools/mongo_tools.py +50 -50
- re_common/baselibrary/tools/move_file.py +170 -170
- re_common/baselibrary/tools/move_mongo/mongo_table_to_file.py +63 -63
- re_common/baselibrary/tools/move_mongo/move_mongo_table.py +354 -354
- re_common/baselibrary/tools/move_mongo/use_mttf.py +18 -18
- re_common/baselibrary/tools/move_mongo/use_mv.py +93 -93
- re_common/baselibrary/tools/mpandas/mpandasreadexcel.py +125 -125
- re_common/baselibrary/tools/mpandas/pandas_visualization.py +7 -7
- re_common/baselibrary/tools/myparsel.py +104 -104
- re_common/baselibrary/tools/rename_dir_file.py +37 -37
- re_common/baselibrary/tools/sequoiadb_utils.py +398 -398
- re_common/baselibrary/tools/split_line_to_many.py +25 -25
- re_common/baselibrary/tools/stringtodicts.py +33 -33
- re_common/baselibrary/tools/workwechant_bot.py +84 -84
- re_common/baselibrary/utils/baseaiohttp.py +296 -296
- re_common/baselibrary/utils/baseaiomysql.py +87 -87
- re_common/baselibrary/utils/baseallstep.py +191 -191
- re_common/baselibrary/utils/baseavro.py +19 -19
- re_common/baselibrary/utils/baseboto3.py +291 -291
- re_common/baselibrary/utils/basecsv.py +32 -32
- re_common/baselibrary/utils/basedict.py +133 -133
- re_common/baselibrary/utils/basedir.py +241 -241
- re_common/baselibrary/utils/baseencode.py +351 -351
- re_common/baselibrary/utils/baseencoding.py +28 -28
- re_common/baselibrary/utils/baseesdsl.py +86 -86
- re_common/baselibrary/utils/baseexcel.py +264 -264
- re_common/baselibrary/utils/baseexcept.py +109 -109
- re_common/baselibrary/utils/basefile.py +654 -654
- re_common/baselibrary/utils/baseftp.py +214 -214
- re_common/baselibrary/utils/basegzip.py +60 -60
- re_common/baselibrary/utils/basehdfs.py +135 -135
- re_common/baselibrary/utils/basehttpx.py +268 -268
- re_common/baselibrary/utils/baseip.py +87 -87
- re_common/baselibrary/utils/basejson.py +2 -2
- re_common/baselibrary/utils/baselist.py +32 -32
- re_common/baselibrary/utils/basemotor.py +190 -190
- re_common/baselibrary/utils/basemssql.py +98 -98
- re_common/baselibrary/utils/baseodbc.py +113 -113
- re_common/baselibrary/utils/basepandas.py +302 -302
- re_common/baselibrary/utils/basepeewee.py +11 -11
- re_common/baselibrary/utils/basepika.py +180 -180
- re_common/baselibrary/utils/basepydash.py +143 -143
- re_common/baselibrary/utils/basepymongo.py +230 -230
- re_common/baselibrary/utils/basequeue.py +22 -22
- re_common/baselibrary/utils/baserar.py +57 -57
- re_common/baselibrary/utils/baserequest.py +279 -279
- re_common/baselibrary/utils/baseset.py +8 -8
- re_common/baselibrary/utils/basesmb.py +403 -403
- re_common/baselibrary/utils/basestring.py +382 -382
- re_common/baselibrary/utils/basetime.py +320 -320
- re_common/baselibrary/utils/baseurl.py +121 -121
- re_common/baselibrary/utils/basezip.py +57 -57
- re_common/baselibrary/utils/core/__init__.py +7 -7
- re_common/baselibrary/utils/core/bottomutils.py +18 -18
- re_common/baselibrary/utils/core/mdeprecated.py +327 -327
- re_common/baselibrary/utils/core/mlamada.py +16 -16
- re_common/baselibrary/utils/core/msginfo.py +25 -25
- re_common/baselibrary/utils/core/requests_core.py +103 -103
- re_common/baselibrary/utils/fateadm.py +429 -429
- re_common/baselibrary/utils/importfun.py +123 -123
- re_common/baselibrary/utils/mfaker.py +57 -57
- re_common/baselibrary/utils/my_abc/__init__.py +3 -3
- re_common/baselibrary/utils/my_abc/better_abc.py +32 -32
- re_common/baselibrary/utils/mylogger.py +414 -414
- re_common/baselibrary/utils/myredisclient.py +861 -861
- re_common/baselibrary/utils/pipupgrade.py +21 -21
- re_common/baselibrary/utils/ringlist.py +85 -85
- re_common/baselibrary/utils/version_compare.py +36 -36
- re_common/baselibrary/utils/ydmhttp.py +126 -126
- re_common/facade/lazy_import.py +11 -11
- re_common/facade/loggerfacade.py +25 -25
- re_common/facade/mysqlfacade.py +467 -467
- re_common/facade/now.py +31 -31
- re_common/facade/sqlite3facade.py +257 -257
- re_common/facade/use/mq_use_facade.py +83 -83
- re_common/facade/use/proxy_use_facade.py +19 -19
- re_common/libtest/base_dict_test.py +19 -19
- re_common/libtest/baseavro_test.py +13 -13
- re_common/libtest/basefile_test.py +14 -14
- re_common/libtest/basemssql_test.py +77 -77
- re_common/libtest/baseodbc_test.py +7 -7
- re_common/libtest/basepandas_test.py +38 -38
- re_common/libtest/get_attr_test/get_attr_test_settings.py +14 -14
- re_common/libtest/get_attr_test/settings.py +54 -54
- re_common/libtest/idencode_test.py +53 -53
- re_common/libtest/iniconfig_test.py +35 -35
- re_common/libtest/ip_test.py +34 -34
- re_common/libtest/merge_file_test.py +20 -20
- re_common/libtest/mfaker_test.py +8 -8
- re_common/libtest/mm3_test.py +31 -31
- re_common/libtest/mylogger_test.py +88 -88
- re_common/libtest/myparsel_test.py +27 -27
- re_common/libtest/mysql_test.py +151 -151
- re_common/libtest/pymongo_test.py +21 -21
- re_common/libtest/split_test.py +11 -11
- re_common/libtest/sqlite3_merge_test.py +5 -5
- re_common/libtest/sqlite3_test.py +34 -34
- re_common/libtest/tomlconfig_test.py +30 -30
- re_common/libtest/use_tools_test/__init__.py +2 -2
- re_common/libtest/user/__init__.py +4 -4
- re_common/studio/__init__.py +4 -4
- re_common/studio/assignment_expressions.py +36 -36
- re_common/studio/mydash/test1.py +18 -18
- re_common/studio/pydashstudio/first.py +9 -9
- re_common/studio/streamlitstudio/first_app.py +65 -65
- re_common/studio/streamlitstudio/uber_pickups.py +23 -23
- re_common/studio/test.py +18 -18
- re_common/v2/baselibrary/business_utils/BusinessStringUtil.py +219 -219
- re_common/v2/baselibrary/business_utils/baseencodeid.py +100 -100
- re_common/v2/baselibrary/business_utils/full_doi_path.py +116 -116
- re_common/v2/baselibrary/business_utils/rel_tools.py +6 -6
- re_common/v2/baselibrary/decorators/utils.py +59 -59
- re_common/v2/baselibrary/helpers/search_packge/NearestNeighbors_test.py +105 -105
- re_common/v2/baselibrary/helpers/search_packge/fit_text_match.py +253 -253
- re_common/v2/baselibrary/helpers/search_packge/scikit_learn_text_matcher.py +260 -260
- re_common/v2/baselibrary/helpers/search_packge/test.py +1 -1
- re_common/v2/baselibrary/s3object/baseboto3.py +230 -230
- re_common/v2/baselibrary/tools/WeChatRobot.py +95 -95
- re_common/v2/baselibrary/tools/ac_ahocorasick.py +75 -75
- re_common/v2/baselibrary/tools/concurrency.py +35 -35
- re_common/v2/baselibrary/tools/data_processer/base.py +53 -53
- re_common/v2/baselibrary/tools/data_processer/data_processer.py +508 -508
- re_common/v2/baselibrary/tools/data_processer/data_reader.py +187 -187
- re_common/v2/baselibrary/tools/data_processer/data_writer.py +38 -38
- re_common/v2/baselibrary/tools/dict_tools.py +44 -44
- re_common/v2/baselibrary/tools/dolphinscheduler.py +187 -187
- re_common/v2/baselibrary/tools/hdfs_base_processor.py +204 -204
- re_common/v2/baselibrary/tools/hdfs_bulk_processor.py +67 -67
- re_common/v2/baselibrary/tools/hdfs_data_processer.py +338 -338
- re_common/v2/baselibrary/tools/hdfs_line_processor.py +74 -74
- re_common/v2/baselibrary/tools/list_tools.py +69 -69
- re_common/v2/baselibrary/tools/resume_tracker.py +94 -94
- re_common/v2/baselibrary/tools/search_hash_tools.py +54 -54
- re_common/v2/baselibrary/tools/text_matcher.py +326 -326
- re_common/v2/baselibrary/tools/unionfind_tools.py +60 -60
- re_common/v2/baselibrary/utils/BusinessStringUtil.py +196 -196
- re_common/v2/baselibrary/utils/api_net_utils.py +270 -270
- re_common/v2/baselibrary/utils/author_smi.py +361 -361
- re_common/v2/baselibrary/utils/base_string_similarity.py +158 -158
- re_common/v2/baselibrary/utils/basedict.py +37 -37
- re_common/v2/baselibrary/utils/basehdfs.py +163 -163
- re_common/v2/baselibrary/utils/basepika.py +180 -180
- re_common/v2/baselibrary/utils/basetime.py +77 -77
- re_common/v2/baselibrary/utils/db.py +156 -156
- re_common/v2/baselibrary/utils/elasticsearch.py +46 -0
- re_common/v2/baselibrary/utils/json_cls.py +16 -16
- re_common/v2/baselibrary/utils/mq.py +83 -83
- re_common/v2/baselibrary/utils/n_ary_expression_tree.py +243 -243
- re_common/v2/baselibrary/utils/string_bool.py +186 -186
- re_common/v2/baselibrary/utils/string_clear.py +246 -246
- re_common/v2/baselibrary/utils/string_smi.py +18 -18
- re_common/v2/baselibrary/utils/stringutils.py +271 -271
- re_common/vip/base_step_process.py +11 -11
- re_common/vip/baseencodeid.py +90 -90
- re_common/vip/changetaskname.py +28 -28
- re_common/vip/core_var.py +24 -24
- re_common/vip/mmh3Hash.py +89 -89
- re_common/vip/proxy/allproxys.py +127 -127
- re_common/vip/proxy/allproxys_thread.py +159 -159
- re_common/vip/proxy/cnki_proxy.py +153 -153
- re_common/vip/proxy/kuaidaili.py +87 -87
- re_common/vip/proxy/proxy_all.py +113 -113
- re_common/vip/proxy/update_kuaidaili_0.py +42 -42
- re_common/vip/proxy/wanfang_proxy.py +152 -152
- re_common/vip/proxy/wp_proxy_all.py +181 -181
- re_common/vip/read_rawid_to_txt.py +91 -91
- re_common/vip/title/__init__.py +5 -5
- re_common/vip/title/transform/TransformBookTitleToZt.py +125 -125
- re_common/vip/title/transform/TransformConferenceTitleToZt.py +139 -139
- re_common/vip/title/transform/TransformCstadTitleToZt.py +195 -195
- re_common/vip/title/transform/TransformJournalTitleToZt.py +203 -203
- re_common/vip/title/transform/TransformPatentTitleToZt.py +132 -132
- re_common/vip/title/transform/TransformRegulationTitleToZt.py +114 -114
- re_common/vip/title/transform/TransformStandardTitleToZt.py +135 -135
- re_common/vip/title/transform/TransformThesisTitleToZt.py +135 -135
- re_common/vip/title/transform/__init__.py +10 -10
- {re_common-10.0.39.dist-info → re_common-10.0.40.dist-info}/LICENSE +201 -201
- {re_common-10.0.39.dist-info → re_common-10.0.40.dist-info}/METADATA +24 -16
- re_common-10.0.40.dist-info/RECORD +249 -0
- {re_common-10.0.39.dist-info → re_common-10.0.40.dist-info}/WHEEL +1 -1
- re_common-10.0.39.dist-info/RECORD +0 -248
- {re_common-10.0.39.dist-info → re_common-10.0.40.dist-info}/top_level.txt +0 -0
|
@@ -1,102 +1,102 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
# @Time : 2020/6/16 9:29
|
|
3
|
-
# @Author : suhong
|
|
4
|
-
# @File : db3_2_sizedb3.py
|
|
5
|
-
# @Software: PyCharm
|
|
6
|
-
"""
|
|
7
|
-
获取输入db3文件夹路径,获取db3表名、列名,创建一个db3
|
|
8
|
-
往新的db3写入select信息直到指定大小,切换
|
|
9
|
-
"""
|
|
10
|
-
import sqlite3
|
|
11
|
-
import sys
|
|
12
|
-
|
|
13
|
-
from re_common.baselibrary.utils.basedir import BaseDir
|
|
14
|
-
from re_common.baselibrary.utils.basefile import BaseFile
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
class UniformSizeDb3(object):
|
|
18
|
-
def __init__(self):
|
|
19
|
-
self.table_name = None
|
|
20
|
-
self.column_name = list()
|
|
21
|
-
self.info_list = list()
|
|
22
|
-
self.all_num = 0
|
|
23
|
-
|
|
24
|
-
def work(self, file_path=None, out_path=None,size=200 * 1024 * 1024):
|
|
25
|
-
if file_path is None and out_path is None:
|
|
26
|
-
print("path error")
|
|
27
|
-
sys.exit(-1)
|
|
28
|
-
for path in BaseDir.get_dir_all_files(file_path):
|
|
29
|
-
count = 1
|
|
30
|
-
print(path)
|
|
31
|
-
# print(BaseFile.get_file_size(path)/1024/1024)
|
|
32
|
-
conn = sqlite3.connect(path)
|
|
33
|
-
cur = conn.cursor()
|
|
34
|
-
# 获取表名和字段名称
|
|
35
|
-
cur.execute("SELECT name FROM sqlite_master where type='table'")
|
|
36
|
-
row1 = cur.fetchone()
|
|
37
|
-
self.table_name = row1[0]
|
|
38
|
-
cur.execute("PRAGMA table_info([{}])".format(self.table_name))
|
|
39
|
-
row2 = cur.fetchall()
|
|
40
|
-
for row in row2:
|
|
41
|
-
self.column_name.append(row[1])
|
|
42
|
-
column_name = tuple(self.column_name)
|
|
43
|
-
self.column_name.clear()
|
|
44
|
-
|
|
45
|
-
# 获取原始db3的创建table语句
|
|
46
|
-
cur.execute("SELECT sql FROM sqlite_master WHERE type='table' AND name = '{}'".format(self.table_name))
|
|
47
|
-
create_table_sql = cur.fetchone()[0]
|
|
48
|
-
insert_sql = "insert into {} {} values ({})".format(self.table_name, column_name, "?," * len(column_name))
|
|
49
|
-
insert_sql = insert_sql.replace("'", "").replace("?,)", "?)")
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
out_file = "{}/{}_{}.db3".format(out_path, BaseFile.get_filename_not_extsep(path), count)
|
|
54
|
-
conn_2 = sqlite3.connect(out_file)
|
|
55
|
-
cur_2 = conn_2.cursor()
|
|
56
|
-
cur_2.execute("SELECT name FROM sqlite_master where type='table'")
|
|
57
|
-
name_row = cur_2.fetchone()
|
|
58
|
-
if name_row is None:
|
|
59
|
-
cur_2.execute(create_table_sql)
|
|
60
|
-
conn_2.commit()
|
|
61
|
-
|
|
62
|
-
# 查询原表信息 并插入新表
|
|
63
|
-
cur.execute("select * from {}".format(self.table_name))
|
|
64
|
-
while True:
|
|
65
|
-
rows = cur.fetchone()
|
|
66
|
-
if rows:
|
|
67
|
-
self.info_list.append(rows)
|
|
68
|
-
|
|
69
|
-
if BaseFile.get_file_size(out_file) >= size:
|
|
70
|
-
count +=1
|
|
71
|
-
out_file = "{}/{}_{}.db3".format(out_path, BaseFile.get_filename_not_extsep(path), count)
|
|
72
|
-
conn_2 = sqlite3.connect(out_file)
|
|
73
|
-
cur_2 = conn_2.cursor()
|
|
74
|
-
cur_2.execute("SELECT name FROM sqlite_master where type='table'")
|
|
75
|
-
name_row = cur_2.fetchone()
|
|
76
|
-
if name_row is None:
|
|
77
|
-
cur_2.execute(create_table_sql)
|
|
78
|
-
conn_2.commit()
|
|
79
|
-
print("outfilepath:{}".format(out_file))
|
|
80
|
-
|
|
81
|
-
if len(self.info_list) >= 10000:
|
|
82
|
-
self.all_num += len(self.info_list)
|
|
83
|
-
cur_2.executemany(insert_sql, self.info_list)
|
|
84
|
-
conn_2.commit()
|
|
85
|
-
print("do all sql:{}".format(self.all_num))
|
|
86
|
-
self.info_list.clear()
|
|
87
|
-
else:
|
|
88
|
-
break
|
|
89
|
-
self.all_num += len(self.info_list)
|
|
90
|
-
cur_2.executemany(insert_sql, self.info_list)
|
|
91
|
-
conn_2.commit()
|
|
92
|
-
cur_2.close()
|
|
93
|
-
print("do all sql:{}".format(self.all_num))
|
|
94
|
-
self.info_list.clear()
|
|
95
|
-
self.all_num = 0
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
if __name__ == '__main__':
|
|
99
|
-
file_path = r'E:\更新数据\adb3'
|
|
100
|
-
out_path = r'E:\更新数据\test_db3'
|
|
101
|
-
u = UniformSizeDb3()
|
|
102
|
-
u.work(file_path, out_path)
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# @Time : 2020/6/16 9:29
|
|
3
|
+
# @Author : suhong
|
|
4
|
+
# @File : db3_2_sizedb3.py
|
|
5
|
+
# @Software: PyCharm
|
|
6
|
+
"""
|
|
7
|
+
获取输入db3文件夹路径,获取db3表名、列名,创建一个db3
|
|
8
|
+
往新的db3写入select信息直到指定大小,切换
|
|
9
|
+
"""
|
|
10
|
+
import sqlite3
|
|
11
|
+
import sys
|
|
12
|
+
|
|
13
|
+
from re_common.baselibrary.utils.basedir import BaseDir
|
|
14
|
+
from re_common.baselibrary.utils.basefile import BaseFile
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class UniformSizeDb3(object):
|
|
18
|
+
def __init__(self):
|
|
19
|
+
self.table_name = None
|
|
20
|
+
self.column_name = list()
|
|
21
|
+
self.info_list = list()
|
|
22
|
+
self.all_num = 0
|
|
23
|
+
|
|
24
|
+
def work(self, file_path=None, out_path=None,size=200 * 1024 * 1024):
|
|
25
|
+
if file_path is None and out_path is None:
|
|
26
|
+
print("path error")
|
|
27
|
+
sys.exit(-1)
|
|
28
|
+
for path in BaseDir.get_dir_all_files(file_path):
|
|
29
|
+
count = 1
|
|
30
|
+
print(path)
|
|
31
|
+
# print(BaseFile.get_file_size(path)/1024/1024)
|
|
32
|
+
conn = sqlite3.connect(path)
|
|
33
|
+
cur = conn.cursor()
|
|
34
|
+
# 获取表名和字段名称
|
|
35
|
+
cur.execute("SELECT name FROM sqlite_master where type='table'")
|
|
36
|
+
row1 = cur.fetchone()
|
|
37
|
+
self.table_name = row1[0]
|
|
38
|
+
cur.execute("PRAGMA table_info([{}])".format(self.table_name))
|
|
39
|
+
row2 = cur.fetchall()
|
|
40
|
+
for row in row2:
|
|
41
|
+
self.column_name.append(row[1])
|
|
42
|
+
column_name = tuple(self.column_name)
|
|
43
|
+
self.column_name.clear()
|
|
44
|
+
|
|
45
|
+
# 获取原始db3的创建table语句
|
|
46
|
+
cur.execute("SELECT sql FROM sqlite_master WHERE type='table' AND name = '{}'".format(self.table_name))
|
|
47
|
+
create_table_sql = cur.fetchone()[0]
|
|
48
|
+
insert_sql = "insert into {} {} values ({})".format(self.table_name, column_name, "?," * len(column_name))
|
|
49
|
+
insert_sql = insert_sql.replace("'", "").replace("?,)", "?)")
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
out_file = "{}/{}_{}.db3".format(out_path, BaseFile.get_filename_not_extsep(path), count)
|
|
54
|
+
conn_2 = sqlite3.connect(out_file)
|
|
55
|
+
cur_2 = conn_2.cursor()
|
|
56
|
+
cur_2.execute("SELECT name FROM sqlite_master where type='table'")
|
|
57
|
+
name_row = cur_2.fetchone()
|
|
58
|
+
if name_row is None:
|
|
59
|
+
cur_2.execute(create_table_sql)
|
|
60
|
+
conn_2.commit()
|
|
61
|
+
|
|
62
|
+
# 查询原表信息 并插入新表
|
|
63
|
+
cur.execute("select * from {}".format(self.table_name))
|
|
64
|
+
while True:
|
|
65
|
+
rows = cur.fetchone()
|
|
66
|
+
if rows:
|
|
67
|
+
self.info_list.append(rows)
|
|
68
|
+
|
|
69
|
+
if BaseFile.get_file_size(out_file) >= size:
|
|
70
|
+
count +=1
|
|
71
|
+
out_file = "{}/{}_{}.db3".format(out_path, BaseFile.get_filename_not_extsep(path), count)
|
|
72
|
+
conn_2 = sqlite3.connect(out_file)
|
|
73
|
+
cur_2 = conn_2.cursor()
|
|
74
|
+
cur_2.execute("SELECT name FROM sqlite_master where type='table'")
|
|
75
|
+
name_row = cur_2.fetchone()
|
|
76
|
+
if name_row is None:
|
|
77
|
+
cur_2.execute(create_table_sql)
|
|
78
|
+
conn_2.commit()
|
|
79
|
+
print("outfilepath:{}".format(out_file))
|
|
80
|
+
|
|
81
|
+
if len(self.info_list) >= 10000:
|
|
82
|
+
self.all_num += len(self.info_list)
|
|
83
|
+
cur_2.executemany(insert_sql, self.info_list)
|
|
84
|
+
conn_2.commit()
|
|
85
|
+
print("do all sql:{}".format(self.all_num))
|
|
86
|
+
self.info_list.clear()
|
|
87
|
+
else:
|
|
88
|
+
break
|
|
89
|
+
self.all_num += len(self.info_list)
|
|
90
|
+
cur_2.executemany(insert_sql, self.info_list)
|
|
91
|
+
conn_2.commit()
|
|
92
|
+
cur_2.close()
|
|
93
|
+
print("do all sql:{}".format(self.all_num))
|
|
94
|
+
self.info_list.clear()
|
|
95
|
+
self.all_num = 0
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
if __name__ == '__main__':
|
|
99
|
+
file_path = r'E:\更新数据\adb3'
|
|
100
|
+
out_path = r'E:\更新数据\test_db3'
|
|
101
|
+
u = UniformSizeDb3()
|
|
102
|
+
u.work(file_path, out_path)
|
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
import gzip
|
|
2
|
-
import json
|
|
3
|
-
|
|
4
|
-
from re_common.baselibrary.utils.basedir import BaseDir
|
|
5
|
-
from re_common.baselibrary.utils.basefile import BaseFile
|
|
6
|
-
|
|
7
|
-
ref_outPathFile = r"F:\fun3\ref\cnkiref.big_json.gz"
|
|
8
|
-
f_ref = gzip.open(ref_outPathFile, "wb")
|
|
9
|
-
if BaseFile.get_file_size(ref_outPathFile) >= 100 * 1024 * 1024:
|
|
10
|
-
f_ref.close()
|
|
11
|
-
ref_outPathFile = BaseFile.change_file(ref_outPathFile, size=100 * 1024 * 1024)
|
|
12
|
-
ref_outPathFile = ref_outPathFile.replace(".big_json", '.big_json.gz')
|
|
13
|
-
f_ref = gzip.open(ref_outPathFile, "wb")
|
|
14
|
-
print("new dst_path: %s" % ref_outPathFile)
|
|
15
|
-
for file in BaseDir.get_dir_all_files(r"F:\fun2\ref"):
|
|
16
|
-
print(file)
|
|
17
|
-
with gzip.open(file, 'r') as f:
|
|
18
|
-
for lineb in f:
|
|
19
|
-
line = lineb.decode()
|
|
20
|
-
linedicts = json.loads(line)
|
|
21
|
-
print(linedicts)
|
|
22
|
-
if "stat" in linedicts:
|
|
23
|
-
for key in linedicts:
|
|
24
|
-
if key == "stat":
|
|
25
|
-
continue
|
|
26
|
-
else:
|
|
27
|
-
print(key)
|
|
28
|
-
tempdicts = linedicts[key]
|
|
29
|
-
print(tempdicts)
|
|
30
|
-
line_ref = json.dumps(tempdicts, ensure_ascii=False) + "\n"
|
|
31
|
-
line_refs = line_ref.encode()
|
|
32
|
-
f_ref.write(line_refs)
|
|
33
|
-
else:
|
|
34
|
-
f_ref.write(lineb)
|
|
35
|
-
if BaseFile.get_file_size(ref_outPathFile) >= 100 * 1024 * 1024:
|
|
36
|
-
f_ref.close()
|
|
37
|
-
ref_outPathFile = BaseFile.change_file(ref_outPathFile, size=100 * 1024 * 1024)
|
|
38
|
-
ref_outPathFile = ref_outPathFile.replace(".big_json", '.big_json.gz')
|
|
39
|
-
f_ref = gzip.open(ref_outPathFile, "wb")
|
|
1
|
+
import gzip
|
|
2
|
+
import json
|
|
3
|
+
|
|
4
|
+
from re_common.baselibrary.utils.basedir import BaseDir
|
|
5
|
+
from re_common.baselibrary.utils.basefile import BaseFile
|
|
6
|
+
|
|
7
|
+
ref_outPathFile = r"F:\fun3\ref\cnkiref.big_json.gz"
|
|
8
|
+
f_ref = gzip.open(ref_outPathFile, "wb")
|
|
9
|
+
if BaseFile.get_file_size(ref_outPathFile) >= 100 * 1024 * 1024:
|
|
10
|
+
f_ref.close()
|
|
11
|
+
ref_outPathFile = BaseFile.change_file(ref_outPathFile, size=100 * 1024 * 1024)
|
|
12
|
+
ref_outPathFile = ref_outPathFile.replace(".big_json", '.big_json.gz')
|
|
13
|
+
f_ref = gzip.open(ref_outPathFile, "wb")
|
|
14
|
+
print("new dst_path: %s" % ref_outPathFile)
|
|
15
|
+
for file in BaseDir.get_dir_all_files(r"F:\fun2\ref"):
|
|
16
|
+
print(file)
|
|
17
|
+
with gzip.open(file, 'r') as f:
|
|
18
|
+
for lineb in f:
|
|
19
|
+
line = lineb.decode()
|
|
20
|
+
linedicts = json.loads(line)
|
|
21
|
+
print(linedicts)
|
|
22
|
+
if "stat" in linedicts:
|
|
23
|
+
for key in linedicts:
|
|
24
|
+
if key == "stat":
|
|
25
|
+
continue
|
|
26
|
+
else:
|
|
27
|
+
print(key)
|
|
28
|
+
tempdicts = linedicts[key]
|
|
29
|
+
print(tempdicts)
|
|
30
|
+
line_ref = json.dumps(tempdicts, ensure_ascii=False) + "\n"
|
|
31
|
+
line_refs = line_ref.encode()
|
|
32
|
+
f_ref.write(line_refs)
|
|
33
|
+
else:
|
|
34
|
+
f_ref.write(lineb)
|
|
35
|
+
if BaseFile.get_file_size(ref_outPathFile) >= 100 * 1024 * 1024:
|
|
36
|
+
f_ref.close()
|
|
37
|
+
ref_outPathFile = BaseFile.change_file(ref_outPathFile, size=100 * 1024 * 1024)
|
|
38
|
+
ref_outPathFile = ref_outPathFile.replace(".big_json", '.big_json.gz')
|
|
39
|
+
f_ref = gzip.open(ref_outPathFile, "wb")
|
|
40
40
|
print("new dst_path: %s" % ref_outPathFile)
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
def get_attrs(settings):
|
|
2
|
-
"""
|
|
3
|
-
获取模块参数转换为字典
|
|
4
|
-
:param settings:
|
|
5
|
-
:return:
|
|
6
|
-
"""
|
|
7
|
-
attr = {}
|
|
8
|
-
for i in (dir(settings)):
|
|
9
|
-
if i.isupper():
|
|
10
|
-
attr[i] = getattr(settings,i)
|
|
1
|
+
def get_attrs(settings):
|
|
2
|
+
"""
|
|
3
|
+
获取模块参数转换为字典
|
|
4
|
+
:param settings:
|
|
5
|
+
:return:
|
|
6
|
+
"""
|
|
7
|
+
attr = {}
|
|
8
|
+
for i in (dir(settings)):
|
|
9
|
+
if i.isupper():
|
|
10
|
+
attr[i] = getattr(settings,i)
|
|
11
11
|
return attr
|
|
@@ -1,62 +1,62 @@
|
|
|
1
|
-
# coding = UTF-8
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
# 导入Python标准库
|
|
5
|
-
import os
|
|
6
|
-
from io import BytesIO
|
|
7
|
-
|
|
8
|
-
# 导入第三方库
|
|
9
|
-
from PIL import Image
|
|
10
|
-
|
|
11
|
-
# 防止中文乱码
|
|
12
|
-
os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.UTF8'
|
|
13
|
-
|
|
14
|
-
# 支持的图片文件格式
|
|
15
|
-
SUPPORT_SUFFIX = ["jpg", "jpeg", "png"]
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
def pic_to_pdf(image_bytes: bytes) -> bytes:
|
|
19
|
-
"""将单个图片转换为单张PDF
|
|
20
|
-
|
|
21
|
-
:param image_bytes: 图片的bytes对象
|
|
22
|
-
:return: PDF的bytes对象
|
|
23
|
-
"""
|
|
24
|
-
# 将bytes对象转换为BytesIO对象
|
|
25
|
-
image_bytes_io = BytesIO(image_bytes)
|
|
26
|
-
# 从内存中读取图片
|
|
27
|
-
image_object = Image.open(image_bytes_io)
|
|
28
|
-
# 打开内存中的文件用于保存PDF
|
|
29
|
-
with BytesIO() as result_bytes_io:
|
|
30
|
-
# 将图片保存为单张PDF
|
|
31
|
-
image_object.save(result_bytes_io, "PDF", resolution=100.0)
|
|
32
|
-
# 获取内存中的文件
|
|
33
|
-
data = result_bytes_io.getvalue()
|
|
34
|
-
# 返回PDF的bytes对象
|
|
35
|
-
return data
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
def batch_convert(image_path: str, pdf_path: str) -> None:
|
|
39
|
-
"""批量将图片转换为单张PDF
|
|
40
|
-
|
|
41
|
-
:param image_path: 图片的文件夹
|
|
42
|
-
:param pdf_path: PDF文件保存的文件夹
|
|
43
|
-
"""
|
|
44
|
-
# 遍历文件夹下所有文件
|
|
45
|
-
for root, dirs, files in os.walk(image_path, topdown=False):
|
|
46
|
-
for name in files:
|
|
47
|
-
# 提取文件的后缀名
|
|
48
|
-
file_suffix = os.path.splitext(name)[-1].lstrip(".").lower()
|
|
49
|
-
# 检测该文件格式是否受到支持
|
|
50
|
-
if file_suffix not in SUPPORT_SUFFIX:
|
|
51
|
-
continue
|
|
52
|
-
# 拼接出图片文件的绝对路径
|
|
53
|
-
source_file_path = os.path.join(root, name)
|
|
54
|
-
# 拼接出PDF文件的绝对路径
|
|
55
|
-
target_file_path = os.path.join(pdf_path, f"{os.path.splitext(name)[0]}.pdf")
|
|
56
|
-
# 将图片文件转换为PDF文件
|
|
57
|
-
with open(source_file_path, "rb") as source:
|
|
58
|
-
with open(target_file_path, "wb") as target:
|
|
59
|
-
target.write(pic_to_pdf(source.read()))
|
|
60
|
-
|
|
61
|
-
|
|
1
|
+
# coding = UTF-8
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
# 导入Python标准库
|
|
5
|
+
import os
|
|
6
|
+
from io import BytesIO
|
|
7
|
+
|
|
8
|
+
# 导入第三方库
|
|
9
|
+
from PIL import Image
|
|
10
|
+
|
|
11
|
+
# 防止中文乱码
|
|
12
|
+
os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.UTF8'
|
|
13
|
+
|
|
14
|
+
# 支持的图片文件格式
|
|
15
|
+
SUPPORT_SUFFIX = ["jpg", "jpeg", "png"]
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def pic_to_pdf(image_bytes: bytes) -> bytes:
|
|
19
|
+
"""将单个图片转换为单张PDF
|
|
20
|
+
|
|
21
|
+
:param image_bytes: 图片的bytes对象
|
|
22
|
+
:return: PDF的bytes对象
|
|
23
|
+
"""
|
|
24
|
+
# 将bytes对象转换为BytesIO对象
|
|
25
|
+
image_bytes_io = BytesIO(image_bytes)
|
|
26
|
+
# 从内存中读取图片
|
|
27
|
+
image_object = Image.open(image_bytes_io)
|
|
28
|
+
# 打开内存中的文件用于保存PDF
|
|
29
|
+
with BytesIO() as result_bytes_io:
|
|
30
|
+
# 将图片保存为单张PDF
|
|
31
|
+
image_object.save(result_bytes_io, "PDF", resolution=100.0)
|
|
32
|
+
# 获取内存中的文件
|
|
33
|
+
data = result_bytes_io.getvalue()
|
|
34
|
+
# 返回PDF的bytes对象
|
|
35
|
+
return data
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def batch_convert(image_path: str, pdf_path: str) -> None:
|
|
39
|
+
"""批量将图片转换为单张PDF
|
|
40
|
+
|
|
41
|
+
:param image_path: 图片的文件夹
|
|
42
|
+
:param pdf_path: PDF文件保存的文件夹
|
|
43
|
+
"""
|
|
44
|
+
# 遍历文件夹下所有文件
|
|
45
|
+
for root, dirs, files in os.walk(image_path, topdown=False):
|
|
46
|
+
for name in files:
|
|
47
|
+
# 提取文件的后缀名
|
|
48
|
+
file_suffix = os.path.splitext(name)[-1].lstrip(".").lower()
|
|
49
|
+
# 检测该文件格式是否受到支持
|
|
50
|
+
if file_suffix not in SUPPORT_SUFFIX:
|
|
51
|
+
continue
|
|
52
|
+
# 拼接出图片文件的绝对路径
|
|
53
|
+
source_file_path = os.path.join(root, name)
|
|
54
|
+
# 拼接出PDF文件的绝对路径
|
|
55
|
+
target_file_path = os.path.join(pdf_path, f"{os.path.splitext(name)[0]}.pdf")
|
|
56
|
+
# 将图片文件转换为PDF文件
|
|
57
|
+
with open(source_file_path, "rb") as source:
|
|
58
|
+
with open(target_file_path, "wb") as target:
|
|
59
|
+
target.write(pic_to_pdf(source.read()))
|
|
60
|
+
|
|
61
|
+
|
|
62
62
|
batch_convert(r"C:\Users\Administrator\Desktop\上传\zhuanhuan\20230404\新建文件夹 (5)",r"C:\Users\Administrator\Desktop\上传\zhuanhuan\20230404\pdf")
|