资讯专栏INFORMATION COLUMN

那些有趣/用的 Python 库

Pikachu / 2543人阅读

摘要:梁振英在星期二月日的答问大会开始之际在其演说中道歉,但强调他在违章建筑问题上没有隐瞒的意图和动机。

图片处理

</>复制代码

  1. pip install pillow
  2. from PIL import Image
  3. import numpy as np
  4. a = np.array(Image.open("test.jpg"))
  5. b = [255,255,255] - a
  6. im = Image.fromarray(b.astype("uint8"))
  7. im.save("new.jpg")
Parse Redis dump.rdb

</>复制代码

  1. pip install rdbtools
  2. > rdb --command json /var/redis/6379/dump.rdb
  3. [{
  4. "user003":{"fname":"Ron","sname":"Bumquist"},
  5. "lizards":["Bush anole","Jackson"s chameleon","Komodo dragon","Ground agama","Bearded dragon"],
  6. "user001":{"fname":"Raoul","sname":"Duke"},
  7. "user002":{"fname":"Gonzo","sname":"Dr"},
  8. "user_list":["user003","user002","user001"]},{
  9. "baloon":{"helium":"birthdays","medical":"angioplasty","weather":"meteorology"},
  10. "armadillo":["chacoan naked-tailed","giant","Andean hairy","nine-banded","pink fairy"],
  11. "aroma":{"pungent":"vinegar","putrid":"rotten eggs","floral":"roses"}}]
youtube-dl下载国外视频

</>复制代码

  1. pip install youtube-dl #直接安装youtube-dl
  2. pip install -U youtube-dl #安装youtube-dl并更新
  3. youtube-dl "http://www.youtube.com/watch?v=-wNyEUrxzFU"
asciinema录制命令行操作

</>复制代码

  1. pip3 install asciinema
  2. asciinema rec
  3. asciinema play https://asciinema.org/a/132560
查看对象的全部属性和方法

</>复制代码

  1. pip install pdir2
  2. >>> import pdir,requests
  3. >>> pdir(requests)
  4. module attribute:
  5. __cached__, __file__, __loader__, __name__, __package__, __path__, __spec__
  6. other:
  7. __author__, __build__, __builtins__, __copyright__, __license__, __title__,
  8. __version__, _internal_utils, adapters, api, auth, certs, codes, compat, cookies
  9. , exceptions, hooks, logging, models, packages, pyopenssl, sessions, status_code
  10. s, structures, utils, warnings
  11. special attribute:
  12. __doc__
  13. class:
  14. NullHandler: This handler does nothing. It"s intended to be used to avoid th
  15. e
  16. PreparedRequest: The fully mutable :class:`PreparedRequest
  17. ` object,
  18. Request: A user-created :class:`Request ` object.
  19. Response: The :class:`Response ` object, which contains a
  20. Session: A Requests session.
  21. exception:
  22. ConnectTimeout: The request timed out while trying to connect to the remote
  23. server.
  24. ConnectionError: A Connection error occurred.
  25. DependencyWarning: Warned when an attempt is made to import a module with mi
  26. ssing optional
  27. FileModeWarning: A file was opened in text mode, but Requests determined its
  28. binary length.
  29. HTTPError: An HTTP error occurred.
  30. ReadTimeout: The server did not send any data in the allotted amount of time
  31. .
  32. RequestException: There was an ambiguous exception that occurred while handl
  33. ing your
  34. Timeout: The request timed out.
  35. TooManyRedirects: Too many redirects.
  36. URLRequired: A valid URL is required to make a request.
  37. function:
  38. delete: Sends a DELETE request.
  39. get: Sends a GET request.
  40. head: Sends a HEAD request.
  41. options: Sends a OPTIONS request.
  42. patch: Sends a PATCH request.
  43. post: Sends a POST request.
  44. put: Sends a PUT request.
  45. request: Constructs and sends a :class:`Request `.
  46. session: Returns a :class:`Session` for context-management.
Python 玩转网易云音乐

</>复制代码

  1. #https://github.com/ziwenxie/netease-dl pip install netease-dl
  2. pip install ncmbot
  3. import ncmbot
  4. #登录
  5. bot = ncmbot.login(phone="xxx", password="yyy")
  6. bot.content # bot.json()
  7. #获取用户歌单
  8. ncmbot.user_play_list(uid="36554272")
下载视频字幕

</>复制代码

  1. pip install getsub

Python 财经数据接口包

</>复制代码

  1. pip install tushare
  2. import tushare as ts
  3. #一次性获取最近一个日交易日所有股票的交易数据
  4. ts.get_today_all()
  5. 代码,名称,涨跌幅,现价,开盘价,最高价,最低价,最日收盘价,成交量,换手率
  6. code name changepercent trade open high low settlement
  7. 0 002738 中矿资源 10.023 19.32 19.32 19.32 19.32 17.56
  8. 1 300410 正业科技 10.022 25.03 25.03 25.03 25.03 22.75
  9. 2 002736 国信证券 10.013 16.37 16.37 16.37 16.37 14.88
  10. 3 300412 迦南科技 10.010 31.54 31.54 31.54 31.54 28.67
  11. 4 300411 金盾股份 10.007 29.68 29.68 29.68 29.68 26.98
  12. 5 603636 南威软件 10.006 38.15 38.15 38.15 38.15 34.68
  13. 6 002664 信质电机 10.004 30.68 29.00 30.68 28.30 27.89
  14. 7 300367 东方网力 10.004 86.76 78.00 86.76 77.87 78.87
  15. 8 601299 中国北车 10.000 11.44 11.44 11.44 11.29 10.40
  16. 9 601880 大连港 10.000 5.72 5.34 5.72 5.22 5.20
  17. 10 000856 冀东装备 10.000 8.91 8.18 8.91 8.18 8.10
开源漏洞靶场

</>复制代码

  1. # 安装pip
  2. curl -s https://bootstrap.pypa.io/get-pip.py | python3
  3. # 安装docker
  4. apt-get update && apt-get install docker.io
  5. # 启动docker服务
  6. service docker start
  7. # 安装compose
  8. pip install docker-compose
  9. # 拉取项目
  10. git clone git@github.com:phith0n/vulhub.git
  11. cd vulhub
  12. # 进入某一个漏洞/环境的目录
  13. cd nginx_php5_mysql
  14. # 自动化编译环境
  15. docker-compose build
  16. # 启动整个环境
  17. docker-compose up -d
  18. #测试完成后,删除整个环境
  19. docker-compose down
北京实时公交

</>复制代码

  1. pip install -r requirements.txt 安装依赖
  2. python manage.py build_cache 获取离线数据,建立本地缓存
  3. #项目自带了一个终端中的查询工具作为例子,运行: python manage.py cli
  4. >>> from beijing_bus import BeijingBus
  5. >>> lines = BeijingBus.get_all_lines()
  6. >>> lines
  7. [, , ...]
  8. >>> lines = BeijingBus.search_lines("847")
  9. >>> lines
  10. [, ]
  11. >>> line = lines[0]
  12. >>> print line.id, line.name
  13. 541 847(马甸桥西-雷庄村)
  14. >>> line.stations
  15. [, , , ...]
  16. >>> station = line.stations[0]
  17. >>> print station.name, station.lat, station.lon
  18. 马甸桥西 39.967721 116.372921
  19. >>> line.get_realtime_data(1) # 参数为站点的序号,从1开始
  20. [
  21. {
  22. "id": 公交车id,
  23. "lat": 公交车的位置,
  24. "lon": 公交车位置,
  25. "next_station_name": 下一站的名字,
  26. "next_station_num": 下一站的序号,
  27. "next_station_distance": 离下一站的距离,
  28. "next_station_arriving_time": 预计到达下一站的时间,
  29. "station_distance": 离本站的距离,
  30. "station_arriving_time": 预计到达本站的时间,
  31. },
  32. ...
  33. ]
文章提取器

</>复制代码

  1. git clone https://github.com/grangier/python-goose.git
  2. cd python-goose
  3. pip install -r requirements.txt
  4. python setup.py install
  5. >>> from goose import Goose
  6. >>> from goose.text import StopWordsChinese
  7. >>> url = "http://www.bbc.co.uk/zhongwen/simp/chinese_news/2012/12/121210_hongkong_politics.shtml"
  8. >>> g = Goose({"stopwords_class": StopWordsChinese})
  9. >>> article = g.extract(url=url)
  10. >>> print article.cleaned_text[:150]
  11. 香港行政长官梁振英在各方压力下就其大宅的违章建筑(僭建)问题到立法会接受质询,并向香港民众道歉。
  12. 梁振英在星期二(12月10日)的答问大会开始之际在其演说中道歉,但强调他在违章建筑问题上没有隐瞒的意图和动机。
  13. 一些亲北京阵营议员欢迎梁振英道歉,且认为应能获得香港民众接受,但这些议员也质问梁振英有
Python 艺术二维码生成器

</>复制代码

  1. pip install MyQR
  2. myqr https://github.com
  3. myqr https://github.com -v 10 -l Q

伪装浏览器身份

</>复制代码

  1. pip install fake-useragent
  2. from fake_useragent import UserAgent
  3. ua = UserAgent()
  4. ua.ie
  5. # Mozilla/5.0 (Windows; U; MSIE 9.0; Windows NT 9.0; en-US);
  6. ua.msie
  7. # Mozilla/5.0 (compatible; MSIE 10.0; Macintosh; Intel Mac OS X 10_7_3; Trident/6.0)"
  8. ua["Internet Explorer"]
  9. # 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)
  10. ua.opera
  11. # Opera/9.80 (X11; Linux i686; U; ru) Presto/2.8.131 Version/11.11
  12. ua.chrome
  13. # Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.2 (KHTML, like Gecko) Chrome/22.0.1216.0 Safari/537.2"
美化 curl

</>复制代码

  1. pip install httpstat
  2. httpstat httpbin.org/get

python shell

</>复制代码

  1. pip install sh
  2. from sh import ifconfig
  3. print ifconfig("eth0")
处理中文文本内容

</>复制代码

  1. pip install -U textblob#英文文本的情感分析
  2. pip install snownlp#中文文本的情感分析
  3. from snownlp import SnowNLP
  4. text = "I am happy today. I feel sad today."
  5. from textblob import TextBlob
  6. blob = TextBlob(text)
  7. TextBlob("I am happy today. I feel sad today.")
  8. blob.sentiment
  9. Sentiment(polarity=0.15000000000000002, subjectivity=1.0)
  10. s = SnowNLP(u"这个东西真心很赞")
  11. s.words # [u"这个", u"东西", u"真心",
  12. # u"很", u"赞"]
  13. s.tags # [(u"这个", u"r"), (u"东西", u"n"),
  14. # (u"真心", u"d"), (u"很", u"d"),
  15. # (u"赞", u"Vg")]
  16. s.sentiments # 0.9769663402895832 positive的概率
  17. s.pinyin # [u"zhe", u"ge", u"dong", u"xi",
  18. # u"zhen", u"xin", u"hen", u"zan"]
  19. s = SnowNLP(u"「繁體字」「繁體中文」的叫法在臺灣亦很常見。")
  20. s.han # u"「繁体字」「繁体中文」的叫法
  21. # 在台湾亦很常见。"
抓取发放代理

</>复制代码

  1. pip install -U getproxy
  2. ➜ ~ getproxy --help
  3. Usage: getproxy [OPTIONS]
  4. Options:
  5. --in-proxy TEXT Input proxy file
  6. --out-proxy TEXT Output proxy file
  7. --help Show this message and exit.

--in-proxy 可选参数,待验证的 proxies 列表文件

--out-proxy 可选参数,输出已验证的 proxies 列表文件,如果为空,则直接输出到终端

--in-proxy 文件格式和 --out-proxy 文件格式一致

zhihu api

</>复制代码

  1. pip install git+git://github.com/lzjun567/zhihu-api --upgrade
  2. from zhihu import Zhihu
  3. zhihu = Zhihu()
  4. zhihu.user(user_slug="xiaoxiaodouzi")
  5. {"avatar_url_template": "https://pic1.zhimg.com/v2-ca13758626bd7367febde704c66249ec_{size}.jpg",
  6. "badge": [],
  7. "name": "我是小号",
  8. "headline": "程序员",
  9. "gender": -1,
  10. "user_type": "people",
  11. "is_advertiser": False,
  12. "avatar_url": "https://pic1.zhimg.com/v2-ca13758626bd7367febde704c66249ec_is.jpg",
  13. "url": "http://www.zhihu.com/api/v4/people/1da75b85900e00adb072e91c56fd9149", "type": "people",
  14. "url_token": "xiaoxiaodouzi",
  15. "id": "1da75b85900e00adb072e91c56fd9149",
  16. "is_org": False}
Python 密码泄露查询模块

</>复制代码

  1. pip install leakPasswd
  2. import leakPasswd
  3. leakPasswd.findBreach("taobao")

解析 nginx 访问日志并格式化输出

</>复制代码

  1. pip install ngxtop
  2. $ ngxtop
  3. running for 411 seconds, 64332 records processed: 156.60 req/sec
  4. Summary:
  5. | count | avg_bytes_sent | 2xx | 3xx | 4xx | 5xx |
  6. |---------+------------------+-------+-------+-------+-------|
  7. | 64332 | 2775.251 | 61262 | 2994 | 71 | 5 |
  8. Detailed:
  9. | request_path | count | avg_bytes_sent | 2xx | 3xx | 4xx | 5xx |
  10. |------------------------------------------+---------+------------------+-------+-------+-------+-------|
  11. | /abc/xyz/xxxx | 20946 | 434.693 | 20935 | 0 | 11 | 0 |
  12. | /xxxxx.json | 5633 | 1483.723 | 5633 | 0 | 0 | 0 |
  13. | /xxxxx/xxx/xxxxxxxxxxxxx | 3629 | 6835.499 | 3626 | 0 | 3 | 0 |
  14. | /xxxxx/xxx/xxxxxxxx | 3627 | 15971.885 | 3623 | 0 | 4 | 0 |
  15. | /xxxxx/xxx/xxxxxxx | 3624 | 7830.236 | 3621 | 0 | 3 | 0 |
  16. | /static/js/minified/utils.min.js | 3031 | 1781.155 | 2104 | 927 | 0 | 0 |
  17. | /static/js/minified/xxxxxxx.min.v1.js | 2889 | 2210.235 | 2068 | 821 | 0 | 0 |
  18. | /static/tracking/js/xxxxxxxx.js | 2594 | 1325.681 | 1927 | 667 | 0 | 0 |
  19. | /xxxxx/xxx.html | 2521 | 573.597 | 2520 | 0 | 1 | 0 |
  20. | /xxxxx/xxxx.json | 1840 | 800.542 | 1839 | 0 | 1 | 0 |
火车余票查询

</>复制代码

  1. pip install iquery
  2. Usage:
  3. iquery (-c|彩票)
  4. iquery (-m|电影)
  5. iquery -p
  6. iquery -l song [singer]
  7. iquery -p
  8. iquery []
  9. iquery [-dgktz]
  10. Arguments:
  11. from 出发站
  12. to 到达站
  13. date 查询日期
  14. city 查询城市
  15. show 演出的类型
  16. days 查询近(几)天内的演出, 若省略, 默认15
  17. city 城市名,加在-p后查询该城市所有莆田医院
  18. hospital 医院名,加在city后检查该医院是否是莆田系
  19. Options:
  20. -h, --help 显示该帮助菜单.
  21. -dgktz 动车,高铁,快速,特快,直达
  22. -m 热映电影查询
  23. -p 莆田系医院查询
  24. -l 歌词查询
  25. -c 彩票查询
  26. Show:
  27. 演唱会 音乐会 音乐剧 歌舞剧 儿童剧 话剧
  28. 歌剧 比赛 舞蹈 戏曲 相声 杂技 马戏 魔术
电脑之间传文件

</>复制代码

  1. pip install magic-wormhole
  2. Sender:
  3. % wormhole send README.md
  4. Sending 7924 byte file named "README.md"
  5. On the other computer, please run: wormhole receive
  6. Wormhole code is: 7-crossover-clockwork
  7. Sending (<-10.0.1.43:58988)..
  8. 100%|=========================| 7.92K/7.92K [00:00<00:00, 6.02MB/s]
  9. File sent.. waiting for confirmation
  10. Confirmation received. Transfer complete.
  11. Receiver:
  12. % wormhole receive
  13. Enter receive wormhole code: 7-crossover-clockwork
  14. Receiving file (7924 bytes) into: README.md
  15. ok? (y/n): y
  16. Receiving (->tcp:10.0.1.43:58986)..
  17. 100%|===========================| 7.92K/7.92K [00:00<00:00, 120KB/s]
  18. Received file written to README.md
Python 数据可视化

</>复制代码

  1. pip install pyecharts
  2. from pyecharts import Bar
  3. bar = Bar("我的第一个图表", "这里是副标题")
  4. bar.add("服装", ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"], [5, 20, 36, 10, 75, 90])
  5. bar.show_config()
  6. bar.render()#在根目录下生成一个 render.html 的文件,用浏览器打开
  7. #pyecharts制作词云图
  8. from pyecharts import WordCloud
  9. wordlist = ["Sam", "Club","Macys", "Amy Schumer", "Jurassic World", "Charter","Communications","Chick Fil A", "Planet Fitness", "Pitch Perfect", "Express", "Home", "Johnny Depp","Lena Dunham", "Lewis", "Hamilton","KXAN", "Mary Ellen Mark", "Farrah","Abraham","Rita Ora", "Serena Williams", "NCAA", " baseball"," tournament","Point Break"]
  10. #对应于wordlist中每个元素的词频
  11. freq = [10000, 6181, 6000, 4386, 4055, 2467, 2244, 1898, 1484, 1112,1112,1112, 965, 847, 847, 555, 555,555,550, 462, 366, 360, 282, 273, 265]
  12. #设置图标尺寸大小
  13. wordcloud = WordCloud(width=1000, height=620)
  14. wordcloud.add(name="",
  15. attr=wordlist,
  16. shape="circle",
  17. value=freq,
  18. word_size_range=[20, 100])
  19. #notebook上渲染出词云图
  20. wordcloud
  21. #将词云图渲染并保存到html文件中
  22. #wordcloud.render(path="词云图.html")
  23. freq = [7000, 6181, 6000, 4386, 4055, 2467, 2244, 1898, 1484, 1112,1112,1112, 965, 847, 847, 555, 555,555,550, 462, 366, 360,299, 10000, 7000]
  24. wordcloud = WordCloud(width=1000, height=620)
  25. wordcloud.add(name="",
  26. attr=wordlist,
  27. shape="star",
  28. value=freq,
  29. word_size_range=[20, 100])
  30. wordcloud

微信公众号爬虫接口

</>复制代码

  1. pip install wechatsogou
  2. from wechatsogou import *
  3. wechats = WechatSogouApi()
  4. name = "南京航空航天大学"
  5. wechat_infos = wechats.search_gzh_info(name)
优雅的重试

</>复制代码

  1. pip install tenacity
  2. #限制重试次数为3次
  3. from tenacity import retry, stop_after_attempt
  4. @retry(stop=stop_after_attempt(3))
  5. def extract(url):
  6. info_json = requests.get(url).content.decode()
  7. info_dict = json.loads(info_json)
  8. data = info_dict["data"]
  9. save(data)
查找IP地址归属地

</>复制代码

  1. pip install qqwry-py3
  2. from qqwry import QQwry
  3. q = QQwry()
  4. q.load_file("qqwry.dat", loadindex=False)
  5. result = q.lookup("8.8.8.8")
导出 python 库列表

</>复制代码

  1. #pip freeze 导出当前环境中所有的 python 库列表
  2. $ pip install pipreqs
  3. $ pipreqs /home/project/location
  4. Successfully saved requirements file in /home/project/location/requirements.txt
Google Chrome Dev Protocol

</>复制代码

  1. pip install -U pychrome
  2. google-chrome --remote-debugging-port=9222
  3. # create a browser instance
  4. browser = pychrome.Browser(url="http://127.0.0.1:9222")
  5. # list all tabs (default has a blank tab)
  6. tabs = browser.list_tab()
  7. if not tabs:
  8. tab = browser.new_tab()
  9. else:
  10. tab = tabs[0]
  11. # register callback if you want
  12. def request_will_be_sent(**kwargs):
  13. print("loading: %s" % kwargs.get("request").get("url"))
  14. tab.Network.requestWillBeSent = request_will_be_sent
  15. # call method
  16. tab.Network.enable()
  17. # call method with timeout
  18. tab.Page.navigate(url="https://github.com/fate0/pychrome", _timeout=5)
  19. # 6. wait for loading
  20. tab.wait(5)
  21. # 7. stop tab (stop handle events and stop recv message from chrome)
  22. tab.stop()
  23. # 8. close tab
  24. browser.close_tab(tab)
模糊搜索

</>复制代码

  1. pip install fuzzywuzzy
  2. >>> from fuzzywuzzy import fuzz
  3. >>> from fuzzywuzzy import process
  4. >>> fuzz.ratio("this is a test", "this is a test!")
  5. 97
  6. >>> choices = ["Atlanta Falcons", "New York Jets", "New York Giants", "Dallas Cowboys"]
  7. >>> process.extract("new york jets", choices, limit=2)
  8. [("New York Jets", 100), ("New York Giants", 78)]
  9. >>> process.extractOne("cowboys", choices)
  10. ("Dallas Cowboys", 90)
算法学习

</>复制代码

  1. from pygorithm.sorting import bubble_sort
  2. myList = [12, 4, 3, 5, 13, 1, 17, 19, 15]
  3. sortedList = bubble_sort.sort(myList)
  4. print(sortedList)
  5. [1, 3, 4, 5, 12, 13, 15, 17, 19]
命令行洪流搜索程序

</>复制代码

  1. pip install torrench --upgrade
  2. $ torrench "ubuntu desktop 16.04" ## Search Linuxtracker for Ubuntu Desktop 16.04 distro ISO
  3. $ torrench "fedora workstation" ## Search for Fedora Workstation distro ISO
  4. $ torrench -d "opensuse" ## Search distrowatch for opensuse ISO
  5. $ torrench -d "solus" ## Search distrowatch for solus ISO

根据姓名来判断性别

</>复制代码

  1. pip install ngender
  2. $ ng 赵本山 宋丹丹
  3. name: 赵本山 => gender: male, probability: 0.9836229687547046
  4. name: 宋丹丹 => gender: female, probability: 0.9759486128949907
  5. >>> import ngender
  6. >>> ngender.guess("赵本山")
  7. ("male", 0.9836229687547046)
Python编写的简单的微信客户端

</>复制代码

  1. #https://github.com/pavlovai/match
  2. pip install pywxclient
  3. pip install git+https://github.com/justdoit0823/pywxclient
  4. >>> from pywxclient.core import Session, SyncClient
  5. >>> s1 = Session()
  6. >>> c1 = SyncClient(s1)
  7. >>> c1.get_authorize_url() # Open the url in web browser
  8. >>> c1.authorize() # Continue authorize when returning False
  9. >>> c1.login()
  10. >>> c1.sync_check()
  11. >>> msgs = c1.sync_message() # Here are your wechat messages
  12. >>> c1.flush_sync_key()
比较相似图片

</>复制代码

  1. $ pip install numpy
  2. $ pip install scipy
  3. $ pip install image_match
  4. from image_match.goldberg import ImageSignature
  5. gis = ImageSignature()
  6. a = gis.generate_signature("https://upload.wikimedia.org/wikipedia/commons/thumb/e/ec/Mona_Lisa,_by_Leonardo_da_Vinci,_from_C2RMF_retouched.jpg/687px-Mona_Lisa,_by_Leonardo_da_Vinci,_from_C2RMF_retouched.jpg")
  7. b = gis.generate_signature("https://pixabay.com/static/uploads/photo/2012/11/28/08/56/mona-lisa-67506_960_720.jpg")
  8. gis.normalized_distance(a, b)
身份证识别OCR 生成各类虚拟数据

</>复制代码

  1. pip install mimesis
  2. >>> import mimesis
  3. >>> person = mimesis.Personal(locale="en")
  4. >>> person.full_name(gender="female")
  5. "Antonetta Garrison"
  6. >>> person.occupation()
  7. "Backend Developer"
视频处理库

</>复制代码

  1. from moviepy.editor import *
  2. video = VideoFileClip("myHolidays.mp4").subclip(50,60)
  3. # Make the text. Many more options are available.
  4. txt_clip = ( TextClip("My Holidays 2013",fontsize=70,color="white")
  5. .set_position("center")
  6. .set_duration(10) )
  7. result = CompositeVideoClip([video, txt_clip]) # Overlay text on video
  8. result.write_videofile("myHolidays_edited.webm",fps=25) # Many options...
微信聊天记录导出、分析工具

</>复制代码

  1. pip install wechat-explorer
  2. wexp list_chatrooms ../Documents user_id
  3. wexp list_friends ../Documents user_id
  4. wexp get_chatroom_stats ../Documents user_id chatroom_id@chatroom 2015-08-01 2015-09-01
  5. wexp export_chatroom_records ../Documents user_id chatroom_id@chatroom 2015-10-01 2015-10-07 ../
  6. wexp get_friend_label_stats ../Documents user_id
  7. wkhtmltopdf --dpi 300 records.html records.pdf
图片爬虫库

</>复制代码

  1. pip install icrawler
  2. from icrawler.builtin import BaiduImageCrawler, BingImageCrawler, GoogleImageCrawler
  3. google_crawler = GoogleImageCrawler(parser_threads=2, downloader_threads=4,
  4. storage={"root_dir": "your_image_dir"})
  5. google_crawler.crawl(keyword="sunny", offset=0, max_num=1000,
  6. date_min=None, date_max=None,
  7. min_size=(200,200), max_size=None)
  8. bing_crawler = BingImageCrawler(downloader_threads=4,
  9. storage={"root_dir": "your_image_dir"})
  10. bing_crawler.crawl(keyword="sunny", offset=0, max_num=1000,
  11. min_size=None, max_size=None)
  12. baidu_crawler = BaiduImageCrawler(storage={"root_dir": "your_image_dir"})
  13. baidu_crawler.crawl(keyword="sunny", offset=0, max_num=1000,
  14. min_size=None, max_size=None)
  15. from icrawler.builtin import GreedyImageCrawler
  16. storage= {"root_dir": "/"}
  17. greedy_crawler = GreedyImageCrawler(storage=storage)
  18. greedy_crawler.crawl(domains="http://qq.com",
  19. max_num=6)
Python 剪贴板

</>复制代码

  1. pip install pyperclip
  2. from pyperclip import copy, paste
  3. copy("2333") # 向剪贴板写入 2333
  4. paste() # 值为剪贴板中的内容
获取图片的相似度

</>复制代码

  1. import face_recognition
  2. image = face_recognition.load_image_file("your_file.jpg")
  3. face_locations = face_recognition.face_locations(image)

浏览器自动化splinter

</>复制代码

  1. #chromedriver.storage.googleapis.com/index.html
  2. >>> from splinter.browser import Browser
  3. >>> xx = Browser(driver_name="chrome")
  4. >>> xx.visit("http://www.zhihu.com/")
为SQLite数据库生成JSON

</>复制代码

  1. pip3 install datasette
  2. datasette serve path/to/database.db
  3. http://localhost:8001/History/downloads.json
numpy 接口直接工作在 CUDA

</>复制代码

  1. >>> import cupy as cp
  2. >>> x = cp.arange(6).reshape(2, 3).astype("f")
  3. >>> x
  4. array([[ 0., 1., 2.],
  5. [ 3., 4., 5.]], dtype=float32)
  6. >>> x.sum(axis=1)
  7. array([ 3., 12.], dtype=float32)
了解一个命令或程序在执行前会做什么

</>复制代码

  1. pip install maybe
  2. maybe rm -r ostechnix/
  3. maybe has prevented rm -r ostechnix/ from performing 5 file system operations:
  4. delete /home/sk/inboxer-0.4.0-x86_64.AppImage
  5. delete /home/sk/Docker.pdf
  6. delete /home/sk/Idhayathai Oru Nodi.mp3
  7. delete /home/sk/dThmLbB334_1398236878432.jpg
  8. delete /home/sk/ostechnix
  9. Do you want to rerun rm -r ostechnix/ and permit these operations? [y/N] y
获取ip

</>复制代码

  1. pip install ng
  2. $ ng ip
  3. local_ip:192.168.1.114
  4. public_ip:49.4.160.250
  5. $ ng wp
  6. $ ng wp flyfish_5g
  7. flyfish_5g:hitflyfish123456
图床服务

</>复制代码

  1. $ pip install qu
  2. $ qu up /somewhere/1.png
  3. $ qu up /somewhere/1.png 2.png
get .gitignore

</>复制代码

  1. #https://www.gitignore.io/
  2. $ pip install gy
  3. $ gy generate python java lisp
PyGithub

</>复制代码

  1. pip install PyGithub
  2. from github import Github
  3. g = Github("xxxxx", "passwd")
  4. my_forks = []
  5. for repo in g.get_user().get_repos():
  6. if repo.fork:
  7. my_forks.append(repo)
爬虫小工具

</>复制代码

  1. pip install lazyspider
  2. from lazyspider.lazyheaders import LazyHeaders
  3. # 注意!字符串要包裹在 三引号 或 双引号 里
  4. curl = "curl "https://pypi.python.org/pypi" -H "cookie: .....balabala...."
  5. lh = LazyHeaders(curl)
  6. headers = lh.getHeaders()
  7. cookies = lh.getCookies()
  8. print("*" * 40)
  9. print("Headers: {}".format(headers))
  10. print("*" * 40)
  11. print("Cookies: {}".format(cookies))
  12. print("*" * 40)
  13. import requests
  14. r = requests.get("https://pypi.python.org/pypi",
  15. headers=headers, cookies=cookies)
  16. print(r.status_code)
中文近义词工具包

</>复制代码

  1. pip install -U synonyms
  2. >>> synonyms.display("飞机")
  3. "飞机"近义词:
  4. 1. 架飞机:0.837399
  5. 2. 客机:0.764609
  6. 3. 直升机:0.762116
  7. 4. 民航机:0.750519
  8. 5. 航机:0.750116
  9. 6. 起飞:0.735736
  10. 7. 战机:0.734975
  11. 8. 飞行中:0.732649
  12. 9. 航空器:0.723945
  13. 10. 运输机:0.720578

公众号:苏生不惑

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/38676.html

相关文章

  • SegmentFault 技术周刊 Vol.30 - 学习 Python 来做一些神奇好玩的事情吧

    摘要:学习笔记七数学形态学关注的是图像中的形状,它提供了一些方法用于检测形状和改变形状。学习笔记十一尺度不变特征变换,简称是图像局部特征提取的现代方法基于区域图像块的分析。本文的目的是简明扼要地说明的编码机制,并给出一些建议。 showImg(https://segmentfault.com/img/bVRJbz?w=900&h=385); 前言 开始之前,我们先来看这样一个提问: pyth...

    lifesimple 评论0 收藏0
  • Python来P图

    摘要:骚操作用来图给大家带来一篇关于的文章,全称是,顾名思义,是用来做图像处理的。支持众多的框架接口,可以用于图像展示。这个可以用来实现图像的自动对比度增强,还有全局的统计分析等。 Python骚操作 | 用Python来P图 给大家带来一篇关于PIL的文章,PIL全称是Python Image Library,顾名思义,是用来做图像处理的。用这个库,可以实现很多PS里的效果,比如像图片模糊...

    dendoink 评论0 收藏0
  • SegmentFault 社区访谈 | 依云: 一只想依偎在云上的野百合

    摘要:依云酱呢,是一名资深用户已经不会用现在的的,喜欢同时也属蛇,看来是命中注定,最近喜欢上了不是那个黄褐色的铁氧化合物哦。清蒸依云酱,我快死在你的标题上了。 showImg(https://segmentfault.com/img/bVRChj?w=900&h=385); 社区访谈的上期说到上帝有明是如何通过他的个人魅力撩得妹纸归,回忆传送门,不过逗得了妹纸笑,引得了汉纸拜(唔,崇拜的拜,...

    wizChen 评论0 收藏0
  • SegmentFault 社区访谈 | 依云: 一只想依偎在云上的野百合

    摘要:依云酱呢,是一名资深用户已经不会用现在的的,喜欢同时也属蛇,看来是命中注定,最近喜欢上了不是那个黄褐色的铁氧化合物哦。清蒸依云酱,我快死在你的标题上了。 showImg(https://segmentfault.com/img/bVRChj?w=900&h=385); 社区访谈的上期说到上帝有明是如何通过他的个人魅力撩得妹纸归,回忆传送门,不过逗得了妹纸笑,引得了汉纸拜(唔,崇拜的拜,...

    fredshare 评论0 收藏0

发表评论

0条评论

Pikachu

|高级讲师

TA的文章

阅读更多
最新活动
阅读需要支付1元查看
<