让生活自动化的5个Python项目:从初级到高级

【关于TalkX】

TalkX是一款基于GPT实现的IDE智能开发插件,专注于编程领域,是开发者在日常编码中提高编码效率及质量的辅助工具,TalkX常用的功能包括但不限于:解释代码、中英翻译、性能检查、安全检查、样式检查、优化并改进、提高可读性、清理代码、生成测试用例等。

TalkX建立了全球加速网络,不需要考虑网络环境,响应速度快,界面效果和交互体验更流畅。并为用户提供了OpenAI的密钥,不需要ApiKey,不需要自备账号,不需要魔法。

TalkX产品支持:JetBrains (包括 IntelliJ IDEA、PyCharm、WebStorm、Android Studio)、HBuilder、VS Code、Goland.

If you’re learning Python, you should try to automate your everyday tasks.

如果您正在学习 Python,您应该尝试将日常任务自动化。

You not only learn more Python by implementing what you already know but, in the end, you can see how all your hard work pays off.

您不仅可以通过实施已有的知识来学习更多 Python 知识,而且最终还能看到您的辛勤付出是如何得到回报的。

Recently, I’ve been automating tasks more than often due to my lack of time. Thanks to that I have 5 new projects that I classified as beginner, intermediate, and advanced.

最近,由于时间不够,我经常将任务自动化。因此,我有了 5 个新项目,并将其分为初级、中级和高级。

You’ll find links to the full scripts and tutorials to solve each project. Also, I’m leaving a challenge to each of them to test your Python skills.

您将找到解决每个项目的完整脚本和教程的链接。此外,我还为每个项目留下了一个挑战,以测试你的 Python 技能。

1. Automate Microsoft Word (Beginner Project)

1.自动化Microsoft word(初级项目)

How many times did you have to use Word to create a cover letter, contract agreement, resume, or report?

您使用 Word 创建求职信、合同协议、简历或报告的次数有多少?

If you can’t count them, this project is for you.
如果你数不清它们,这个项目适合你。

In this project, we’ll automate the generation of Word documents using Python and a library called docxtpl. To do so, we need a template of the document we want to automate. Inside the template, we have to introduce placeholders on each word we want to replace later. We use the {{}} symbol for the placeholders.

在本项目中,我们将使用 Python 和名为 docxtpl 的库自动生成 Word 文档。为此,我们需要一个要自动生成的文档模板。在模板中,我们必须在每个要替换的单词上引入占位符。我们使用 {{}} 符号来表示占位符。

To make things easier, I already created a template for a cover letter. Here’s how the template we’ll use looks.

为了方便起见,我已经创建了一个求职信模板。下面就是我们要使用的模板。

Image by author

To make this project beginner friendly, we only have to replace the elements {{my_name}}, {{my_phone}}, {{my_email}}, {{my_address}}, and {{today_date}} using Python anddocxtpl.

为了让这个项目更适合初学者,我们只需使用 Python 和 docxtpl 替换 {{my_name}}, {{my_phone}}, {{my_email}}, {{my_address}} 和 {{today_date}} 元素即可。

In the video below, you can download this template, get the script, and follow the steps to solve this project.

在下面的视频中,你可以下载这个模板,获取脚本,并按照步骤解决这个项目。

https://youtu.be/H8Ars15wGRM

Challenge: If you want to take this project to the next level, try extracting data from an Excel file and introducing it in the Word template.

挑战:如果你想让这个项目更上一层楼,可以尝试从 Excel 文件中提取数据,并将其引入 Word 模板中。

The second part of the tutorial above has an Excel file that looks like the following table.

上述教程第二部分的 Excel 文件如下表所示。

2

You should generate a new document, for each row of the table.

您应该为表格的每一行生成一个新文档。

2. Automate Sending Emails (Beginner Project)

2.自动发送电子邮件(初学者项目)

One of the most boring tasks I used to do at work was sending emails.

我过去在工作中做的最无聊的任务之一就是发送电子邮件。

Important emails should be read and answered carefully, but emails that are part of an everyday routine should be automated! This is what this beginner project is all about. We’ll automate sending emails with Python.

重要的电子邮件应该仔细阅读和回复,但作为日常工作一部分的电子邮件应该自动化!这就是本初学者的目的所在。我们将使用 Python 自动发送电子邮件。

How to automate this task? We only need to use the built-in modulessmtplib and email . We need smtplib to send emails using the Simple Mail Transfer Protocol (SMTP), and the email package to read, write, and send more complex MIME messages.

如何自动执行这项任务?我们只需使用内置模块 smtplib 和 email。我们需要 smtplib 来使用简单邮件传输协议(SMTP)发送邮件,而 email 软件包则用于读取、写入和发送更复杂的 MIME 邮件。

Below there’s a step-by-step tutorial to automate sending emails with Gmail. Here’s what it covers:

下面是使用 Gmail 自动发送电子邮件的分步教程。内容如下:

  • How to turn on 2-step verification to be able to use Gmail with
    Python

如何开启两步验证,以便使用 Python 创建 Gmail

  • How to send a plain email with Python

如何使用 Python 发送普通电子邮件

  • How to deal with an SSL error you may encounter

如何处理您可能遇到的SSL错误

https://youtu.be/g_j6ILT-X0k

Challenge: If you want to make this project more challenging, try to attach images to your emails. To do so, you need to use the imghdr library.

挑战:如果你想让这个项目更具挑战性,请尝试在电子邮件中附加图片。为此,您需要使用 imghdr 库。

3. Automate Filling Web Form (Intermediate Project)

3. 自动填写 Web 表单(中间项目)

One of the most tedious tasks on the internet is filling in web forms.
互联网上最繁琐的任务之一是填写网络表单。

I mean that! Filling in your name, phone number, address, and more information over and over again is boring. Things get worse when you have to come up with fake data to fill in a survey.

我是说真的!一遍又一遍地填写姓名、电话号码、地址和更多信息是很无聊的。当你不得不编造虚假数据来填写调查问卷时,情况就更糟了。

In this intermediate project, we’re going to fill in fake data to web forms using Python. How to automate this task? We’ll use a web automation library that allows us to perform web actions like going to websites, typing text, and clicking on buttons.

在这个中级项目中,我们将使用 Python 在网络表单中填写虚假数据。如何自动完成这项任务?我们将使用一个网络自动化库,它允许我们执行网络操作,如访问网站、输入文本和点击按钮。

Below there’s a step-by-step tutorial on how to automate this tedious task with Python. Here’s what it covers:

下面是如何用 Python 自动完成这项繁琐任务的分步教程。内容如下:

  • How to fill in data in a single form

如何在单个表单中填写数据

  • How to generate fake data with the faker library

如何使用 faker 生成虚假数据

  • How to fill in multiple web forms

如何填写多个网络表单

https://youtu.be/LQ0r_vsdqQw

Challenge: The form we fill in this tutorial has simple elements. If you want to make this project more challenging, add advanced elements to the form such as dropdowns and multiple-choice questions. Then try to automate this advanced form.

挑战:我们在本教程中填写的表单只有简单的元素。如果你想让这个项目更具挑战性,可以在表单中添加下拉菜单和多选题等高级元素。然后尝试自动完成这个高级表单。

4. Automate Tinder (Advanced Project)

4. 自动化 Tinder(高级项目)

Swiping right on dating apps is so time-consuming that once you get matches, you become lazy in the most important part of online dating — converting matches into actual dates!

在交友软件上向右滑动非常耗时,以至于一旦有了匹配对象,你就会在网上约会最重要的部分(将匹配对象转化为实际约会)变得懒惰!

This advanced project consists in creating a bot that swipes right for you, so you can later work on your pickup lines and increase your conversion rate.

这个高级项目包括创建一个为您向右滑动的机器人,以便您以后可以练习搭讪台词并提高转化率。

What makes this project advanced? Many things. To name a few:

是什么让这个项目取得了进展?很多方面。仅举几例:

Login: No matter what login option you use (Google, Facebook), Tinder will send a code to your phone number. You need to use this code to log in to Tinder. To easily deal with this, we need to keep a Google Chrome session active and then control it with Selenium.

登录: 无论您使用哪种登录方式(谷歌、Facebook),Tinder 都会向您的电话号码发送一个代码。您需要使用该代码登录 Tinder。为了轻松解决这个问题,我们需要保持 Google Chrome 会话处于活动状态,然后用 Selenium 对其进行控制。

Tricky buttons: If you use the .click method to click on the like button, you might get errors sometimes. For this particular website, we need to use an alternative.

棘手的按钮:如果您使用 .click 该方法单击 "喜欢 "按钮,有时可能会出错。对于这个特定的网站,我们需要使用替代方案。

Popups: While swiping right you may encounter different pop-ups. You have to get rid of them.

弹出窗口:向右滑动时,您可能会遇到不同的弹出窗口。你必须摆脱它们。

Below there’s a tutorial that will help you deal with all of these issues.

下面有一个教程可以帮助您处理所有这些问题。

https://youtu.be/NJTNeXofbps

Challenge: Make your bot send random pickup lines to your matches.

挑战: 让你的机器人向你的匹配对象随机发送搭讪台词。

But only do that for the sake of this project! If you want to get more replies, don’t automate sending messages. I tried it and it’s not as effective as sending high-quality messages yourself.

但这样做只是为了这个项目!如果您想获得更多回复,请不要自动发送消息。我试过这样做,效果还不如自己发送高质量的信息。

5. Automate Your Own Tasks at Work (Super Advanced Project)

5. 在工作中自动化自己的任务(超级高级项目)

Without a doubt, automating a tedious task you have at work is the most challenging thing you can ever do.

毫无疑问,将工作中乏味的任务自动化是最具挑战性的事情。

Why? Most likely there isn’t a step-by-step tutorial to guide you, you have to think of what library you’d need to use, and the best approach to automate it.

为什么?很可能没有一个循序渐进的教程来指导你,你必须考虑需要使用什么库,以及自动运行的最佳方法。

  • To find out what to automate ask yourself these questions:

    要想知道哪些工作需要自动化,可以问自己以下问题:

  • What tasks do I keep doing over and over again?

    哪些工作 任务是我一直重复做的?

  • What specific parts can I automate with Python?

    我可以使用 Python 自动执行哪些特定的部分?

  • What Python libraries should I use to automate this project?

    我应该使用哪些 Python 库来自动化这个项目?

Even if you don’t find a tutorial on how to automate that specific task if you know the answer to question #3, you can check the documentation or read a guide to get started with that library.

如果知道问题 3 的答案,即使找不到如何自动执行特定任务的教程,也可以查看文档或阅读指南,开始使用该库。

Let me know in the comments what task you’re automating right now!

在评论中告诉我,你现在正在自动执行什么任务!

文章:《5 Python Projects to Automate Your Life: From Beginner to
Advanced》

作者:The PyCoach

发布日期:2022年10月14日

上述译文仅供参考,原文请查看下面链接,解释权归原作者所有

⚠️:文章翻译如有语法不准确或者内容纰漏,欢迎评论区指正。

【关于TalkX】

TalkX是一款基于GPT实现的IDE智能开发插件,专注于编程领域,是开发者在日常编码中提高编码效率及质量的辅助工具,TalkX常用的功能包括但不限于:解释代码、中英翻译、性能检查、安全检查、样式检查、优化并改进、提高可读性、清理代码、生成测试用例等。

TalkX建立了全球加速网络,不需要考虑网络环境,响应速度快,界面效果和交互体验更流畅。并为用户提供了OpenAI的密钥,不需要ApiKey,不需要自备账号,不需要魔法。

TalkX产品支持:JetBrains (包括 IntelliJ IDEA、PyCharm、WebStorm、Android Studio)、HBuilder、VS Code、Goland.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值