summaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authorNikita Kostovsky <nikita@kostovsky.me>2025-06-22 16:54:02 +0200
committerNikita Kostovsky <nikita@kostovsky.me>2025-06-22 16:54:02 +0200
commitf674e179d602d3ccb9818d28fe06f371059449dc (patch)
tree996fb624986512de91581a18332f004d34220ba2 /src/main.cpp
parse and insert feeds and items
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp90
1 files changed, 90 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp
new file mode 100644
index 0000000..f9fab22
--- /dev/null
+++ b/src/main.cpp
@@ -0,0 +1,90 @@
+#include <QCoreApplication>
+#include <QDir>
+#include <QFile>
+#include <QFileInfo>
+#include <QStandardPaths>
+#include <QTimer>
+
+#include "constants.h"
+#include "playground.h"
+#include "rsshit_db.h"
+
+int main(int argc, char *argv[])
+{
+ QCoreApplication a(argc, argv);
+
+ // Set up code that uses the Qt event loop here.
+ // Call a.quit() or a.exit() to quit the application.
+ // A not very useful example would be including
+ // #include <QTimer>
+ // near the top of the file and calling
+ // QTimer::singleShot(5000, &a, &QCoreApplication::quit);
+ // which quits the application after 5 seconds.
+
+ // If you do not need a running Qt event loop, remove the call
+ // to a.exec() or use the Non-Qt Plain C++ Application template.
+
+ QFile dbSqliteResource{rsshit::db::dbSqliteResourceFilename};
+ const auto dataLocation = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
+ qDebug() << "data location:" << dataLocation;
+
+ if (!QDir{}.mkpath(dataLocation)) {
+ qWarning() << "cannot create " << dataLocation;
+ return EXIT_FAILURE;
+ }
+
+ const QString newDbFilepath{dataLocation + '/' + QFileInfo{dbSqliteResource}.fileName()};
+
+ // #define RECREATE_DB_FILE
+
+#ifdef RECREATE_DB_FILE
+ if (!QFile::remove(newDbFilepath)) {
+ qWarning() << "cannot remove" << newDbFilepath;
+ }
+
+ if (!dbSqliteResource.copy(newDbFilepath)) {
+ qWarning() << "cannot copy db file (" << dbSqliteResource.fileName()
+ << ") from resources to data dir (" << newDbFilepath
+ << "):" << dbSqliteResource.errorString();
+ return EXIT_FAILURE;
+ }
+#endif
+
+ QFile newDbFile{newDbFilepath};
+
+ if (!newDbFile.setPermissions(QFileDevice::Permission::ReadUser
+ | QFileDevice::Permission::WriteUser)) {
+ qWarning() << "cannot set file permissions:" << newDbFile.fileName() << Qt::endl
+ << newDbFile.errorString();
+
+ return EXIT_FAILURE;
+ }
+
+ Playground playground;
+
+ QTimer::singleShot(0, [&]() {
+ // const QString url{"https://jenngott.com/feed/"};
+ // const QUrl url{"https://liliputing.com/feed"};
+ // playground.fetchUrl(url);
+ // return;
+ // QFile f{"/tmp/rss/feed"};
+ QFile f{"/home/nikita/tmp/rss/feed"};
+ // QFile f{"/tmp/rss/feed.1"};
+ // QFile f{"/tmp/rss/rss"};
+
+ if (!f.open(QFile::ReadOnly)) {
+ qWarning() << "cannot open file" << f.fileName() << ":" << f.errorString();
+ return;
+ }
+
+ const auto channel = playground.parseFeed(&f);
+
+ if (!applyToDb(channel)) {
+ qWarning() << "cannot apply channel to db";
+
+ return;
+ }
+ });
+
+ return a.exec();
+}