Skip to content

Commit

Permalink
Add support for atom feeds
Browse files Browse the repository at this point in the history
  • Loading branch information
meisenzahl committed Nov 10, 2019
1 parent a6347e5 commit f1b3e0c
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
62 changes: 61 additions & 1 deletion src/Controllers/FeedController.vala
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public class Controllers.FeedController : Object {
view: new Views.FeedView (model)
);


update ();
}

Expand Down Expand Up @@ -58,6 +57,8 @@ public class Controllers.FeedController : Object {
parse_rss (root);
break;
case "feed":
parse_atom (root);
break;
default:
stderr.printf ("not implemented\n");
break;
Expand Down Expand Up @@ -119,4 +120,63 @@ public class Controllers.FeedController : Object {
}
}
}

private void parse_atom (Xml.Node* root) {
for (var child = root->children; child != null; child = child->next) {
switch (child->name) {
case "title":
model.title = child->get_content ();
break;
case "subtitle":
model.description = child->get_content ();
break;
case "link":
if (child->get_prop ("rel") == "self") {
model.source = child->get_prop ("href");
} else {
model.url = child->get_prop ("href");
}
break;
case "entry":
var article = new Models.Article ();
for (var childitem = child->children; childitem != null; childitem = childitem->next) {
switch (childitem->name) {
case "title":
article.title = childitem->get_content ();
break;
case "summary":
article.about = childitem->get_content ();
break;
case "link":
if (article.url == null) {
article.url = childitem->get_prop ("href");
}
break;
case "published":
article.published = new DateTime.from_iso8601 (
childitem->get_content (), new TimeZone.utc ()
);
break;
case "updated":
article.updated = new DateTime.from_iso8601 (
childitem->get_content (), new TimeZone.utc ()
);

if (article.published == null) {
article.published = new DateTime.from_iso8601 (
childitem->get_content (), new TimeZone.utc ()
);
}

break;
}
}

new Controllers.ArticleController (article).update ();

model.add_article (article);
break;
}
}
}
}
1 change: 1 addition & 0 deletions src/Models/Feed.vala
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class Models.Feed : Object {
public string title { get; set; }
public string description { get; set; }
public string link { get; set; }
public string source { get; set; }
public string copyright { get; set; }

public signal void added_article (Models.Article article);
Expand Down

0 comments on commit f1b3e0c

Please sign in to comment.