reddit_如何使用Python创建自定义Reddit通知系统
by Kelsey Wang
王凯西
如何使用Python创建自定义Reddit通知系统 (How to make a custom Reddit notification system with Python)
Don’t you just love automated emails? I know I do. I mean, who doesn’t enjoy waking up to 236 new messages from Nike, Ticketmaster, and Adobe Creative Cloud every morning? What a fantastic way to start my day! ??
您不只是喜欢自动发送的电子邮件吗? 我知道 我的意思是,谁不喜欢每天早晨从耐克,Ticketmaster和Adobe Creative Cloud唤醒多达236条新消息? 美好的一天开始了! ??
Anyway, today I’ll be showing you how to drown your inbox in more clutter, for God-knows-what reason. We’re going to be using Python to create a custom Reddit email-notification system. That means we’ll be writing a script that looks for Reddit posts matching some keywords and then emails us when such posts appear.
无论如何,今天,我将向您展示如何因神所知而更加混乱地淹没您的收件箱。 我们将使用Python创建自定义Reddit电子邮件通知系统。 这意味着我们将编写一个脚本,查找与某些关键字匹配的Reddit帖子,然后在出现此类帖子时通过电子邮件发送给我们。
There are a few reasons that you might be doing this. Maybe you’re really excited about some topic on Reddit. Maybe you’re trying to discover a new karma-farming technique because Internet points are important to you. Maybe you want to send annoying emails to your friends. Or maybe you just want more emails in your inbox to deal with your crippling loneliness. Oops, sorry — went too far. Let’s get started.
您可能会出于某些原因这样做。 也许您对Reddit上的某个话题感到非常兴奋。 也许您正在尝试发现一种新的业力养殖技术,因为互联网点对您很重要。 也许您想发送烦人的电子邮件给您的朋友。 或者,也许您只希望收件箱中有更多电子邮件来应对您的残酷孤独感。 糟糕,抱歉-太过分了。 让我们开始吧。
通过Reddit看 (Looking through Reddit)
Reddit has a nice API that you can do a lot with. To make things even easier, we will be using PRAW, the Python Reddit API Wrapper.
Reddit有一个不错的API ,您可以做很多事情。 为了使事情变得更加简单,我们将使用PRAW (Python Reddit API包装器)。
You’ll need a Reddit account first. Once you have one, go here to create an app. Name it anything, and make sure “script” is selected. As per the docs, you can just put http://localhost:8080
for your redirect URI.
您首先需要一个Reddit帐户。 拥有一个应用程序后,请转到此处创建一个应用程序。 对其进行命名,并确保选择“脚本”。 根据文档,您只需将http://localhost:8080
用作重定向URI。
Now, you’re ready to start that nifty script! In the code below, I look through a subreddit, picking out posts that match my needs.
现在,您准备开始该漂亮的脚本! 在下面的代码中, 我浏览了一个subreddit,挑选出符合我需要的帖子。
I consider a post a match if it is relevant enough and if it is popular enough. More specifically, the post is relevant enough when it has a keyword_count
that’s not -1 (I’ll explain this below) and popular enough when it has a weighted_score
greater than a predefined MIN_RELEVANT_WEIGHTED_SCORE
. The weighted score simply factors in the score of the post and the number of comments on the post. Anyway, this is what best fit my needs, so feel free to better define what a match means to you.
如果相关性足够高且受欢迎程度高,我认为该职位是一场比赛 。 更具体地说,如果该帖子的keyword_count
不为-1(我将在下面解释),则该帖子足够相关,而当weighted_score
大于预定义的MIN_RELEVANT_WEIGHTED_SCORE
时,该帖子足够受欢迎。 加权分数只是考虑帖子的分数和帖子评论的数量。 无论如何,这是最适合我需要的东西,所以随时可以更好地定义匹配对您的意义。
Now, I promised you I would talk about the keyword_count
party going on. Spoiler: it’s not really a party. I just devised this simple way of assessing relevancy: there are required terms and secondary terms. A post is relevant if and only if all the required terms are in the title, and at least X number of secondary terms are in the title (where X is some predefined number). Again, this part can be re-imagined in infinitely different ways, but this is just what I did.
现在,我向您保证,我将谈论正在进行的keyword_count
派对。 剧透:这不是一场派对。 我只是设计了一种简单的评估相关性的方法:有必要的术语和次要术语。 且仅当标题中包含所有必需术语且标题中至少包含X个辅助术语(其中X是一些预定义的数字)时,该帖子才有意义。 同样,可以用无限不同的方式重新想象这部分,但这就是我所做的。
Now we have everything to comb through our subreddit and tease out the good stuff about conspiracies or whatever. Cool. So, like my homie Ariana says, “thank u, next.”
现在,我们可以梳理所有内容,梳理一下关于串谋之类的好东西。 凉。 因此,就像我的亲爱的阿丽亚娜(Ariana)说的:“谢谢,接下来。”
电子邮件通知 (Emailing notifications)
Time to start spamming. In the code below, I’m using smtplib (the Simple Mail Transfer Protocol client) to help me send my emails. I then craft the beautiful email with HTML, using the info from Reddit that we got above to populate it. And the best (or worst?) part is, if you want to notify everyone you know about the latest and greatest Reddit posts, you can simply add more email addresses to the email_list
.
是时候开始发送垃圾邮件了。 在下面的代码中,我正在使用smtplib (简单邮件传输协议客户端)来帮助我发送电子邮件。 然后,我使用上面提供的Reddit信息填充HTML,用HTML编写精美的电子邮件。 最好的(或最糟的?)部分是,如果您想将Reddit的最新和最email_list
帖子通知给您认识的所有人,则只需在email_list
添加更多电子邮件地址即可。
Important side note: make sure the email you use to send the emails have less secure app access enabled if it’s a Gmail address, or this will not work.
重要的旁注:请确保您用于发送的电子邮件 如果这是Gmail地址,则电子邮件启用的安全性应用访问权限较低 ,否则将无法使用。
使它永远运行 (Make it run forever)
If you don’t have time to continually browse Reddit, you don’t have time to continually run this script. I used Heroku Scheduler to run this script every 10 minutes, as suggested by this Stack Overflow answer. It’s pretty easy to follow: add in a few additional files and a dummy web server, push to Heroku, add the Heroku Scheduler add-on, and BAM! You’re set until you run out of free dyno-hours. ??
如果您没有时间继续浏览Reddit,则没有时间继续运行此脚本。 根据堆栈溢出答案的建议,我使用Heroku Scheduler每10分钟运行一次此脚本。 这很容易遵循:添加一些其他文件和一个虚拟Web服务器,推送到Heroku,添加Heroku Scheduler附加组件,以及BAM! 您将一直处于设置状态,直到用尽了免费的动态小时。 ??
Is this the best solution? No. But is it sufficient for my purposes? Yep. If you know of a similarly trivial way to do this, please let me know!
这是最好的解决方案吗? 否。但是这足以满足我的目的吗? 是的 如果您知道执行此操作的类似方法,请告诉我!
结论 (In conclusion)
That’s pretty much all to this project. This GitHub repo contains all my code. Because of all the work that literally everyone else has already done, it’s quite a simple task to build this custom Reddit notification system. Gotta love the ✨magic✨ of software development.
这几乎就是这个项目的全部。 这个GitHub仓库包含了我所有的代码。 由于实际上每个人都已经完成了所有工作,因此构建此自定义Reddit通知系统是一项非常简单的任务。 一定喜欢软件开发的“魔术”。
If you made it all the way down to here, please comment “North Dakota is the top producer of barley in the USA” in the box below.
如果一直到这里,请在下面的框中评论“北达科他州是美国最大的大麦生产国”。
Thanks for reading!
谢谢阅读!
翻译自: https://www.freecodecamp.org/news/make-a-custom-reddit-notification-system-with-python-4dd560667b35/
相关文章:

1016. Phone Bills (25)
时间限制400 ms内存限制65536 kB代码长度限制16000 B判题程序Standard作者CHEN, Yue去掉非法数据计算账单A long-distance telephone company charges its customers by the following rules:Making a long-distance call costs a certain amount per minute, depending on the…

样式集(五)微信朋友圈样式模拟
效果图: 小图标: 源码: <!--pages/findList/findList.wxml--> <image class"xxiangji" catchtap"xxiangji" src"/images/xxiangji.png"></image> <image class"top_img" src&…

为什么要选择useState而不是useReducer
by Austin Malerba奥斯汀马勒巴(Austin Malerba) 为什么要选择useState而不是useReducer (Why you should choose useState instead of useReducer) 通过useState进行本地和全局状态管理的指南 (A guide to local and global state management via useState) Since the introd…

php 类中的变量的定义
php 如果在类中定义变量,在类的方法中调用时应该加上$this-> . class ClassName {private $a 333;function __construct(){$this->a 2222;}public function bbb($value){echo $this->a;} } $b new className(); echo $b->bbb();转载于:https://www.c…

微信小程序云数据库触底分页加载,下拉无限加载,第一次请求数据随机,随机获取数据库的数据
效果图 小程序云开发分页加载代码 <!--pages/chatList/chatList.wxml--> <view class"pageTitle">家博慧</view> <view class" search_arr"><icon class"searchcion" size16 typesearch></icon><input …

Linux(Centos)之安装Java JDK及注意事项
1.准备工作 a.因为Java JDK区分32位和64位系统,所以在安装之前必须先要判断以下我们的Centos系统为多少位系统,命令如下: uname -a解释:如果有x86_64就是64位的,没有就是32位的。后面是X686或X86_64则内核是64位的&…

2019web前端趋势_2019年最值得关注的Web开发趋势
2019web前端趋势by Mrudul Shah通过Mrudul Shah 2019年最值得关注的Web开发趋势 (Top Web Development trends to look out for in 2019) Do you know that nearly 200 websites are pushed out every minute? Sounds astonishing right? But it is a fact and that’s why …

WPF入门教程系列九——布局之DockPanel与ViewBox(四)
七. DockPanel DockPanel定义一个区域,在此区域中,您可以使子元素通过描点的形式排列,这些对象位于 Children 属性中。停靠面板其实就是在WinForm类似于Dock属性的元 素。DockPanel会对每个子元素进行排序,并停靠在面板的一侧&…

tabBar 自定义,小程序自定义底部导航栏
创建一个自定义组件 my_tab,组件代码在后面,先看调用自定义组件的代码,比如我需要在index 页面调用,就在index.json中引用组件,index.json 代码(引用的路径为你创建的自定义组件路径) {"n…

2015年最新出炉的JavaScript开发框架
前端框架简化了开发过程中,像 Bootstrap 和 Foundation 就是前端框架的佼佼者。在这篇文章了,我们编制了一组新鲜的,实用的,可以帮助您建立高质量的 Web 应用程序的 JavaScript 框架清单。 1.Aurelia Aurelia是下一代JavaScript客…

小程序前端性能测试_如何提高前端应用程序的性能
小程序前端性能测试If your website takes longer than 3 seconds to load, you could already be losing nearly half of your visitors.如果您的网站加载时间超过3秒,则可能已经失去了将近一半的访问者。 Yes this is a fact, proven by several research studie…

10-TypeScript中的接口
接口是一种规约的约定,从接口继承的类必须实现接口的约定。在高级开发中,通常接口是用于实现各种设计模式的基础,没有接口,设计模式无从谈起。 定义接口: interface ILog{recordlog():boolean; } 类从接口继承…

样式集(六)仿微信通讯录样式
效果图: 这里有引用到 自定义底部导航,自定义底部导航组件链接 <!--pages/chatList/chatList.wxml--><!-- <include src"/components/common/common" /> --> <view class"top"><view class"pageTi…

WCF动态添加ServiceKnownType
WCF中传输自定义类型时,必须在服务接口类(服务协定)上加上ServiceKnownType(typeof(yourClass)), 在实际应用中比较麻烦,可以用动态的办法来实现动态添加。 服务接口类,加上一行 [ServiceKnownType("GetKnownType…

博客 rss 如何使用_如何使用RSS从您的GatsbyJS博客自动交叉发布
博客 rss 如何使用With the recent exodus from Medium many developers are now creating their own GatsbyJS Blogs and then cross-posting to Medium or publications like freecodecamp.org and dev.to.随着Medium最近的离职,许多开发人员现在正在创建自己的Ga…

大型技术网站的技术( 高并发、大数据、高可用、分布式....)(一)
面对高并发、大流量、高可用、海量数据、用户分布广泛、网络情况复杂这类网站系统我们如何应对??? 第一阶段 一台服务器不行就上多台服务器 1.应用程序与数据服务分离 将应用程序、数据库、文件等资源放在一台服务器上,面对海量…

BestCoder Round #65 B C D || HDU 5591 5592 5593
B 题意:ZYB在远足中,和同学们玩了一个“数字炸弹”游戏:由主持人心里想一个在[1,N][1,N]中的数字XX,然后玩家们轮流猜一个数字,如果一个玩家恰好猜中XX则算负,否则主持人将告诉全场的人当前的数和XX比是偏大还是偏小&a…

数组去重,ES6数组去重 new Set()
普通数组去重 var b [...new Set([1,2, 3, 4, 5, 5, 5, 5])]console.log(b); 输出结果: 包含对象的数组去重 var o {a:1}var b [...new Set([o, o, 3, 4, 5, 5, 5, 5])]console.log(b); 输出结果: 包含对象的数组去重有一个坑 var b [...new Set([{…

使用angular的好处_在项目中使用Angular的最大好处
使用angular的好处by Irina Sidorenko伊琳娜西多连科(Irina Sidorenko) 在项目中使用Angular的最大好处 (The top benefits of using Angular for your project) 在项目实施中使用Angular的11个理由及其好处 (11 reasons to use Angular and its benefits for your project im…

python之路——模块和包
一、模块 1、什么是模块? 常见的场景:一个模块就是一个包含了Python定义和声明的文件,文件名就是模块名字加上.py的后缀。 但其实import加载的模块分为四个通用类别: 1、使用Python编写的代码(.py文件) 2、…

夺命雷公狗---linux NO:3 centos_mini版的安装和备份
废话不多说,和前面的其实是差不多的,如下图所示: 安装其实是和桌面版的差不多的,但是经典版的不能自定义分区(如详细区,如home之类的)。。。 因为我们使用的是命令行方式的所以直接选英文&#…

快速学习 async await 的使用, Demo 解析
async 和 await 字面都很好理解,分别是异步和等待。 来两个简单的 demo, demo1 tt2(){return new Promise(rps>{setTimeout(() > {rps(true)}, 1500);})},async tt1(){var a await this.tt2();console.log(a)},/*** 生命周期函数--监听页面加载*…

小型工作室创业项目_为什么新开发人员应该在小型创业公司工作
小型工作室创业项目In my first year of working in the industry (6 months as an intern, 6 months as a full-time employee), I worked at startups that were less than 10 people large. I was one of the only 2 or 3 developers, and usually one of the first. Throug…

head first python菜鸟学习笔记(第六章)
1. Python提供字典,允许有效组织数据,将数据与名关联,从而实现快速查找,而不是以数字关联。 字典是内置数据结构,允许将数据与键而不是数字关联。这样可以使内存中的数据与实际数据的结构保持一致。?&#…

小程序聊天室开发,发送文字,表情,图片,音频,视频,即时通讯,快速部署,可定制开发
效果图: 微信小程序聊天功能模块,现在已经支持发送图片,文字,音频,视频,表情,在线即时聊天啦。 需要做的可以联系我微信。13977284413 上代码: <view class"bo">…

常用浏览器插件
modify headers :firefox的IP伪造插件 httpRequester:firefox的模拟http请求插件JSON-handle:chrome格式化json插件firebug:firefox查看http请求工具firepath:firefox中获取元素路径转载于:https://www.cnblogs.com/xx…

编码中统一更该变量的快捷键_更多项目想法,以提高您的编码技能
编码中统一更该变量的快捷键Two weeks ago I published an article containing 15 project ideas that you can build to level up your coding skills, and people were very excited about that resource.两周前,我发表了一篇文章,其中包含15个项目构想…
My97DatePicker日历控件日报、每周和每月的选择
My97DatePicker日历控件日报、每周和每月的选择 1、设计源代码 <% page language"java" import"java.util.*" pageEncoding"UTF-8"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><h…

DotNet Core Console 程序使用NLog
参考:https://github.com/NLog/NLog/wiki/Tutorial 步骤: 1. 使用Nuget安装NLog.Extensions.Logging Install-Package NLog.Extensions.Logging 2.编写代码(到这步运行代码,不报错,但是也不会有log输出,因为…

小程序判断用户在线状态
在页面的两个生命周期组件里面 onShow() {console.log(-----上线线)let info wx.getStorageSync(chat_item)DB.collection(friends).where({_id: info._id}).get().then(res > {console.log(-----, res)if (res.data[0].a wx.getStorageSync(userInfo)._openid) {console.…