圖片處理
pip install pillow
from PIL import Image
import numpy as np
a = np.array(Image.open('test.jpg'))
b = [255,255,255] - a
im = Image.fromarray(b.astype('uint8'))
im.save('new.jpg')
youtube-dl下載國外視頻
pip install youtube-dl #直接安裝youtube-dl
pip install -U youtube-dl #安裝youtube-dl並更新
youtube-dl "http://www.youtube.com/watch?v=-wNyEUrxzFU"
查看對象的全部屬性和方法
pip install pdir2
>>> import pdir,requests
>>> pdir(requests)
module attribute:
__cached__, __file__, __loader__, __name__, __package__, __path__, __spec__
other:
__author__, __build__, __builtins__, __copyright__, __license__, __title__,
__version__, _internal_utils, adapters, api, auth, certs, codes, compat, cookies
, exceptions, hooks, logging, models, packages, pyopenssl, sessions, status_code
s, structures, utils, warnings
special attribute:
__doc__
class:
NullHandler: This handler does nothing. It's intended to be used to avoid th
e
PreparedRequest: The fully mutable :class:`PreparedRequest <PreparedRequest>
` object,
Request: A user-created :class:`Request <Request>` object.
Response: The :class:`Response <Response>` object, which contains a
Session: A Requests session.
exception:
ConnectTimeout: The request timed out while trying to connect to the remote
server.
ConnectionError: A Connection error occurred.
DependencyWarning: Warned when an attempt is made to import a module with mi
ssing optional
FileModeWarning: A file was opened in text mode, but Requests determined its
binary length.
HTTPError: An HTTP error occurred.
ReadTimeout: The server did not send any data in the allotted amount of time
.
RequestException: There was an ambiguous exception that occurred while handl
ing your
Timeout: The request timed out.
TooManyRedirects: Too many redirects.
URLRequired: A valid URL is required to make a request.
function:
delete: Sends a DELETE request.
get: Sends a GET request.
head: Sends a HEAD request.
options: Sends a OPTIONS request.
patch: Sends a PATCH request.
post: Sends a POST request.
put: Sends a PUT request.
request: Constructs and sends a :class:`Request <Request>`.
session: Returns a :class:`Session` for context-management.
Python 玩轉網易雲音樂
pip install ncmbot
import ncmbot
#登錄
bot = ncmbot.login(phone='xxx', password='yyy')
bot.content # bot.json()
#獲取用戶歌單
ncmbot.user_play_list(uid='36554272')
下載視頻字幕
pip install getsub
Python 財經數據接口包
pip install tushare
import tushare as ts
#一次性獲取最近一個日交易日所有股票的交易數據
ts.get_today_all()
代碼,名稱,漲跌幅,現價,開盤價,最高價,最低價,最日收盤價,成交量,換手率
code name changepercent trade open high low settlement \
0 002738 中礦資源 10.023 19.32 19.32 19.32 19.32 17.56
1 300410 正業科技 10.022 25.03 25.03 25.03 25.03 22.75
2 002736 國信證券 10.013 16.37 16.37 16.37 16.37 14.88
3 300412 迦南科技 10.010 31.54 31.54 31.54 31.54 28.67
4 300411 金盾股份 10.007 29.68 29.68 29.68 29.68 26.98
5 603636 南威軟件 10.006 38.15 38.15 38.15 38.15 34.68
6 002664 信質電機 10.004 30.68 29.00 30.68 28.30 27.89
7 300367 東方網力 10.004 86.76 78.00 86.76 77.87 78.87
8 601299 中國北車 10.000 11.44 11.44 11.44 11.29 10.40
9 601880 大連港 10.000 5.72 5.34 5.72 5.22 5.20
10 000856 冀東裝備 10.000 8.91 8.18 8.91 8.18 8.10
開源漏洞靶場
# 安裝pip
curl -s https://bootstrap.pypa.io/get-pip.py | python3
# 安裝docker
apt-get update && apt-get install docker.io
# 啓動docker服務
service docker start
# 安裝compose
pip install docker-compose
# 拉取項目
git clone git@github.com:phith0n/vulhub.git
cd vulhub
# 進入某一個漏洞/環境的目錄
cd nginx_php5_mysql
# 自動化編譯環境
docker-compose build
# 啓動整個環境
docker-compose up -d
#測試完成後,刪除整個環境
docker-compose down
北京實時公交
pip install -r requirements.txt 安裝依賴
python manage.py build_cache 獲取離線數據,建立本地緩存
#項目自帶了一個終端中的查詢工具作爲例子,運行: python manage.py cli
>>> from beijing_bus import BeijingBus
>>> lines = BeijingBus.get_all_lines()
>>> lines
[<Line: 運通122(農業展覽館-華紡易城公交場站)>, <Line: 運通101(廣順南大街北口-藍龍家園)>, ...]
>>> lines = BeijingBus.search_lines('847')
>>> lines
[<Line: 847(馬甸橋西-雷莊村)>, <Line: 847(雷莊村-馬甸橋西)>]
>>> line = lines[0]
>>> print line.id, line.name
541 847(馬甸橋西-雷莊村)
>>> line.stations
[<Station 馬甸橋西>, <Station 馬甸橋東>, <Station 安華橋西>, ...]
>>> station = line.stations[0]
>>> print station.name, station.lat, station.lon
馬甸橋西 39.967721 116.372921
>>> line.get_realtime_data(1) # 參數爲站點的序號,從1開始
[
{
'id': 公交車id,
'lat': 公交車的位置,
'lon': 公交車位置,
'next_station_name': 下一站的名字,
'next_station_num': 下一站的序號,
'next_station_distance': 離下一站的距離,
'next_station_arriving_time': 預計到達下一站的時間,
'station_distance': 離本站的距離,
'station_arriving_time': 預計到達本站的時間,
},
...
]
文章提取器
git clone https://github.com/grangier/python-goose.git
cd python-goose
pip install -r requirements.txt
python setup.py install
>>> from goose import Goose
>>> from goose.text import StopWordsChinese
>>> url ='http://www.bbc.co.uk/zhongwen/simp/chinese_news/2012/12/121210_hongkong_politics.shtml'
>>> g = Goose({'stopwords_class': StopWordsChinese})
>>> article = g.extract(url=url)
>>> print article.cleaned_text[:150]
香港行政長官梁振英在各方壓力下就其大宅的違章建築(僭建)問題到立法會接受質詢,並向香港民衆道歉。
梁振英在星期二(12月10日)的答問大會開始之際在其演說中道歉,但強調他在違章建築問題上沒有隱瞞的意圖和動機。
一些親北京陣營議員歡迎梁振英道歉,且認爲應能獲得香港民衆接受,但這些議員也質問梁振英有
Python 藝術二維碼生成器
pip install MyQR
myqr https://github.com
myqr https://github.com -v 10 -l Q
僞裝瀏覽器身份
pip install fake-useragent
from fake_useragent import UserAgent
ua僞裝瀏覽器身份
pip install fake-useragent
from fake_useragent import UserAgent
ua = UserAgent()
ua.ie
# Mozilla/5.0 (Windows; U; MSIE 9.0; Windows NT 9.0; en-US);
ua.msie
# Mozilla/5.0 (compatible; MSIE 10.0; Macintosh; Intel Mac OS X 10_7_3; Trident/6.0)'
ua['Internet Explorer']
# Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; GTB7.4; InfoPath.2; SV1; .NET CLR 3.3.69573; WOW64; en-US)
ua..opera
# Opera/9.80 (X11; Linux i686; U; ru) Presto/2.8.131 Version/11.11
ua.chrome
# Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.2 (KHTML, like Gecko) Chrome/22.0.1216.0 Safari/537.2'
美化 curl
pip install httpstat
httpstat httpbin.org/get
python shell
.chrome
# Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.2 (KHTML, like Gecko) Chrome/22.0.1216.0 Safari/537.2'