01
The image processing
1. pip install pillow
2. from PIL import Image
3. import numpy as np
4.
5. a = np.array(Image.open(‘test.jpg’))
6. A = [255,255,255
7. im = Image.fromarray(b.astype(‘uint8’))
8. im.save(‘new.jpg’)
02
Youtube-dl downloads foreign videos
1. #https://github.com/rg3/youtube-dl/
PIP install youtube-dl
PIP install -u youtube-dl # install youtube-dl
4. youtube-dl “http://www.youtube.com/watch?v=-wNyEUrxzFU”
03
View all properties and methods of the object
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.
04
Python plays netease Cloud music
1. #https://github.com/xiyouMc/ncmbot
2. pip install ncmbot
3. import ncmbot
# 4. To log in
5. bot = ncmbot.login(phone=’xxx’, password=’yyy’)
6. bot.content # bot.json()
7. # Get user playlists
8. ncmbot.user_play_list(uid=’36554272′)
05
Download video subtitles
1. #https://github.com/gyh1621/GetSubtitles
2. pip install getsub
06
Python Finance Data Interface package
1. # https://github.com/waditu/tushare
2. pip install tushare
3. import tushare as ts
4. # Obtain the trading data of all stocks in the most recent daily trading day at one time
5. ts.get_today_all()
6.
7. Code, name, up or down, current price, open price, high price, low price, daily closing price, volume, turnover rate
8. code name changepercent trade open high low settlement \
9. 0 002738 Medium mineral Resources 10.023 19.32 19.32 19.32 19.32 19.32 17.56
10. 1 300410 Zhengye Technology 10.022 25.03 25.03 25.03 25.03 22.75
11. 2 002736 Guosen Securities 10.013 16.37 16.37 16.37 16.37 14.88
12. 3 300412 Canaan Science and Technology 10.010 31.54 31.54 31.54 31.54 28.67
13. 4 300411 Jindun Shares 10.007 29.68 29.68 29.68 29.68 29.68 26.98
14. 5 603636 Nanwei Software 10.006 38.15 38.15 38.15 38.15 38.15 34.68
6 002664 Quality motor 10.004 30.68 29.00 30.68 28.30 27.89
7 300367 NETpower 10.004 86.76 78.00 86.76 77.87 78.87
17. 8 601299 CNR 10.000 11.44 11.44 11.44 11.29 10.40
18. 9 601880 Dalian Port 10.000 5.72 5.34 5.72 5.22 5.20
19. 10 000856 Jidong Equipment 10.000 8.91 8.18 8.91 8.18 8.10
07
Open source vulnerability shooting range
1. # https://github.com/phith0n/vulhub installation PIP
2. curl -s https://bootstrap.pypa.io/get-pip.py | python3
3.
4. # Install Docker
5. apt-get update && apt-get install docker.io
6.
7. # Start docker service
8. service docker start
9.
10. # Install compose
11. pip install docker-compose
12. # Pull items
13. git clone [email protected]:phith0n/vulhub.git
14. cd vulhub
15.
16. # Access a vulnerability/environment directory
17. cd nginx_php5_mysql
18.
19. # Automated build environment
20. docker-compose build
21.
22. # Boot up the entire environment
23. docker-compose up -d
24. # After the test is complete, delete the entire environment
25. docker-compose down
08
Beijing Real-time Public Transport
1. #https://github.com/wong2/beijing_bus
PIP install -r requirements. TXT
3. Python manage.py build_cache Retrieves offline data and builds a local cache
4. # The project comes with a query tool in the terminal as an example, run python manage.py cli
5. >>> from beijing_bus import BeijingBus
6. >>> lines = BeijingBus.get_all_lines()
7. >>> lines
8. [<Line: Yuntong 122(Agricultural Exhibition Hall – Huafangyi City Bus station)>, <Line: Yuntong 101(Guangshun South Dajie beikou – Lanlong Jiayuan)>,
9. >>> lines = BeijingBus.search_lines(‘847’)
10. >>> lines
11. [< Line: 847 (every single mardian southwest – LeiZhuang village) >, < the Line: 847 (LeiZhuang village – every single mardian southwest) >]
12. >>> line = lines[0]
13. >>> print line.id, line.name
14. 541 847(Ma Dian Qiao West – Leizhuang Village)
15. >>> line.stations
16. [west of Station Madian Bridge, East of Station Madian Bridge, West of Station Anhua Bridge…]
17. >>> station = line.stations[0]
18. >>> print station.name, station.lat, station.lon
19. Madian Bridge West 39.967721 116.372921
20. >>> line.get_realtime_data(1) # specifies the sequence number of the site, starting with 1
21. [
22. {
23. ‘id’: bus ID,
24. ‘Lat ‘: the location of the bus,
25. ‘LON ‘: Bus location,
26. ‘next_station_name’: name of next station,
27. ‘next_station_num’: serial number of the next station,
28. ‘next_station_distance’: distance to the next station,
29. ‘next_station_arriving_time’: estimated time of arrival at next station,
30. ‘station_distance’: distance from this site,
31. ‘station_arriving_time’: estimated time of arrival at this site,
32.},
33….
34.]
09
Article extractor
1. #https://github.com/grangier/python-goose
2. git clone https://github.com/grangier/python-goose.git
3. cd python-goose
4. pip install -r requirements.txt
5. python setup.py install
6.
7. >>> from goose import Goose
8. >>> from goose.text import StopWordsChinese
9. >>> url = ‘http://www.bbc.co.uk/zhongwen/simp/chinese_news/2012/12/121210_hongkong_politics.shtml’
10. >>> g = Goose({‘stopwords_class’: StopWordsChinese})
11. >>> article = g.extract(url=url)
12. >>> print article.cleaned_text[:150]
Hong Kong’s chief executive, Leung Chun-ying, has apologised to the people of Hong Kong under pressure to appear in the legislative Council for questioning over illegal construction of his mansion.
14.
15. In his speech at the start of the question-and-answer session on Tuesday (10 December), Mr Leung apologised but stressed that he had no intention or motive to hide the issue of illegal construction.
16.
17. Some pro-Beijing lawmakers welcomed Leung’s apology and said it should be accepted by the Hong Kong people, but they also questioned leung’s apology
10
Python art QR code generator
1. #https://github.com/sylnsfar/qrcode
2. pip install MyQR
3. myqr https://github.com
4. myqr https://github.com -v 10 -l Q
11
Disguise your Browser identity
1. #https://github.com/hellysmile/fake-useragent
2. pip install fake-useragent
3. from fake_useragent import UserAgent
4. ua = UserAgent()
5.
6. ua.ie
7. # Mozilla / 5.0 (Windows; U; MSIE 9.0; Windows NT 9.0; en-US);
8. ua.msie
9. # Mozilla / 5.0 (compatible; MSIE 10.0; Macintosh; Intel Mac OS X 10_7_3; Trident / 6.0) ‘
10. ua[‘Internet Explorer’]
11. # Mozilla / 5.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident / 4.0; GTB7.4; InfoPath.2; SV1; The.net CLR 3.3.69573; WOW64; en-US)
12. ua.opera
13. # Opera / 9.80 (X11; Linux i686; U; Ru) Presto / 2.8.131 Version / 11.11
14. ua.chrome
# Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.2 (KHTML, like Gecko) Chrome/22.0.1216.0 Safari/537.2′
12
Beautify the curl
1. #https://github.com/reorx/httpstat
2. pip install httpstat
3. httpstat httpbin.org/get
13
python shell
1. #https://github.com/amoffat/sh
2. pip install sh
3. from sh import ifconfig
4. print ifconfig(“eth0”)
14
Process Chinese text content
1. #https://github.com/isnowfy/snownlp
2. pip install snownlp
3. from snownlp import SnowNLP
4.
5. S = SnowNLP(u’ This thing is really cool ‘)
6.
7. S. wods # [u’ this ‘, u’ thing ‘, u’ heart ‘,
8. # u’ very ‘, u’ like ‘]
9.
S.tag # [(u’ this ‘, u’r’), (u’ thing ‘, u’n’),
11. # (u’ sincerely ‘, u’d’), (u’ very ‘, u’d’),
12. # (u’ like ‘, u’Vg’)]
13.
14. S. Entiments # 0.9769663402895832 probability of positive
15.
16. s.pinyin # [u’zhe’, u’ge’, u’dong’, u’xi’,
17. # u’zhen’, u’xin’, u’hen’, u’zan’]
18.
The term “traditional Chinese” is also common in Taiwan. ‘)
20.
The term for traditional Chinese
22. # Is also common in Taiwan. ‘
15
Capture release agent
1. #https://github.com/fate0/proxylist
2. pip install -U getproxy
3. ➜ ~ getproxy –help
4. Usage: getproxy [OPTIONS]
5.
6. Options:
7. –in-proxy TEXT Input proxy file
8. –out-proxy TEXT Output proxy file
9. –help Show this message and exit.
§ — In-proxy Optional parameter, Proxies list of files to be verified
§ –out-proxy This parameter is optional. Output proxies of verified proxies to tables (if empty)
The –in-proxy file format is the same as the — out-of-proxy file format
16
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.
6. {‘avatar_url_template’: ‘https://pic1.zhimg.com/v2-ca13758626bd7367febde704c66249ec_{size}.jpg’,
7. ‘badge’: [],
8. ‘name’: ‘I’m a trumpet ‘,
9. ‘Headline ‘:’ programmer ‘,
10. ‘gender’: -1,
11. ‘user_type’: ‘people’,
12. ‘is_advertiser’: False,
13. ‘avatar_url’: ‘https://pic1.zhimg.com/v2-ca13758626bd7367febde704c66249ec_is.jpg’,
14. ‘url’: ‘http://www.zhihu.com/api/v4/people/1da75b85900e00adb072e91c56fd9149’, ‘type’: ‘people’,
15. ‘url_token’: ‘xiaoxiaodouzi’,
16. ‘id’: ‘1da75b85900e00adb072e91c56fd9149’,
17. ‘is_org’: False}
17
Python password leak query module
1. #https://github.com/lauixData/leakPasswd
2. pip install leakPasswd
3. import leakPasswd
4. leakPasswd.findBreach(‘taobao’)