Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Started writeCSVData function
  • Loading branch information
Jackie committed Jan 16, 2019
1 parent c337fcb commit 6a130b2
Showing 1 changed file with 19 additions and 25 deletions.
44 changes: 19 additions & 25 deletions MHealth_GroupFBScraper/src/Main.java
@@ -1,6 +1,8 @@
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
Expand Down Expand Up @@ -33,22 +35,23 @@ public class Main {
Connection<Group> userGroups = fbClient.fetchConnection("me/groups", Group.class);
for(List<Group> page : userGroups) {
for(Group currGroup : page) {
// This loop doesn't make any sense I should replace it
//System.out.println("Do you want to get posts from "+currGroup.getName()+" ? Yes/NO"); // Eventually switch to GUI
//String response = input.nextLine();
//if(response.equals("Yes")) {
// Removed above lines for testing (will need them in the future but not now since I'm only testing on one group)
if(currGroup.getId().equals("250530099176185")){
Connection<Post> postFeed = fbClient.fetchConnection(currGroup.getId()+"/feed", Post.class, Parameter.with("fields","from,actions,message,likes,reactions"));
writeCSVData(postFeed);
Connection<Post> postFeed = fbClient.fetchConnection(currGroup.getId()+"/feed", Post.class, Parameter.with("fields","from,actions,message,likes,reactions, story"));
// Note - ask Jess if they want to be able to specify a start date / end date when pulling data
writeCSVData(currGroup, postFeed);
}
}
}
input.close();


}
public static void writeCSVData(Connection<Post> postFeed)
public static void writeCSVData(Group currGroup, Connection<Post> postFeed)
{
// TODO - Finish
// File Name should be of format: Health Chat_Data Type_Group Name_Date Pulled.csv
Expand All @@ -60,34 +63,25 @@ public class Main {
* shares - headers: Id, UserId, UserName, CreatedTime, StatusType, Message, Story, Link, Picture
*
*/
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd.MM.yyyy");
LocalDateTime now = LocalDateTime.now();
try {
File file = new File("Health Chat_chat_feed_"+currGroup.getName()+"_"+dtf.format(now)+".csv"); // Filepath needs to be more specific in final
FileWriter outputfile = new FileWriter(file);
// create CSVWriter object filewriter object as parameter
CSVWriter writer = new CSVWriter(outputfile);
List<String[]> chat_data = new ArrayList<String[]>();
chat_data.add(new String[] {"Id", "UserId", "UserName", "CreatedTime", "StatusType", "Message", "Story", "Link", "Picture"});

for(List<Post> getPosts : postFeed) {
//Create a list of posts from the post feed Y
for(Post currPost : getPosts) {
// Individual posts
// System.out.println(currPost.getFrom().getName());
// System.out.println(currPost.getReactions().getData());
// System.out.println(currPost.getLikes());
// System.out.println("--> "+currPost.getMessage());
// System.out.println("fb.com/"+currPost.getId());
chat_data.add(new String[] {currPost.getId(), currPost.getFrom().getId(), currPost.getFrom().getName(), "Date", currPost.getType(), currPost.getMessage(), currPost.getStory(), currPost.getLink(), currPost.getPicture()});
}
}
File file = new File();
FileWriter outputfile = new FileWriter(file);
writer.writeAll(chat_data);
writer.close();

// create CSVWriter object filewriter object as parameter
CSVWriter writer = new CSVWriter(outputfile);

// create a List which contains String array
List<String[]> data = new ArrayList<String[]>();
data.add(new String[] { "Name", "Class", "Marks" });
data.add(new String[] { "Aman", "10", "620" });
data.add(new String[] { "Suraj", "10", "630" });
writer.writeAll(data);

// closing writer connection

writer.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Expand Down

0 comments on commit 6a130b2

Please sign in to comment.