I have a program that scans posts from a subreddit over an arbitrary length of time. With each post that is scraped, I am able to collect certain pieces of data. Ultimately, I intend to pickle the data from each day separately in order to analyze it on a separate python program.
Here is some of the relevant code:
epoch = datetime.utcfromtimestamp(0)
print('Enter scanning start time:')
now = input()
now = datetime.strptime(now, '%Y-%m-%d %H:%M:%S.%f')
sDate = now - epoch
sDate = sDate.total_seconds()
print('
Enter scanning end time:')
later = input()
later = datetime.strptime(later, '%Y-%m-%d %H:%M:%S.%f')
eDate = later - epoch
eDate = eDate.total_seconds()
for submission in subreddit.new(limit = None):
if sDate > submission.created_utc > eDate:
do something...
My question is: how can I best group submissions based on a date? I've still pretty new to python, and have been reading up on classes, but I am not sure if that is the best route to go. The data I am collecting can just be simply thrown together into a list. But is there an efficient way to link submission posts together based on submission.created_utc? I've already created a for loop that creates a list of date() objects that might be useful:
delta = now - later
dateRange = []
for i in range(delta.days + 1):
dateRange.append(now - timedelta(days=i))
for i in dateRange:
date = i.strftime('%Y-%m-%d')
print(date)
question from:
https://stackoverflow.com/questions/66067412/what-is-the-most-efficient-way-to-group-submissions-based-on-submission-created 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…