# Nim RSS (Really Simple Syndication) module # Orginally written by Adam Chesak. # Rewritten by John Conway # Released under the MIT open source license. import httpclient import strutils import sequtils import xmlparser import xmltree import streams import sugar type RSS* = object title*: string link*: string description*: string language*: string copyright*: string managingEditor*: string webMaster*: string pubDate*: string lastBuildDate*: string categories*: seq[RSSCategory] generator*: string docs*: string cloud*: RSSCloud ttl*: int image*: RSSImage rating*: string textInput*: RSSTextInput skipHours*: seq[int] skipDays*: seq[string] items*: seq[RSSItem] RSSText = ref object of RootObj text*: string RSSCategory = ref object of RSSText domain*: string RSSEnclosure* = object url*: string length*: string enclosureType*: string RSSCloud* = object domain*: string port*: string path*: string registerProcedure*: string protocol*: string RSSImage* = object url*: string title*: string link*: string width*: string height*: string description*: string RSSTextInput* = object title*: string description*: string name*: string link*: string RSSSource* = ref object of RSSText url*: string RSSItem* = object title*: string link*: string description*: string author*: string categories*: seq[RSSCategory] comments*: string enclosure*: RSSEnclosure guid*: string pubDate*: string source*: RSSSource converter rssToString*(obj: RSSText): string = return obj.text func parseCategories( node: XmlNode ): seq[RSSCategory] = var categories:seq[RSSCategory] for cat_node in node.findAll("category"): var category: RSSCategory = RSSCategory() if cat_node.attr("domain") != "": category.domain = cat_node.attr("domain") category.text = cat_node.innerText categories.add(category) if categories.len == 0: return @[] return categories func parseText ( node: XmlNode ): string = var content = node.innerText if content[0 .. 8] == " int => x.innerText.parseInt() ) if channel.child("skipDays") != nil: rss.skipDays = map(channel.findAll("day"), (x: XmlNode) -> string => x.innerText) # If there are no items: if channel.child("item") == nil and root.child("item") == nil: rss.items = @[] return rss # Otherwise, add the items. if channel.child("item") != nil: rss.items = map(channel.findAll("item"), parseItem) else: rss.items = map(root.findAll("item"), parseItem) # Return the RSS data. return rss