├── .gitignore
├── LICENSE
├── README.md
├── README_cn.md
├── _v_images
├── 20191220185122289_8134.png
├── 20191220190307589_28533.png
├── 20191220191832613_15118.png
├── 20191220193145179_20665.png
├── 20191220203803479_15260.png
├── 20191220204054677_12422.png
└── 20191220204416988_4614.jpg
├── chineseStopWords.txt
├── ename.py
├── free_ip_pool.py
├── hide_file.py
├── ip_pool_browse.py
├── net_speed_monitor.pyw
├── pocketuni_crack.zip
├── portable_sync.py
├── power_views.py
├── random_userAgents.py
├── run_any_py.py
├── send_to_editor.py
├── setting.json
├── simple_screen_recorder.py
├── web2md.py
├── windows_focus.py
├── zhihu_answer_wordcloud.py
└── zhihu_video_downloader.py
/.gitignore:
--------------------------------------------------------------------------------
1 | # Byte-compiled / optimized / DLL files
2 | __pycache__/
3 | *.py[cod]
4 | *$py.class
5 |
6 | # C extensions
7 | *.so
8 |
9 | # Distribution / packaging
10 | .Python
11 | build/
12 | develop-eggs/
13 | dist/
14 | downloads/
15 | eggs/
16 | .eggs/
17 | lib/
18 | lib64/
19 | parts/
20 | sdist/
21 | var/
22 | wheels/
23 | pip-wheel-metadata/
24 | share/python-wheels/
25 | *.egg-info/
26 | .installed.cfg
27 | *.egg
28 | MANIFEST
29 |
30 | # PyInstaller
31 | # Usually these files are written by a python script from a template
32 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
33 | *.manifest
34 | *.spec
35 |
36 | # Installer logs
37 | pip-log.txt
38 | pip-delete-this-directory.txt
39 |
40 | # Unit test / coverage reports
41 | htmlcov/
42 | .tox/
43 | .nox/
44 | .coverage
45 | .coverage.*
46 | .cache
47 | nosetests.xml
48 | coverage.xml
49 | *.cover
50 | *.py,cover
51 | .hypothesis/
52 | .pytest_cache/
53 |
54 | # Translations
55 | *.mo
56 | *.pot
57 |
58 | # Django stuff:
59 | *.log
60 | local_settings.py
61 | db.sqlite3
62 | db.sqlite3-journal
63 |
64 | # Flask stuff:
65 | instance/
66 | .webassets-cache
67 |
68 | # Scrapy stuff:
69 | .scrapy
70 |
71 | # Sphinx documentation
72 | docs/_build/
73 |
74 | # PyBuilder
75 | target/
76 |
77 | # Jupyter Notebook
78 | .ipynb_checkpoints
79 |
80 | # IPython
81 | profile_default/
82 | ipython_config.py
83 |
84 | # pyenv
85 | .python-version
86 |
87 | # pipenv
88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies
90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not
91 | # install all needed dependencies.
92 | #Pipfile.lock
93 |
94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow
95 | __pypackages__/
96 |
97 | # Celery stuff
98 | celerybeat-schedule
99 | celerybeat.pid
100 |
101 | # SageMath parsed files
102 | *.sage.py
103 |
104 | # Environments
105 | .env
106 | .venv
107 | env/
108 | venv/
109 | ENV/
110 | env.bak/
111 | venv.bak/
112 |
113 | # Spyder project settings
114 | .spyderproject
115 | .spyproject
116 |
117 | # Rope project settings
118 | .ropeproject
119 |
120 | # mkdocs documentation
121 | /site
122 |
123 | # mypy
124 | .mypy_cache/
125 | .dmypy.json
126 | dmypy.json
127 |
128 | # Pyre type checker
129 | .pyre/
130 |
131 | .DS_Store
132 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 wolverinn
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Python-tools
2 | Useful tools implemented with Python in 200 lines or less.
3 |
4 | ### [中文版本](./README_cn.md)
5 |
6 | This repository is a collection of various Python scripts I've written since I began to use Python in 2018. You can use these tools to improve efficiency, or, you can use them as small projects to practice Python :)
7 |
8 | These tools are very lightweight. Each has only one single Python file with around **100 lines** of code and very few third-party libraries. The tools are made for various purposes, such as build a **free ip pool** for crawlers:globe_with_meridians:, **increase page views**:eyeglasses:, **record the computer screen**:movie_camera:, **monitor net speed**:satellite:, **hide files**:books:, **sync files**:file_folder: and so on. Hope you can find something you like.:heart:
9 |
10 | Welcome to contribute!
11 |
12 | (PS: *The usage of each tool is explained in their .py file*)
13 |
14 | ## Directory
15 | - [Screen Recorder:movie_camera:](#screen-recordermovie_camera----simple-screen-recorder)
16 | - [Build your own free ip pool:globe_with_meridians:](#build-your-own-free-ip-poolglobe_with_meridians----free-ip-pool)
17 | - [Monitor computer net speed:satellite:](#monitor-computer-net-speedsatellite----simple-net-speed-monitor)
18 | - [Increase page views:eyeglasses:](#increase-page-viewseyeglasses)
19 | - [File sync:file_folder:](#file-syncfile_folder----portable-sync)
20 | - [Simple tool to hide files:books:](#simple-tool-to-hide-filesbooks----hide-file)
21 | - [Edit "send to" menu](#edit-send-to-menu----send-to-editor)
22 | - [Get all Windows Focus images on your computer with one click](#get-all-windows-focus-images-on-your-computer-with-one-click----windows-focus)
23 | - [zhihu video downloader:beginner:](#zhihu-video-downloaderbeginner----zhihu-video-downloader)
24 | - [Crawls zhihu answers and generate wordcloud:book:](#crawls-zhihu-answers-and-generate-wordcloudbook----zhihu-answer-wordcloud)
25 | - [Save a web page to markdown](#save-a-web-page-to-markdown----web2md)
26 | - [Run any py](#run-any-py----run_any_py)
27 | - [Get an English name](#get-an-english-name----ename)
28 | - [Get random UserAgent](#get-random-useragent----random-useragents)
29 |
30 | -------
31 |
32 | ### Screen Recorder:movie_camera: -- [simple-screen-recorder](simple_screen_recorder.py)
33 |
34 | > Record the computer screen using python and ffmpeg. (Graphical User Interface)
35 |
36 | Functions:
37 |
38 | - Self-define save path. Self-define **frame** and **resolution**.
39 | - Automatically save settings, and load the previous settings when opened the next time.
40 | - A 3-second hint before recording.
41 | - Press F10 to stop recording.
42 |
43 |
44 |

45 |
46 |
47 | ([Click here to download](https://github.com/wolverinn/Python-tools/releases/tag/v1.0) executable)
48 |
49 | ### Build your own free ip pool:globe_with_meridians: -- [free-ip-pool](free_ip_pool.py)
50 |
51 | > Self-made ip pool stored in SQLite3, crawling free proxies from websites that offer them.
52 |
53 | Functions:
54 |
55 | - Crawls ip from 3 websites that offer free high-anomonous ip and stores them in SQLite3.
56 | - Validate the ip and delete invalid ip.
57 |
58 | ### Monitor computer net speed:satellite: -- [simple-net-speed-monitor](net_speed_monitor.pyw)
59 |
60 | > A simple net speed monitor using python3 tkinter library. (Graphical User Interface)
61 |
62 | A simple net speed monitor that shows the upload and download speed of a computer in real time.
63 |
64 |
65 |

66 |
67 |
68 | Right-click menu functions:
69 |
70 | - Adjust position (and auto-save the setting)
71 | - Adjust transparency (auto-save)
72 | - Re-start monitoring
73 |
74 |
75 |

76 |
77 |
78 | ([Click here to download](https://github.com/wolverinn/Python-tools/releases/tag/v1.1) executable)
79 |
80 | ### Increase page views:eyeglasses:
81 |
82 | Input an URL, the script will view this page continuously to increase page views. Implemented with selenium. Can be used to increase the views of blogs.
83 |
84 | - Increase views by page views:[power-views](power_views.py)
85 |
86 | Implemented by using incognito mode to view the webpage.
87 |
88 | - Increase views by unique users:[ip-pool-browse](ip_pool_browse.py)
89 |
90 | Implemented with ip pool.
91 |
92 | ### File sync:file_folder: -- [portable-sync](portable_sync.py)
93 |
94 | > A tool to sync the files in the computer to the portable devices, including auto-update and deletion.
95 |
96 | This is a handy synchronization tool that can automatically synchronize folders on your computer to a portable device (U disk / mobile hard disk ...). You can customize the folders you want to sync (you can choose multiple), the suffixes of files that you don't want to synchronize will be automatically blocked, and you can choose what to do when the files are updated or deleted.
97 |
98 | Personally, I think it's a fragile way to sync your files on clouds and a more reliable way is to sync files to portable devices. However, when copying files on Windows, first, it won't check whether the file has been changed. It either skips or overwrites. Besides, it can't delete files when you copy, which is far from the demands of synchronization. So I wrote this simple Python tool.
99 |
100 |
101 |

102 |
103 |
104 | ### Simple tool to hide files:books: -- [hide-file](hide_file.py)
105 |
106 | Hide files/folders in Windows (haven't tried Linux). Protect files in a simple way.
107 |
108 | When hidden, others won't be able to see the files/folders in explorer, and won't see it using ```ls``` command either, which is enough for normal needs.
109 |
110 |
111 |

112 |
113 |
114 | ### Edit "send to" menu -- [send-to-editor](send_to_editor.py)
115 |
116 | Delete content in "send to" menu. Add a path or an application to send-to.
117 |
118 |
119 |

120 |
121 |
122 | ### Get all Windows Focus images on your computer with one click -- [windows-focus](windows_focus.py)
123 |
124 | Windows focus images are beautiful and are updated frequently on your computer. However, saving them is a hassle:
125 |
126 | - The picture storage path is too complicated, you must write it down in Notepad, copy and paste it when you use it;
127 | - After entering the image storage path, you will find that all files have no suffix, you must manually add the ``` .jpg ``` suffix to view the image;
128 | - After making it to a picture format, you will find that many pictures are actually only a part of a complete picture, such as size ```488x216```. it will take a long time to find the one you really want.
129 |
130 | This small tool can scan the path directly, remove those incomplete pictures, and save other pictures to the current directory. It's very trouble-free.
131 |
132 | ### zhihu video downloader:beginner: -- [zhihu-video-downloader](zhihu_video_downloader.py)
133 |
134 | > Download videos from zhihu.com using python3 and ffmpeg. (Graphical User Interface)
135 |
136 |
137 |

138 |
139 |
140 | ([Click here to download](https://github.com/wolverinn/Python-tools/releases/tag/v1.0) executable.)
141 |
142 | ### Crawls zhihu answers and generate wordcloud:book: -- [zhihu-answer-wordcloud](zhihu_answer_wordcloud.py)
143 |
144 | ### Save a web page to markdown -- [web2md](web2md.py)
145 |
146 | Calls a third-party library, and saves the web page as markdown, which is suitable for relatively simple web pages, such as some articles. Complicated webpages cannot guarantee the typesetting of the saved markdown. The advantage of saving a web page as markdown instead of PDF is that it is small and easier to modify。
147 |
148 | ### Run any py -- [run_any_py](run_any_py.py)
149 |
150 | Useful when there're a lot of Python files in a directory. You can simply input a number to run a Python script and you can do it over and over again. It's a lot easier than inputting ```python3 XXX.py```
151 |
152 | ### Get an English name -- [ename](ename.py)
153 |
154 | Generate an English name based on Chinese name and gender. Using the API provided by shanbay.
155 |
156 | ### Get random UserAgent -- [random-userAgents](random_userAgents.py)
157 |
158 | Get a random User Agent, useful for web crawling.
159 |
160 | *Inspired by [GitHub - geekcomputers/Python: My Python Examples](https://github.com/geekcomputers/Python)*
161 |
--------------------------------------------------------------------------------
/README_cn.md:
--------------------------------------------------------------------------------
1 | # Python-tools
2 | Useful tools implemented with Python in 200 lines or less.
3 |
4 | ### [English version](./README.md)
5 |
6 | 这个 repository 收集了我从 2018 年开始用 Python 以来,写的一些小工具,涵盖了爬虫、系统操作等方面。你可以使用这些工具来解决一些问题,提高生产效率;或者,也可以将它们作为小项目练习 Python 这门语言~
7 |
8 | 我编写的这些工具都比较轻量级,只有一个 Python 文件,**100行**左右的代码,并且只调用了很少的第三方库或者只需要内置库就OK。这些工具涉及到的方面很多,包括建立爬虫的**免费IP池**:globe_with_meridians:,**刷网页浏览量**:eyeglasses:,**爬取知乎答案**:book:,**下载知乎视频**:beginner:;**屏幕录制**:movie_camera:,**网速监测**:satellite:工具,**文件隐藏**:books:,文件**同步工具**:file_folder:等等。希望你能从中找到自己喜欢的:heart:
9 |
10 | 如果你有新的想法,或者对代码的优化,欢迎提 issues 或者 pull request !
11 |
12 | (PS: *每个工具的用法都写在了对应的.py文件中,部分工具我生成了exe文件可以直接运行*)
13 |
14 | ## 目录
15 | - [屏幕录制工具:movie_camera:](#屏幕录制工具movie_camera----simple-screen-recorder)
16 | - [知乎视频下载器:beginner:](#知乎视频下载器beginner----zhihu-video-downloader)
17 | - [建立免费IP池:globe_with_meridians:](#建立免费ip池globe_with_meridians----free-ip-pool)
18 | - [网速实时监测:satellite:](#网速实时监测satellite----simple-net-speed-monitor)
19 | - [刷网页浏览量:eyeglasses:](#刷网页浏览量eyeglasses)
20 | - [文件同步工具:file_folder:](#文件同步工具file_folder----portable-sync)
21 | - [文件隐藏小工具:books:](#文件隐藏小工具books----hide-file)
22 | - [爬取知乎回答并生成词云图:book:](#爬取知乎回答并生成词云图book----zhihu-answer-wordcloud)
23 | - [修改右键“发送到”菜单](#修改右键发送到菜单----send-to-editor)
24 | - [一键获取Windows聚焦的图片](#一键获取windows聚焦的图片----windows-focus)
25 | - [Show off in front of your classmates](#show-off-in-front-of-your-classmates----pocketuni-crack)
26 | - [将网页文章保存为markdown](#将网页文章保存为markdown----web2md)
27 | - [Run any py](#run-any-py----run_any_py)
28 | - [取一个地道英文名](#取一个地道英文名----ename)
29 | - [获取随机的UserAgent](#获取随机的useragent----random-useragents)
30 |
31 | ------
32 |
33 | ### 屏幕录制工具:movie_camera: -- [simple-screen-recorder](simple_screen_recorder.py)
34 |
35 | > Record the computer screen using python and ffmpeg. (图形操作界面)
36 |
37 | 功能:
38 |
39 | - 选择保存位置,选择录制**帧数**和**分辨率**
40 | - 设置自动保存,下次打开时会自动加载上次的设置
41 | - 开始录制之前会有3秒提示
42 | - 结束录制按下F10即可
43 |
44 |
45 |

46 |
47 |
48 | ([点此下载](https://github.com/wolverinn/Python-tools/releases/tag/v1.0)可执行exe文件)
49 |
50 | ### 知乎视频下载器:beginner: -- [zhihu-video-downloader](zhihu_video_downloader.py)
51 |
52 | > Download videos from zhihu.com using python3 and ffmpeg. (图形操作界面)
53 |
54 | 通过知乎视频id下载视频到当前目录,可一次性添加多个id下载。视频id就是知乎视频链接末尾的数字,在知乎收藏夹中打开带有视频的回答,便可找到视频id
55 |
56 |
57 |

58 |
59 |
60 | ([点此下载](https://github.com/wolverinn/Python-tools/releases/tag/v1.0)可执行exe文件)
61 |
62 | ### 建立免费IP池:globe_with_meridians: -- [free-ip-pool](free_ip_pool.py)
63 |
64 | > Self-made ip pool stored in SQLite3, crawling free proxies from websites that offer them.
65 |
66 | 功能:
67 |
68 | - 从3个提供免费高匿IP的网站上,爬取IP保存到SQLite3数据库中,构建IP池
69 | - 测试数据库中IP的有效性,删除失效的IP
70 |
71 | ### 网速实时监测:satellite: -- [simple-net-speed-monitor](net_speed_monitor.pyw)
72 |
73 | > A simple net speed monitor using python3 tkinter library. (图形界面)
74 |
75 | 一个简洁的网速监视器,实时显示计算机上传和下载速度。
76 |
77 |
78 |

79 |
80 |
81 | 右键菜单支持更多功能:
82 |
83 | - 调整位置 Adjust position :可按键调整,也可输入坐标调整。调整完后选择保存则下次自动应用新位置
84 | - 调整透明度 Adjust transparency :新的设置会保存,下次自动加载
85 | - 重启监测:若关闭调整窗口后(由于直接关闭了调整窗口而不是点击“save”)发现监测停止,可右键“Start monitoring”或者直接双击,就可开始监测
86 | - 退出程序
87 |
88 |
89 |

90 |
91 |
92 | ([点此下载](https://github.com/wolverinn/Python-tools/releases/tag/v1.1)可执行exe文件)
93 |
94 | ### 刷网页浏览量:eyeglasses:
95 |
96 | 输入一个URL,程序会不断访问,来增加这个网页的访问量。使用 selenium 实现。可以用在博客文章刷阅读量
97 |
98 | - 按浏览次数刷:[power-views](power_views.py)
99 |
100 | 实现方式是通过隐身模式不断访问网页,这种方式只能增加浏览次数,但是网站不会增加浏览的人数
101 |
102 | - 按浏览人数刷:[ip-pool-browse](ip_pool_browse.py)
103 |
104 | 通过上面提到的IP池实现,每次都用不同的IP访问网页,网站会计数为不同的人。
105 |
106 | ### 文件同步工具:file_folder: -- [portable-sync](portable_sync.py)
107 |
108 | > A tool to sync the files in the computer to the portable devices, including auto-update and deletion.
109 |
110 | 这是一个小巧的同步工具,可以自动将电脑上的文件夹同步到移动设备(U盘/移动硬盘...)上。可以自定义想要同步的文件夹(可以选多个),对不想同步的文件后缀会自动屏蔽,还可以选择当文件发生更新或删除时如何处理。
111 |
112 | 之所以写这样一个同步工具,是因为个人觉得将东西同步在云盘上其实是一个很脆弱的做法,就算是自己搭建的云盘,也说不准就崩了,觉得最稳妥的还是同步到自己的移动硬盘或者U盘。然后试了试,发现Windows复制文件夹的时候,首先不会检测文件是否有变化,要么跳过,要么选择替换,效率很低,而且多余的文件不会删除,相当于是合并,这显然和同步的要求相去甚远,所以只好自己写一个简单的同步的 Python 工具。既可以方便快速地访问,又保证了一定的个人信息安全。
113 |
114 |
115 |

116 |
117 |
118 | ### 文件隐藏小工具:books: -- [hide-file](hide_file.py)
119 |
120 | 隐藏Windows文件系统(Linux没试过)下的文件或者文件夹,以一种极简的方式达到保护文件的目的。
121 |
122 | 其他人使用文件资源管理器打开文件所在目录的时候,无法看到该文件。就算设置了“显示隐藏的文件(夹)”也看不到。在命令行中使用```dir```或者```ls```命令也看不到。对于一般需求的文件保护来说足够了。
123 |
124 |
125 |

126 |
127 |
128 | ### 爬取知乎回答并生成词云图:book: -- [zhihu-answer-wordcloud](zhihu_answer_wordcloud.py)
129 |
130 | 首先实现了批量爬取知乎某个问题下的答案,并以markdown形式保存到本地。
131 |
132 | 之后再对markdown文件中的内容进行分析,使用了中文分词工具和词云图第三方库,生成某一问题下的热门答案的词云图。
133 |
134 | ### 修改右键“发送到”菜单 -- [send-to-editor](send_to_editor.py)
135 |
136 | 既可以删除“发送到”菜单中你不想要的内容,也可以往里面添加路径,或者添加某个应用程序,实现用此应用程序打开。
137 |
138 |
139 |

140 |
141 |
142 | ### 一键获取Windows聚焦的图片 -- [windows-focus](windows_focus.py)
143 |
144 | Windows聚焦的图片比较漂亮,会经常在电脑上更新。但是,保存Windows聚焦的图片是一件很麻烦的事情:
145 |
146 | - Windows聚焦的图片存储路径太复杂,必须记在记事本上,用的时候复制粘贴一遍;
147 | - 进入了图片的存储路径之后,会发现全都是没有后缀名的文件,必须手动添加```.jpg```的后缀才能得到图片;
148 | - 变成图片格式之后,才会发现很多图片其实只是某一张完整图片的一个部分,比如```488x216```这种大小,找了好久才找到真正要的那张
149 |
150 | 这个小工具可以直接扫描该路径,剔除掉那些并不完整的图,把其它图片保存到当前目录,非常省心。
151 |
152 | ### Show off in front of your classmates -- [pocketuni-crack](pocketuni_crack.zip)
153 |
154 | > 这是一个爬虫工具,但和一般的Python爬虫不同,它可以让你小小地在同学面前装个逼。当然,前提是如果你在上学的某个时候,需要用到 pocketuni 这个平台,给一些活动投票什么的。你可以用这个工具在上面大量注册一些用户,从而实现刷票。
155 |
156 | ### 将网页文章保存为markdown -- [web2md](web2md.py)
157 |
158 | 本质上是调用了一个第三方库的功能,将网页保存为markdown,适合用在比较简洁的网页,比如一些文章,像微信公众号的文章什么的。复杂一些的网页就不能保证保存下来的markdown的排版了。将网页保存为markdown而不是PDF的好处就是体积小,而且修改更加方便。
159 |
160 | ### Run any py -- [run_any_py](run_any_py.py)
161 |
162 | 如果一个目录下面有很多 Python 文件,打开命令行再输入```python xxx.py```有些麻烦。而这个工具会一直开启,只需要输入一个数字就可以运行对应的 Python 文件了。
163 |
164 | ### 取一个地道英文名 -- [ename](ename.py)
165 |
166 | 输入中文名和性别,得到一个地道的英文名。其实就是调用了扇贝网的接口。
167 |
168 | ### 获取随机的UserAgent -- [random-userAgents](random_userAgents.py)
169 |
170 | 里面收集了很多不同的 UserAgent ,爬虫的时候可以用到,获取一个随机的 UserAgent .
171 |
172 | *Inspired by [GitHub - geekcomputers/Python: My Python Examples](https://github.com/geekcomputers/Python)*
173 |
--------------------------------------------------------------------------------
/_v_images/20191220185122289_8134.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wolverinn/Python-tools/7a317475b32915db1d8cb8abea2d5ca476173fef/_v_images/20191220185122289_8134.png
--------------------------------------------------------------------------------
/_v_images/20191220190307589_28533.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wolverinn/Python-tools/7a317475b32915db1d8cb8abea2d5ca476173fef/_v_images/20191220190307589_28533.png
--------------------------------------------------------------------------------
/_v_images/20191220191832613_15118.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wolverinn/Python-tools/7a317475b32915db1d8cb8abea2d5ca476173fef/_v_images/20191220191832613_15118.png
--------------------------------------------------------------------------------
/_v_images/20191220193145179_20665.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wolverinn/Python-tools/7a317475b32915db1d8cb8abea2d5ca476173fef/_v_images/20191220193145179_20665.png
--------------------------------------------------------------------------------
/_v_images/20191220203803479_15260.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wolverinn/Python-tools/7a317475b32915db1d8cb8abea2d5ca476173fef/_v_images/20191220203803479_15260.png
--------------------------------------------------------------------------------
/_v_images/20191220204054677_12422.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wolverinn/Python-tools/7a317475b32915db1d8cb8abea2d5ca476173fef/_v_images/20191220204054677_12422.png
--------------------------------------------------------------------------------
/_v_images/20191220204416988_4614.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wolverinn/Python-tools/7a317475b32915db1d8cb8abea2d5ca476173fef/_v_images/20191220204416988_4614.jpg
--------------------------------------------------------------------------------
/chineseStopWords.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wolverinn/Python-tools/7a317475b32915db1d8cb8abea2d5ca476173fef/chineseStopWords.txt
--------------------------------------------------------------------------------
/ename.py:
--------------------------------------------------------------------------------
1 | import requests
2 | from bs4 import BeautifulSoup
3 |
4 | '''
5 | @author: github/wolverinn
6 | @date: 04/27/2018
7 |
8 | requirements:
9 | Python 3.x
10 | requests
11 | bs4
12 |
13 | 功能: 根据中文名和性别,起一个地道英文名,调用了扇贝网的接口
14 | function: Generate an English name based on Chinese name and gender. Using the API provided by shanbay
15 | '''
16 |
17 | url1="http://ename.shanbay.com.cn/?gender="
18 | url2="&name_cn="
19 | url3="&for_friend=0"
20 |
21 | n=input("input your chinese name:")
22 | g=input("input your gender(m for male/f for female)")
23 | if g=="m":g="1"
24 | if g=="f":g="0"
25 | def get_name(n):
26 | url=url1+g+url2+n+url3
27 | nameweb = requests.get(url)
28 | soup = BeautifulSoup(nameweb.text, 'html.parser')
29 | name1 = soup.find('div', attrs={'class': 'name-container'})
30 | name = name1.find('span', attrs={'class': 'name-en'})
31 | print(name.string)
32 |
33 | i=1
34 | while i==1:
35 | get_name(n)
36 | con=input("continue?y/n")
37 | if con=="y" or con=="":
38 | i=1
39 | else:
40 | i=0
41 |
--------------------------------------------------------------------------------
/free_ip_pool.py:
--------------------------------------------------------------------------------
1 | import requests
2 | import os
3 | import webbrowser
4 | from bs4 import BeautifulSoup
5 | import sqlite3
6 | import json
7 | import time
8 | from random_userAgents import GetUserAgent
9 | from selenium import webdriver
10 | import re
11 |
12 | '''
13 | @author: github/wolverinn
14 | @date: 01/22/2019
15 |
16 | requirements:
17 | Python 3.x
18 | requests
19 | bs4
20 | selenium
21 | chrome
22 | chrome driver(add to PATH)
23 | random_userAgents.py
24 |
25 | function:
26 | Crawls free proxies from several websites that offer them, and save them to a database to build an ip pool.
27 | Also validates the ip in the pool.
28 |
29 | 待改进:使用多线程验证IP有效性
30 | TODO: Validate ip using multiprocess
31 | '''
32 |
33 | conn = sqlite3.connect('pool.db')
34 | c = conn.cursor()
35 | try:
36 | c.execute('''CREATE TABLE IP
37 | (ID INTEGER PRIMARY KEY AUTOINCREMENT,
38 | IPPORT VARCHAR(50) NOT NULL UNIQUE);''')
39 | conn.commit()
40 | print("created new table IP")
41 | except:
42 | pass
43 | print("existing proxies in table IP:{}".format(str(len(list(c.execute("SELECT * FROM IP"))))))
44 |
45 | def get_xici():
46 | print("getting ip from xicidaili.com...")
47 | headers_xici = {
48 | "Host": "www.xicidaili.com",
49 | "Referer": "https://www.xicidaili.com/nn/1",
50 | "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36",
51 | }
52 | # webbrowser.open("https://www.xicidaili.com/nn/1")
53 | # cookie = input("input a valid cookie for xicidaili.com first:")
54 | # headers_xici[""]
55 | # 只爬取xici前3页的IP,后面的验证时间太久了失效的可能性大,ps:这个网站会封IP...
56 | for i in range(3):
57 | ses = requests.session()
58 | ses.get("https://www.xicidaili.com/nn/1")
59 | xici_url = "https://www.xicidaili.com/nn/{}".format(str(i+1))
60 | xici_req = requests.get(xici_url,headers=headers_xici)
61 | print(xici_req.status_code)
62 | if xici_req.status_code == 200:
63 | soup = BeautifulSoup(xici_req.text,'html.parser')
64 | ip_table = soup.find('table',attrs={'id':'ip_list'})
65 | trs = ip_table.find_all('tr')
66 | for i,tr in enumerate(trs):
67 | if i>0:
68 | td = tr.find_all('td')
69 | ip_port = td[1].string + ":" + td[2].string
70 | print(ip_port)
71 | insert_cmd = "INSERT INTO IP (IPPORT) VALUES ('{}')".format(ip_port)
72 | try:
73 | c.execute(insert_cmd)
74 | conn.commit()
75 | except:
76 | pass
77 | # temp_set.add(ip_port)
78 | time.sleep(2)
79 |
80 | def get_66ip():
81 | print("getting ip from 66ip.cn...")
82 | headers = {
83 | "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
84 | "Accept-Encoding": "gzip, deflate",
85 | "Accept-Language": "en-US,en;q=0.9",
86 | "Cache-Control": "max-age=0",
87 | "Connection": "keep-alive",
88 | #"Cookie": "yd_cookie=14383921-5354-46e8e6700ba090ad2c96a202cbb6d2145786; _ydclearance=3b1c64af06ff7ca0605ca864-eaf1-4a18-bbb8-b239a592ed41-1547569877",
89 | "DNT": "1",
90 | "Host": "www.66ip.cn",
91 | "Upgrade-Insecure-Requests": "1",
92 | "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36",
93 | }
94 | webbrowser.open("http://www.66ip.cn/areaindex_1/1.html")
95 | cookie = input("input a valid cookie for 66ip.cn first:")
96 | headers["Cookie"] = cookie
97 | ses = requests.session()
98 | for i in range(26):
99 | fucking_url = "http://www.66ip.cn/areaindex_{}/1.html".format(str(i+1)) #每个地区只有第一页的是最近验证的
100 | addr = ses.get(fucking_url,headers=headers)
101 | print("getting the {} page of 66ip.cn...".format(str(i)))
102 | if addr.status_code == 200:
103 | soup = BeautifulSoup(addr.content,'html.parser')
104 | table = soup.find_all('table')[2]
105 | trs = table.find_all('tr')
106 | for i,tr in enumerate(trs):
107 | if i > 0:
108 | td = tr.find_all('td')
109 | ip_port = td[0].string+ ":" + td[1].string
110 | # print(ip_port)
111 | # temp_set.add(ip_port)
112 | try:
113 | insert_cmd = "INSERT INTO IP (IPPORT) VALUES ('{}')".format(ip_port)
114 | c.execute(insert_cmd)
115 | conn.commit()
116 | except:
117 | pass
118 | time.sleep(0.5)
119 |
120 | def get_freeproxylist():
121 | print("getting ip from freeproxylist...")
122 | fpl_url = "http://proxylist.fatezero.org/proxy.list"
123 | proxy_list = requests.get(fpl_url)
124 | if proxy_list.status_code == 200:
125 | lines = proxy_list.text.split('\n')
126 | for i,line in enumerate(lines):
127 | try:
128 | content = json.loads(line)
129 | except:
130 | continue
131 | if str(content["anonymity"]) == "high_anonymous" and str(content["type"]) == "http" and str(content["country"]) == "CN":
132 | ip_port = str(content["host"]) + ":" + str(content["port"])
133 | # print(ip_port)
134 | # temp_set.add(ip_port)
135 | insert_cmd = "INSERT INTO IP (IPPORT) VALUES ('{}')".format(ip_port)
136 | c.execute(insert_cmd)
137 | conn.commit()
138 | if i%1000 == 0:
139 | print("processed {} in free proxy list".format(str(i)))
140 |
141 | def add_ip():
142 | get_freeproxylist()
143 | get_xici()
144 | get_66ip()
145 | print("total ip count:{}".format(str(len(list(c.execute("SELECT * FROM IP"))))))
146 |
147 | def test_ip():
148 | ip_list = list(c.execute("SELECT * FROM IP"))
149 | test_url = "http://www.baidu.com/"
150 | for i,ip_port in enumerate(ip_list):
151 | if i>0 and i%100 is 0:
152 | print("testing {} ip".format(str(i)))
153 | user_agent = GetUserAgent()
154 | header = {
155 | "User-Agent":user_agent,
156 | }
157 | proxy = {
158 | 'http': ip_port[1],
159 | # 'https': 'https://' + proxy,
160 | }
161 | try:
162 | r = requests.get(test_url,headers=header,proxies=proxy,timeout=5)
163 | print(r.status_code)
164 | except:
165 | del_cmd = "DELETE FROM IP WHERE IPPORT = \"" + ip_port[1] + "\""
166 | c.execute(del_cmd)
167 | conn.commit()
168 | print("failed:{}".format(ip_port[1]))
169 | print("total ip count:{}".format(str(len(list(c.execute("SELECT * FROM IP"))))))
170 |
171 | while(1):
172 | print("1) add more ip to ip pool")
173 | print("2) test avaliability of ip in the ip pool")
174 | print("3) exit")
175 | user_choice = input("\ninput your choice: ")
176 | if user_choice == "1":
177 | add_ip()
178 | elif user_choice == "2":
179 | test_ip()
180 | elif user_choice == "3":
181 | break
182 | else:
183 | continue
184 | conn.close()
185 |
--------------------------------------------------------------------------------
/hide_file.py:
--------------------------------------------------------------------------------
1 | import os
2 | from tkinter import *
3 | from tkinter import filedialog,messagebox
4 |
5 | '''
6 | @author: github/wolverinn
7 | @date: 12/12/2018
8 |
9 | requirements:
10 | - Python 3.x
11 |
12 | function:
13 | Hide files or folders in Windows filesystem.
14 | Hide them visually. Anyone using the file explorer even with the option "show hidden files" can't see the files/folders.
15 | Using command "dir" or "ls" can't show the files/folders either.
16 | However, using tab auto-complete in command line will show the filename, if the person knows the first few words of the file.
17 | To restore the file to unhidden state, you have to remember the filename you have made hidden.
18 | '''
19 |
20 | def choose_file():
21 | filename = filedialog.askopenfilename()
22 | # filename = filedialog.askdirectory()
23 | if filename != '':
24 | l3.config(text = filename)
25 | b3['state'] = 'normal'
26 | else:
27 | l3.config(text = "(您没有选择任何文件)")
28 | def choose_directory():
29 | # filename = filedialog.askopenfilename()
30 | filename = filedialog.askdirectory()
31 | if filename != '':
32 | l3.config(text = filename)
33 | b3['state'] = 'normal'
34 | else:
35 | l3.config(text = "(您没有选择任何文件(夹))")
36 |
37 | def choose_directory1():
38 | # filename = filedialog.askopenfilename()
39 | filename = filedialog.askdirectory()
40 | if filename != '':
41 | l7.config(text = filename)
42 | b5['state'] = 'normal'
43 | else:
44 | l7.config(text = "(您没有选择任何路径)")
45 |
46 | def hide_file():
47 | filename = l3["text"]
48 | # print(filename)
49 | hide_cmd = "attrib +s +a +h +r "+filename
50 | os.system(hide_cmd)
51 | b3['state'] = DISABLED
52 | l3.config(text = "(您没有选择任何文件(夹))")
53 | messagebox.showinfo('提示','hide ok')
54 |
55 | def unhide():
56 | filename = e1.get()
57 | filepath = l7["text"]
58 | unhide_cmd = "attrib -s -a -h -r "+filepath+'\\'+filename
59 | os.system(unhide_cmd)
60 | b5['state'] = DISABLED
61 | l7.config(text = "(您没有选择任何路径)")
62 | messagebox.showinfo('提示','unhide ok')
63 |
64 | root = Tk()
65 | root.geometry("320x480")
66 | root.wm_title("file hidder")
67 | l_hide = Label(root,text="********HIDE********")
68 | b1 = Button(root,text="选择文件",command=choose_file)
69 | l1 = Label(root,text = '或')
70 | b2 = Button(root,text="选择文件夹",command=choose_directory)
71 | l2 = Label(root,text='你选择的是')
72 | l3 = Label(root,text="(您没有选择任何文件(夹))")
73 | b3 = Button(root,text="confirm hide",state=DISABLED,command=hide_file)
74 | l4 = Label(root,text="----------------------------------------------------------")
75 | l5 = Label(root,text="tips:在浏览器中打开路径可查看隐藏文件")
76 | l6 = Label(root,text="----------------------------------------------------------")
77 | l_unhide = Label(root,text="********UNHIDE********")
78 | b4 = Button(root,text="选择文件或文件夹所在路径",command=choose_directory1)
79 | l7 = Label(root,text='')
80 | l8 = Label(root,text="输入文件或文件夹名")
81 | e1 = Entry(root)
82 | b5 = Button(root,text="unhide",state=DISABLED,command=unhide)
83 |
84 | l_hide.pack()
85 | b1.pack()
86 | l1.pack()
87 | b2.pack()
88 | l2.pack()
89 | l3.pack()
90 | b3.pack()
91 | l4.pack()
92 | l5.pack()
93 | l6.pack()
94 | l_unhide.pack()
95 | b4.pack()
96 | l7.pack()
97 | l8.pack()
98 | e1.pack()
99 | b5.pack()
100 | root.mainloop()
--------------------------------------------------------------------------------
/ip_pool_browse.py:
--------------------------------------------------------------------------------
1 | import sqlite3
2 | from selenium import webdriver
3 | from random_userAgents import GetUserAgent
4 | import re
5 | # import time
6 |
7 | '''
8 | @author: github/wolverinn
9 | @date: 01/31/2019
10 |
11 | requirements:
12 | Python 3.x
13 | random_userAgents.py
14 | free-ip-pool.py: to create and add ip to ip pool
15 |
16 | function:
17 | Use the proxies in the ip pool to browse the web pages. To increase the viewers of the web page.
18 | '''
19 |
20 | conn = sqlite3.connect('pool.db')
21 | c = conn.cursor()
22 | ip_list = list(c.execute("SELECT * FROM IP"))
23 | print("existing proxies in table IP:{}".format(str(len(ip_list))))
24 |
25 | def auto_open(url,ip_port):
26 | chrome_options = webdriver.ChromeOptions()
27 | usr_agents = GetUserAgent()
28 | proxy_argument = "--proxy-server=http://" + ip_port
29 | ua_argument = 'User-Agent="'+usr_agents+'"'
30 | chrome_options.add_argument(proxy_argument)
31 | chrome_options.add_argument(ua_argument)
32 | chrome_options.add_argument('--headless')
33 | chrome_options.add_argument('--disable-gpu')
34 | chrome_options.add_argument('log-level=3')
35 | try:
36 | driver = webdriver.Chrome(chrome_options=chrome_options)
37 | # driver.set_page_load_timeout(6)
38 | # driver.set_script_timeout(6)
39 | driver.get(url)
40 | # time.sleep(0.5)
41 | a = driver.page_source
42 | if re.search("ERR_PROXY_CONNECTION_FAILED",a):
43 | print("connection error:{}".format(ip_port))
44 | driver.quit()
45 | return False
46 | else:
47 | print("200 OK")
48 | driver.quit()
49 | return True
50 | except:
51 | # time.sleep(3)
52 | driver.quit()
53 | print("timeout:{}".format(ip_port))
54 | return False
55 |
56 | url = input("input the url:")
57 | valid_sum = 0
58 | for i,ip_port in enumerate(ip_list):
59 | if i>0 and i%50 is 0:
60 | print("used {} ip".format(str(i)))
61 | print("ip valid:{}".format(str(valid_sum)))
62 | result = auto_open(url,ip_port[1])
63 | if result:
64 | valid_sum = valid_sum + 1
65 | else:
66 | del_cmd = "DELETE FROM IP WHERE IPPORT = \"" + ip_port[1] + "\""
67 | c.execute(del_cmd)
68 | conn.commit()
69 |
70 | conn.close()
--------------------------------------------------------------------------------
/net_speed_monitor.pyw:
--------------------------------------------------------------------------------
1 | import os
2 | import re
3 | import time
4 | import getpass
5 | from tkinter import *
6 |
7 | '''
8 | @author: github/wolverinn
9 | @date: 07/29/2018
10 |
11 | requirements: only Python 3
12 |
13 | 功能:实时显示计算机上传和下载速度
14 | function: Show the upload & download speed of the computer in real time
15 |
16 | 待改进:
17 | - 颜色不可自定义
18 | - 少数操作略显不流畅
19 | - 调整窗口布局可以改进
20 | - 没有流量统计功能
21 | TODO:
22 | - Support self-define color
23 | - Some operations are not smooth
24 | - "Adjust position" can be improved
25 | - Don't have the function for traffic statistics
26 |
27 | (本来生成exe的时候只想生成单个文件,但pyinstaller貌似-F -w同时使用的话生成的GUI程序无法调用os.popen())
28 | '''
29 |
30 | def start():
31 | while(True):
32 | #取一次数据开始计时
33 | count_start=time.time()
34 | raw_info = os.popen("netstat -e")
35 | temp = raw_info.readlines()
36 | info_str = temp[4]
37 | info = re.findall('\d+', info_str)
38 | upload_before = int(info[1])
39 | download_before = int(info[0])
40 | time.sleep(0.8)
41 | count_end=time.time()
42 | #取第二次数据结束计时
43 | raw_info = os.popen("netstat -e")
44 | temp = raw_info.readlines()
45 | info_str = temp[4]
46 | info = re.findall('\d+', info_str)
47 | upload_after = int(info[1])
48 | download_after = int(info[0])
49 | time_cost=count_end-count_start
50 | upload_speed=(upload_after-upload_before)/time_cost/1000
51 | download_speed=(download_after-download_before)/time_cost/1000
52 | str_upload_speed=str(upload_speed)
53 | str_download_speed=str(download_speed)
54 | if 100 1:
75 | position_xy[1] = position_xy[1] - 1
76 | else:
77 | pass
78 | geo = "+" + str(position_xy[0]) + "+" + str(position_xy[1])
79 | root.geometry(geo)
80 | root.update()
81 | posi_x.delete(0, len(posi_x.get()))
82 | posi_y.delete(0, len(posi_y.get()))
83 | posi_x.insert(END, str(position_xy[1]))
84 | posi_y.insert(END, str(position_xy[0]))
85 | ad_window.update()
86 | def ad_down():
87 | global position_xy
88 | position_xy[1] = position_xy[1] + 1
89 | geo = "+" + str(position_xy[0]) + "+" + str(position_xy[1])
90 | root.geometry(geo)
91 | root.update()
92 | posi_x.delete(0, len(posi_x.get()))
93 | posi_y.delete(0, len(posi_y.get()))
94 | posi_x.insert(END, str(position_xy[1]))
95 | posi_y.insert(END, str(position_xy[0]))
96 | ad_window.update()
97 | def ad_left():
98 | global position_xy
99 | position_xy[0] = position_xy[0] - 1
100 | geo = "+" + str(position_xy[0]) + "+" + str(position_xy[1])
101 | root.geometry(geo)
102 | root.update()
103 | posi_x.delete(0, len(posi_x.get()))
104 | posi_y.delete(0, len(posi_y.get()))
105 | posi_x.insert(END, str(position_xy[1]))
106 | posi_y.insert(END, str(position_xy[0]))
107 | ad_window.update()
108 | def ad_right():
109 | global position_xy
110 | position_xy[0] = position_xy[0] + 1
111 | geo = "+" + str(position_xy[0]) + "+" + str(position_xy[1])
112 | root.geometry(geo)
113 | root.update()
114 | posi_x.delete(0,len(posi_x.get()))
115 | posi_y.delete(0, len(posi_y.get()))
116 | posi_x.insert(END, str(position_xy[1]))
117 | posi_y.insert(END, str(position_xy[0]))
118 | ad_window.update()
119 | def mannual_adjust():
120 | global position_xy
121 | position_xy[1]=posi_x.get()
122 | position_xy[0]=posi_y.get()
123 | geo = "+" + str(position_xy[0]) + "+" + str(position_xy[1])
124 | root.geometry(geo)
125 | root.update()
126 | def save():
127 | global position_xy
128 | user=getpass.getuser()
129 | save_info_path="C:/users/"+str(user)+"/AppData/Roaming/net-speed-monitor-position"
130 | f=open(save_info_path,'w')
131 | f.write(str(position_xy[0]))
132 | f.write(',')
133 | f.write(str(position_xy[1]))
134 | f.close()
135 | ad_window.destroy()
136 | start()
137 | ad_window=Tk()
138 | ad_window.wm_title("Adjust Position")
139 | ad_window.geometry("420x360")
140 | label_x=Label(ad_window,text="x:")
141 | posi_x=Entry(ad_window)
142 | posi_x.insert(END, str(position_xy[1]))
143 | label_y=Label(ad_window,text="y:")
144 | posi_y=Entry(ad_window)
145 | posi_y.insert(END,str(position_xy[0]))
146 | ad_button=Button(ad_window,text="Adjust Position",command=mannual_adjust)
147 | line1=Label(ad_window,text="----------------------------------------")
148 | up_button=Button(ad_window,text="Up",command=ad_up)
149 | down_button=Button(ad_window,text="Down",command=ad_down)
150 | left_button=Button(ad_window,text="Left",command=ad_left)
151 | right_button=Button(ad_window,text="Right",command=ad_right)
152 | line2 = Label(ad_window, text="----------------------------------------")
153 | save_arg=Button(ad_window,text="Save setting",command=save)
154 | label_x.pack()
155 | posi_x.pack()
156 | label_y.pack()
157 | posi_y.pack()
158 | ad_button.pack()
159 | line1.pack()
160 | up_button.pack()
161 | down_button.pack()
162 | left_button.pack()
163 | right_button.pack()
164 | line2.pack()
165 | save_arg.pack()
166 | ad_window.mainloop()
167 |
168 | #设置调整透明度的函数
169 | def adjust_transparency():
170 | def adjust_trans_bn():
171 | global intransparency
172 | user=getpass.getuser()
173 | save_path2="C:/users/"+str(user)+"/AppData/Roaming/net-speed-monitor-tranparency"
174 | trans_num=ad_trans.get()
175 | intransparency=trans_num
176 | root.attributes("-alpha", trans_num)
177 | root.update()
178 | f=open(save_path2,'w')
179 | f.write(str(trans_num))
180 | f.close()
181 | trans.destroy()
182 | start()
183 | global intransparency
184 | trans=Tk()
185 | trans.geometry("300x200")
186 | trans.wm_title("Transparency")
187 | parency=Label(trans,text="不透明度:")
188 | ad_trans=Entry(trans)
189 | ad_trans.insert(END,intransparency)
190 | ad_button=Button(trans,text="确定",command=adjust_trans_bn)
191 | parency.pack()
192 | ad_trans.pack()
193 | ad_button.pack()
194 | trans.mainloop()
195 | #设置退出程序的函数
196 | def exit_netmonitor():
197 | root.destroy()
198 | #双击开始monitor
199 | def double_click_start(event):
200 | start()
201 | #打印欢迎界面,因为打包之后必须出现命令行的无奈选择
202 | # print('''
203 | # * * * * * * * * * * * * * * * * * *
204 | # * * * * * * * * * * * * * *
205 | # * * * * * * * * * -------- * * * * * * * * *
206 | # * * * * * * ** * * * * * *
207 | # * * * * * * * * * * * * *
208 | #
209 | # -------------------------You have entered the world of net-speed-monitor----------------------
210 | # ---------------------------------Please keep the window open----------------------------------
211 | # -----------------------------------------Enjoy it!--------------------------------------------
212 | # ''')
213 |
214 | #初始化窗口
215 | root = Tk()
216 | root.wm_attributes('-topmost',1)#始终置顶
217 | root.overrideredirect(True)
218 | user=getpass.getuser()
219 | file_path1="C:/users/"+str(user)+"/AppData/Roaming/net-speed-monitor-position"
220 | file_path2="C:/users/"+str(user)+"/AppData/Roaming/net-speed-monitor-tranparency"
221 | if os.path.exists(file_path1):
222 | f=open(file_path1,'r')
223 | position_xy=f.readline()
224 | position_xy=position_xy.split(",")
225 | f.close()
226 | else:
227 | position_xy = [970, 631]
228 | if os.path.exists(file_path2):
229 | f=open(file_path2,'r')
230 | intransparency=f.readline()
231 | f.close()
232 | else:
233 | intransparency=0.8
234 | try:
235 | position_xy[0]=int(position_xy[0])
236 | position_xy[1]=int(position_xy[1])
237 | intransparency=float(intransparency)
238 | except:
239 | position_xy = [970, 631]
240 | intransparency=0.8
241 | root.attributes("-alpha", intransparency)#窗口不透明度
242 | geo="+"+str(position_xy[0])+"+"+str(position_xy[1])
243 | root.geometry(geo)#设置窗口大小和位置
244 | menu=Menu(root)#设置右键菜单:退出程序以及调整方向
245 | menu.add_command(label="Start monitoring",command=start)
246 | menu.add_command(label="Adjust tranparency",command=adjust_transparency)
247 | menu.add_command(label="Adjust position",command=position_adjust)
248 | menu.add_command(label="Exit",command=exit_netmonitor)
249 | root.bind("",popmenu)
250 | root.bind("",double_click_start)
251 | up_info = Label(root,fg="red", text="U:--kb/s")
252 | down_info = Label(root,fg="green", text="D:--kb/s")
253 | up_info.after(600,start)#600ms后开始刷新窗口获取数据
254 | up_info.pack()
255 | down_info.pack()
256 | root.mainloop()
257 |
--------------------------------------------------------------------------------
/pocketuni_crack.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wolverinn/Python-tools/7a317475b32915db1d8cb8abea2d5ca476173fef/pocketuni_crack.zip
--------------------------------------------------------------------------------
/portable_sync.py:
--------------------------------------------------------------------------------
1 | import json
2 | import os
3 | import re
4 | import psutil
5 | import shutil
6 | import hashlib
7 |
8 | '''
9 | @author: github/wolverinn
10 | @date: 03/22/2019
11 |
12 | requirements:
13 | Python 3.x
14 | psutil
15 | setting.json
16 |
17 | function:
18 | Sync the files on computer to portable devices, including auto-update and deletion.
19 |
20 | 待改进:setting.json 可以直接放在U盘的同步文件夹中。setting.json可以直接不要U盘文件夹这一项,直接硬编码
21 | TODO: setting.json can be directly put in the /sync folder in u-drive. setting.json can abandon the setting of u-drive folders, but hard-coding instead.
22 | '''
23 |
24 | '''
25 | setting.json:
26 | At the minimum, you need to complete the "computer_locations"
27 |
28 | "computer_locations" is a list of locations in your computer that you want to sync
29 | "portable_device_folder" is the location in the portable device where your sync folder exists, you can also leave it blank and a default sync folder will be created automatically
30 | "ignore" is a list of suffixs to exclude those you don't want to sync
31 | "override_updates": "y" means when some files have changed, it will be automatically updated without asking; "n" means otherwise
32 | "override_delete": "y" means when some files no longer exist on the computer, automatically delete the files in the portable device without asking
33 | '''
34 |
35 | '''
36 | 先设置电脑中需要同步的文件夹的绝对路径
37 | 对应的U盘路径如果不设置则会自动检测U盘然后创建同步文件夹
38 | ignore填文件后缀名,出现在ignore中的文件后缀不会同步
39 | override_updates表示需要更新时是否询问
40 | override_delete表示需要删除时是否询问
41 | '''
42 |
43 | sync_folder = "" # 移动设备的同步文件夹路径
44 | portable_part = "" # 移动设备的盘符
45 | global dir_list # 需要同步的所有文件夹(包括子文件夹)
46 |
47 | # 获取移动设备的盘符,以及判断是否有移动设备插入,如没有则推出
48 | disk = psutil.disk_partitions()
49 | for single_disk in disk:
50 | attr = single_disk.opts.split(",")
51 | if "fixed" not in attr and "cdrom" not in attr:
52 | portable_part = single_disk.device[:2] + "/"
53 | if portable_part is "":
54 | print("no portable device detected!")
55 | os.system("pause")
56 | exit(1)
57 |
58 | def right_dir(location):
59 | # 将目录统一格式为:,同时返回当前文件夹的名称
60 | try:
61 | right_location = location.replace("\\","/")
62 | except:
63 | pass
64 | if right_location[-1] is not "/":
65 | right_location = right_location + "/"
66 | locs = right_location.split("/")
67 | folder_name = locs[-2]
68 | return folder_name,right_location
69 |
70 | def list_all_dir(upper_dir,location):
71 | # 返回当前目录下的所有文件夹,以子目录的形式装在全局变量dir_list中
72 | global dir_list
73 | temp_list = []
74 | temp_upper = []
75 | for item in os.listdir(location):
76 | if os.path.splitext(item)[1] is "":
77 | temp_item = upper_dir + item + "/"
78 | temp_list.append(item + "/")
79 | temp_upper.append(temp_item)
80 | dir_list.append(temp_item)
81 | if len(temp_list) == 0:
82 | return
83 | else:
84 | for i,ti in enumerate(temp_list):
85 | new_location = location + ti
86 | list_all_dir(temp_upper[i],new_location)
87 | return
88 |
89 | def file_only_process(com_location,port_location):
90 | '''
91 | 对于每一个目录,同步目录下的文件
92 | 1. 如果文件不是文件夹且不在“ignore”中,则进行同步
93 | 2. 如果移动设备中的文件不在电脑上,则询问删除
94 | 3. 如果电脑上的文件不在移动设备上,则进行复制
95 | 4. 如果一个文件同时在电脑和移动设备上,则比较MD5码,若不同则询问更新
96 | '''
97 | try:
98 | os.mkdir(port_location)
99 | except:
100 | pass
101 | port_files = os.listdir(port_location)
102 | for item in os.listdir(com_location):
103 | item_app = os.path.splitext(item)[1]
104 | if item_app is not "" and item_app not in setting["ignore"]:
105 | if item in port_files:
106 | f_port = open(port_location+item,'rb')
107 | f_com = open(com_location+item,'rb')
108 | md5_port = hashlib.md5(f_port.read()).hexdigest()
109 | md5_com = hashlib.md5(f_com.read()).hexdigest()
110 | f_port.close()
111 | f_com.close()
112 | if str(md5_port) != str(md5_com):
113 | if setting["override_updates"] is "y" or setting["override_updates"] is "Y":
114 | shutil.copyfile(com_location+item,port_location+item)
115 | else:
116 | ask_update = input(port_location+item+" has been changed in the computer, update? y/n ")
117 | if ask_update is "y" or ask_update is "Y":
118 | shutil.copyfile(com_location+item,port_location+item)
119 | else:
120 | shutil.copyfile(com_location+item,port_location+item)
121 | for item in port_files:
122 | if item not in os.listdir(com_location):
123 | if setting["override_delete"] is "y" or setting["override_delete"] is "Y":
124 | os.remove(port_location+item)
125 | else:
126 | ask_delete = input(port_location+item+" no longer exists in the computer, delete? y/n ")
127 | if ask_delete is "Y" or ask_delete is "y":
128 | os.remove(port_location+item)
129 |
130 |
131 | try:
132 | # 检查setting.json是否可以使用,否则退出
133 | with open("setting.json",'r') as f:
134 | # 检查是否指定了移动设备上的同步文件夹,若没有则默认创建
135 | # 检查指定的同步文件夹是否有效
136 | setting = json.load(f)
137 | if setting["portable_device_folder"] is "":
138 | print("No folder on the portable device is assigned")
139 | print("creating a sync folder {}sync/ in the portable device by default...".format(portable_part))
140 | sync_folder = portable_part+"sync/"
141 | try:
142 | os.mkdir(sync_folder)
143 | except:
144 | print("sync folder already exists on the portable device")
145 | else:
146 | sync_folder = setting["portable_device_folder"]
147 | _,sync_folder = right_dir(sync_folder)
148 | try:
149 | os.mkdir(sync_folder)
150 | except:
151 | pass
152 | try:
153 | os.listdir(sync_folder)
154 | except:
155 | print("The folder: {} doesn't exist".format(sync_folder))
156 | print("check the settings")
157 | os.system("pause")
158 | exit(1)
159 | except:
160 | print("setting.json required")
161 | os.system("pause")
162 | exit(1)
163 |
164 | for i,location in enumerate(setting["computer_locations"]):
165 | # 同步所有电脑上的文件夹中的文件
166 | # 先获取所有的次级目录
167 | print("syncing location: {} ...".format(location))
168 | global dir_list
169 | dir_list = [""]
170 | try:
171 | all_files = os.listdir(location)
172 | except:
173 | print("location:{} doesn't exist on the computer".format(location))
174 | print("skipping this location...")
175 | continue
176 | folder_name,location = right_dir(location)
177 | list_all_dir("",location)
178 | portable_location = sync_folder + folder_name + "/"
179 | try:
180 | os.mkdir(portable_location)
181 | except:
182 | pass
183 | for single_location in dir_list:
184 | print(" syncing /{}".format(single_location))
185 | com_location = location + single_location
186 | port_location = portable_location + single_location
187 | file_only_process(com_location,port_location)
188 |
189 | os.system("pause")
--------------------------------------------------------------------------------
/power_views.py:
--------------------------------------------------------------------------------
1 | import requests
2 | from random_userAgents import GetUserAgent
3 | from selenium import webdriver
4 | from bs4 import BeautifulSoup
5 | import os
6 | import time
7 | import re
8 | import pickle
9 |
10 | '''
11 | @author: github/wolverinn
12 | @date: 12/19/2019
13 |
14 | requirements:
15 | - Python 3.x
16 | - requests
17 | - selenium
18 | - chrome
19 | - chrome driver with the right version and add to ENVironment PATH
20 | - bs4
21 |
22 | function:
23 | Increase the views of a webpage. For example, a blog.
24 | But as it doesn't change the ip address. So it only increase the number of views, not the number of viewers.
25 | '''
26 |
27 | def get_page(url):
28 | chrome_options = webdriver.ChromeOptions()
29 | ua_argument = 'User-Agent="'+GetUserAgent()+'"'
30 | chrome_options.add_argument(ua_argument)
31 | chrome_options.add_argument('--headless')
32 | chrome_options.add_argument('--disable-gpu')
33 | chrome_options.add_argument('--incognito')
34 | chrome_options.add_argument('log-level=3')
35 | try:
36 | driver = webdriver.Chrome(chrome_options=chrome_options)
37 | #driver.set_page_load_timeout(6)
38 | # driver.set_script_timeout(6)
39 | driver.get(url)
40 | # time.sleep(0.5)
41 | driver.quit()
42 | except:
43 | driver.quit()
44 | print("timeout")
45 |
46 | url = input("input jianshu url: ")
47 | count = input("input reads: ")
48 | for i in range(int(count)):
49 | get_page(url)
50 | print("visited time: {}".format(i))
--------------------------------------------------------------------------------
/random_userAgents.py:
--------------------------------------------------------------------------------
1 | import random
2 |
3 | def GetUserAgent():
4 | '''
5 | 功能:随机获取HTTP_User_Agent
6 | function: get random User Agent headers
7 | '''
8 | user_agents=[
9 | "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; AcooBrowser; .NET CLR 1.1.4322; .NET CLR 2.0.50727)",
10 | "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Acoo Browser; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.0.04506)",
11 | "Mozilla/4.0 (compatible; MSIE 7.0; AOL 9.5; AOLBuild 4337.35; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)",
12 | "Mozilla/5.0 (Windows; U; MSIE 9.0; Windows NT 9.0; en-US)",
13 | "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET CLR 2.0.50727; Media Center PC 6.0)",
14 | "Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET CLR 1.0.3705; .NET CLR 1.1.4322)",
15 | "Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 5.2; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.2; .NET CLR 3.0.04506.30)",
16 | "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN) AppleWebKit/523.15 (KHTML, like Gecko, Safari/419.3) Arora/0.3 (Change: 287 c9dfb30)",
17 | "Mozilla/5.0 (X11; U; Linux; en-US) AppleWebKit/527+ (KHTML, like Gecko, Safari/419.3) Arora/0.6",
18 | "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.2pre) Gecko/20070215 K-Ninja/2.1.1",
19 | "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9) Gecko/20080705 Firefox/3.0 Kapiko/3.0",
20 | "Mozilla/5.0 (X11; Linux i686; U;) Gecko/20070322 Kazehakase/0.4.5",
21 | "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.8) Gecko Fedora/1.9.0.8-1.fc10 Kazehakase/0.5.6",
22 | "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11",
23 | "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.20 (KHTML, like Gecko) Chrome/19.0.1036.7 Safari/535.20",
24 | "Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; fr) Presto/2.9.168 Version/11.52",
25 | "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.11 TaoBrowser/2.0 Safari/536.11",
26 | "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.71 Safari/537.1 LBBROWSER",
27 | "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; LBBROWSER)",
28 | "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; QQDownload 732; .NET4.0C; .NET4.0E; LBBROWSER)",
29 | "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.84 Safari/535.11 LBBROWSER",
30 | "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)",
31 | "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; QQBrowser/7.0.3698.400)",
32 | "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; QQDownload 732; .NET4.0C; .NET4.0E)",
33 | "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; SV1; QQDownload 732; .NET4.0C; .NET4.0E; 360SE)",
34 | "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; QQDownload 732; .NET4.0C; .NET4.0E)",
35 | "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)",
36 | "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1",
37 | "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1",
38 | "Mozilla/5.0 (iPad; U; CPU OS 4_2_1 like Mac OS X; zh-cn) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C148 Safari/6533.18.5",
39 | "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:2.0b13pre) Gecko/20110307 Firefox/4.0b13pre",
40 | "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:16.0) Gecko/20100101 Firefox/16.0",
41 | "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11",
42 | "Mozilla/5.0 (X11; U; Linux x86_64; zh-CN; rv:1.9.2.10) Gecko/20100922 Ubuntu/10.10 (maverick) Firefox/3.6.10"
43 | ]
44 | user_agent = random.choice(user_agents)
45 | return user_agent
--------------------------------------------------------------------------------
/run_any_py.py:
--------------------------------------------------------------------------------
1 | import os
2 |
3 | '''
4 | @author: github/wolverinn
5 | @date: 01/23/2019
6 |
7 | requirements: None
8 |
9 | function: if you have lots of python files in a directory, you can run this script to choose a .py file to run
10 | '''
11 |
12 | py_files = []
13 | for all_file in os.listdir():
14 | if ".py" in all_file:
15 | py_files.append(all_file)
16 |
17 | for i,a in enumerate(py_files):
18 | print(str(i),a)
19 |
20 | choice = input("which one do you want to python it?")
21 | try:
22 | ch_num = int(choice)
23 | except:
24 | print("did you make a tiny mistake or did it deliberatly???")
25 | if ch_num>=len(list(py_files)):
26 | print("OF!!")
27 | else:
28 | os.system("python "+list(py_files)[ch_num])
29 |
30 | os.system("pause")
--------------------------------------------------------------------------------
/send_to_editor.py:
--------------------------------------------------------------------------------
1 | import os
2 | import getpass
3 | import shutil
4 |
5 | '''
6 | @author: github/wolverinn
7 | @date: 08/10/2018
8 |
9 | requirements:
10 | - Python 3.x
11 |
12 | function:
13 | Edit the send-to options in Windows when you right-click a file/folder.
14 | You can remove the existing options, or add a shortcut/program as the send-to option.
15 |
16 | 这个程序最好做成图形操作界面
17 | TODO: make a GUI for this program
18 | '''
19 |
20 | sendto="C:/users/"+str(getpass.getuser())+"/AppData/Roaming/Microsoft/Windows/SendTo"
21 | def remv():
22 | for i, file in enumerate(os.listdir(sendto)):
23 | print(str(i), end='.')
24 | print(file)
25 | num=input("input the number of the object you want to remove from send-to(multiple objects should be seperated by \';\'):")
26 | try:
27 | num=num.split(';')
28 | except:
29 | return
30 | for i, file in enumerate(os.listdir(sendto)):
31 | if str(i) in num:
32 | remv_file=sendto+"/"+str(file)
33 | os.remove(remv_file)
34 | print(file,"removed")
35 |
36 | def loc(add,app=''):
37 | if app is not '':
38 | app="/"+app
39 | add=add+app
40 | shortcutname = input("name the shortcut:")
41 | f = open("temp.vbs", 'w')
42 | f.write("set WshShell = WScript.CreateObject(\"WScript.Shell\")\n")
43 | shortcutname = "\"" + shortcutname + ".lnk\""
44 | temp = "set oShellLink = WshShell.CreateShortcut(" + shortcutname + ")\n"
45 | f.write(temp)
46 | temp = "oShellLink.TargetPath = \"" + add + "\"\n"
47 | f.write(temp)
48 | f.write("oShellLink.WindowStyle = 1\n")
49 | temp = "oShellLink.WorkingDirectory =\"" + add + "\"\n"
50 | f.write(temp)
51 | temp = "oShellLink.IconLocation = \"" + add + ",0\"\n"
52 | f.write(temp)
53 | f.write("oShellLink.Save\n")
54 | f.close()
55 | os.system("temp.vbs")
56 | os.remove("temp.vbs")
57 | for file in os.listdir():
58 | if str(file).split('.')[-1] == "lnk":
59 | shutil.move(file, sendto)
60 | print("added successfully")
61 |
62 | while(True):
63 | print("1) remove elements of send-to;")
64 | print("2) add a location to send-to;")
65 | print("3) add an application to send-to")
66 | option=input("your option(1/2/3):")
67 | if option=="1":
68 | remv()
69 | elif option=="2":
70 | location=input("add location:")
71 | loc(location)
72 | elif option=="3":
73 | location = input("add location of the application:")
74 | app = input("application name(including .exe):")
75 | loc(location,app)
76 | else:
77 | print("invalid option")
--------------------------------------------------------------------------------
/setting.json:
--------------------------------------------------------------------------------
1 | {
2 | "computer_locations":["D:\\test"],
3 | "portable_device_folder":"",
4 | "ignore":[".pkg"],
5 | "override_updates":"y",
6 | "override_delete":"y"
7 | }
--------------------------------------------------------------------------------
/simple_screen_recorder.py:
--------------------------------------------------------------------------------
1 | from tkinter import *
2 | import os
3 | import getpass
4 | import time
5 | import subprocess
6 | import win32con
7 | import ctypes
8 | import ctypes.wintypes
9 | import threading
10 |
11 | '''
12 | @author: github/wolverinn
13 | @date: 08/09/2018
14 |
15 | requirements:
16 | - Python 3.x
17 | - pywin32
18 | - ffmpeg(add to PATH)
19 |
20 | function:
21 | Records the screen using ffmpeg.
22 | Supports self-define frame rate, resolutions, and save location.
23 | A 3-second delay before starting recording.
24 | Press F10 to stop.
25 | Remembers the settings.
26 |
27 | 待改进:选择路径时可以使用按钮来选择文件夹。参考:hide_file.py
28 | TODO: Use a "choose path.." button to choose a path. refer to: hide_file.py
29 | '''
30 |
31 | #添加ffmpeg环境变量
32 | # try:
33 | # ffpath=os.getcwd()
34 | # set_cmd="set PATH= "+str(ffpath)+"\\ffmpeg"+";"
35 | # os.system(set_cmd)
36 | # except:
37 | # exit(1)
38 | # 创建键盘监听以便按下F10的时候停止录制
39 | EXIT = False # 用来传递退出的参数
40 | user32 = ctypes.windll.user32 # 加载user32.dll
41 | id2=106 # 注册热键的唯一id,用来区分热键
42 | class Hotkey(threading.Thread):
43 |
44 | def run(self):
45 | global EXIT # 定义全局变量,这个可以在不同线程间共用。
46 |
47 | if not user32.RegisterHotKey(None, id2, 0, win32con.VK_F10): # 注册快捷键F10并判断是否成功,该热键用于结束程序,且最好这么结束,否则影响下一次注册热键。
48 | print("Unable to register id", id2)
49 |
50 | # 以下为检测热键是否被按下,并在最后释放快捷键
51 | try:
52 | msg = ctypes.wintypes.MSG()
53 | while True:
54 | if user32.GetMessageA(ctypes.byref(msg), None, 0, 0) != 0:
55 | if msg.message == win32con.WM_HOTKEY:
56 | if msg.wParam == id2:
57 | EXIT=True
58 | return
59 | user32.TranslateMessage(ctypes.byref(msg))
60 | user32.DispatchMessageA(ctypes.byref(msg))
61 | finally:
62 | user32.UnregisterHotKey(None, id2)# 必须得释放热键,否则下次就会注册失败,所以当程序异常退出,没有释放热键,
63 | # 那么下次很可能就没办法注册成功了,这时可以换一个热键测试
64 |
65 | def control(a):
66 | # 监听按键
67 | hotkey=Hotkey()
68 | hotkey.run()
69 | while(True):
70 | if EXIT == True:
71 | global self_destroy
72 | self_destroy=True
73 | endcmd = "q".encode('utf-8')
74 | a.stdin.write(endcmd)
75 | a.communicate()
76 | print("Recording info:")
77 | size=str(os.path.getsize(video_name)/1000)+"kb"
78 | print("Resolution:",resolution,"\t帧数:",quality,"\tSize:",size)
79 | print("Recording saved to:",video_loc)
80 | os.system("pause")
81 |
82 | def start():
83 | global quality
84 | global video_loc
85 | global resolution
86 | global filepath,video_name
87 | video_loc=loc_et.get()
88 | quality=e1.get()
89 | res_ind=v.get()-1
90 | resolution=["1920x1080","1280x720","720x480"][res_ind]
91 | # 保存设置信息
92 | try:
93 | quality=int(quality)
94 | except:
95 | quality=20
96 | if quality>60 or quality<0:
97 | print("quality more than 60")
98 | quality=20
99 | f=open(filepath,'w')
100 | f.write(video_loc)
101 | f.write(',')
102 | f.write(str(quality))
103 | f.write(',')
104 | f.write(resolution)
105 | f.close()
106 | try:
107 | save_path=video_loc.replace('\\','/')
108 | except:
109 | save_path=video_loc
110 | if save_path[-1] == "/":
111 | save_path=save_path[:-1]
112 | try:
113 | os.listdir(save_path)
114 | except:
115 | user=getpass.getuser()
116 | save_path = "C:/users/" + str(user) + "/desktop"
117 | print("invalid save path,the video will be saved to desktop")
118 | root.destroy()
119 | # 提示3秒后开始录制
120 | for i in range(3):
121 | start_win = Tk()
122 | start_win.overrideredirect(True)
123 | start_win.geometry("+400+300")
124 | start_win.attributes("-alpha", 0.6)
125 | msg = Label(start_win, text="starts in:")
126 | show_time=str(3-i)
127 | msg_time_count = Label(start_win, text=show_time, font="楷书 36")
128 | msg.pack()
129 | msg_time_count.pack()
130 | start_win.update()
131 | time.sleep(1)
132 | start_win.destroy()
133 | # 创建录制命令
134 | t=time.time()
135 | t=str(t).split('.')[0]
136 | video_name=save_path+"/ouput_"+t+".mkv"
137 | start_cmd = "ffmpeg -f gdigrab -r " + str(
138 | quality) + " -i desktop -vcodec libx264 -s "+resolution+" \"" + save_path + "/ouput_"+t+".mkv\""
139 | # libvpx-vp9
140 | a=subprocess.Popen(start_cmd,stdin=subprocess.PIPE)
141 | control(a)
142 |
143 | self_destroy=True
144 | while(self_destroy):
145 | # 读取设置信息
146 | self_destroy=False
147 | user = getpass.getuser()
148 | filepath = "C:/users/" + str(user) + "/AppData/Roaming/screen_capture_tool_setting"
149 | if os.path.exists(filepath):
150 | try:
151 | f = open(filepath, 'r')
152 | info = f.readline().split(',')
153 | video_loc = info[0]
154 | quality = info[1]
155 | resolution = info[2]
156 | quality = int(quality)
157 | f.close()
158 | except:
159 | video_loc = "C:/users/" + str(user) + "/Videos"
160 | quality = 20
161 | resolution = "720x480"
162 | else:
163 | video_loc = "C:/users/" + str(user) + "/Videos"
164 | quality = 20
165 | resolution = "720x480"
166 | if quality > 60 or quality < 0:
167 | quality = 20
168 |
169 | # 创建主窗口
170 | video_name = "ouput.mkv"
171 | root = Tk()
172 | # root.iconbitmap("camera.ico")
173 | root.geometry("420x270")
174 | root.wm_title("Simple screen recording tool")
175 | loc_lbl = Label(root, text="Video save location:")
176 | loc_et = Entry(root)
177 | loc_et.insert(0, video_loc)
178 | l1 = Label(root, text="帧数:")
179 | e1 = Entry(root)
180 | e1.insert(END, str(quality))
181 | loc_lbl.pack()
182 | loc_et.pack()
183 | l1.pack()
184 | e1.pack()
185 | res_lbl = Label(root, text="分辨率:")
186 | res_lbl.pack(anchor=W)
187 | v = IntVar()
188 | r1 = Radiobutton(root, text="1080p", variable=v, value=1)
189 | r2 = Radiobutton(root, text="720p", variable=v, value=2)
190 | r3 = Radiobutton(root, text="480p", variable=v, value=3)
191 | r1.pack(anchor=W)
192 | r2.pack(anchor=W)
193 | r3.pack(anchor=W)
194 | start_btn = Button(root, text="start", command=start)
195 | start_btn.pack()
196 | exit_lbl = Label(root, text="Press F10 to stop recording", font="宋体 20")
197 | exit_lbl.pack()
198 | root.mainloop()
199 |
--------------------------------------------------------------------------------
/web2md.py:
--------------------------------------------------------------------------------
1 | import html2text
2 | import requests
3 | import re
4 | import os
5 |
6 | '''
7 | @author: github/wolverinn
8 | @date: 12/19/2019
9 |
10 | requirements:
11 | - Python 3.x
12 | - html2text
13 | - requests
14 |
15 | function:
16 | A simple implementation using html2text library. Save the webpage to markdown.
17 | Useful when the webpage is an article.
18 |
19 | 当然,还存在很多可以改进的地方,有时图片没法保存下来
20 | 最重要的是大部分情况下会保存除了文章之外的杂乱信息影响排版
21 | TODO: Sometimes can't save pictures
22 | Save only the article, trim other content
23 | '''
24 |
25 | headers = {
26 | "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36",
27 | }
28 |
29 | def get_flow(page_url):
30 | h = html2text.HTML2Text()
31 | h.ignore_links = False
32 | h.ignore_images = False
33 | h.ignore_emphasis = False
34 | h.ignore_tables = False
35 | filename = "{}.txt".format(page_url.split('/')[-1])
36 | f = open(filename,'w',encoding='utf-8')
37 | r = requests.get(page_url,headers=headers)
38 | if r.status_code == 200:
39 | converted_content = h.handle(r.text)
40 | f.write(converted_content)
41 | f.write('\n')
42 | f.close()
43 |
44 | page_url = input("输入链接:")
45 | get_flow(page_url)
46 | print("required page saved successfully")
47 |
--------------------------------------------------------------------------------
/windows_focus.py:
--------------------------------------------------------------------------------
1 | import os
2 | import shutil
3 | from PIL import Image
4 | import getpass
5 |
6 | '''
7 | @author: github/wolverinn
8 | @date: 08/03/2018
9 |
10 | requirements:
11 | - Python 3.x
12 | - Pillow
13 |
14 | Function:
15 | Save Windows-Focus images to a folder. Original Windows-Focus images:
16 | - don't have a right image format with ".jpg" or ".png".
17 | - image sizes are mixed in a large number of images.
18 | - are in a location very hard to find.
19 | '''
20 |
21 | try:
22 | os.mkdir("./windows-focus")
23 | except:
24 | pass
25 |
26 | focus_loc="C:/Users/"+str(getpass.getuser())+"/AppData/Local/Packages/Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy/LocalState/Assets/"
27 | for files in os.listdir(focus_loc):
28 | new_file="./windows-focus/"+str(files)
29 | old_file=focus_loc + str(files)
30 | shutil.copyfile(old_file,new_file)
31 |
32 | os.chdir("./windows-focus")
33 | for file in os.listdir():
34 | if len(str(file).split(".")) is 1:
35 | new_name=str(file)+".jpg"
36 | try:
37 | os.rename(file,new_name)
38 | except:
39 | os.remove(file)
40 | else:
41 | new_name=file
42 | img=Image.open(new_name)
43 | h=img.size[1]
44 | w=img.size[0]
45 | if w<1920:
46 | img.close()
47 | os.remove(new_name)
48 | # print("h:",h,";w:",w)
49 |
50 | print("All the images have been save to ./windows-focus")
51 | os.system("pause")
52 |
--------------------------------------------------------------------------------
/zhihu_answer_wordcloud.py:
--------------------------------------------------------------------------------
1 | import html2text
2 | import requests
3 | import re
4 | import jieba
5 | from wordcloud import WordCloud
6 | import os
7 | # sudo apt-get install python3-tk
8 |
9 | '''
10 | @author: github/wolverinn
11 | @date: 01/20/2019
12 |
13 | requirements:
14 | Python 3.x
15 | requests
16 | html2text
17 | jieba
18 | wordcloud
19 | chineseStopWords.txt
20 | if not Windows, please change the directory of the fonts
21 |
22 | function:
23 | Input a zhihu question URL, get 150 answers, save them to markdown, and generates wordcloud.
24 |
25 | 待添加功能:输入答案URL,保存答案到markdown
26 | TODO: Input the URL of an answer, save it to markdown
27 | '''
28 |
29 | headers = {
30 | "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36",
31 | "Host": "www.zhihu.com",
32 | "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
33 | }
34 | question = []
35 |
36 | def get_flow():
37 | h = html2text.HTML2Text()
38 | h.ignore_links = True
39 | h.ignore_images = True
40 | h.ignore_emphasis = True
41 | h.ignore_tables = True
42 | filename = "{}.txt".format(question_id)
43 | f = open(filename,'w',encoding='utf-8')
44 | for i in range(15):
45 | limit = "10"
46 | offset = str(i*10)
47 | print("getting the {} answer...".format(offset))
48 | api_base_url = "https://www.zhihu.com/api/v4/questions/{}/answers?include=data%5B%2A%5D.is_normal%2Ccontent%2Ceditable_content%2Cvoteup_count&limit={}&offset={}&platform=desktop&sort_by=default".format(question_id,limit,offset)
49 | answer_flow = requests.get(api_base_url,headers=headers)
50 | if answer_flow.status_code == 200:
51 | answer_data = answer_flow.json()["data"]
52 | question.append(answer_data[0]["question"]["title"])
53 | answer_count = answer_flow.json()["paging"]["totals"]
54 | if int(answer_count) < int(offset) + 10:
55 | return 0
56 | for single_answer in answer_data:
57 | single_content = single_answer["content"]
58 | single_vote = single_answer["voteup_count"]
59 | converted_content = h.handle(single_content)
60 | f.write(converted_content)
61 | f.write('\n')
62 | f.close()
63 |
64 | def seg_answer():
65 | answer_content = open(question_id + ".txt",'r',encoding='utf-8').read()
66 | print("segging answers...")
67 | answer_seg = jieba.cut(answer_content)
68 | stopwords = open("chineseStopWords.txt",'r',encoding='GBK').read()
69 | new_answer_seg = []
70 | for text in answer_seg:
71 | if text not in stopwords:
72 | new_answer_seg.append(text)
73 | string = ' '.join(new_answer_seg)
74 | print("making wordcloud...")
75 | wc = WordCloud(font_path='C:/Windows/Fonts/simkai.ttf',background_color='white',width=1000,height=800).generate(string)
76 | wc.to_file(question[0]+'.png')
77 |
78 | question_url = input("输入知乎问题链接(如:https://www.zhihu.com/question/23819007):")
79 | valid_check = re.search('question/\d*',question_url)
80 | if valid_check:
81 | question_id = valid_check.group().replace("question/",'')
82 | get_flow()
83 | print("required answers saved successfully")
84 | seg_answer()
85 | img_name = ".\\"+"\""+question[0]+".png"+"\""
86 | os.system(img_name)
87 | # print(question_id)
88 | else:
89 | print("Not a valid zhihu question URL !")
90 |
--------------------------------------------------------------------------------
/zhihu_video_downloader.py:
--------------------------------------------------------------------------------
1 | '''
2 | 知乎视频下载器,只需手动添加要下载的视频id(在视频链接的末尾),下载到当前目录
3 | 视频链接:收藏之后在收藏夹中点开回答便可找到视频链接
4 | 视频id就是知乎视频链接末尾的数字,如视频" https://v.vzuu.com/video/963459652725526528 " 的视频id为“963459652725526528”
5 | 可选:添加多个视频id,选择视频质量,ld/hd/sd分别为标清/高清/超清
6 | '''
7 |
8 | import requests
9 | import subprocess
10 | from tkinter import *
11 |
12 | '''
13 | @author: github/wolverinn
14 | @date: 07/27/2018
15 |
16 | requirements:
17 | - Python 3.x
18 | - requests
19 | - ffmpeg (add to PATH)
20 |
21 | 待改进:直接下载回答下面的所有视频
22 | TODO: Directly download all videos in an answer
23 | '''
24 |
25 | headers={
26 | "User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36",
27 | "Content-Type": "application/json",
28 | "Origin": "https://v.vzuu.com"
29 | }
30 | def download_m3u8_url(QUALITY,video_id):
31 | headers["Referer"]="https://v.vzuu.com/video/"+str(video_id)
32 | headers["X-Referer"]="https://link.zhihu.com/?target=https%3A//www.zhihu.com/video/"+str(video_id)
33 | ses=requests.session()
34 | ses.get("https://www.zhihu.com/collection/253903004")
35 | info_url="https://lens.zhihu.com/api/videos/"+str(video_id)
36 | video_info=ses.get(info_url,headers=headers)
37 | # print(video_info.text)
38 | m3u8_url=video_info.json()["playlist"][QUALITY]["play_url"]
39 | # print(m3u8_url)
40 | sub_cmd="ffmpeg -i "+str(m3u8_url)+" -c copy "+str(video_id)+".mp4"
41 | subprocess.call(sub_cmd)
42 |
43 | def click():
44 | if v.get()==2:
45 | QUALITY="hd"
46 | elif v.get()==3:
47 | QUALITY="sd"
48 | else:
49 | QUALITY="ld"
50 | all_ids=e1.get()
51 | e1.delete(0, len(all_ids))
52 | id_list=all_ids.split(";")
53 | try:
54 | if id_list[-1] == '':
55 | for video_id in id_list[0, -1]:
56 | download_m3u8_url(QUALITY, video_id)
57 | else:
58 | for video_id in id_list:
59 | download_m3u8_url(QUALITY, video_id)
60 | except:
61 | c["text"]="视频id有误,重新输入"
62 |
63 | root=Tk()
64 | root.geometry("360x240")
65 | # root.iconbitmap("file_cloud.ico")
66 | root.wm_title("知乎视频下载器")
67 | wl=Label(root,text="输入视频id(多个id以英文分号间隔)",font="楷书 15")
68 | e1=Entry(root,font="28")
69 | v=IntVar()
70 | r1=Radiobutton(root,text="标清",variable=v,value=1)
71 | r2=Radiobutton(root,text="高清",variable=v,value=2)
72 | r3=Radiobutton(root,text="超清",variable=v,value=3)
73 | b1=Button(root,text="Donwload",font="Helvetica 12 bold italic",borderwidth="4",command=click)
74 | c=Label(root,text="")
75 | wl.pack()
76 | e1.pack()
77 | c.pack()
78 | r1.pack(anchor=W)
79 | r2.pack(anchor=W)
80 | r3.pack(anchor=W)
81 | b1.pack()
82 | root.mainloop()
83 |
84 | # import json
85 | # info=open("info.json",'rb')
86 | # info_json=json.load(info)
87 | # video_ids=info_json["video_ids"]
88 | # QUALITY=info_json["QUALITY"]
89 | # for video_id in video_ids:
90 | # download_m3u8_url(QUALITY,video_id)
--------------------------------------------------------------------------------