Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View zhwei's full-sized avatar
🌏
Remote working

ZHANG Wei zhwei

🌏
Remote working
View GitHub Profile
@zhwei
zhwei / fabfile.py
Created March 18, 2014 12:41
Django项目中使用的fabfile, 其实也是通用的
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from fabric.colors import green, red
from fabric.contrib.console import confirm
from fabric.api import run, env, cd, put, sudo, abort
# configs
env.user = 'username'
env.hosts = ['IP:PORT',]
@zhwei
zhwei / gpa.py
Created May 12, 2014 12:22
计算学分绩点Python脚本
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import re
import requests
data = {"post_xuehao": "111111789"}
page = requests.post('http://xkzx.sdut.edu.cn/cjcx/zcjcx_list.php', data=data)
par = re.compile('<td scope="col" align=".*" valign="middle" nowrap>&nbsp;(.*?)</td>')
@zhwei
zhwei / fetch_baixing.py
Created June 7, 2014 02:35
抓取百姓网指定城市中二手车栏目下一百个帖子的详细内容
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import re
import sys
import time
import threading
try:
import requests
except ImportError:
@zhwei
zhwei / gotit-doc.md
Last active August 29, 2015 14:05
Gotit 开放接口文档

Gotit 开放接口文档

  • 更新时间: 2014-05-05
  • 数据格式均为JSON
  • 接口使用说明:
    1. 由于中文验证码的存在, 接口或许有点另类, 希望见谅.
    2. 验证类接口需要登录后才能使用, 如果仅查询单项信息推荐使用下面的成绩类或课表类接口
    3. 开发者在使用接口前先通过邮件联系作者 索要accesstoken, 将其放入请求header中.
    4. 次数限制 1000次/小时, 防止端口被恶意使用, 如果配额不够请联系作者.
@zhwei
zhwei / BaixingAPIv2.py
Last active August 29, 2015 14:05
百姓网开放APIv2 Python版SDK
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# 百姓网开放APIv2 Python版SDK
# 支持 Python2.7+
# Author: zhangwei@baixing.net
# Date: 2014-08-13
# 开发文档:http://api.baixing.com.cn/developer/
import json
python-dev python3-dev
@zhwei
zhwei / rename_file.py
Created February 9, 2015 03:01
rename file script
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Rename: baixing.log-1420614280.gz => baixing.log-20150107-150440.gz
import os
import datetime
to_date = lambda x: datetime.datetime.fromtimestamp(int(x)).strftime('%Y%m%d-%H%M%S')
file_list = os.listdir(".")
@zhwei
zhwei / sendmail.py
Last active August 29, 2015 14:16
Python Send Mail
import smtplib
from email.utils import formataddr
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
def send_mail(sender, alias, to, subject, body, msg_type='plain', reply_to=None):
msg = MIMEMultipart('alternative')
msg['From'] = formataddr((alias, sender))
@zhwei
zhwei / asyncredis.py
Created April 2, 2015 02:56
AsyncRedis
import tornadoredis
class AsyncRedis(Redis):
CONNECTION_POOLS = {}
@classmethod
def get_conn(cls, name='DEFAULT'):
host, port, db = cls._get_config(name)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = "zhwei"
# 使用imgur的api上传图片并返回url
import urllib2
import urllib
import json