Skip to content

Instantly share code, notes, and snippets.

#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 / trip-coroutine-demo.py
Created October 31, 2017 03:54
Trip coroutine demo
import time, functools
import requests, trip
def timeit(fn):
start_time = time.time()
fn()
return time.time() - start_time
url = 'http://httpbin.org/get'
@littlecodersh
littlecodersh / flask_qr.py
Created December 5, 2016 01:22
A demo of how to show itchat qrcode through website.
import threading
from flask import Flask, make_response
import itchat
qrSource = ''
def start_flask():
flaskApp = Flask('itchat')
@flaskApp.route('/')
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):
from tornado import httpclient, gen, ioloop, locks
def fetch(urlList, minRequire):
l = locks.Semaphore(len(urlList))
resultList = []
@gen.coroutine
def _fetch():
@gen.coroutine
def __fetch(url):
@littlecodersh
littlecodersh / WeChatCheckFriend.py
Created September 28, 2016 04:59
Demo of checking friends' status of wechat.
#coding=utf8
import itchat
CHATROOM_NAME = 'friend'
CHATROOM = None
HELP_MSG = u'''\
好友状态监测
* 发送名片将会返回好友状态
* 请确有名为%s的未使用的群聊
* 并将该群聊保存到通讯录
@littlecodersh
littlecodersh / WechatSmartWish.py
Created September 28, 2016 03:01
Demo of sending smart wishes through wechat.
#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 September 28, 2016 02:12
Demo of controlling music player through wechat.
#coding=utf8
import os
import itchat
from NetEaseMusicApi import interact_select_song
# 第三方包通过该命令安装:pip install itchat, NetEaseMusicApi
HELP_MSG = u'''\
欢迎使用微信网易云音乐
帮助: 显示帮助
@littlecodersh
littlecodersh / fields.py
Created September 17, 2016 00:48
Put this in requests/packages/urllib3 and you may upload files with Chinese name in itchat (python 2)
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
Last active December 9, 2023 00:37
Put this in requests/packages/urllib3 and you may upload files with Chinese name in itchat (python 3)
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.