Skip to content

Instantly share code, notes, and snippets.

@ficapy
ficapy / google_chrome_webstore_devtools_users_rank.py
Created October 27, 2015 12:21
谷歌浏览器应用商店使用人数排行 P.S 因木有代理 使用单线程执行,有极少部分请求被ban没有得到结果
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Author: Ficapy
# Create: '15/10/27'
from pyquery import PyQuery as pq
from operator import attrgetter
from concurrent.futures import ThreadPoolExecutor, as_completed
from operator import methodcaller
import requests
@ficapy
ficapy / file_transfer.py
Last active November 16, 2015 15:55
CDN文件中转
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Author: Ficapy
from __future__ import division, print_function
import sys
import re
import urllib
import sqlite3
import tempfile
@ficapy
ficapy / ali_oss.py
Last active December 21, 2015 13:02
阿里云OSS单文件上传
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Author: Ficapy
import requests
import base64
import hmac
import os
import sys
import datetime
from concurrent.futures import ThreadPoolExecutor, as_completed
from user_agent import generate_user_agent
import requests
from pyquery import PyQuery as pq
def singal_parse(id):
url = 'http://www.miaoss.net/reg.php?id={}'.format(id)
ret = requests.get(url, params={'User-Agent': generate_user_agent()}, timeout=30)
ret.encoding = 'utf-8'
@ficapy
ficapy / chardetect.py
Created September 10, 2015 03:36
编码检测
total = 2292627
import sys
import codecs
from encodings.aliases import aliases
import mmap
all_encoding = aliases.values()
all_encoding = list(set(all_encoding))
@ficapy
ficapy / json_output_chinese.py
Last active September 9, 2015 02:03
JSON输出中文
# http://stackoverflow.com/questions/18337407/saving-utf-8-texts-in-json-dumps-as-utf8-not-as-u-escape-sequence
print(json.dumps({u'卧槽': u'卧槽'}, indent=4).decode('unicode-escape').encode('utf8'))
print(json.dumps({u'卧槽': u'卧槽'}, indent=4, ensure_ascii=False))
@ficapy
ficapy / test.py
Last active September 16, 2015 03:41
将装饰器改成with语句,使用with语句实现错误重试
import random
from tt import retrys
def g():
pass
class A():
def __init__(self):
@ficapy
ficapy / adding_method.py
Created August 22, 2015 02:30
adding a method to an exists object&Monkey Path
class A(object):
pass
a = A()
# 给类添加方法
def baz(self):
print('baz')
A.baz = baz
# ==========或者
@ficapy
ficapy / regex_whole_file.py
Created August 20, 2015 08:09
不进行迭代文件使用正则匹配
import codecs
import re
import mmap
with codecs.open('a.txt', 'r+', 'utf-8') as f:
data = mmap.mmap(f.fileno(), 0)
print(re.findall(b'AccountType\=(.*)', data))
@ficapy
ficapy / check_status.py
Last active August 29, 2015 14:26
多线程请求
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Author: Ficapy
# Create: '15/8/6'
import time
import math
import requests
from concurrent.futures import ThreadPoolExecutor, as_completed
from xlrd import open_workbook