python 3.6 MJ小工具
2017.07.14 update
做了个界面,不需要使用cmd命令行+文件路径的方式来使用了;
链接如下:
http://www.cnblogs.com/chenyuebai/p/7150382.html
- - - - - - - - - - - - - - - - - - - - - - - - - - - - -原博文- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
周末给妹子做的小工具集;大体框架差不多了,支持执行传入参数,从而指定功能;
再写个readme放桌面上,里面描述命令对应功能,把命令行粘贴到cmd命令台,回车执行即可; #原始文件路径写死了(放她PC桌面上)
#common_tools.py路径配到环境变量里
如:1.格式化手机号: python common_tools.py 1
2.XXXXXX功能: python common_tools.py 2
...
目前就一个功能:批量格式化手机号,适配她公司短信群发平台
详细涉及:
(1)文件读取 (2)数据格式化 (3)短信群发平台每次仅支持50人,需要适配 (4)支持默认收件人 (5)异常手机号提示 (6)自动将前50拷贝到剪切板【未实现】
另外后续可能加其他功能,需要支持外部参数传入,指定某功能
#20170613更新:自动将执行结果拷贝至剪切板
代码:
#################################################################
#author: 陈月白
#_blogs: http://www.cnblogs.com/chenyuebai/
################################################################# #coding: utf -8
import sys
import traceback
import pyperclip class COMMON_TOOLS():
def __init__(self):
#原始数据文件
self.data_file = r"C:\Apps\install_zmj\workspace_ch\cfg\data.txt"
#函数表
self.function_map = {
"":"format_msg_receiver"
} #参数转function
def args_trans2function(self,argCode):
if argCode:
try:
function_name = self.function_map[argCode]
#print("INFO:function_name =",function_name)
return function_name
except:
print("ERROR:code:%s no this function,plz connect CHEN...输入函数代码不在此工具的函数列表中,请联系陈"%argCode) #拉起功能函数
def start_execute_function(self,function_name):
if function_2_exe == "format_msg_receiver":
try:
print("now begin to execute:",function_2_exe)
data = open(self.data_file, "r", encoding="UTF-8")
self.format_msg_receiver(data)
except:
traceback.print_exc()
print("ERROR:begin exe format_msg_receiver failed") #格式化短信收件人
def format_msg_receiver(self,receiver_info):
#配置默认收件人
result = "132******96,135******23"
flag = 0
if receiver_info:
try:
for receiver_num in receiver_info.readlines():
#print(receiver_num)
#原始数据格式检查是否为手机号;如果不是11位,且不是空,打出错误信息;空值过滤
if not len(receiver_num.replace("\n","")) == 11:
if not receiver_num.replace("\n","") == "":
print("WARNING:手机号异常--> %s 建议人工修改最后输出结果 或原始文件:data.txt"%(receiver_num.replace("\n","")))
#格式化,空值跳过
if not receiver_num.replace("\n","") == "":
#print("receiver_num =",receiver_num)
result = result + "," + receiver_num.replace("\n","")
flag = flag + 1 print("\nINFO:格式化联系人完成,共格式化联系人 %s 个 提示:最大支持100个"%flag)
if result:
result_list = result.split(",")
#print("result_list =",result_list)
if len(result_list) <= 50:
print("INFO:最终结果如下:\n")
print(result)
#拷贝内容至剪切板
try:
self.copy_2_clipboard(result)
print("\n【结果已自动拷贝至剪切板,直接粘贴即可】\n")
except:
pass
#适配群发短信工具,大于50人处理,支持最大100个联系人
else:
#处理前50个
result_list_50 = result_list[0:50]
result_50_out = ""
flag_50 = 0
#print("result_list_50 =",result_list_50)
for i in result_list_50:
if flag_50 == 0:
result_50_out = result_50_out + i
flag_50 = flag_50 + 1
else:
result_50_out = result_50_out + "," + i
flag_50 = flag_50 + 1
#处理剩余部分
result_list_other = result_list[50:]
flag_other = 0
result_other_out = ""
for i in result_list_other:
if flag_other == 0:
result_other_out = result_other_out + i
flag_other = flag_other + 1
else:
result_other_out = result_other_out + "," + i
flag_other = flag_other + 1
print("INFO:适配群发短信工具,前50个为:\n%s\n"%result_50_out)
#拷贝内容至剪切板
try:
self.copy_2_clipboard(result_50_out)
print("【上述前50个已自动拷贝至剪切板,直接粘贴即可】\n")
except:
pass print("INFO:其他部分为:\n%s\n"%result_other_out)
return 0
except:
traceback.print_exc()
print("ERROR:function format_msg_receiver execute failed!\n 请联系陈") #拷贝str至剪切板
def copy_2_clipboard(self,str_data):
try:
if str_data:
pyperclip.copy(str_data)
#print("INFO:拷贝至剪切板成功")
except:
traceback.print_exc()
#print("ERROR:拷贝至剪切板失败") def main():
global function_2_exe
print("\n--------------------------开始执行--------------------------")
ZMJ = COMMON_TOOLS()
#获取函数
try:
code_input = sys.argv[1]
print("INFO:code_input =",code_input)
function_2_exe = ZMJ.args_trans2function(code_input)
print("INFO:function_2_exe =",function_2_exe)
except:
traceback.print_exc()
print("ERROR:请输出功能参数")
print(r"help info in C:\Apps\install_zmj\workspace_ch\cfg\readme.txt") #执行
if function_2_exe:
ZMJ.start_execute_function(function_2_exe)
else:
print("ERROR:function_2_exe为空,code获取函数名失败") print("--------------------------执行完成--------------------------\n") #入口
main()
执行:
1.原始联系人数据拷贝到指定文件下

2.从readme中拷贝"python common_tools.py 1"至cmd,执行

未完待续。。。
python 3.6 MJ小工具的更多相关文章
- python开发目录合并小工具 PathMerge
前言 这个程序陆陆续续开发了几天,正好我在学Python,就一边做一边学,倒是学到不少东西. 不得不说python是快速开发的好工具. 程序做了一些改进,这两天又忙着毕设,现在才想起来发到博客上.想想 ...
- 目不识丁的我使用Python编写汉字注音小工具
一万点暴击伤害 人懒起来太可怕了,放了个十一充分激发了我的惰性.然后公众号就这么停了半个月,好惭愧- 新学期儿子的幼儿园上线了APP,每天作业通过app布置后,家长需要陪着孩子学习,并上传视频才算完成 ...
- python转exe的小工具
其实只是在cxfreeze的基础上加了个壳,做成窗口软件了 使用了pyqt做的界面,软件发布在了开源中国上,可以直接去下面的地址查看 http://git.oschina.net/robocky/py ...
- Python: tkinter实例改名小工具
#!/usr/bin/env python #coding=utf-8 # # 版权所有 2014 yao_yu (http://blog.csdn.net/yao_yu_126) # 本代码以MIT ...
- 入坑python 自己写的小工具,纪念一下
这个程序的功能是可以从表格中读取某一列数据,传到IDs 这一个参数里,然后在url中获取相应的请求值,并打印 import urllib.request import json import xlrd ...
- python一些实用的小工具
1 搭一个简易的本地局域网 python -m http.server 2 获取当前目录下的所有文件名 3 进度条效果 import sys,time for i in range(50): sy ...
- python之字符聊天小工具
server side: # coding: gb2312#socket server端#获取socket构造及常量from socket import *#''代表服务器为localhostmyHo ...
- 几个可以提高工作效率的Python内置小工具
在这篇文章里,我们将会介绍4个Python解释器自身提供的小工具.这些小工具在笔者的日常工作中经常用到,减少了各种时间的浪费,然而,却很容易被大家忽略.每当有新来的同事看到我这么使用时,都忍不住感叹, ...
- 【python】【开源】使用Tkinter和matplotlib实时显示图像,打造属于自己的性能测试小工具
在腾讯的perfdog工具还未公开时,当时需要查看内存使用情况等信息,就用python写了个小工具 为了提升开发效率,就直接借用了雷子开源的性能测试工具的布局,自己美化了一下,然后加入了实时显示数据的 ...
随机推荐
- Long Long Message(后缀数组)
Long Long Message Time Limit: 4000MS Memory Limit: 131072K Total Submissions: 30427 Accepted: 12 ...
- easyui dialog 中嵌入html页面
最近使用easyui比较多,这个插件确实很好用.在使用时也遇到了大大小小的问题,好在都一一解决了. 记录一下今天遇到的问题. 目的:用easyui的dialog嵌入一个html页面(html中仍有要执 ...
- OpenCV畸变校正源代码分析
图像算法中会经常用到摄像机的畸变校正,有必要总结分析OpenCV中畸变校正方法,其中包过普通针孔相机模型和鱼眼相机模型fisheye两种畸变校正方法. 普通相机模型畸变校正函数针对OpenCV中的cv ...
- python3 多线程获取数据实例
import requestsimport jsonfrom retrying import retryfrom lxml import etreefrom queue import Queueimp ...
- 一:Spring Boot、Spring Cloud
上次写了一篇文章叫Spring Cloud在国内中小型公司能用起来吗?介绍了Spring Cloud是否能在中小公司使用起来,这篇文章是它的姊妹篇.其实我们在这条路上已经走了一年多,从16年初到现在. ...
- javaweb学习方案1
一.JAVA环境变量的配置1.首先下载JDK JDK可以在Oracle(甲骨文)公司的官方网站http://www.oracle.com下载2.安装完成后查看JDK安装路径一般是C:\Program ...
- Python之re正则模块
正则表达式可以帮助我们更好的描述复制的文本格式,可以更好地利用它们对文本数据进行检索.替换.提取和修改操作. http://www.cnblogs.com/huxi/archive/2010/07/0 ...
- FPGA DDR3调试
FPGA DDR3调试 Spartan6 FPGA芯片中集成了MCB硬核,它可以支持到DDR3.在Xilinx的开发工具Xilinx ISE中提供了MIG IP核,设计者可以用它来直接生成 DDR3 ...
- CentOS下安装Tomcat 8
CentOS下安装Tomcat 8 安装Tomcat8 去http://tomcat.apache.org/download-80.cgi下载Tomcat8的安装文件apache-tomcat-8.0 ...
- mac 安装protobuf,并编译
因公司接口协议是PB文件,需要将 PB 编译成JAVA文件,且MAC 电脑,故整理并分享MAC安装 google 下的protobuf 文件 MAC 安装protobuf 流程 1.下载 http ...