Skip to content

Instantly share code, notes, and snippets.

Created January 31, 2016 23:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/935fccb25380cae4d71d to your computer and use it in GitHub Desktop.
Save anonymous/935fccb25380cae4d71d to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Stupidposthistorything
{
class Post
{
private string body;
private string author;
public Post(string bod, string aut)
{
body = bod;
author = aut;
}
public string returnVal(string sort)
{
if (sort == "body") { return body; }
if (sort == "author") { return author; }
return null;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Net.Http;
using System.Net;
using Newtonsoft.Json;
namespace Stupidposthistorything
{
class Program
{
public static HttpClient client;
public static WebRequest webrequest;
public static string requeststring = "https://www.reddit.com/user/me/comments/.json";
static void Main(string[] args)
{
List<Post> Postlist;
Postlist = new List<Post>();
webrequest = WebRequest.Create(requeststring);
StreamReader streamReader = new StreamReader(webrequest.GetResponse().GetResponseStream());
JsonTextReader jsonReader = new JsonTextReader(streamReader);
string tokenName = "";
string body = "";
string author = "";
while (jsonReader.Read())
{
if (Convert.ToInt32(jsonReader.TokenType) == 4)
{
tokenName = jsonReader.Value.ToString();
}
if (Convert.ToInt32(jsonReader.TokenType) == 9 )
{
if (tokenName == "author")
{
author = jsonReader.Value.ToString();
}
if (tokenName == "body")
{
body = jsonReader.Value.ToString();
}
}
if (Convert.ToInt32(jsonReader.TokenType) == 14)
{
if (author != "" & body != "")
{
Postlist.Add(new Post(body, author));
}
body = "";
author = "";
}
}
foreach (Post post in Postlist)
{
//those functions probably are not needed anymore.
Console.WriteLine(post.returnVal("author") + " wrote the following: ");
Console.WriteLine(post.returnVal("body"));
Console.WriteLine();
Console.WriteLine();
}
Console.ReadLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment