Created
January 31, 2016 23:28
-
-
Save anonymous/935fccb25380cae4d71d 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 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; | |
} | |
} | |
} |
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 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