Skip to content

Instantly share code, notes, and snippets.

@spiral6
Created April 18, 2016 03:37
Show Gist options
  • Save spiral6/a9946b8bbdd7edf2fcc467a1a5ff2fbc to your computer and use it in GitHub Desktop.
Save spiral6/a9946b8bbdd7edf2fcc467a1a5ff2fbc to your computer and use it in GitHub Desktop.
//Comment class
import java.util.List;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonProperty;
public class redditComment {
@JsonProperty("data")
private List<redditCommentData> data;
public Object getdata() {
return data;
}
public void setdata(List<redditCommentData> data) {
this.data = data;
}
public String toString(){
return "\n" + data;
}
}
//commentCreator class
import java.io.IOException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
public class redditCommentCreator {
public static void main(String[] args) throws IOException {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
List<redditComment> comments = mapper.readValue(new URL("https://api.pushshift.io/reddit/search/comment?q=yang&subreddit=rwby&limit=3"), new TypeReference<List<redditComment>>() {});
System.out.println(containers.size());
for(redditComment comment : comments) {
System.out.println("Container Id : " + comment.getdata());
}
}
}
//CommentData class
import java.util.List;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonProperty;
public class redditCommentData {
@JsonProperty("body")
private String body;
@JsonProperty("link_permalink")
private String link_permalink;
public String getBody(){
return body;
}
public String getlink(){
return link_permalink;
}
public void setBody(String body){
this.body = body;
}
public void setlink(String link_permalink){
this.link_permalink = link_permalink;
}
public String toString(){
return body + "\n" + link_permalink;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment