图片处理

  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')

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"

查看对象的全部属性和方法

  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 <PreparedRequest>
  17. ` object,
  18. Request: A user-created :class:`Request <Request>` object.
  19. Response: The :class:`Response <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 <Request>`.
  46. session: Returns a :class:`Session` for context-management.

Python 玩转网易云音乐

  1. pip install ncmbot
  2. import ncmbot
  3. #登录
  4. bot = ncmbot.login(phone='xxx', password='yyy')
  5. bot.content # bot.json()
  6. #获取用户歌单
  7. 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. [<Line: 运通122(农业展览馆-华纺易城公交场站)>, <Line: 运通101(广顺南大街北口-蓝龙家园)>, ...]
  8. >>> lines = BeijingBus.search_lines('847')
  9. >>> lines
  10. [<Line: 847(马甸桥西-雷庄村)>, <Line: 847(雷庄村-马甸桥西)>]
  11. >>> line = lines[0]
  12. >>> print line.id, line.name
  13. 541 847(马甸桥西-雷庄村)
  14. >>> line.stations
  15. [<Station 马甸桥西>, <Station 马甸桥东>, <Station 安华桥西>, ...]
  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]

香港行政长官梁振英在各方压力下就其大宅的违章建筑(僭建)问题到立法会接受质询,并向香港民众道歉。

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

一些亲北京阵营议员欢迎梁振英道歉,且认为应能获得香港民众接受,但这些议员也质问梁振英有

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

  1. python shell
  2. pip install sh
  3. from sh import ifconfig
  4. 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}

解析 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 <city>
  6. iquery -l song [singer]
  7. iquery -p <city> <hospital>
  8. iquery <city> <show> [<days>]
  9. iquery [-dgktz] <from> <to> <date>
  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. 歌剧 比赛 舞蹈 戏曲 相声 杂技 马戏 魔术

作者:佚名

来源:51CTO

那些有趣/用的Python库相关推荐

  1. 那些有趣/有用的 Python 库

    图片处理 pip install pillow from PIL import Image import numpy as np a = np.array(Image.open('test.jpg') ...

  2. 那些有趣/用的 Python 库 1

    来源:苏生不惑    编辑:Python开发者 segmentfault.com/a/1190000010103386 图片处理 1pip install pillow2from PIL import ...

  3. 这5个有趣的Python库带你花式编码!

    图源:unsplash Python是如今最流行的编程语言之一,这点也给它本身带来很多好处,其中之一就是,为了方便进行程序开发,它拥有了大量优秀的库,如Pandas.Numpy.Matplotlib. ...

  4. python有趣的代码-趣味至上主义:这5个有趣的Python库带你花式编码

    本文转载自公众号"读芯术"(ID:AI_Discovery) Python是如今最流行的编程语言之一,这点也给它本身带来很多好处,其中之一就是,为了方便进行程序开发,它拥有了大量优 ...

  5. 学Python太枯燥?不多BB这几个有趣的python 库让你爱上python

    随着每个 Python 版本的发布,都会添加新模块,并引入新的更好的做事方式,虽然我们都习惯了使用好的旧 Python 库和某些做事方式,但现在也时候升级并利用新的和改进的模块及其特性了. 今天给大家 ...

  6. 10个优秀的Python库,实用且有趣

    为什么这么多人选择学习python?首先,python是一门全场景编程语言,对于初学编程的人而言,选择一门全场景编程语言是非常不错的选择;其次,python语言简单易学,对初学者十分友好,即便没有任何 ...

  7. 那些有趣 Python 库

    转载出处 苏生不惑 图片处理 pip install pillow from PIL import Image import numpy as npa = np.array(Image.open('t ...

  8. 独家 | Bamboolib:你所见过的最有用的Python库之一(附链接)

    作者:Ismael Araujo 翻译:王可汗 校对:欧阳锦本文约3200字,建议阅读5分钟 本文介绍了Python数据分析的一个利器--Bamboolib,它无需编码技能,能够自动生成pandas代 ...

  9. 必备 | 人工智能和数据科学的七大 Python 库

    来源:新智元 本文约3100字,建议阅读10+分钟. 本文汇总了2018年针对数据科学家/AI的最佳库.repos.包和工具. [ 导读 ]作者根据每周发布总结的系列文章,汇总了2018年针对数据科学 ...

最新文章

  1. mysql的安装和启动_mysql安装和启动
  2. 数据量高并发的数据库优化
  3. webpack配置vue组件加载器
  4. Eclipse Class Decompiler——Java反编译插件(转)
  5. C++用顶层函数重载操作符
  6. js最小化浏览器_Handtrack.js 开源:3行JS代码搞定手部动作跟踪
  7. linux故障排除与修复(troubleshooting)
  8. 使用IntelliJ IDEA 构建Maven的web项目
  9. mysql学习笔记(常用语句)
  10. centos 7 php目录权限设置密码,Linux系统中(CentOS 7)的用户和权限管理
  11. paip.NullPointerException --ApplicationImpl. createValueBinding错误的解决
  12. 混合线性模型学习笔记2
  13. LED背光源的使用寿命多久?
  14. [裴礼文数学分析中的典型问题与方法习题参考解答]4.3.21
  15. 使用unity粒子系统制作烟花
  16. PHP Warning: ‘ vcruntime140.dll‘ 14.0 is not compatible with this PHP build linked with 14.16 in Unk
  17. [深入浅出C语言]理解取整、取余和取模
  18. Monkey框架(测试方法篇) - monkey测试实例
  19. [JVM]了断局: 类加载机制
  20. Java_数组(声明、创建、初始化、复制、增强型for循环、二维数组、排序、Arrays类)

热门文章

  1. soul网关-4-sign插件签名认证
  2. Hive数据库创建表
  3. 微软试图导演互联网版的“赤壁之战”?
  4. 教师节祝福短信:送给有个性的老师
  5. 【转】c# 图片压缩 (非图片大小变化)----使得显示效果差点,但是图片占用空间需要变小
  6. 嵌入式(十三):嵌入式系统概念
  7. 云端3d虚拟现实展制作
  8. 指针pt的值(pt,pt,*pt)
  9. 减少2021年度汇算清缴补税
  10. 基于深度学习的自动车牌识别(详细步骤+源码)