Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
p2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cse332-20au
p2
Commits
31fdd0d7
Commit
31fdd0d7
authored
6 years ago
by
Danny Allen
Browse files
Options
Downloads
Patches
Plain Diff
Update ParseFBMessages
parent
35c35dd2
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/p2/wordsuggestor/ParseFBMessages.java
+28
-31
28 additions, 31 deletions
src/p2/wordsuggestor/ParseFBMessages.java
with
28 additions
and
31 deletions
src/p2/wordsuggestor/ParseFBMessages.java
+
28
−
31
View file @
31fdd0d7
package
p2.wordsuggestor
;
import
java.io.File
;
import
java.io.FileReader
;
import
java.io.IOException
;
import
java.io.PrintWriter
;
import
java.util.Stack
;
import
org.jsoup.Jsoup
;
import
org.jsoup.nodes.Document
;
import
org.jsoup.nodes.Element
;
import
org.jsoup.select.Elements
;
import
cse332.interfaces.worklists.LIFOWorkList
;
import
datastructures.worklists.ArrayStack
;
import
org.json.simple.JSONObject
;
import
org.json.simple.parser.JSONParser
;
import
org.json.simple.parser.ParseException
;
import
org.json.simple.JSONArray
;
public
final
class
ParseFBMessages
{
private
ParseFBMessages
()
{
...
...
@@ -30,37 +29,35 @@ public final class ParseFBMessages {
// You may be able to use a relative path like "./MyArchiveName", but results can
// vary from machine to machine.
public
static
void
main
(
String
[]
args
)
throws
IOException
{
if
(
args
.
length
!=
2
)
{
System
.
out
.
println
(
"USAGE: ParseFBMessages <Your FB Name> <Your FB Archive>"
);
System
.
exit
(
1
);
}
// Note: you can replace these with your FB Name and Archive instead of
// using the command line if you'd like.
String
name
=
args
[
0
];
String
archive
=
args
[
1
];
String
name
=
"<Your FB Name>"
;
// e.g. "Ruth Anderson"
String
archive
=
"<Your FB Archive>"
;
// e.g. "/Users/rea/workspace/332/messages"
LIFOWorkList
<
String
>
message
s
=
new
Array
Stack
<
String
>();
File
[]
listOfFiles
=
(
new
File
(
archive
+
File
.
separator
+
"
messages
"
)).
listFiles
();
Stack
<
String
>
corpu
s
=
new
Stack
<>();
File
[]
listOfFiles
=
(
new
File
(
archive
+
File
.
separator
+
"
inbox
"
)).
listFiles
();
for
(
int
i
=
0
;
i
<
listOfFiles
.
length
;
i
++)
{
if
(
listOfFiles
[
i
].
isFile
())
{
Document
doc
=
Jsoup
.
parse
(
listOfFiles
[
i
],
"UTF-8"
);
Elements
messagesElements
=
doc
.
getElementsByTag
(
"p"
);
for
(
Element
content
:
messagesElements
)
{
if
(
content
.
previousElementSibling
().
getElementsByClass
(
"user"
).
text
()
.
equals
(
name
))
{
messages
.
add
(
content
.
text
());
}
}
}
File
conversation
=
new
File
(
listOfFiles
[
i
],
"message.json"
);
if
(
conversation
.
isFile
())
{
try
{
JSONObject
obj
=
(
JSONObject
)
new
JSONParser
().
parse
(
new
FileReader
(
conversation
));
JSONArray
messages
=
(
JSONArray
)
obj
.
get
(
"messages"
);
for
(
Object
m:
messages
)
{
JSONObject
msg
=
(
JSONObject
)
m
;
String
sender
=
(
String
)
msg
.
get
(
"sender_name"
);
if
(
sender
!=
null
&&
sender
.
equals
(
name
))
{
corpus
.
push
((
String
)
msg
.
get
(
"content"
));
}
}
}
catch
(
ParseException
e
)
{
System
.
err
.
println
(
"Could not parse: "
+
conversation
.
toString
());
}
}
}
PrintWriter
out
=
new
PrintWriter
(
"me.txt"
,
"UTF-8"
);
while
(
messages
.
hasWork
())
{
out
.
println
(
messages
.
next
());
while
(
!
corpus
.
isEmpty
())
{
out
.
println
(
corpus
.
pop
());
}
out
.
close
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment