Advertisement
Guest User

Untitled

a guest
Nov 25th, 2015
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. using RedditSharp;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Net;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9.  
  10. namespace EarthPaper
  11. {
  12. class Program
  13. {
  14. static void Main(string[] args)
  15. {
  16. string[] subs = { "earthporn" };
  17.  
  18. var reddit = new Reddit();
  19.  
  20. Directory.CreateDirectory("imgCache");
  21.  
  22. int imgNum = 0;
  23.  
  24. foreach (var subName in subs)
  25. {
  26. var sub = reddit.GetSubreddit(subName);
  27. var posts = sub.GetTop(RedditSharp.Things.FromTime.Week).Take(50).Where(a => !a.IsSelfPost).Where(a => a.Score > 500);
  28.  
  29. foreach (var post in posts)
  30. {
  31. try
  32. {
  33. var url = post.Url;
  34. if (post.Url.Host.EndsWith("imgur.com") && !post.Url.PathAndQuery.Contains("."))
  35. {
  36. url = new Uri(post.Url.ToString() + ".jpg");
  37. }
  38.  
  39. WebClient wc = new WebClient();
  40. wc.DownloadFile(url, Path.Combine("imgCache", (imgNum++) + ".jpg"));
  41. }
  42. catch (Exception e)
  43. {
  44.  
  45. }
  46. }
  47. }
  48.  
  49. if (Directory.Exists("imgResult"))
  50. Directory.Delete("imgResult", true);
  51.  
  52. Directory.Move("imgCache", "imgResult");
  53. }
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement