愚人节导入



“With great power comes great responsibility.

“拥有权利的同时也被赋予了重大的责任。

Do you know someone who Karma’s been slacking on lately? Looking for a harmless April Fools’ Day prank that allows you to flex your Pythonic muscles? Well look no further. Here’s a simple little prank you can quickly code up in Python, customize for maximum effect, and maybe even learn about a couple useful Python packages along the way.

你知道最近有人K业业的人吗? 寻找愚人节的无害恶作剧,使您可以弯曲自己的Python肌肉吗? 好吧,不要再进一步了。 这是一个简单的小恶作剧,您可以在Python中快速编写代码,自定义最大效果,甚至可能在此过程中了解几个有用的Python包。

You will want Python installed to code the prank, but the victim probably won’t need to have Python on their machine. This prank makes use of the wonderfully easy-to-use pyautogui package, which allows you to automate mouse and keyboard actions, as well as make message boxes and take screenshots.

您可能希望安装Python来编码恶作剧,但是受害者可能不需要在其计算机上安装Python。 这个恶作剧利用了非常好用的pyautogui软件包,该软件包使您可以自动执行鼠标和键盘操作,以及创建消息框和截屏。

So here’s the idea: the victim gets on their computer (after you’ve had a minute or two with it) and sees a seemingly harmless message that they close, which triggers their cursor to start freaking out (after which, we hope, the victim starts freaking out…at least a little bit).

所以这是一个主意:受害者进入计算机(一两分钟之后),然后看到关闭的看似无害的消息,这会触发他们的光标开始跳出来(在此之后,我们希望受害者开始吓到……至少一点。

If you haven’t used pyautogui before, install it by entering the following command in Windows Command Prompt (or the Mac OS X or Linux equivalent):

如果您以前从未使用过pyautogui,请在Windows命令提示符(或Mac OS X或等效的Linux)中输入以下命令进行安装:

pip install pyautogui

Looking over some pyautogui examples, you should start to get some ideas of what’s possible. Keep in mind that a fail-safe mechanism is built into pyautogui where if you move the cursor to the top-left corner of the screen (which you can usually do if you are quick with the mouse, even if the cursor’s moving quite fast on its own), an exception will be raised and the program will abort. This can be disabled, but exercise caution if you choose to do so.

查看一些pyautogui示例 ,您应该开始对可能的想法有所了解。 请记住,pyautogui内置了一种故障保护机制,如果您将光标移动到屏幕的左上角,通常会执行此操作(即使您快速移动鼠标,即使光标在屏幕上快速移动,通常也可以这样做)它本身),将引发异常,程序将中止。 可以禁用此功能,但是如果您选择这样做,请谨慎行事。

Now let’s get to coding. Here’s that starter script I mentioned:

现在开始编码。 这是我提到的入门脚本:

import time
import random
import pyautogui
def move_mouse(how_long_in_seconds):
start_time = time.time()
time_elapsed = time.time() - start_time
xsize, ysize = pyautogui.size()
while time_elapsed < how_long_in_seconds:
x, y = random.randrange(xsize), random.randrange(ysize)
pyautogui.moveTo(x, y, duration=0.2)
time_elapsed = time.time() - start_time
if __name__ == "__main__":
pyautogui.alert("Your Java update is now complete")
move_mouse(120)

Once you’ve tailored this to your liking, we’ll want to be able to run your program on your victim’s machine even if Python isn’t installed on that machine. To accomplish this, we’ll use the PyInstaller package, which “freezes” Python programs into stand-alone executables that can then be run on any machine with the same operating system as the one that the program was frozen on. Install PyInstaller if you need to:

一旦根据自己的喜好对它进行了调整,即使您的受害者的计算机上未安装Python,我们也希望能够在您的计算机上运行您的程序。 为此,我们将使用PyInstaller软件包,该软件包将Python程序“冻结”成独立的可执行文件,然后可以在与冻结该程序的操作系统相同的任何计算机上运行。 如果需要,请安装PyInstaller:

pip install pyinstaller

and once that’s finished, while still in your OS’s version of Command Prompt, navigate to the folder where your Python script is stored and enter the following command to initiate the creation of your executable:

完成后,仍然在您的操作系统版本的命令提示符下,导航到存储Python脚本的文件夹,然后输入以下命令以启动可执行文件的创建:

pyinstaller your_prank_script.py

This will result in PyInstaller creating 3 things: a file with the same name as your prank script but with a “.spec” file extension, a folder named “build”, and a folder named “dist”. Open the “dist” folder and you will find the folder which constitutes your brand new app (and which should have the same name as your script). Going into that folder, you should see a file named “your_prank_script.exe”, and when you run it you will hopefully see your program execute like a charm without Python ever being needed.

这将导致PyInstaller创建3件事:一个与恶作剧脚本同名但文件扩展名为“ .spec”的文件,一个名为“ build”的文件夹和一个名为“ dist”的文件夹。 打开“ dist”文件夹,您将找到构成全新应用程序的文件夹(该文件夹应与脚本名称相同)。 进入该文件夹,您应该看到一个名为“ your_prank_script.exe”的文件,当您运行该文件时,希望您的程序像超级按钮一样执行,而无需使用Python。

All you need to do now is wait for an opportune moment to copy that first folder in the “dist” folder over to your victim’s machine and then run the executable. Once you run it, take a moment to position everything on their screen to your liking (a command prompt window may pop up which you’ll want to minimize) and then sit back and drink some Yoo-hoo as your prey falls helplessly for your ingenious ploy.

您现在需要做的就是等待适当的时机,将“ dist”文件夹中的第一个文件夹复制到受害者的计算机上,然后运行可执行文件。 一旦运行它,花点时间将他们屏幕上的所有内容放置到您喜欢的位置(可能会弹出一个命令提示符窗口,您需要将其最小化),然后坐下来喝点哟哟,因为您的猎物会无助地跌倒。巧妙的策略。

A few ideas on how to improve the above script:

有关如何改善上述脚本的一些想法:

  • Make the cursor movements spell something out, perhaps the victim’s name.
  • Make your program run at startup, so turning the computer off and back on doesn’t make it go away.
  • Incorporate mouse clicks, keyboard actions (hotkeys to change screen orientation?), or more messages.
  • 使光标移动拼出一些东西,也许是受害者的名字。
  • 使程序在启动时运行 ,因此关闭计算机电源然后再打开电源不会使计算机消失。
  • 包含鼠标单击,键盘操作(更改屏幕方向的热键?)或更多消息。

Good luck, don’t get fired, and let me know how it goes!

祝你好运,不要被炒鱿鱼,让我知道这是怎么回事!



Subscribe for free content on learning Python and automation 订阅有关学习Python和自动化的免费内容

翻译自: https://www.pybloggers.com/2017/03/april-fools-day-python-prank/

愚人节导入

愚人节导入_愚人节Python恶作剧相关推荐

  1. 愚人节导入_愚人节! 将您PHP页面更改为ASP ...

    愚人节导入 I don't know a lot of PHP developers that think very much of ASP. This, of course, sets the st ...

  2. 愚人节导入_在愚人节的恶作剧破坏之后,如何重置键盘的映射?

    愚人节导入 A few small harmless pranks between friends is one thing, but what do you do when you are the ...

  3. 愚人节导入_最好的开发商愚人节

    愚人节导入 在一个安静的星期天,开发人员世界中发生了许多事态发展,这使您无法逃脱您的注意. 但是,在对写作团队寄予厚望和烦人的同时,似乎所有人都参与了愚人节活动. 这些年来,技术失误足够多了,我们不应 ...

  4. 愚人节导入_您是否发现了这些愚人节愚人节的插科打??

    愚人节导入 昨天对科技编辑而言是令人讨厌的一天. 每年4月1日,可信赖的消息来源都会泛滥成灾,突发新闻的色彩令人怀疑,到了下午3点,即使是最有说服力的作品也开始显得可疑. 对于其他人,虽然,这是一个互 ...

  5. python父亲节礼物_父亲节程序员硬核示爱:你能看懂几条

    摘要:祝所有的父亲,节日快乐! 父亲节要送什么? 对老爸的爱在心口难开怎么办? 都说父爱如山,山也需要偶尔的温情问候,与其在网上遍寻各种攻略,不如敲起手中的键盘,码出几行代码,用你最熟悉的方式表达对父 ...

  6. python父亲节祝福_父亲节祝福语精选简短 父亲节祝福语简短独特

    1.您的坚忍不拔和铮铮硬骨是我的榜样,我从您那儿汲取到奋发的力量,走过挫折,迈向成功,爸爸,您是我永远的榜样,我爱您!祝您节日快乐! 2.您的怀抱,是我的小天地:您的背影,是我的小甜蜜:您的手掌,是我 ...

  7. python光棍节快乐_光棍节快乐的祝福语12条

    光棍节快乐的祝福语12条 说你大光棍吧,你没那么老:说你中光棍吧,又没那么巧:你就一个超级光棍,你天天傻笑没烦恼!祝光棍节快乐!下面是小编为大家收集的光棍节快乐的祝福语12条,希望大家喜欢. 1.饭局 ...

  8. python父亲节礼物_父亲节礼物篇——父亲节适合父亲的礼物良心推荐

    父亲节快到了,很多人都不知道应该送什么礼物给自己的父亲,其实很简单,给爸爸什么礼物还要根据自己父亲的喜好来选择,在考虑给予什么之前,应该先了解父母的个性特征和需求.一般来说,这一代的父母只对实用性.面 ...

  9. python父亲节符号_菲菲用python编程绘制的父亲节礼物

    爱心热气球 菲菲说带着爸爸一起坐热气球 绘制此图菲菲一共写了60行代码 视频动画 Turtle 库 代码 importturtle t = turtle t.bgcolor("pink&qu ...

最新文章

  1. libtorchWindows中的使用
  2. 【错误记录】Flutter 设备连接显示 Loading... ( 断网 | 删除 flutter/bin/cache/lockfile 文件 )
  3. .NET引用类型与值类型
  4. HBase1.2.3 数据模型
  5. php判断学生姓名,PHP基础案例三:判断学生星座
  6. java批量上传文件_Spring Boot2(十四):单文件上传/下载,文件批量上传
  7. pie函数--Matplotlib
  8. 程序员的情人节「GitHub 热点速览 v.22.07」
  9. c#绝对值函数图像_取绝对值(C#、C++、js)
  10. 慧都科技邀您品鉴“2021重庆高效加工与智能化升级峰会”
  11. python判断火车票座位是否靠窗_Python查询火车票(一)
  12. 浅谈辅助功能 AccessibilityService
  13. K480N解决安装win10键盘失灵的方法
  14. 交换机/路由器基本配置
  15. SEDA源码解读(二)
  16. 检查企业71万余家(次),查处椎
  17. android发布release版本,Android同时安装Release和Debug版本的方法
  18. Vector2.js详解
  19. MySQL SELECT查询语句练习2(中级篇)
  20. MQTT:用Mosquitto搭建轻量级的设备接入网关

热门文章

  1. Go语言1-环境搭建
  2. ElasticSearch学习笔记二 初识Elasticsearch
  3. 条件互信息(conditional mutual information,CMI)
  4. golang接收 post和get请求参数处理
  5. [转载]Hive日期函数
  6. tomcat卸载与安装
  7. [Tomcat9]Tomcat卸载旧版本与安装新版本
  8. LabVIEW数字、字符串转换为枚举型
  9. 一行修改网页内容的代码
  10. Win10微软商店怎么改中文?