Skip to content

Instantly share code, notes, and snippets.

@moritzuehling
Created November 25, 2015 23:39
Show Gist options
  • Save moritzuehling/b27e4a8328f632438d95 to your computer and use it in GitHub Desktop.
Save moritzuehling/b27e4a8328f632438d95 to your computer and use it in GitHub Desktop.
using RedditSharp;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace EarthPaper
{
class Program
{
static void Main(string[] args)
{
string[] subs = { "earthporn" };
var reddit = new Reddit();
Directory.CreateDirectory("imgCache");
int imgNum = 0;
foreach (var subName in subs)
{
var sub = reddit.GetSubreddit(subName);
var posts = sub.GetTop(RedditSharp.Things.FromTime.Week).Take(50).Where(a => !a.IsSelfPost).Where(a => a.Score > 500);
foreach (var post in posts)
{
try
{
var url = post.Url;
if (post.Url.Host.EndsWith("imgur.com") && !post.Url.PathAndQuery.Contains("."))
{
url = new Uri(post.Url.ToString() + ".jpg");
}
WebClient wc = new WebClient();
wc.DownloadFile(url, Path.Combine("imgCache", (imgNum++) + ".jpg"));
}
catch (Exception e)
{
}
}
}
if (Directory.Exists("imgResult"))
Directory.Delete("imgResult", true);
Directory.Move("imgCache", "imgResult");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment