Commit cf900802 by xxlv

Add tools

parent 82f94d62
#!/usr/bin/python
#-*- coding:utf-8 -*-
class Parser(Object):
"""
解析指令 进行chatOps
"""
def parse(cmd):
pass
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#-*- coding:utf-8 -*- #-*- coding:utf-8 -*-
import Bot import Bot
import itchat
class XiaoLingBot(Bot.Bot): class XiaoLingBot(Bot.Bot):
......
#!/usr/bin/python
#-*- coding:utf-8 -*-
# Author ghost<lvxiang119@gmail.com>
import pymysql as db_handle
def _get_store_driver():
config={
"user":"root",
"password":"123456",
"host":"127.0.0.1",
"database":"chatbot",
'charset':'utf8'
}
cnx=db_handle.connect(**config)
return cnx
def set(k,v,c=0):
connection=_get_store_driver()
with connection.cursor() as cursor:
set_query="INSERT SQL EXP"
cursor.execute(set_query,(k,v,c))
connection.commit()
#!/usr/bin/python
#-*- coding:utf-8 -*-
# Author ghost<lvxiang119@gmail.com>
def sendMail(TO, CC, TEXT, SUBJECT="SUBJECT", FROM_TITLE="FROM?", TO_TITLE="TO?"):
"""
Send a email
"""
import smtplib
from email.mime.text import MIMEText
from email.header import Header
def _format_addr(s):
from email.utils import parseaddr, formataddr
from email.header import Header
name, addr = parseaddr(s)
return formataddr((Header(name, 'utf-8').encode(), addr))
FROM = os.environ['sender']
SERVER = os.environ['sender_host']
message = MIMEText(TEXT, 'html', 'utf-8')
message['From'] = _format_addr('%s <%s>' % FROM,FROM)
message['To'] = Header(",".join(TO), 'utf-8')
message['Cc'] = ",".join("{} <{}>;".format(a, a) for a in CC)
message['Subject'] = Header(SUBJECT, 'utf-8')
# Send the mail
server = smtplib.SMTP(SERVER)
server.starttls()
server.login(FROM, os.environ['sender_mail_pass'])
server.sendmail(FROM, TO + CC, message.as_string())
server.quit()
print("Send mail from {} to {} ".format(FROM, TO))
...@@ -2,16 +2,51 @@ ...@@ -2,16 +2,51 @@
#-*- coding:utf-8 -*- #-*- coding:utf-8 -*-
import itchat import itchat
import sys
from bot import XiaoLingBot
from bot import XiaoLingBot
def main(): msglist = list()
bot =XiaoLingBot.XiaoLingBot(itchat)
bot.handle() @itchat.msg_register(
[
itchat.content.TEXT,
itchat.content.PICTURE,
itchat.content.MAP,
itchat.content.CARD,
itchat.content.SHARING,
itchat.content.NOTE,
itchat.content.RECORDING,
itchat.content.ATTACHMENT,
itchat.content.VIDEO,
itchat.content.FRIENDS,
],
isFriendChat=True,
isGroupChat=True
)
def msg_acceptor(msg):
msg['Visitor'] = 0
msglist.append(msg)
if __name__ == '__main__': if __name__ == '__main__':
main() if len(sys.argv) > 1:
if sys.argv[1] == '-t':
itchat.auto_login(hotReload=True, enableCmdQR=2)
else:
if sys.platform == 'linux':
if "XDG_CURRENT_DESKTOP" in os.environ:
itchat.auto_login(hotReload=True)
else:
itchat.auto_login(hotReload=True, enableCmdQR=2)
else:
itchat.auto_login(hotReload=True)
run_thread = Thread(target=itchat.run)
bot_thread=Thread(target=XiaoLingBot.XiaoLingBot().handle)
run_thread.join()
bot_thread.join()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment