Add initial attempt at rss feed generation

This commit is contained in:
Nathan McRae 2025-04-16 22:58:01 -07:00
parent 897dcac243
commit a2fece0143
2 changed files with 48 additions and 0 deletions

View File

@ -97,6 +97,11 @@
<artifactId>result</artifactId>
<version>1.0.0.0</version>
</dependency>
<dependency>
<groupId>com.rometools</groupId>
<artifactId>rome</artifactId>
<version>2.1.0</version>
</dependency>
</dependencies>
<build>

View File

@ -7,9 +7,20 @@ import com.jcraft.jsch.Session;
import com.jcraft.jsch.SftpException;
import com.leakyabstractions.result.api.Result;
import com.leakyabstractions.result.core.Results;
import com.rometools.rome.feed.synd.SyndContent;
import com.rometools.rome.feed.synd.SyndContentImpl;
import com.rometools.rome.feed.synd.SyndEntry;
import com.rometools.rome.feed.synd.SyndEntryImpl;
import com.rometools.rome.feed.synd.SyndFeed;
import com.rometools.rome.feed.synd.SyndFeedImpl;
import com.rometools.rome.io.SyndFeedInput;
import com.rometools.rome.io.SyndFeedOutput;
import com.tearsofaunicorn.wordpress.api.model.Post;
import com.tearsofaunicorn.wordpress.api.WordpressClient;
import java.io.IOException;
import java.io.File;
import java.io.Writer;
import java.io.FileWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
@ -250,6 +261,37 @@ public class Main extends Application {
break;
case StationSettings.MessageMethod.SFTP:
//loadedStation.uploadNextMessageToSFTP();
Path rssPath = stationDirPath.resolve("feed.xml");
SyndFeed feed;
if (Files.exists(rssPath)) {
SyndFeedInput input = new SyndFeedInput();
feed = input.build(new File(rssPath.toString()));
} else {
feed = new SyndFeedImpl();
feed.setFeedType("rss_1.0");
feed.setTitle("Blog");
feed.setLink(loadedStation.getAddress());
feed.setDescription("Sample blog");
}
SyndEntry entry = new SyndEntryImpl();
entry.setTitle("TODO: date?");
entry.setLink(loadedStation.getAddress());
SyndContent description = new SyndContentImpl();
description.setType("text/html");
description.setValue(messageText);
entry.setDescription(description);
feed.getEntries().add(entry);
Writer writer = new FileWriter(rssPath.toString());
SyndFeedOutput syndFeedOutput = new SyndFeedOutput();
syndFeedOutput.output(feed, writer);
writer.close();
JSch jsch = new JSch();
try {
Session session = jsch.getSession(loadedStation.getUsername(), loadedStation.getAddress(), 22);
@ -263,6 +305,7 @@ public class Main extends Application {
String localFile = loadedStation.nextMessagePath().toString();
channel.put(localFile, "www/message.txt");
channel.put(rssPath.toString(), "www/feed.xml");
channel.exit();
session.disconnect();
} else {