init
This commit is contained in:
commit
00faf31c82
4 changed files with 9625 additions and 0 deletions
9445
DevFest Nantes 2018.html
Normal file
9445
DevFest Nantes 2018.html
Normal file
File diff suppressed because one or more lines are too long
40
pom.xml
Normal file
40
pom.xml
Normal file
|
@ -0,0 +1,40 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>tk.nyyu</groupId>
|
||||
<artifactId>devfest2018</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jsoup</groupId>
|
||||
<artifactId>jsoup</artifactId>
|
||||
<version>1.11.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi-ooxml</artifactId>
|
||||
<version>4.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.8.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<version>2.11.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.8.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
126
src/main/java/Program.java
Normal file
126
src/main/java/Program.java
Normal file
|
@ -0,0 +1,126 @@
|
|||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.CellStyle;
|
||||
import org.apache.poi.ss.usermodel.ClientAnchor;
|
||||
import org.apache.poi.ss.usermodel.Comment;
|
||||
import org.apache.poi.ss.usermodel.CreationHelper;
|
||||
import org.apache.poi.ss.usermodel.Drawing;
|
||||
import org.apache.poi.ss.usermodel.HorizontalAlignment;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.VerticalAlignment;
|
||||
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
public class Program {
|
||||
|
||||
private static final Logger logger = LogManager.getLogger(Program.class);
|
||||
|
||||
public static void main(String[] args) throws IOException, InvalidFormatException {
|
||||
|
||||
Document doc = Jsoup.parse(new File("DevFest Nantes 2018.html"), "UTF-8");
|
||||
|
||||
JsonObject sessions = new JsonParser().parse(
|
||||
IOUtils.toString(new URL("https://devfest.gdgnantes.com/data/sessions.json"), Charset.forName("UTF-8")))
|
||||
.getAsJsonObject();
|
||||
XSSFWorkbook workBook = new XSSFWorkbook();
|
||||
|
||||
CreationHelper factory = workBook.getCreationHelper();
|
||||
|
||||
CellStyle styleWrap = workBook.createCellStyle();
|
||||
styleWrap.setWrapText(true);
|
||||
styleWrap.setAlignment(HorizontalAlignment.CENTER);
|
||||
styleWrap.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||
|
||||
for (int i = 1; i <= 2; i++) {
|
||||
Map<String, List<ImmutablePair<String, String>>> map = new LinkedHashMap<String, List<ImmutablePair<String, String>>>();
|
||||
|
||||
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<ImmutablePair<String, String>> list = map.get(time);
|
||||
if (list == null)
|
||||
list = new LinkedList<ImmutablePair<String, String>>();
|
||||
|
||||
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");
|
||||
|
||||
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);
|
||||
|
||||
list.add(new ImmutablePair<String, String>(title, details));
|
||||
logger.info("{} -> {}", time, title);
|
||||
}
|
||||
|
||||
map.put(time, list);
|
||||
}
|
||||
|
||||
XSSFSheet sheet = workBook.createSheet();
|
||||
workBook.setSheetName(i - 1, "Day " + i);
|
||||
int rownum = 0;
|
||||
for (Map.Entry<String, List<ImmutablePair<String, String>>> entry : map.entrySet()) {
|
||||
|
||||
Row row = sheet.createRow(rownum++);
|
||||
|
||||
int cellnum = 0;
|
||||
Cell cell = row.createCell(cellnum++);
|
||||
cell.setCellValue(entry.getKey());
|
||||
|
||||
for (ImmutablePair<String, String> value : entry.getValue()) {
|
||||
cell = row.createCell(cellnum++);
|
||||
cell.setCellValue(value.getKey());
|
||||
cell.setCellStyle(styleWrap);
|
||||
if (value.getValue() != null) {
|
||||
Drawing<?> drawing = cell.getSheet().createDrawingPatriarch();
|
||||
ClientAnchor anchor = factory.createClientAnchor();
|
||||
anchor.setCol1(cellnum);
|
||||
anchor.setCol2(cellnum + 5);
|
||||
anchor.setRow1(row.getRowNum());
|
||||
anchor.setRow2(row.getRowNum() + 8);
|
||||
Comment comment = drawing.createCellComment(anchor);
|
||||
comment.setString(factory.createRichTextString(value.getValue()));
|
||||
cell.setCellComment(comment);
|
||||
}
|
||||
sheet.setColumnWidth(cellnum - 1, 1024 * 5);
|
||||
}
|
||||
if (cellnum > 2)
|
||||
sheet.createRow(rownum++);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
workBook.write(new FileOutputStream(new File(doc.title() + ".xlsx")));
|
||||
workBook.close();
|
||||
}
|
||||
|
||||
}
|
14
src/main/resources/log4j2-test.xml
Normal file
14
src/main/resources/log4j2-test.xml
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration>
|
||||
<Appenders>
|
||||
<Console name="Console" target="SYSTEM_OUT">
|
||||
<PatternLayout
|
||||
pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
|
||||
</Console>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
<Root level="debug">
|
||||
<AppenderRef ref="Console" />
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Configuration>
|
Reference in a new issue