Created
September 1, 2021 04:45
-
-
Save hyrmn/f98ed2a1267c363688099811ac8b79ba to your computer and use it in GitHub Desktop.
RSS + media thumbnail with XLinq and I don't know why
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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