- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
所以我在过滤我的虾的结果时遇到了一些问题。我想在结果中排除诸如([request]、[off topic] 或 [nsfw])之类的关键字。我不想在 tweepy 上发布类似 praw 结果中的帖子。我正在寻找文档,但在 PRAW 网站上找不到任何内容。
这是我的代码:
def poster():
conn = sqlite3.connect('jb_id.db')
c = conn.cursor()
toTweet = []
for submission in reddit.subreddit(SUB).hot(limit=POST_LIMIT):
if not submission.stickied and len(submission.title) < 255:
url = submission.shortlink
title = submission.title
udate = time.strftime("%Y-%m-%d %X",time.gmtime(submission.created_utc))
try:
# This keeps a record of the posts in a the database
c.execute("INSERT INTO posts (id, title, udate) VALUES (?, ?, ?)",
(url, title, udate))
conn.commit()
message = title + " " + url
print(message)
toTweet.append(message)
except sqlite3.IntegrityError:
# This means the post was already tweeted and is ignored
print("Duplicate", url)
c.close()
conn.close()
tweeter(toTweet)
如您所见,我排除了超过 255 个字符的标签和标题。我想知道是否有一种方法可以用我上面提到的关于 praw 的结果的关键字来过滤 reddit 上的帖子。谢谢!
最佳答案
列出不应出现在提交标题中的关键字
bad_keywords = "[request]", "[off topic]", "[nsfw]"
如果提交标题包含列表中的项目,则跳过循环
title_lowercase = submission.title.lower()
if any(x in title_lowercase for x in bad_keywords):
continue
我会将其与您的其他排除项结合使用以减少缩进并使其更具可读性
bad_title = any(x in title_lowercase for x in bad_keywords)
skip_submission = submission.stickied and len(submission.title) > 255 and bad_title
if skip_submission:
continue
完整的解决方案
def poster():
conn = sqlite3.connect('jb_id.db')
c = conn.cursor()
toTweet = []
bad_keywords = "[request]", "[off topic]", "[nsfw]"
for submission in reddit.subreddit(SUB).hot(limit=POST_LIMIT):
title = submission.title
title_lowercase = title.lower()
bad_title = any(x in title_lowercase for x in bad_keywords)
skip_submission = submission.stickied and len(submission.title) > 255 and bad_title
if skip_submission:
continue
url = submission.shortlink
udate = time.strftime("%Y-%m-%d %X",time.gmtime(submission.created_utc))
try:
# This keeps a record of the posts in a the database
c.execute("INSERT INTO posts (id, title, udate) VALUES (?, ?, ?)",
(url, title, udate))
conn.commit()
message = title + " " + url
print(message)
toTweet.append(message)
except sqlite3.IntegrityError:
# This means the post was already tweeted and is ignored
print("Duplicate", url)
c.close()
conn.close()
tweeter(toTweet)
关于python - PRAW/Tweepy 过滤关键字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58799355/
是否可以使用 PRAW 检查指定用户是否存在,如果存在,正确的方法是什么?我找不到执行此操作的任何内置函数,因此非常感谢您的帮助。 最佳答案 Arnav 的回答仅适用于旧版本的 PRAW (prior
我想在后台运行一个脚本,它会每隔一小时左右获取 subreddit 数据。现在因为我不想在我的数据库中有重复的条目,我想根据 created_utc 过滤我的搜索结果 这是我目前拥有的: r = pr
我想安装 PRAW,这样我就可以制作 reddit 机器人和其他东西,但是所有的安装指南都让我感到困惑,所以有人可以解释一下如何让新手尽可能友好。我对 Vanilla python 有一些经验。谢谢!
我正在尝试使用 PRAW 来组织活跃在/r/nba 中的用户根据他们的天赋发表的所有评论。如果我有用户名,是否有好的方法来获得用户的天赋? 我的最终目标是对按 NBA 球迷分组的用户评论进行一些文本分
正如标题所说,我无法在 PRAW 中找到回复 Reddit 上的帖子的功能。 到目前为止,我已经编写了一个相当简单的机器人,它可以在某个 subreddit 上寻找新帖子。我的问题是,一旦找到提交,我
所以我试图制作一个从 subreddit 中获取随机帖子 url 的机器人,并希望它检查登录凭据是否有效,所以我想出了以下内容: import praw import pandas as pd imp
当我尝试打印带有表情符号的评论或提交时收到错误消息。我怎样才能忽略并只打印字母和数字? 使用 Praw 进行网页抓取 top_posts2 = page.top(limit = 25) for pos
我正在使用 praw 编写一个机器人,我想知道自帖子发布以来已经过去了多长时间。天真的解决方案是使用datetime import datetime import praw ... """read a
是否有任何方法可以限制 Reddit 上特定帖子的评论探索深度。我们有replace_more_comments,它试图替换尽可能多的more_comments,但我们可以限制这种扩展吗?或者我是否需
编辑:在您开始删除/修改安装之前,请浏览 StvnW 的回答/摘要以确保您正在应用适合您的解决方案。 我已经安装了 python 2.7.5 和 pip [编辑:mac OSX Mountain Li
我正在阅读 doc for get_comments而且我不知道 time 参数的正确输入是什么。我知道默认值是“全部”,但我是输入具体日期,还是必须输入“天”、“周”等词? 假设我想获得用户在一周内
该脚本从 Reddit 上的特定评论中获取信息。它的工作与否取决于给它的永久链接。 import praw from pprint import pprint clipboard = ['permal
我正在尝试开始使用 PRAW,但在使用 login() 时遇到问题。 我有以下代码: import praw r = praw.Reddit('This is a test bot') r.login
我希望能够迭代帖子中的评论,最高可达 n 级别,并记录每个评论及其深度。不过,我认为在 Praw 中没有办法轻松做到这一点。 我想做这样的事情: def get_post_comments(post,
我的目标是从 Reddit 获取顶部提交,将其附加到数组中,然后获取第二个顶部提交、第三个、第四个等等。我使用 place_holder 来获取下一个提交,其中第一次有效,但随后只是循环一遍又一遍地获
我正在尝试扫描特定的 Reddit 子版 block ,以查看评论在热门提交中出现的次数。 我无法得到任何迹象表明它实际上正在读取消息,因为它根本不会打印消息正文。注意:sr = Reddit 子版
我正在尝试为我的测试 subreddit 编写一个机器人,但在运行它之前,我正在 PRAW 中测试提交方法。要提交文本帖子,请使用以下行: r.submit('Subreddit', 'Post Ti
所以我在过滤我的虾的结果时遇到了一些问题。我想在结果中排除诸如([request]、[off topic] 或 [nsfw])之类的关键字。我不想在 tweepy 上发布类似 praw 结果中的帖
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 8 年前。 Improve this qu
我无法理解这在 praw API 中是否可行:我想获得所有评论中提到关键字(比如“python”)的帖子的列表。似乎搜索功能总是从特定的 subreddit 中调用,如 for submission
我是一名优秀的程序员,十分优秀!