re-common 2.0.1__py3-none-any.whl → 10.0.1__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.
Files changed (196) hide show
  1. re_common/baselibrary/__init__.py +4 -0
  2. re_common/baselibrary/baseabs/__init__.py +7 -0
  3. re_common/baselibrary/baseabs/baseabs.py +26 -0
  4. re_common/baselibrary/database/__init__.py +0 -0
  5. re_common/baselibrary/database/mbuilder.py +132 -0
  6. re_common/baselibrary/database/moudle.py +93 -0
  7. re_common/baselibrary/database/msqlite3.py +194 -0
  8. re_common/baselibrary/database/mysql.py +169 -0
  9. re_common/baselibrary/database/sql_factory.py +26 -0
  10. re_common/baselibrary/mthread/MThreadingRun.py +486 -0
  11. re_common/baselibrary/mthread/MThreadingRunEvent.py +349 -0
  12. re_common/baselibrary/mthread/__init__.py +3 -0
  13. re_common/baselibrary/mthread/mythreading.py +695 -0
  14. re_common/baselibrary/pakge_other/__init__.py +0 -0
  15. re_common/baselibrary/pakge_other/socks.py +404 -0
  16. re_common/baselibrary/readconfig/__init__.py +0 -0
  17. re_common/baselibrary/readconfig/config_factory.py +18 -0
  18. re_common/baselibrary/readconfig/ini_config.py +317 -0
  19. re_common/baselibrary/readconfig/toml_config.py +49 -0
  20. re_common/baselibrary/temporary/__init__.py +0 -0
  21. re_common/baselibrary/temporary/envdata.py +36 -0
  22. re_common/baselibrary/tools/__init__.py +0 -0
  23. re_common/baselibrary/tools/all_requests/__init__.py +0 -0
  24. re_common/baselibrary/tools/all_requests/aiohttp_request.py +118 -0
  25. re_common/baselibrary/tools/all_requests/httpx_requet.py +102 -0
  26. re_common/baselibrary/tools/all_requests/mrequest.py +412 -0
  27. re_common/baselibrary/tools/all_requests/requests_request.py +81 -0
  28. re_common/baselibrary/tools/batch_compre/__init__.py +0 -0
  29. re_common/baselibrary/tools/batch_compre/bijiao_batch.py +31 -0
  30. re_common/baselibrary/tools/contrast_db3.py +123 -0
  31. re_common/baselibrary/tools/copy_file.py +39 -0
  32. re_common/baselibrary/tools/db3_2_sizedb3.py +102 -0
  33. re_common/baselibrary/tools/foreachgz.py +40 -0
  34. re_common/baselibrary/tools/get_attr.py +11 -0
  35. re_common/baselibrary/tools/image_to_pdf.py +62 -0
  36. re_common/baselibrary/tools/java_code_deal.py +139 -0
  37. re_common/baselibrary/tools/javacode.py +79 -0
  38. re_common/baselibrary/tools/mdb_db3.py +48 -0
  39. re_common/baselibrary/tools/merge_file.py +171 -0
  40. re_common/baselibrary/tools/merge_gz_file.py +165 -0
  41. re_common/baselibrary/tools/mhdfstools/__init__.py +0 -0
  42. re_common/baselibrary/tools/mhdfstools/down_hdfs_files.py +42 -0
  43. re_common/baselibrary/tools/mhdfstools/hdfst.py +42 -0
  44. re_common/baselibrary/tools/mhdfstools/up_hdfs_files.py +38 -0
  45. re_common/baselibrary/tools/mongo_tools.py +50 -0
  46. re_common/baselibrary/tools/move_file.py +170 -0
  47. re_common/baselibrary/tools/move_mongo/__init__.py +0 -0
  48. re_common/baselibrary/tools/move_mongo/mongo_table_to_file.py +63 -0
  49. re_common/baselibrary/tools/move_mongo/move_mongo_table.py +354 -0
  50. re_common/baselibrary/tools/move_mongo/use_mttf.py +18 -0
  51. re_common/baselibrary/tools/move_mongo/use_mv.py +93 -0
  52. re_common/baselibrary/tools/mpandas/__init__.py +0 -0
  53. re_common/baselibrary/tools/mpandas/mpandasreadexcel.py +125 -0
  54. re_common/baselibrary/tools/mpandas/pandas_visualization.py +8 -0
  55. re_common/baselibrary/tools/myparsel.py +104 -0
  56. re_common/baselibrary/tools/rename_dir_file.py +37 -0
  57. re_common/baselibrary/tools/sequoiadb_utils.py +398 -0
  58. re_common/baselibrary/tools/split_line_to_many.py +25 -0
  59. re_common/baselibrary/tools/stringtodicts.py +33 -0
  60. re_common/baselibrary/tools/workwechant_bot.py +84 -0
  61. re_common/baselibrary/utils/__init__.py +0 -0
  62. re_common/baselibrary/utils/baseaiohttp.py +296 -0
  63. re_common/baselibrary/utils/baseaiomysql.py +87 -0
  64. re_common/baselibrary/utils/baseallstep.py +191 -0
  65. re_common/baselibrary/utils/baseavro.py +19 -0
  66. re_common/baselibrary/utils/baseboto3.py +291 -0
  67. re_common/baselibrary/utils/basecsv.py +32 -0
  68. re_common/baselibrary/utils/basedict.py +133 -0
  69. re_common/baselibrary/utils/basedir.py +241 -0
  70. re_common/baselibrary/utils/baseencode.py +351 -0
  71. re_common/baselibrary/utils/baseencoding.py +29 -0
  72. re_common/baselibrary/utils/baseesdsl.py +86 -0
  73. re_common/baselibrary/utils/baseexcel.py +264 -0
  74. re_common/baselibrary/utils/baseexcept.py +109 -0
  75. re_common/baselibrary/utils/basefile.py +654 -0
  76. re_common/baselibrary/utils/baseftp.py +214 -0
  77. re_common/baselibrary/utils/basegzip.py +60 -0
  78. re_common/baselibrary/utils/basehdfs.py +135 -0
  79. re_common/baselibrary/utils/basehttpx.py +268 -0
  80. re_common/baselibrary/utils/baseip.py +87 -0
  81. re_common/baselibrary/utils/basejson.py +2 -0
  82. re_common/baselibrary/utils/baselist.py +32 -0
  83. re_common/baselibrary/utils/basemotor.py +190 -0
  84. re_common/baselibrary/utils/basemssql.py +98 -0
  85. re_common/baselibrary/utils/baseodbc.py +113 -0
  86. re_common/baselibrary/utils/basepandas.py +302 -0
  87. re_common/baselibrary/utils/basepeewee.py +11 -0
  88. re_common/baselibrary/utils/basepika.py +180 -0
  89. re_common/baselibrary/utils/basepydash.py +143 -0
  90. re_common/baselibrary/utils/basepymongo.py +230 -0
  91. re_common/baselibrary/utils/basequeue.py +22 -0
  92. re_common/baselibrary/utils/baserar.py +57 -0
  93. re_common/baselibrary/utils/baserequest.py +279 -0
  94. re_common/baselibrary/utils/baseset.py +8 -0
  95. re_common/baselibrary/utils/basesmb.py +403 -0
  96. re_common/baselibrary/utils/basestring.py +382 -0
  97. re_common/baselibrary/utils/basetime.py +320 -0
  98. re_common/baselibrary/utils/basetuple.py +0 -0
  99. re_common/baselibrary/utils/baseurl.py +121 -0
  100. re_common/baselibrary/utils/basezip.py +57 -0
  101. re_common/baselibrary/utils/core/__init__.py +8 -0
  102. re_common/baselibrary/utils/core/bottomutils.py +18 -0
  103. re_common/baselibrary/utils/core/mdeprecated.py +327 -0
  104. re_common/baselibrary/utils/core/mlamada.py +16 -0
  105. re_common/baselibrary/utils/core/msginfo.py +25 -0
  106. re_common/baselibrary/utils/core/requests_core.py +103 -0
  107. re_common/baselibrary/utils/fateadm.py +429 -0
  108. re_common/baselibrary/utils/importfun.py +123 -0
  109. re_common/baselibrary/utils/mfaker.py +57 -0
  110. re_common/baselibrary/utils/my_abc/__init__.py +3 -0
  111. re_common/baselibrary/utils/my_abc/better_abc.py +32 -0
  112. re_common/baselibrary/utils/mylogger.py +414 -0
  113. re_common/baselibrary/utils/myredisclient.py +861 -0
  114. re_common/baselibrary/utils/pipupgrade.py +21 -0
  115. re_common/baselibrary/utils/ringlist.py +85 -0
  116. re_common/baselibrary/utils/version_compare.py +36 -0
  117. re_common/baselibrary/utils/ydmhttp.py +126 -0
  118. re_common/facade/__init__.py +1 -0
  119. re_common/facade/lazy_import.py +11 -0
  120. re_common/facade/loggerfacade.py +25 -0
  121. re_common/facade/mysqlfacade.py +467 -0
  122. re_common/facade/now.py +31 -0
  123. re_common/facade/sqlite3facade.py +257 -0
  124. re_common/facade/use/__init__.py +0 -0
  125. re_common/facade/use/mq_use_facade.py +83 -0
  126. re_common/facade/use/proxy_use_facade.py +20 -0
  127. re_common/libtest/__init__.py +0 -0
  128. re_common/libtest/base_dict_test.py +19 -0
  129. re_common/libtest/baseavro_test.py +13 -0
  130. re_common/libtest/basefile_test.py +14 -0
  131. re_common/libtest/basemssql_test.py +77 -0
  132. re_common/libtest/baseodbc_test.py +8 -0
  133. re_common/libtest/basepandas_test.py +38 -0
  134. re_common/libtest/get_attr_test/__init__.py +0 -0
  135. re_common/libtest/get_attr_test/get_attr_test_settings.py +14 -0
  136. re_common/libtest/get_attr_test/settings.py +55 -0
  137. re_common/libtest/idencode_test.py +54 -0
  138. re_common/libtest/iniconfig_test.py +35 -0
  139. re_common/libtest/ip_test.py +35 -0
  140. re_common/libtest/merge_file_test.py +20 -0
  141. re_common/libtest/mfaker_test.py +9 -0
  142. re_common/libtest/mm3_test.py +32 -0
  143. re_common/libtest/mylogger_test.py +89 -0
  144. re_common/libtest/myparsel_test.py +28 -0
  145. re_common/libtest/mysql_test.py +151 -0
  146. re_common/libtest/pymongo_test.py +21 -0
  147. re_common/libtest/split_test.py +12 -0
  148. re_common/libtest/sqlite3_merge_test.py +6 -0
  149. re_common/libtest/sqlite3_test.py +34 -0
  150. re_common/libtest/tomlconfig_test.py +30 -0
  151. re_common/libtest/use_tools_test/__init__.py +3 -0
  152. re_common/libtest/user/__init__.py +5 -0
  153. re_common/studio/__init__.py +5 -0
  154. re_common/studio/assignment_expressions.py +37 -0
  155. re_common/studio/mydash/__init__.py +0 -0
  156. re_common/studio/mydash/test1.py +19 -0
  157. re_common/studio/pydashstudio/__init__.py +0 -0
  158. re_common/studio/pydashstudio/first.py +9 -0
  159. re_common/studio/streamlitstudio/__init__.py +0 -0
  160. re_common/studio/streamlitstudio/first_app.py +66 -0
  161. re_common/studio/streamlitstudio/uber_pickups.py +24 -0
  162. re_common/studio/test.py +19 -0
  163. re_common/v2/baselibrary/utils/author_smi.py +14 -3
  164. re_common/v2/baselibrary/utils/stringutils.py +1 -0
  165. re_common/vip/__init__.py +0 -0
  166. re_common/vip/base_step_process.py +11 -0
  167. re_common/vip/baseencodeid.py +91 -0
  168. re_common/vip/changetaskname.py +28 -0
  169. re_common/vip/core_var.py +24 -0
  170. re_common/vip/mmh3Hash.py +90 -0
  171. re_common/vip/proxy/__init__.py +0 -0
  172. re_common/vip/proxy/allproxys.py +127 -0
  173. re_common/vip/proxy/allproxys_thread.py +159 -0
  174. re_common/vip/proxy/cnki_proxy.py +153 -0
  175. re_common/vip/proxy/kuaidaili.py +87 -0
  176. re_common/vip/proxy/proxy_all.py +113 -0
  177. re_common/vip/proxy/update_kuaidaili_0.py +42 -0
  178. re_common/vip/proxy/wanfang_proxy.py +152 -0
  179. re_common/vip/proxy/wp_proxy_all.py +182 -0
  180. re_common/vip/read_rawid_to_txt.py +92 -0
  181. re_common/vip/title/__init__.py +5 -0
  182. re_common/vip/title/transform/TransformBookTitleToZt.py +125 -0
  183. re_common/vip/title/transform/TransformConferenceTitleToZt.py +139 -0
  184. re_common/vip/title/transform/TransformCstadTitleToZt.py +196 -0
  185. re_common/vip/title/transform/TransformJournalTitleToZt.py +203 -0
  186. re_common/vip/title/transform/TransformPatentTitleToZt.py +132 -0
  187. re_common/vip/title/transform/TransformRegulationTitleToZt.py +114 -0
  188. re_common/vip/title/transform/TransformStandardTitleToZt.py +135 -0
  189. re_common/vip/title/transform/TransformThesisTitleToZt.py +135 -0
  190. re_common/vip/title/transform/__init__.py +11 -0
  191. {re_common-2.0.1.dist-info → re_common-10.0.1.dist-info}/METADATA +1 -1
  192. re_common-10.0.1.dist-info/RECORD +213 -0
  193. re_common-2.0.1.dist-info/RECORD +0 -25
  194. {re_common-2.0.1.dist-info → re_common-10.0.1.dist-info}/LICENSE +0 -0
  195. {re_common-2.0.1.dist-info → re_common-10.0.1.dist-info}/WHEEL +0 -0
  196. {re_common-2.0.1.dist-info → re_common-10.0.1.dist-info}/top_level.txt +0 -0
@@ -0,0 +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)
@@ -0,0 +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")
40
+ print("new dst_path: %s" % ref_outPathFile)
@@ -0,0 +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)
11
+ return attr
@@ -0,0 +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
+
62
+ batch_convert(r"C:\Users\Administrator\Desktop\上传\zhuanhuan\20230404\新建文件夹 (5)",r"C:\Users\Administrator\Desktop\上传\zhuanhuan\20230404\pdf")
@@ -0,0 +1,139 @@
1
+ from re_common.baselibrary.utils.baselist import BaseList
2
+
3
+
4
+ class JavaCodeDeal(object):
5
+
6
+ def __init__(self):
7
+ self.strings = """
8
+ """
9
+ self.lists = []
10
+ self.baselist = BaseList()
11
+ self.keylist = []
12
+
13
+ def set_strings(self, strings):
14
+ """
15
+ 设置源数据
16
+ :param strings:
17
+ :return:
18
+ """
19
+ self.strings = strings
20
+
21
+ def strings_split(self, split="\n"):
22
+ """
23
+ 根据条件切割为单独的数据
24
+ :param split:
25
+ :return:
26
+ """
27
+ self.lists = self.strings.split(split)
28
+
29
+ def list_deal(self):
30
+ """
31
+ 去除空字符串,空数据,以及字符串前后空格
32
+ :return:
33
+ """
34
+ self.lists = self.baselist.remove_null(self.lists)
35
+ self.lists = self.baselist.remove_blank_space(self.lists)
36
+ self.lists = self.baselist.clean_space_first_end(self.lists)
37
+
38
+ def get_key(self):
39
+ """
40
+ 获取等号前的变量
41
+ :return:
42
+ """
43
+ for item in self.lists:
44
+ key = item.split("=")[0].replace("String", "").strip()
45
+ self.keylist.append(key)
46
+
47
+ def set_outmap(self):
48
+ """
49
+ 生成outMap的put代码
50
+ :return:
51
+ """
52
+ for item in self.lists:
53
+ key = item.split("=")[0].replace("String", "").strip()
54
+ print('outMap.put("{}", {});'.format(key, key))
55
+
56
+ def set_sql_deal(self):
57
+ """
58
+ 生成mysql处理代码
59
+ :return:
60
+ """
61
+ for item in self.lists:
62
+ key = item.split("=")[0].replace("String", "").strip()
63
+ print("{} = {}.replace('\\0', ' ').replace(\"'\", \"''\").trim();".format(key, key))
64
+
65
+ def create_sql(self):
66
+ strinsgs = "String sql = \"INSERT INTO modify_title_info_zt("
67
+ for key in self.keylist:
68
+ strinsgs += "[{}],".format(key)
69
+ strinsgs = strinsgs[:-1]
70
+ strinsgs += ")\";"
71
+ print(strinsgs)
72
+
73
+ def create_s(self):
74
+ Strings = "sql += \" VALUES ("
75
+ for key in self.keylist:
76
+ Strings += "'%s', "
77
+ Strings = Strings[:-2]
78
+ Strings += ")\";"
79
+ print(Strings)
80
+
81
+ def create_value(self):
82
+ Strings = "sql = String.format(sql,"
83
+ for key in self.keylist:
84
+ Strings += key + ","
85
+ Strings = Strings[:-1]
86
+ Strings += ");"
87
+ print(Strings)
88
+
89
+ def create_java_sql(self):
90
+ self.create_sql()
91
+ self.create_s()
92
+ self.create_value()
93
+
94
+
95
+ if __name__ == "__main__":
96
+ strings = """
97
+ String rawid = outMap.getOrDefault("rawid", "");
98
+ String lngid = outMap.getOrDefault("lngid", "");
99
+ gch = gch;
100
+ String title = outMap.getOrDefault("rawid", "");
101
+ String title_alternative = outMap.getOrDefault("title_alt", "");
102
+ String identifier_issn = outMap.getOrDefault("issn", "");
103
+ String identifier_cnno = outMap.getOrDefault("cnno", "");
104
+ String creator = outMap.getOrDefault("author", "");
105
+ String creator_en = outMap.getOrDefault("author_raw", "");
106
+ String creator_institution = outMap.getOrDefault("organ", "");
107
+ String source = outMap.getOrDefault("journal_name", "");
108
+ String source_en = outMap.getOrDefault("journal_name_alt", "");
109
+ String date = StringHelper.getYear(pub_year);
110
+ String volume = outMap.getOrDefault("vol", "");
111
+ String issue = outMap.getOrDefault("num", "");
112
+ String description = outMap.getOrDefault("abstract", "");
113
+ String description_en = outMap.getOrDefault("abstract_alt", "");
114
+ String description_fund = outMap.getOrDefault("fund", "");
115
+ String description_core = "";
116
+ String subject = outMap.getOrDefault("keyword", "");
117
+ String subject_en = outMap.getOrDefault("keyword_alt", "");
118
+ String begin_page = outMap.getOrDefault("begin_page", "");
119
+ String end_page = outMap.getOrDefault("end_page", "");
120
+ String page = format_page(begin_page, end_page);
121
+ String subject_clc = clc_no.replace(" ", ";").replace(",", ";");//分类号,将空格,逗号替换为分号
122
+ String date_created = format_data_create(publishdate, pub_year);//日期,不是4位的解析出四位数字,如果是空和1900开头,改成data+0000
123
+ String identifier_doi = outMap.getOrDefault("doi", "");
124
+ String country = "CN";
125
+ String language = "ZH";
126
+ String provider = "cnkijournal";
127
+ String owner = "cqu";
128
+ String type = "3";
129
+ String medium = "2";
130
+ batch = batch;
131
+ String provider_url = "cnkijournal@http://kns.cnki.net/KCMS/detail/detail.aspx?dbcode=CJFD&filename=" + rawid;
132
+ String provider_id = "cnkijournal@" + rawid;
133
+ """
134
+ j = JavaCodeDeal()
135
+ j.set_strings(strings)
136
+ j.strings_split()
137
+ j.list_deal()
138
+ j.get_key()
139
+ j.create_java_sql()
@@ -0,0 +1,79 @@
1
+ """
2
+ 不想写循环代码 生成循环代码
3
+ """
4
+ from re_common.baselibrary.utils.basedir import BaseDir
5
+ from re_common.baselibrary.utils.basefile import BaseFile
6
+
7
+
8
+ class CreateCode():
9
+
10
+ def __init__(self):
11
+ self.inputobj1 = set()
12
+
13
+ def read_file(self, filepath):
14
+ for file in BaseDir.get_dir_all_files(filepath):
15
+ for line in BaseFile.read_file_r_mode_yield(file):
16
+ if line.find("String") > -1:
17
+ var = line.split("=")[0].replace("String", "").strip()
18
+ self.inputobj1.add(var)
19
+ yield file
20
+
21
+ def create_code(self, file):
22
+ with open(file, mode="w", encoding="utf-8") as f:
23
+ for var in self.inputobj1:
24
+ f.write("if (updateItem.getKey().equals(\"%s\")) {\n" % var)
25
+ f.write(" {} = updateItem.getValue().trim();\n".format(var))
26
+ f.write("}\n")
27
+
28
+ def create_put(self, file):
29
+ with open(file, mode="w", encoding="utf-8") as f:
30
+ for var in self.inputobj1:
31
+ f.write("xObj_a_table.data.put(\"%s\", %s);\n" % (var,var))
32
+
33
+ def create_replace(self, file):
34
+ with open(file, mode="w", encoding="utf-8") as f:
35
+ for var in self.inputobj1:
36
+ f.write("%s = %s.replace('\\0', ' ').replace(\"'\", \"''\").trim();\n" % (var, var))
37
+
38
+ def set_to_list(self):
39
+ self.inputs1 = list(self.inputobj1)
40
+
41
+ def create_sql(self,file):
42
+ with open(file, mode="w", encoding="utf-8") as f:
43
+ strinsgs = "String sql = \"INSERT INTO modify_title_info_zt("
44
+ for key in self.inputs1:
45
+ strinsgs += "[{}],".format(key)
46
+ strinsgs = strinsgs[:-1]
47
+ strinsgs += ")\";"
48
+ f.write(strinsgs)
49
+
50
+ def create_s(self):
51
+ Strings = "sql += \" VALUES ("
52
+ for key in self.inputs1:
53
+ Strings += "'%s', "
54
+ Strings = Strings[:-2]
55
+ Strings += ")\";"
56
+ print(Strings)
57
+
58
+ def create_value(self):
59
+ Strings = "sql = String.format(sql,"
60
+ for key in self.inputs1:
61
+ Strings += key+","
62
+ Strings = Strings[:-1]
63
+ Strings += ");"
64
+ print(Strings)
65
+
66
+
67
+ if __name__ == "__main__":
68
+ createcode = CreateCode()
69
+ for file in createcode.read_file(r"./inputs"):
70
+ createcode.set_to_list()
71
+ # createcode.create_replace(file.replace("input", "output"))
72
+ # createcode.create_code(file.replace("input", "output"))
73
+ createcode.create_put(file.replace("input", "output"))
74
+ # createcode.set_to_list()
75
+ # createcode.create_sql(file.replace("input", "output"))
76
+ # createcode.create_s()
77
+ # createcode.create_value()
78
+
79
+
@@ -0,0 +1,48 @@
1
+ import pypyodbc
2
+
3
+ from re_common.baselibrary.utils.baseodbc import BaseODBC
4
+ from re_common.facade.sqlite3facade import Sqlite3Utiles
5
+
6
+
7
+ class MdbDb3(object):
8
+ """
9
+ mdb和db3的相互转换
10
+ """
11
+
12
+ def __init__(self):
13
+ self.MdbFile = ''
14
+ self.db3file = ''
15
+ self.baseodbc = None
16
+ self.sqliteutils = None
17
+
18
+ def set_mdb(self, MdbFile):
19
+ self.MdbFile = MdbFile
20
+ self.baseodbc = BaseODBC(self.MdbFile)
21
+ return self
22
+
23
+ def set_db3(self, db3_file):
24
+ self.db3file = db3_file
25
+ self.sqliteutils = Sqlite3Utiles().Sqlite3DBConnectFromFilePath(self.db3file)
26
+ return self
27
+
28
+ def get_db3_table_name(self):
29
+ """
30
+ 获取db3的table表明
31
+ :return:
32
+ """
33
+ lists_tablename = []
34
+ for tables in self.sqliteutils.sqllite3.get_table_name():
35
+ table = tables[0]
36
+ lists_tablename.append(table)
37
+ return lists_tablename
38
+
39
+ def get_db3_fields(self, tablename):
40
+ self.sqliteutils.sqllite3.set_result_dict()
41
+ result = self.sqliteutils.sqllite3.get_all_field_info(tablename)
42
+ print(result)
43
+
44
+
45
+ if __name__ == "__main__":
46
+ md3 = MdbDb3().set_db3(r'C:\Users\xuzhu\Desktop\cnkijournallist_1628228383.4636774.db3')
47
+ for tablename in md3.get_db3_table_name():
48
+ md3.get_db3_fields(tablename)
@@ -0,0 +1,171 @@
1
+ """
2
+ 多文件合并到一个文件
3
+ 方法一:按行读取写入
4
+ 方法二: 按块读取写入
5
+
6
+ """
7
+
8
+ ###########################################
9
+ # 同项目调用基础包
10
+ import os
11
+ import sys
12
+
13
+ filepath = os.path.abspath(__file__)
14
+ pathlist = filepath.split(os.sep)
15
+ pathlist = pathlist[:-4]
16
+ TopPath = os.sep.join(pathlist)
17
+ sys.path.insert(0, TopPath)
18
+ ############################################
19
+
20
+ import time
21
+
22
+ from re_common.baselibrary.utils.basedir import BaseDir
23
+ from re_common.baselibrary.utils.basefile import BaseFile
24
+
25
+
26
+ class MergeFile(object):
27
+ def __init__(self):
28
+ """
29
+ :param src: 输入文件夹路径
30
+ :param dst: 输出文件夹路径
31
+ """
32
+ self.outPathFile = None
33
+ self.a_num = 1000
34
+ self.b_num = 20000
35
+
36
+ self.a_size = 1024 * 1024 * 1024
37
+ self.block_size = 2 * 1024 * 1024 * 1024
38
+
39
+ def get_outpathfile(self, dst):
40
+ BaseDir.create_dir(dst)
41
+ now_time = time.strftime('%Y%m%d', time.localtime())
42
+ self.filename = "{}.big_json".format(now_time)
43
+ self.outPathFile = BaseFile.get_new_path(dst, self.filename)
44
+ return self.outPathFile
45
+
46
+ def line_all_2_one(self, src, dst, source_size=None, dst_size=None, a_num=None, b_num=None):
47
+ """
48
+ :param src: 输入路径
49
+ :param dst: 输出路径
50
+ :param source_size: 输入文件大于source_size,就直接复制过去
51
+ :param dst_size: 指定输出文件的最大值
52
+ :param a_num: 打印条数的取值(默认1000条输出一次信息)
53
+ :param b_num: 打印路径的取值(默认20000条输出一次信息)
54
+ :return:
55
+ """
56
+ # 程序开始时间
57
+ StartTime = time.time()
58
+ if a_num is None:
59
+ a_num = self.a_num
60
+ if b_num is None:
61
+ b_num = self.b_num
62
+ count_all = 0
63
+ dst_count = 0
64
+ src_file_num = 0
65
+ src_file_location = 0
66
+ if self.outPathFile is None:
67
+ self.get_outpathfile(dst)
68
+ for files in BaseDir.get_dir_all_files(src):
69
+ src_file_num += 1
70
+ for files in BaseDir.get_dir_all_files(src):
71
+ # 处理每个文件的开始时间
72
+ start_time = time.time()
73
+ src_file_location += 1
74
+ print("next source_path:" + files)
75
+ if source_size is not None:
76
+ if BaseFile.get_file_size(files) >= source_size:
77
+ out_path = BaseFile.get_new_path(dst, BaseFile.get_file_name(files))
78
+ BaseFile.copy_file_to_file(files, out_path)
79
+ print("process_src:%d/%d, Time total:%s, source_path: %s , dst_path:%s" % (
80
+ src_file_location, src_file_num, (repr(time.time() - start_time)), files, out_path))
81
+ continue
82
+ count = 0
83
+ for line in BaseFile.read_file_r_mode_yield(files):
84
+ count += 1
85
+ count_all += 1
86
+ dst_count += 1
87
+ line = line + '\n'
88
+ BaseFile.single_add_file(self.outPathFile, line)
89
+ if count % a_num == 1:
90
+ print("process_src:%d/%d, Time total:%s, source_count: %d, dst_count: %d, allcount: %d" % (
91
+ src_file_location, src_file_num, (repr(time.time() - start_time)), count, dst_count, count_all))
92
+ if count % b_num == 1:
93
+ print("source_path: %s , dst_path:%s" % (files, self.outPathFile))
94
+ if dst_size is not None:
95
+ if BaseFile.get_file_size(self.outPathFile) >= dst_size:
96
+ print("cut dst file, now:source_count: %d,dst_count: %d, allcount: %d" % (
97
+ count, dst_count, count_all))
98
+ dst_count = 0
99
+ self.outPathFile = BaseFile.change_file(self.outPathFile, size=dst_size)
100
+ print("new dst_path: %s" % self.outPathFile)
101
+
102
+ print("finish one file;Time total:%s, process_src:%d/%d, source_count: %d, dst_count: %d, allcount: %d" % (
103
+ repr(time.time() - start_time), src_file_location, src_file_num, count, dst_count, count_all))
104
+ # 程序结束花费时间时间
105
+ print('\nProce Over\nTime total:' + repr(time.time() - StartTime) + '\n')
106
+
107
+ def block_all_2_one(self, src, dst, source_size=None, dst_size=None, block_size=None, a_size=None):
108
+ """
109
+ 按块读取小文件,并写入文件
110
+ :param src: 输入路径
111
+ :param dst: 输出路径
112
+ :param source_size: 输入文件大于source_size,就直接复制过去
113
+ :param dst_size: 指定输出文件的最大值(但是需要操作完一个输入文件后判断大小)
114
+ :param block_size: 按块读取的值
115
+ :param a_size: 打印路径的取值(默认1G大小输出一次信息)
116
+ :return:
117
+ """
118
+ # 程序开始时间
119
+ StartTime = time.time()
120
+ src_file_num = 0
121
+ src_all_size = 0
122
+ src_file_location = 0
123
+ if a_size is None:
124
+ a_size = self.a_size
125
+ if block_size is None:
126
+ block_size = self.block_size
127
+
128
+ if self.outPathFile is None:
129
+ self.get_outpathfile(dst)
130
+ for files in BaseDir.get_dir_all_files(src):
131
+ src_file_num += 1
132
+ for files in BaseDir.get_dir_all_files(src):
133
+ # 处理每个文件的开始时间
134
+ src_all_size += BaseFile.get_file_size(files)
135
+ dst_file_size = 0
136
+ start_time = time.time()
137
+ src_file_location += 1
138
+ print("next source_path:" + files)
139
+ if source_size is not None:
140
+ if BaseFile.get_file_size(files) >= source_size:
141
+ out_path = BaseFile.get_new_path(dst, BaseFile.get_file_name(files))
142
+ BaseFile.copy_file_to_file(files, out_path)
143
+ print("process_src:%d/%d, Time total:%.2f/%.2f, source_path: %s , dst_path:%s" % (
144
+ src_file_location, src_file_num, (time.time() - start_time), (time.time() - StartTime), files,
145
+ out_path))
146
+ continue
147
+ for block in BaseFile.read_file_rb_block(files, BLOCK_SIZE=block_size):
148
+ BaseFile.single_write_ab_file(block, self.outPathFile)
149
+ if BaseFile.get_file_size(self.outPathFile) % a_size == 1:
150
+ print("process_src:%d/%d, dst_size:%d, src_size:%d, src_all_size:%d, Time total:%.2f/%.2f" % (
151
+ src_file_location, src_file_num, dst_file_size, BaseFile.get_file_size(files), src_all_size,
152
+ (time.time() - start_time), (time.time() - StartTime)))
153
+ dst_file_size = BaseFile.get_file_size(self.outPathFile)
154
+ print(
155
+ "finish one file;process_src:%d/%d, dst_size:%d, src_size:%d, src_all_size:%d, Time total:%.2f/%.2f" % (
156
+ src_file_location, src_file_num, dst_file_size, BaseFile.get_file_size(files), src_all_size,
157
+ (time.time() - start_time), (time.time() - StartTime)))
158
+ if dst_size is not None:
159
+ if BaseFile.get_file_size(self.outPathFile) >= dst_size:
160
+ self.outPathFile = BaseFile.change_file(self.outPathFile, size=dst_size)
161
+ print("new dst_path: %s" % self.outPathFile)
162
+ dst_file_size = 0
163
+ # 程序结束花费时间时间
164
+ print('\nProce Over\nTime total:' + repr(time.time() - StartTime) + '\n')
165
+
166
+ # if __name__ == '__main__':
167
+ # old_path = r'E:\work\pnasjournal\big_json\20200116'
168
+ # new_path = r'E:\work\pnasjournal\big_json\new'
169
+ # a = MergeFile()
170
+ # # a.line_all_2_one(old_path,new_path)
171
+ # a.block_all_2_one(old_path,new_path,dst_size=1024*1024*10)