Skip to content

Commit

Permalink
Fix little problems
Browse files Browse the repository at this point in the history
  • Loading branch information
littlecodersh committed Mar 12, 2016
1 parent 271042e commit f554187
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 30 deletions.
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.pyc
*.swp
plugin/config/tuling.json
log/*
storage/*
plugin/config/tuling.json
!storage/upload/*
*.pyc
*.swp
7 changes: 4 additions & 3 deletions PluginTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def sys_print(level, msg):
pluginList.append('tuling')
sys_print('SUCC', 'Tuling')
except:
sys_print('WARN', 'Your key for tuling robot can\'t be used now, change one in plugin/config/tuling.json')
sys_print('INFO', 'Your key for tuling robot can\'t be used now, change one in plugin/config/tuling.json')
sys_print('~~~~', 'You can get it from http://www.tuling123.com/')
except:
sys_print('WARN', 'There is something wrong with the format of your plugin/config/tuling.json')
Expand All @@ -51,7 +51,7 @@ def sys_print(level, msg):
pluginList.append('msgdealers.autoreply')
sys_print('SUCC', 'msgdealers.autoreply')
except Exception, e:
sys_print('WARN', str(e))
sys_print('WARN', e.message)

# Test msgdealers.vote
if 'msgdealers.vote' in pluginList:
Expand Down Expand Up @@ -80,9 +80,10 @@ def send_msg(msg):

if __name__ == '__main__':
try:
print plugin_load_succeed()
print 'Loading %s'%('successfully' if plugin_load_succeed() else 'failed')
while True:
msg = raw_input('>').decode(sys.stdin.encoding)
if not msg: continue
if 'msgdealers.autoreply' in pluginList:
r = autoreply(msg)
if 'tuling' in pluginList:
Expand Down
64 changes: 51 additions & 13 deletions itchat/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ def login(self):
while 1:
voidUserList = self.get_contract()
if not voidUserList: break
for voidUser in voidUserList:
out.print_line('This user needs a new RemarkName', False)
out.print_line(str(voidUser), False)
raw_input('Continue?')
out.print_line('These uses need new RemarkNames and are added to a group', True)
chatRoomName = self.create_chatroom(voidUserList, 'RemarkNames')
self.delete_member(chatRoomName, [voidUserList[0]])
self.add_member(chatRoomName, [voidUserList[0]])
while raw_input('Enter "ready" after you rename all of them and DELETE the group: ') != 'ready': pass
out.print_line('Start reload contract list', False)
out.print_line('Login successfully as %s\n'%(
self.storageClass.find_nickname(self.storageClass.userName)), False)
Expand Down Expand Up @@ -140,21 +141,25 @@ def get_contract(self):
if m['Sex'] == 0 or m['Sex'] == '0': memberList.remove(m);i+=1
# deal with emoji
memberList = tools.emoji_dealer(memberList)
# PYQuanPin & RemarkPYQuanPin is used as identifier
# RemarkPYQuanPin & PYQuanPin is used as identifier
voidUserList = []
validUserList = []
for m in memberList:
if m['PYQuanPin'] == '':
if m['UserName'] == self.storageClass.userName:
m['PYQuanPin'] = m['NickName']
elif m['RemarkPYQuanPin'] == '':
voidUserList.append(m)
else:
m['PYQuanPin'] = m['RemarkPYQuanPin']
if m['RemarkPYQuanPin'] != '': m['PYQuanPin'] = m['RemarkPYQuanPin']
if m['UserName'] == self.storageClass.userName:
m['PYQuanPin'] = m['NickName']
elif m['PYQuanPin'] == '':
voidUserList.append(m)
continue
insertResult = self.storageClass.update_user(m['PYQuanPin'], NickName = m['RemarkName'] or m['NickName'],
UserName = m['UserName'])
if insertResult != True: out.print_line(str(insertResult) + ' need a new RemarkName')
if insertResult and not m['PYQuanPin'] in validUserList:
validUserList.append(m['PYQuanPin'])
else:
voidUserList.append(m)
if DEBUG:
with open('MemberList.txt', 'w') as f: f.write(str(memberList))
return voidUserList
def show_mobile_login(self):
url = '%s/webwxstatusnotify'%self.loginInfo['url']
payloads = {
Expand Down Expand Up @@ -423,6 +428,39 @@ def add_friend(self, Status, UserName, Ticket):
'skey': self.loginInfo['skey'],}
headers = { 'ContentType': 'application/json; charset=UTF-8' }
r = self.s.post(url, data = json.dumps(payloads), headers = headers)
def create_chatroom(self, memberList, topic = ''):
url = ('%s/webwxcreatechatroom?pass_ticket=%s&r=%s'%(
self.loginInfo['url'], self.loginInfo['pass_ticket'], int(time.time())))
params = {
'BaseRequest': self.loginInfo['BaseRequest'],
'MemberCount': len(memberList),
'MemberList': [{'UserName': member['UserName']} for member in memberList],
'Topic': topic, }
headers = {'content-type': 'application/json; charset=UTF-8'}

r = self.s.post(url, data=json.dumps(params),headers=headers)
dic = json.loads(r.content.decode('utf8', 'replace'))
return dic['ChatRoomName']
def delete_member(self, chatRoomName, memberList):
url = ('%s/webwxupdatechatroom?fun=delmember&pass_ticket=%s'%(
self.loginInfo['url'], self.loginInfo['pass_ticket']))
params = {
'BaseRequest': self.loginInfo['BaseRequest'],
'ChatRoomName': chatRoomName,
'DelMemberList': ','.join([member['UserName'] for member in memberList]),}
headers = {'content-type': 'application/json; charset=UTF-8'}
r = self.s.post(url, data=json.dumps(params),headers=headers)
print r.content.decode('utf8','replace')
def add_member(self, chatRoomName, memberList):
url = ('%s/webwxupdatechatroom?fun=addmember&pass_ticket=%s'%(
self.loginInfo['url'], self.loginInfo['pass_ticket']))
params = {
'BaseRequest': self.loginInfo['BaseRequest'],
'ChatRoomName': chatRoomName,
'AddMemberList': ','.join([member['UserName'] for member in memberList]),}
headers = {'content-type': 'application/json; charset=UTF-8'}
r = self.s.post(url, data=json.dumps(params),headers=headers)
print r.content.decode('utf8','replace')
def storage(self):
return self.msgList

Expand Down
9 changes: 3 additions & 6 deletions plugin/QRCode.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
from PIL import Image
import sys, os
import itchat.config as config
import sys, os, platform

QR_DIR = config.QR_DIR
OS = config.OS
BLOCK = '\xA1\xF6' if OS == 'Windows' else 'MM'
BLOCK = '\xA1\xF6' if platform.system() == 'Windows' else 'MM'

class QRCode():
def __init__(self, fileName, size, padding = 0, background = 'BLACK'):
Expand All @@ -29,5 +26,5 @@ def print_qr(self):
print self.white * (self.size + 2)

if __name__ == '__main__':
q = QRCode(os.path.join(QR_DIR, 'QR.jpg'), 37, 3, 'BLACK')
q = QRCode(os.path.join(os.path.pardir, 'log', 'QR.jpg'), 37, 3, 'BLACK')
q.print_qr()
9 changes: 4 additions & 5 deletions plugin/msgdealers/autoreply.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ def detectFiles(tableName):
try:
with Sqlite3Client(os.path.join(SQLITE_DIR, 'autoreply.db')) as s3c:
for qa in s3c.data_source('select * from %s'%tableName):
if qa[:5] == '@fil@':
fileName = qa[5:]
with open(os.join(FILE_DIR, fileName)): pass
if qa[1][:5] == '@fil@':
fileName = qa[1][5:]
with open(os.path.join(FILE_DIR, fileName)): pass
except:
traceback.print_exc()
raise Exception('Error occured when loading %s in table %s, it should be in storage/upload'%(
raise Exception('Error occured when loading "%s" in table %s, it should be in storage/upload'%(
fileName, tableName))

def getreply():
Expand Down

0 comments on commit f554187

Please sign in to comment.