Last active
December 22, 2016 20:40
-
-
Save dylanrenwick/6b4c08ac00998f93108026f06ea0573e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using RedditSharp; | |
using RedditSharp.Things; | |
namespace RedditScanner | |
{ | |
public class RedditScreener | |
{ | |
private readonly string[] regexStrings = new string[] | |
{ | |
"gdl", | |
"game dev league", | |
"game developers league", | |
"game development league", | |
"gamedev league", | |
"discord.gg/gamedev" | |
}; | |
private Reddit reddit; | |
private List<Subreddit> subreddits; | |
public RedditScreener(params string[] subreddits) | |
{ | |
for(int i = 0; i < subreddits.Length; i++) | |
{ | |
if (!subreddits[i].StartsWith("/r/")) subreddits[i] = "/r/" + subreddits[i]; | |
} | |
reddit = new Reddit(); | |
this.subreddits = new List<Subreddit>(); | |
foreach (string subreddit in subreddits) | |
{ | |
this.subreddits.Add(reddit.GetSubreddit(subreddit)); | |
} | |
} | |
public List<Post> Scan() | |
{ | |
var posts = new List<Post>(); | |
foreach (var subreddit in subreddits) | |
{ | |
posts = getPosts(subreddit); | |
} | |
return posts; | |
} | |
private List<Post> getPosts(Subreddit subreddit) | |
{ | |
var ret = new List<Post>(); | |
var posts = subreddit.Search(DateTime.UtcNow.AddHours(-18), DateTime.UtcNow.AddHours(-6)); | |
foreach(Post post in posts) | |
{ | |
if (checkPost(post)) | |
{ | |
ret.Add(post); | |
} | |
} | |
return ret; | |
} | |
private bool checkPost(Post post) | |
{ | |
foreach (var str in regexStrings) | |
{ | |
if (post.Title.ToLower().Contains(str)) return true; | |
if (post.SelfText.ToLower().Contains(str)) return true; | |
} | |
foreach(var comment in post.Comments) | |
{ | |
foreach (var str in regexStrings) if (comment.Body.ToLower().Contains(str)) return true; | |
} | |
return false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment