forked from sirkris/Reddit.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPaginated Posts.cs
44 lines (40 loc) · 1.44 KB
/
Paginated Posts.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using Reddit;
using Reddit.Controllers;
using System;
using System.Collections.Generic;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
var reddit = new RedditClient("YourRedditAppID", "YourBotUserRefreshToken");
// Since we only need the posts, there's no need to call .About() on this one. --Kris
var worldnews = reddit.Subreddit("worldnews");
// Just keep going until we hit a post from before today. Note that the API may sometimes return posts slightly out of order. --Kris
var posts = new List<Post>();
string after = "";
DateTime start = DateTime.Now;
DateTime today = DateTime.Today;
bool outdated = false;
do
{
foreach (Post post in worldnews.Posts.GetNew(after: after))
{
if (post.Created >= today)
{
posts.Add(post);
}
else
{
outdated = true;
break;
}
after = post.Fullname;
}
} while (!outdated
&& start.AddMinutes(5) > DateTime.Now
&& worldnews.Posts.New.Count > 0); // This is automatically populated with the results of the last GetNew call. --Kris
}
}
}