Skip to content

Commit

Permalink
Upload to pypi
Browse files Browse the repository at this point in the history
  • Loading branch information
littlecodersh committed Mar 28, 2016
1 parent 292821c commit 03e3b7f
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
dist/*
itchat.egg-info/*
*.pyc
*.swp
17 changes: 10 additions & 7 deletions __init__.py → itchat/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import time, thread
from client import client

import traceback

__version__ = '0.1b'

__client = client()
Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand Down
5 changes: 1 addition & 4 deletions client.py → itchat/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions requirement.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

requests==2.9.1
43 changes: 43 additions & 0 deletions run.py
Original file line number Diff line number Diff line change
@@ -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()
58 changes: 58 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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='[email protected]',

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={},
)

0 comments on commit 03e3b7f

Please sign in to comment.