Skip to content

Instantly share code, notes, and snippets.

@littlecodersh
littlecodersh / main.py
Last active Oct 19, 2021
Main script behind itchat robot
View main.py
#coding=utf8
import itchat
# tuling plugin can be get here:
# https://github.com/littlecodersh/EasierLife/tree/master/Plugins/Tuling
from tuling import get_response
@itchat.msg_register('Text')
def text_reply(msg):
if u'作者' in msg['Text'] or u'主人' in msg['Text']:
return u'你可以在这里了解他:https://github.com/littlecodersh'
View multilinereprintforwindows.py
#coding=utf8
import re, sys, time, os
from ctypes import Structure, c_short, windll, byref
try:
from shutil import get_terminal_size
except:
from backports.shutil_get_terminal_size import get_terminal_size
CN_REGEX = re.compile(u'[\u4e00-\u9fff]')
@littlecodersh
littlecodersh / fields.py
Last active Mar 7, 2020
Put this in requests/packages/urllib3 and you may upload files with Chinese name in itchat (python 3)
View fields.py
from __future__ import absolute_import
import email.utils
import mimetypes
from .packages import six
def guess_content_type(filename, default='application/octet-stream'):
"""
Guess the "Content-Type" of a file.
@littlecodersh
littlecodersh / fields.py
Created Sep 17, 2016
Put this in requests/packages/urllib3 and you may upload files with Chinese name in itchat (python 2)
View fields.py
from __future__ import absolute_import
import email.utils
import mimetypes
from .packages import six
def guess_content_type(filename, default='application/octet-stream'):
"""
Guess the "Content-Type" of a file.
@littlecodersh
littlecodersh / WeChatCheckFriend.py
Created Sep 28, 2016
Demo of checking friends' status of wechat.
View WeChatCheckFriend.py
#coding=utf8
import itchat
CHATROOM_NAME = 'friend'
CHATROOM = None
HELP_MSG = u'''\
好友状态监测
* 发送名片将会返回好友状态
* 请确有名为%s的未使用的群聊
* 并将该群聊保存到通讯录
@littlecodersh
littlecodersh / flask_qr.py
Created Dec 5, 2016
A demo of how to show itchat qrcode through website.
View flask_qr.py
import threading
from flask import Flask, make_response
import itchat
qrSource = ''
def start_flask():
flaskApp = Flask('itchat')
@flaskApp.route('/')
@littlecodersh
littlecodersh / WechatSmartWish.py
Created Sep 28, 2016
Demo of sending smart wishes through wechat.
View WechatSmartWish.py
#coding=utf8
import itchat, time
SINCERE_WISH = u'祝%s新年快乐!'
REAL_SINCERE_WISH = u'祝%s新年快乐!!'
def send_wishes():
friendList = itchat.get_friends(update=True)[1:]
for friend in friendList:
# 如果不是演示目的,把下面的方法改为itchat.send即可
@littlecodersh
littlecodersh / PCMusicViaWechat.py
Created Sep 28, 2016
Demo of controlling music player through wechat.
View PCMusicViaWechat.py
#coding=utf8
import os
import itchat
from NetEaseMusicApi import interact_select_song
# 第三方包通过该命令安装:pip install itchat, NetEaseMusicApi
HELP_MSG = u'''\
欢迎使用微信网易云音乐
帮助: 显示帮助
View trip-coroutine-demo.py
import time, functools
import requests, trip
def timeit(fn):
start_time = time.time()
fn()
return time.time() - start_time
url = 'http://httpbin.org/get'
View future-demo.py
from tornado import httpclient, gen, ioloop, concurrent
def fetch(urlList, minRequire):
resultList = []
@gen.coroutine
def _fetch():
fetchList = [httpclient.AsyncHTTPClient().fetch(url) for url in urlList]
yieldList = [concurrent.Future() for i in range(minRequire)]
def callback(f):