Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Собираем таблицу с базовой информацией о статьях
- Loading branch information
Showing
6 changed files
with
79 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
/.idea/ | ||
/out/ | ||
/*.json | ||
/*.csv |
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
39 changes: 39 additions & 0 deletions
39
src/main/java/com/newbilius/HabrStatisticCollector/AnalyticsGenerators/FullTable.java
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,39 @@ | ||
package com.newbilius.HabrStatisticCollector.AnalyticsGenerators; | ||
|
||
import com.newbilius.HabrStatisticCollector.CSVWriteHelper; | ||
import com.newbilius.HabrStatisticCollector.HabrItem; | ||
|
||
import java.io.IOException; | ||
|
||
public class FullTable implements IAnalyticsGenerator { | ||
@Override | ||
public void generate(HabrItem[] items) { | ||
try { | ||
try (var csvWriter = CSVWriteHelper.createCSVWriter("Статьи с основными параметрами.csv")) { | ||
csvWriter.writeNext(new String[]{ | ||
"Заголовок", | ||
"Плюсов", | ||
"Закладки", | ||
"Комментариев", | ||
"Просмотров", | ||
"URL", | ||
"Автор", | ||
}); | ||
|
||
for (var item : items) { | ||
csvWriter.writeNext(new String[]{ | ||
item.Title, | ||
String.valueOf(item.Score), | ||
String.valueOf(item.Bookmarks), | ||
String.valueOf(item.Comments), | ||
String.valueOf(item.Views), | ||
item.Url, | ||
item.Author | ||
}); | ||
} | ||
} | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...in/java/com/newbilius/HabrStatisticCollector/AnalyticsGenerators/IAnalyticsGenerator.java
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,7 @@ | ||
package com.newbilius.HabrStatisticCollector.AnalyticsGenerators; | ||
|
||
import com.newbilius.HabrStatisticCollector.HabrItem; | ||
|
||
public interface IAnalyticsGenerator { | ||
void generate(HabrItem[] items); | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/newbilius/HabrStatisticCollector/CSVWriteHelper.java
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,15 @@ | ||
package com.newbilius.HabrStatisticCollector; | ||
|
||
import au.com.bytecode.opencsv.CSVWriter; | ||
|
||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
public class CSVWriteHelper { | ||
public static CSVWriter createCSVWriter(String fileName) throws IOException { | ||
return new CSVWriter(new FileWriter(fileName, | ||
StandardCharsets.UTF_8, | ||
false), ';'); | ||
} | ||
} |
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