From 03e3b7f056952105aaa55fc3e89cf75dba8071b3 Mon Sep 17 00:00:00 2001 From: LittleCoder Date: Mon, 28 Mar 2016 13:25:21 +0800 Subject: [PATCH] Upload to pypi --- .gitignore | 2 ++ __init__.py => itchat/__init__.py | 17 +++++---- client.py => itchat/client.py | 5 +-- config.py => itchat/config.py | 0 out.py => itchat/out.py | 0 storage.py => itchat/storage.py | 0 tools.py => itchat/tools.py | 0 requirement.txt | 2 ++ run.py | 43 +++++++++++++++++++++++ setup.py | 58 +++++++++++++++++++++++++++++++ 10 files changed, 116 insertions(+), 11 deletions(-) rename __init__.py => itchat/__init__.py (85%) rename client.py => itchat/client.py (96%) rename config.py => itchat/config.py (100%) rename out.py => itchat/out.py (100%) rename storage.py => itchat/storage.py (100%) rename tools.py => itchat/tools.py (100%) create mode 100644 requirement.txt create mode 100644 run.py create mode 100644 setup.py diff --git a/.gitignore b/.gitignore index 583ced28..bd2dd18c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ +dist/* +itchat.egg-info/* *.pyc *.swp diff --git a/__init__.py b/itchat/__init__.py similarity index 85% rename from __init__.py rename to itchat/__init__.py index 622e9bbb..6b182c39 100644 --- a/__init__.py +++ b/itchat/__init__.py @@ -1,6 +1,8 @@ import time, thread from client import client +import traceback + __version__ = '0.1b' __client = client() @@ -34,7 +36,7 @@ def send(msg = 'Test Message', toUserName = None): return __client.send_msg(toUserName, msg) # decorations -__functionDict = {} +__functionDict = {'GroupChat': {}} def configured_reply(): try: msg = __client.storageClass.msgList.pop() @@ -59,12 +61,13 @@ def _msg_dealer(*args, **kwargs): elif _type is None: return configured_reply else: - def _msg_dealer(fn, *args, **kwargs): - if kwargs.get('isGroupChat', False): - __functionDict['GroupChat'][_type] = fn - else: - __functionDict[_type] = fn - return fn + if not isinstance(_type, list): _type = [_type] + def _msg_dealer(fn, *_args, **_kwargs): + for msgType in _type: + if kwargs.get('isGroupChat', False): + __functionDict['GroupChat'][msgType] = fn + else: + __functionDict[msgType] = fn return _msg_dealer # in-build run diff --git a/client.py b/itchat/client.py similarity index 96% rename from client.py rename to itchat/client.py index 738005b7..186de941 100644 --- a/client.py +++ b/itchat/client.py @@ -244,11 +244,8 @@ def download_voice(voiceDir): 'Type': 'Friends', 'Text': { 'Status': m['Status'], - 'UserName': m['UserName'], + 'UserName': m['RecommendInfo']['UserName'], 'Ticket': m['Ticket'], }, } - # self.add_friend(m['Status'], m['RecommendInfo']['UserName'], m['Ticket']) - # self.get_contract() - # self.send_msg(m['RecommendInfo']['UserName'], config.WELCOME_WORDS) elif m['MsgType'] == 42: # name card msg = { 'Type': 'Card', diff --git a/config.py b/itchat/config.py similarity index 100% rename from config.py rename to itchat/config.py diff --git a/out.py b/itchat/out.py similarity index 100% rename from out.py rename to itchat/out.py diff --git a/storage.py b/itchat/storage.py similarity index 100% rename from storage.py rename to itchat/storage.py diff --git a/tools.py b/itchat/tools.py similarity index 100% rename from tools.py rename to itchat/tools.py diff --git a/requirement.txt b/requirement.txt new file mode 100644 index 00000000..a24411cd --- /dev/null +++ b/requirement.txt @@ -0,0 +1,2 @@ + +requests==2.9.1 diff --git a/run.py b/run.py new file mode 100644 index 00000000..54203fee --- /dev/null +++ b/run.py @@ -0,0 +1,43 @@ +import time +import itchat + +itchat.auto_login() + +def simple_reply(): + @itchat.msg_dealer + def simple_reply(msg): + if msg.get('Type', '') == 'Text': + return 'I received: %s'%msg.get('Content', '') + + while 1: + simple_reply() + time.sleep(1) + +def complex_reply(): + + @itchat.msg_dealer(['Text', 'Map', 'Card', 'Note', 'Sharing']) + def text_reply(msg): + itchat.send('%s: %s'%(msg['Type'], msg['Text']), msg['FromUserName']) + + @itchat.msg_dealer(['Picture', 'Recording', 'Attachment', 'Video']) + def download_files(msg): + fileDir = '%s%s'%(msg['Type'], int(time.time())) + msg['Text'](fileDir) + itchat.send('%s received'%msg['Type'], msg['FromUserName']) + itchat.send('@%s@%s'%('img' if msg['Type'] == 'Picture' else 'fil', fileDir), msg['FromUserName']) + + @itchat.msg_dealer('Friends') + def add_friend(msg): + print msg['Text'] + itchat.add_friend(**msg['Text']) + itchat.get_contract() + itchat.send_msg(msg['RecommendInfo']['UserName'], 'Nice to meet you!') + + @itchat.msg_dealer('Text', isGroupChat = True) + def text_reply(msg): + itchat.send(u'@%s\u2005I received: %s'%(msg['ActualNickName'], msg['Content']), msg['FromUserName']) + + itchat.run() + +if __name__ == '__main__': + complex_reply() diff --git a/setup.py b/setup.py new file mode 100644 index 00000000..2dc194e8 --- /dev/null +++ b/setup.py @@ -0,0 +1,58 @@ +""" A wechat personal account api project +See: +https://github.com/littlecodersh/ItChat/tree/api +https://github.com/littlecodersh/ItChat +""" + +from setuptools import setup, find_packages +from codecs import open +from os import path + +here = path.abspath(path.dirname(__file__)) + +with open(path.join(here, 'README.md'), encoding='utf-8') as f: + long_description = f.read() + +setup( + name='itchat', + + version='1.0.0', + + description='A complete wechat personal account api', + long_description=long_description, + + url='https://github.com/littlecodersh/ItChat/tree/api', + + author='LittleCoder', + author_email='i7meavnktqegm1b@qq.com', + + license='MIT', + + classifiers=[ + 'Development Status :: 3 - Alpha', + + 'Intended Audience :: Developers', + 'Topic :: Software Development :: Libraries :: Python Modules', + + 'License :: OSI Approved :: MIT License', + + 'Programming Language :: Python :: 2', + 'Programming Language :: Python :: 2.6', + 'Programming Language :: Python :: 2.7', + # 'Programming Language :: Python :: 3', + # 'Programming Language :: Python :: 3.3', + # 'Programming Language :: Python :: 3.4', + # 'Programming Language :: Python :: 3.5', + ], + + keywords='wechat itchat api robot weixin personal extend', + + # You can just specify the packages manually here if your project is + # simple. Or you can use find_packages(). + # packages=find_packages(exclude=['contrib', 'docs', 'tests']), + + install_requires=['requests'], + + # List additional groups of dependencies here + extras_require={}, +)