Skip to content

Instantly share code, notes, and snippets.

@hyrmn
Created September 1, 2021 04:45
Show Gist options
  • Save hyrmn/f98ed2a1267c363688099811ac8b79ba to your computer and use it in GitHub Desktop.
Save hyrmn/f98ed2a1267c363688099811ac8b79ba to your computer and use it in GitHub Desktop.
RSS + media thumbnail with XLinq and I don't know why
record Pan(string Style, decimal Price, string ProductUrl, string ThumbnailUrl)
{
public XElement ToRss(XNamespace mediaNs)
{
return new XElement("item",
new XElement("title", Style),
new XElement("description", $"Buy now for {Price}"),
new XElement("link", ProductUrl),
new XElement(mediaNs + "thumbnail", new XAttribute("url", ThumbnailUrl))
);
}
}
public class why
{
public void make_an_rss()
{
var pans = new List<Pan> { new Pan("Detroit", 30m, "https://onlypans.pizza/buy-detroit", "https://hotpanaction.pizza/detroitpan.png") };
var mediaNs = XNamespace.Get("http://search.yahoo.com/mrss");
var doc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"),
new XElement("rss", new XAttribute("version", "2.0"), new XAttribute(XNamespace.Xmlns + "media", mediaNs),
new XElement("channel",
new XElement("title", "xt0rted's house of deals"),
new XElement("link", "https://onlypans.pizza/"),
new XElement("description", "Bring the cheese if you please"),
new XElement("lastBuildDate", DateTimeOffset.UtcNow.ToString("O")),
pans.Select(pan => pan.ToRss(mediaNs))
)));
var rss = doc.ToString(SaveOptions.None);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment