Skip to content

Instantly share code, notes, and snippets.

View ly0's full-sized avatar
👊
已全仓买入

latyas ly0

👊
已全仓买入
View GitHub Profile
r = requests.get(file_url)
size = int(r.headers['Content-Length'].strip())
self.bytes = 0
widgets = [name, ": ", Bar(marker="|", left="[", right=" "),
Percentage(), " ", FileTransferSpeed(), "] ",
self,
" of {0}MB".format(str(round(size / 1024 / 1024, 2))[:4])]
pbar = ProgressBar(widgets=widgets, maxval=size).start()
file = []
for buf in r.iter_content(1024):
@ly0
ly0 / streamingupload.py
Created February 5, 2014 08:55
Making requests support stream file upload with a processbar
import requests
from io import BytesIO
import progressbar
class CancelledError(Exception):
def __init__(self, msg):
self.msg = msg
Exception.__init__(self, msg)
def __str__(self):
@ly0
ly0 / colafile.py
Created February 5, 2014 09:13
colafile netdisk downloader
# colafile downloader
import re
import sys
import requests
s = requests.session()
ids = []
if len(sys.argv) < 2:
# print usage
@ly0
ly0 / dict.py
Created February 5, 2014 09:15
终端下的海词(dict.cn)词典,支持中英文,带查询日志
#!/usr/bin/python
#coding=utf-8
import urllib2
import sys
import re
import bs4
import os
import time
@ly0
ly0 / etym.py
Created February 5, 2014 09:18
a etymology dict script in CLI and results are from etymonline.com 终端下的词源在线查询脚本,支持日志
#!/usr/bin/python
#coding=utf-8
import urllib2
import sys,os
from bs4 import BeautifulSoup
import re
import time
def etymology(key):
page = urllib2.urlopen("http://www.etymonline.com/index.php?term=" + key).read().decode("utf-8")
@ly0
ly0 / webster.py
Created February 5, 2014 09:21
webster dict in terminal, 终端下的在线韦氏词典
#!/usr/bin/python
#coding=utf-8
import urllib2
import re
import sys
from bs4 import BeautifulSoup
def get_context(key):
ret = urllib2.urlopen('http://www.merriam-webster.com/dictionary/%s' % key).read().decode("utf-8")
@ly0
ly0 / pdfbooklet.py
Created February 5, 2014 09:25
pdf booklet maker by shuffling
from pyPdf import PdfFileWriter, PdfFileReader
import sys
def generate_page_list(n):
print n,'pages'
foo = []
flag1 = n % 2
# if n is an odd number, page n+1 is a BlankPage
if flag1 == 1:
n += 1
@ly0
ly0 / baidupcs-sync.py
Created February 8, 2014 17:27
百度网盘同步
#coding=utf-8
import os
import json
import sys
import re
from baidupcsapi import PCS
import progressbar
CWD = os.getcwd()
DIR_INFO = {}
@ly0
ly0 / baidupcsapi-walk.py
Created February 8, 2014 18:16
百度网盘api范例 遍历网盘
import json
from baidupcsapi import PCS
pcs = PCS('username','password')
def walk(path, tabs=0):
print '\t'*tabs+path
files = json.loads(pcs.list_files(path).content)['list']
for file in files:
if file['isdir'] == 1:
@ly0
ly0 / baidupcsapi-get_folder.py
Created February 8, 2014 18:20
百度网盘api接口范例,获得所有文件夹
import json
from baidupcsapi import PCS
pcs = PCS('u','p')
folders = set()
def get_folder(path):
print '* found',path
files = json.loads(pcs.list_files(path).content)['list']