-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Go to localhost:4567 while it's running to view the website.
- Loading branch information
Showing
7 changed files
with
142 additions
and
10 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,47 @@ | ||
package com.medee.wikigraph; | ||
|
||
/** This is the main class. */ | ||
import org.json.JSONArray; | ||
import spark.Request; | ||
import spark.Response; | ||
import spark.Route; | ||
import spark.template.freemarker.FreeMarkerRoute; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static spark.Spark.get; | ||
import static spark.Spark.staticFileLocation; | ||
|
||
/** | ||
* This is the main class. | ||
*/ | ||
public class Main { | ||
|
||
public static void main(String[] args) { | ||
if (args.length != 1) { | ||
System.out.println("Specify a single article"); | ||
return; | ||
} | ||
String wikiPage = args[0]; | ||
WikipediaReader wikipediaReader = new WikipediaReader(); | ||
for (String link : wikipediaReader.linksOnArticle(wikiPage)) { | ||
System.out.println(link); | ||
} | ||
staticFileLocation("static"); | ||
|
||
get(new FreeMarkerRoute("/") { | ||
@Override | ||
public Object handle(Request request, Response response) { | ||
Map<String, Object> templateValues = new HashMap<String, Object>(); | ||
|
||
return modelAndView(templateValues, "index.ftl"); | ||
} | ||
}); | ||
|
||
get(new Route("/page") { | ||
@Override | ||
public Object handle(Request request, Response response) { | ||
String wikiPage = (String) request.queryParams("page"); | ||
WikipediaReader wikipediaReader = new WikipediaReader(); | ||
List<String> links = wikipediaReader.linksOnArticle(wikiPage); | ||
|
||
JSONArray linksJson = new JSONArray(links); | ||
|
||
return linksJson.toString(); | ||
} | ||
}); | ||
|
||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Wiki Graph</title> | ||
|
||
<link rel="stylesheet" href="/css/bootstrap.min.css"> | ||
<link href="//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css" rel="stylesheet"> | ||
|
||
<link rel="stylesheet" href="/css/index.css"> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<div class="jumbotron"> | ||
<h1>Wiki Graph</h1> | ||
<div class="input-group"> | ||
<input id="input-page" class="form-control input-large" type="text" placeholder="Page to query"> | ||
<span class="input-group-btn"> | ||
<button id="btn-refresh" class="btn btn-primary btn-large">Refresh</button> | ||
</span> | ||
</div> | ||
</div> | ||
|
||
<div class="panel" id="panel-links"> | ||
<div class="panel-heading"> | ||
<h2>Links on page - <span id="count-links">0</span> links found</h2> | ||
</div> | ||
<div id="links"> | ||
<h3>Run a query to see the links.</h3> | ||
</div> | ||
</div> | ||
</div> | ||
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script> | ||
<script src="/js/bootstrap.min.js"></script> | ||
<script src="/js/index.js"></script> | ||
</body> | ||
</html> |
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
body { | ||
background-color: #aaa; | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
var WikiGraph = {}; | ||
|
||
WikiGraph.getDataForPage = function(page) { | ||
$('#links').html('<i class="icon-spinner icon-spin icon-4x"></i>'); | ||
$.ajax('/page', { | ||
method: 'get', | ||
data: {page: page}, | ||
success: function(data) { | ||
data = JSON.parse(data); | ||
result = data.join('<br>'); | ||
$('#links').html(result); | ||
$('#count-links').html(data.length); | ||
}, | ||
error: function() { | ||
$('#links').html('<h3>That page doesn\'t exist.</h3>'); | ||
$('#count-links').html('0'); | ||
} | ||
}); | ||
}; | ||
|
||
WikiGraph.init = function() { | ||
$('#btn-refresh').click(function() { | ||
WikiGraph.getDataForPage($('#input-page').val()); | ||
}); | ||
|
||
$('#input-page').keypress(function(e) { | ||
if (e.which === 13) { | ||
e.preventDefault(); | ||
$('#btn-refresh').click(); | ||
} | ||
}); | ||
}; | ||
|
||
WikiGraph.init(); |