diff --git a/pom.xml b/pom.xml
index ca95d4e..f813f5e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,6 +5,10 @@
tk.nyyu
devfest2018
0.0.1-SNAPSHOT
+
+ 1.8
+ 1.8
+
org.jsoup
diff --git a/src/main/java/Program.java b/src/main/java/Program.java
index 4cdd81d..c31a91e 100644
--- a/src/main/java/Program.java
+++ b/src/main/java/Program.java
@@ -2,7 +2,8 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
-import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
@@ -29,6 +30,7 @@ import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
+import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
@@ -39,11 +41,29 @@ public class Program {
public static void main(String[] args) throws IOException, InvalidFormatException {
- Document doc = Jsoup.parse(new File("DevFest Nantes 2018.html"), "UTF-8");
+ Document doc = Jsoup.parse(new File("DevFest Nantes 2018.html"), StandardCharsets.UTF_8.name());
JsonObject sessions = new JsonParser().parse(
- IOUtils.toString(new URL("https://devfest.gdgnantes.com/data/sessions.json"), Charset.forName("UTF-8")))
+ IOUtils.toString(new URL("https://devfest.gdgnantes.com/data/sessions.json"), StandardCharsets.UTF_8))
.getAsJsonObject();
+
+ JsonArray schedule = new JsonParser().parse(
+ IOUtils.toString(new URL("https://devfest.gdgnantes.com/data/schedule.json"), StandardCharsets.UTF_8))
+ .getAsJsonArray();
+
+ Map timeslotSessions = new HashMap<>();
+ for (JsonElement day : schedule) {
+ JsonArray timeslots = day.getAsJsonObject().get("timeslots").getAsJsonArray();
+ for (JsonElement timeslot : timeslots) {
+ JsonArray sessionIds = timeslot.getAsJsonObject().get("sessions").getAsJsonArray();
+ String startTime = timeslot.getAsJsonObject().get("startTime").getAsString();
+ String endTime = timeslot.getAsJsonObject().get("endTime").getAsString();
+ for (JsonElement id : sessionIds) {
+ timeslotSessions.put(id.getAsString(), String.format("%s - %s", startTime, endTime));
+ }
+ }
+ }
+
XSSFWorkbook workBook = new XSSFWorkbook();
CreationHelper factory = workBook.getCreationHelper();
@@ -54,35 +74,28 @@ public class Program {
styleWrap.setVerticalAlignment(VerticalAlignment.CENTER);
for (int i = 1; i <= 2; i++) {
- Map>> map = new LinkedHashMap>>();
+ Map>> map = new LinkedHashMap<>();
Elements timeSlots = doc.select("schedule-day[name=day" + i + "] .timeslot");
for (Element timeSlot : timeSlots) {
- String time = timeSlot.select(".hours").text() + ":" + timeSlot.select(".minutes").text();
-
- List> list = map.get(time);
- if (list == null)
- list = new LinkedList>();
-
Elements contents = timeSlot.select(".session-content");
for (Element content : contents) {
String title = content.select(".session-title").text();
String id = content.parent().parent().parent().select("a").attr("href").split("=")[1];
- String type = sessions.getAsJsonObject(id).get("type").getAsString();
- JsonElement cat = sessions.getAsJsonObject(id).get("category");
- JsonElement comp = sessions.getAsJsonObject(id).get("complexity");
- JsonElement lang = sessions.getAsJsonObject(id).get("language");
- JsonElement desc = sessions.getAsJsonObject(id).get("description");
+ JsonObject session = sessions.getAsJsonObject(id);
+ String type = session.get("type").getAsString();
+ String cat = getIfNotNull(session, "category");
+ String comp = getIfNotNull(session, "complexity");
+ String lang = getIfNotNull(session, "language");
+ String desc = getIfNotNull(session, "description");
+ String time = timeslotSessions.get(id);
String details = String.format("type: %s, category: %s, complexity: %s, language: %s\n\n%s", type,
- cat != null ? cat.getAsString() : null, comp != null ? comp.getAsString() : null,
- lang != null ? lang.getAsString() : null, desc != null ? desc.getAsString() : null);
+ cat, comp, lang, desc);
- list.add(new ImmutablePair(title, details));
+ putOrNew(map, time, new ImmutablePair(title, details));
logger.info("{} -> {}", time, title);
}
-
- map.put(time, list);
}
XSSFSheet sheet = workBook.createSheet();
@@ -91,7 +104,7 @@ public class Program {
for (Map.Entry>> entry : map.entrySet()) {
Row row = sheet.createRow(rownum++);
-
+
int cellnum = 0;
Cell cell = row.createCell(cellnum++);
cell.setCellValue(entry.getKey());
@@ -116,11 +129,25 @@ public class Program {
if (cellnum > 2)
sheet.createRow(rownum++);
}
-
+ sheet.autoSizeColumn(0);
}
workBook.write(new FileOutputStream(new File(doc.title() + ".xlsx")));
workBook.close();
}
+ private static void putOrNew(Map> map, K key, V val) {
+ List list = map.get(key);
+
+ if (list == null)
+ list = new LinkedList();
+
+ list.add(val);
+
+ map.put(key, list);
+ }
+
+ private static String getIfNotNull(JsonObject jsonObject, String name) {
+ return jsonObject.get(name) == null ? "" : jsonObject.get(name).getAsString();
+ }
}