from datetime import datetime, timedelta
import praw
# assuming you run this script every hour
an_hour_ago = datetime.utcnow() - timedelta(hours=1)
r = praw.Reddit(user_agent='soc')
submissions = r.get_subreddit('soccer').get_new()
submissions_list = [
# iterate through the submissions generator object
x for x in submissions
# add item if item.created_utc is newer than an hour ago
if datetime.utcfromtimestamp(x.created_utc) >= an_hour_ago
]
^{} class 和{a2}都没有所需的基于日期的筛选方法,因此有一个选项可供选择:
在将结果放入数据库之前,用Python过滤结果。
get_hot
和get_new
返回生成器对象,因此可以使用如下列表理解:默认情况下,Reddit只返回25个列表,因此如果需要更多的列表,则必须对其进行分页。在
^{pr2}$如果提交量大于200,则必须将其放入一个递归函数中:subreddit_latest.py
您应该比较datetime对象而不是字符串,以便将它们转换为datetime,如下所示:
您也应该对created_utc执行相同的操作,然后将两者进行比较。我不知道你可以在gethu hot函数中进行比较,因为我从来没有用过。在
相关问题 更多 >
编程相关推荐