[tracker/miner-rss-0.11-fixes: 3/3] tracker-miner-rss: Added --add-feed and --title options
- From: Martyn James Russell <mr src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/miner-rss-0.11-fixes: 3/3] tracker-miner-rss: Added --add-feed and --title options
- Date: Wed, 27 Apr 2011 17:16:06 +0000 (UTC)
commit e9c9742d8f3b23c28b5b13068a739f2025400ffc
Author: Martyn Russell <martyn lanedo com>
Date: Wed Apr 27 18:15:01 2011 +0100
tracker-miner-rss: Added --add-feed and --title options
This allows people to add feeds easily which can then be tracked using
tracker-search --feeds.
docs/manpages/Makefile.am | 5 ++
docs/manpages/tracker-miner-rss.1 | 54 ++++++++++++++++++++++
src/miners/rss/tracker-main.c | 88 ++++++++++++++++++++++++++++++++++++-
3 files changed, 145 insertions(+), 2 deletions(-)
---
diff --git a/docs/manpages/Makefile.am b/docs/manpages/Makefile.am
index 16ca716..127787f 100644
--- a/docs/manpages/Makefile.am
+++ b/docs/manpages/Makefile.am
@@ -12,6 +12,10 @@ if HAVE_TRACKER_NEEDLE
tn = tracker-needle.1
endif
+if HAVE_TRACKER_MINER_RSS
+tmrss = tracker-miner-rss.1
+endif
+
common = \
tracker-extract.1 \
tracker-import.1 \
@@ -27,6 +31,7 @@ common = \
# Install only common and enabled manpages
man_MANS = \
$(common) \
+ $(tmrss) \
$(tsb) \
$(tn) \
$(ta) \
diff --git a/docs/manpages/tracker-miner-rss.1 b/docs/manpages/tracker-miner-rss.1
new file mode 100644
index 0000000..9df56ca
--- /dev/null
+++ b/docs/manpages/tracker-miner-rss.1
@@ -0,0 +1,54 @@
+.TH tracker-miner-rss 1 "September 2009" GNU "User Commands"
+
+.SH NAME
+tracker-miner-rss \- Used to populate Tracker with RSS feed data.
+
+.SH SYNOPSIS
+\fBtracker-miner-rss\fR [\fIOPTION\fR...]
+
+.SH DESCRIPTION
+.B tracker-miner-rss
+is not supposed to be run by the user since it is started by
+its .desktop file when the user logs in. It can also be started
+manually of course for debugging purposes. You can not run more than
+one instance of this at the same time.
+
+.B tracker-miner-rss
+mines information about RSS feeds only.
+
+.SH OPTIONS
+.TP
+.B \-?, \-\-help
+Show summary of options.
+.TP
+.B \-V, \-\-version
+Returns the version of this binary.
+.TP
+.B \-v, \-\-verbosity={0|1|2|3}
+Sets the logging level, 0=errors, 1=minimal, 2=detailed, 3=debug.
+.TP
+.B \-a, \-\-add-feed=URL
+Adds a feed to the Tracker store. This must be used with
+.B \-\-title
+option. An examples of such a URL would be:
+
+ http://planet.gnome.org/atom.xml
+
+ http://newsrss.bbc.co.uk/rss/sportplayer_uk_edition/motorsport/rss.xml
+
+ ...
+
+You can use
+.B tracker-search --feeds
+to get the latest feed information.
+
+.TP
+.B \-t, \-\-title=STRING
+The title to use when adding a feed (see the
+.B \-\-add-feed
+option).
+
+.SH SEE ALSO
+.BR tracker-store (1),
+.BR tracker-info (1),
+.BR tracker-search (1).
diff --git a/src/miners/rss/tracker-main.c b/src/miners/rss/tracker-main.c
index 58f62bb..b3b2501 100644
--- a/src/miners/rss/tracker-main.c
+++ b/src/miners/rss/tracker-main.c
@@ -30,6 +30,8 @@
#include "tracker-miner-rss.h"
static gint verbosity = -1;
+static gchar *add_feed;
+static gchar *title;
static GOptionEntry entries[] = {
{ "verbosity", 'v', 0,
@@ -37,6 +39,14 @@ static GOptionEntry entries[] = {
N_("Logging, 0 = errors only, "
"1 = minimal, 2 = detailed and 3 = debug (default=0)"),
NULL },
+ { "add-feed", 'a', 0,
+ G_OPTION_ARG_STRING, &add_feed,
+ N_("Add feed (must be used with --title)"),
+ N_("URL") },
+ { "title", 't', 0,
+ G_OPTION_ARG_STRING, &title,
+ N_("Title to use (must be used with --add-feed)"),
+ NULL },
{ NULL }
};
@@ -48,6 +58,7 @@ main (int argc, char **argv)
GOptionContext *context;
TrackerMinerRSS *miner;
GError *error = NULL;
+ const gchar *error_message;
g_type_init ();
g_thread_init (NULL);
@@ -65,8 +76,81 @@ main (int argc, char **argv)
context = g_option_context_new (_("- start the feeds indexer"));
g_option_context_add_main_entries (context, entries, NULL);
g_option_context_parse (context, &argc, &argv, NULL);
+
+ if ((add_feed && !title) || (!add_feed && title)) {
+ error_message = _("Adding a feed requires --add-feed and --title");
+ } else {
+ error_message = NULL;
+ }
+
+ if (error_message) {
+ gchar *help;
+
+ g_printerr ("%s\n\n", error_message);
+
+ help = g_option_context_get_help (context, TRUE, NULL);
+ g_option_context_free (context);
+ g_printerr ("%s", help);
+ g_free (help);
+
+ return EXIT_FAILURE;
+ }
+
g_option_context_free (context);
+ if (add_feed && title) {
+ TrackerSparqlConnection *connection;
+ const gchar *query;
+
+ g_print ("Adding feed:\n"
+ " title:'%s'\n"
+ " url:'%s'\n",
+ title,
+ add_feed);
+
+ connection = tracker_sparql_connection_get (NULL, &error);
+
+ if (!connection) {
+ g_printerr ("%s: %s\n",
+ _("Could not establish a connection to Tracker"),
+ error ? error->message : _("No error given"));
+ g_clear_error (&error);
+ return EXIT_FAILURE;
+ }
+
+ /* FIXME: Make interval configurable */
+ query = g_strdup_printf ("INSERT {"
+ " _:FeedSettings a mfo:FeedSettings ;"
+ " mfo:updateInterval 20 ."
+ " _:Feed a nie:DataObject, mfo:FeedChannel ;"
+ " mfo:feedSettings _:FeedSettings ;"
+ " nie:url \"%s\" ;"
+ " nie:title \"%s\" . "
+ "}",
+ add_feed,
+ title);
+
+ tracker_sparql_connection_update (connection,
+ query,
+ G_PRIORITY_DEFAULT,
+ NULL,
+ &error);
+
+ if (error) {
+ g_printerr ("%s, %s\n",
+ _("Could not add feed"),
+ error->message);
+ g_error_free (error);
+ g_object_unref (connection);
+
+ return EXIT_FAILURE;
+ }
+
+ g_print ("Done\n");
+
+ return EXIT_SUCCESS;
+ }
+
tracker_log_init (verbosity, &log_filename);
g_print ("Starting log:\n File:'%s'\n", log_filename);
g_free (log_filename);
@@ -75,7 +159,7 @@ main (int argc, char **argv)
if (!miner) {
g_printerr ("Cannot create new RSS miner: '%s', exiting...\n",
error ? error->message : "unknown error");
- return -1;
+ return EXIT_FAILURE;
}
tracker_miner_start (TRACKER_MINER (miner));
@@ -87,5 +171,5 @@ main (int argc, char **argv)
g_main_loop_unref (loop);
g_object_unref (miner);
- return 0;
+ return EXIT_SUCCESS;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]