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写了个小工具 为了提升开发效率,就直接借用了雷子开源的性能测试工具的布局,自己美化了一下,然后加入了实时显示数据的 ...
随机推荐
- zookeeper分布式搭建
1下载并解压zookeeper安装包 2进入zookeeper配置文件目录,找到zoo_sample.cfg,执行cp zoo_sample.cfg zoo.cfg 3打开zoo.cfg文件,修改d ...
- ajax参数解析
url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. type: 要求为String类型的参数,请求方式(post或get)默认为get.注意其他http请求方法,例如put和 ...
- day2--课前考试题
Linux 系统命令操作语法的格式: 命令 [参数选项] [文件或路径] rm -f ...
- seajs笔记
Amd和Cmd的区别有哪些? 1. 对于依赖的模块,AMD 是提前执行,CMD 是延迟执行.不过 RequireJS 从 2.0 开始,也改成可以延迟执行(根据写法不同,处理方式不同).CMD 推崇 ...
- ImageAnimator类方法(动画设计)
ImageAnimator类常用方法如表所示. 表 ImageAnimator类常用方法 方法 说明 Animate 将多帧图像显示为动画 CanAnimate 返回一个布尔值,该值指示指定图像 ...
- [转载] 基于Redis实现分布式消息队列
转载自http://www.linuxidc.com/Linux/2015-05/117661.htm 1.为什么需要消息队列?当系统中出现“生产“和“消费“的速度或稳定性等因素不一致的时候,就需要消 ...
- 【RabbitMQ+Python入门经典】兔子和兔子窝 笔记
RabbitMQ工业级的消息队列服务器. 兔子和兔子窝 动机来源:从生产环境的电子邮件处理流程当中分支出一个特定的离线分析流程. 解决方案1: 开始使用MySQL处理,将要处理的东西放在表里面,另一个 ...
- OpenTSDB - 分布式可扩展的监控系统
OpenTSDB - A Distributed, Scalable Monitoring System http://opentsdb.net/getting-started.html http:/ ...
- ASP.NET Core 认证与授权[6]:授权策略是怎么执行的?
在上一章中,详细介绍了 ASP.NET Core 中的授权策略,在需要授权时,只需要在对应的Controler或者Action上面打上[Authorize]特性,并指定要执行的策略名称即可,但是,授权 ...
- Maven 整合 SSH 框架
前面的一系列文章中,我们总结了三大框架:Struts2,Hibernate,Spring 的基本知识.本篇就姑且尝试着使用 Maven 这个项目构建工具来将这三个框架整合一起.说到这里,如果有对 Ma ...