From the course: Practical GitHub Actions
Finishing up the RSS feed - GitHub Tutorial
From the course: Practical GitHub Actions
Finishing up the RSS feed
- [Instructor] All right, so let's build out more of our XML document. Some of this is pretty boring because basically we're going to take this right here and copy it a bunch of times to create most of the other elements from the RSS feed. So we'll do like the length language, like all the different things that are right here. And it's pretty much just a copy of what's in here. So I'm going to copy this a bunch of times and I'll be just replacing the different elements here. So we'll get the format, let's see, we'll get the subtitle as well. There's an element called author. Now here, although I've called this element just to make it easier for me to write author, the actual element is called iTunes author. So here, the element on this side is going to call the iTunes prefix, but it's going to retrieve from the YAML data the author element. All right, then we need a description. We're going to need an image. And this one also gets the iTunes prefix here. We're going to get language. And let's see, I think that's all the ones that we need for right now. We're also going to create a link element, so we're going to use that in different places. So I'm going to create one called link prefix and it's going to hold the URL that we got when we created the GitHub page. So we'll do YAML data and we'll read the link variable, which we'll need to add and create. So let's go ahead and do that. So somewhere in this YAML file, I'm going to add an additional item called link. And what I want to do here is go back into my repo and make sure that I go to settings and I scroll down to pages, and I copy whatever this link is right here. Remember, yours will be a little bit different. I have a custom URL setup on my website, so yours might be a little bit longer and have like your username. So let's go ahead and go back here, and we'll paste that in there. I'm not going to add that trailing slash, just this right here. All right, so next, let's go back into the Python document. And when I use the image, I'm going to add the prefix to that. So iTunes image is actually going to be a little bit different. So if we look at the RSS feed, the image is kind of like an image tag, right? So it has the attribute not inside the item. So it's not like a simple one like this title that has the data right here, but it's like the RSS feed. It has an attribute. So that does need to be written a little bit different. And I'm going to use this link prefix variable that I created here to add that. So instead of that text, it's going to say iTunes image right here. And then it's going to have a list of attributes here, and href. And then I'm going to use that link prefix and also get that YAML data image variable here. And I don't need to put the text right there. So that's that one. And I need to go ahead and create one for the link now that I have it available to me. This'll be just like all the other ones. It'll say link, and then I'll use just the link prefix variable, right? Let's do another one that's sort of a little bit odd, and I think I'm going to call P, this image, one because it's the category. And the category is like the image. It stores the data in the attribute. So category, and this is going to have an element called text, and it's just going to be read it from the YAML data and category. So that should work for that. Okay, so now, after the sort of header section of the feed, so basically all this stuff right here, you have this section called item, right? And there are a series of items. I can see them all here. And each one of those items is basically an episode for the podcast. So we need to create that section, and for that we're going to need to create a loop. So we'll save for item in YAML data, and we're going to read the item section. And then in here, item element. Let's see, element. It's going to go to the XML tree sub element, sort of similar to before channel element item. So we're creating kind of the container for the items for the episodes. And then in here, XML tree, sub element, item element. And then sort of similar to before, title.text = for each of the items. All right, so if you look at the YAML file, here's the items sort of container, and each one of these items has the information right here, which is what we're reading now into these different variables. So they're all going to be pretty similar. This one will be title, then iTunes author. We're including an author tag for each episode. I'm the author for every episode. So here, I'm just actually going to use YAML data instead of the item data, and look for the author. So I do have like an author section right here, and I'm just using that instead of having to put in an additional, you know, sort of thing here in each of these items that is going to be the same. I'm just creating it up here, and then I'm bringing it into feed.py, so. Okay, so now we need a description for the episode. We need a duration, that should be also here. And this should be another one that gets the iTunes prefix here for duration. And then we get something called pub date. And in my YAML file, it's called published, right? So I guess I was a little bit fancy and I, instead of calling it pub date, I called it publish. It has like a very strange kind of format, formatting Greenwich Mean Time. Other than that, we need to create another strange element. It's called the enclosure. So the enclosure, each one of these items has an enclosure element. It has the length in bytes of the episode, plus the type of element that it is, plus the URL of the episode. So we're going to need this as a separate item. So let's see, we'll do enclosure, XML tree, sub element, item, element. And it's similar to the other ones that we've done. So this one has sub items. It's basically an item with attributes, so it gets this sort of notation that we've been using in different places. So for the URL, I'm going to use the link prefix variable so I don't have to type all that out, and then plus item file. Now here, my types are always going to be the same. I could put an attribute that has that, but they're always going to be MP3 files. So the type is always going to be exactly the same. I'm just going to hardcode that in here. You can put in another element if you want to. And then length, item length right here. Cool. And then the rest should be just fine. So let's go ahead and save this. We'll try it out and we'll go ahead and execute it. So we'll do Python and then feed.py. All right, so it looks like I need to go ahead and add quotes in a few places here. So this data should have referred to an item, and this item right here should have quotes for this file. And also each of these should have quotes, like that. So let's try this out. Clear this out, and you can see that now it execute it. And if I look at podcast.xml, I'll do a word wrap so you can see that it's a lot longer because it has all the data in the nice RSS feed format with each of the different items for the different episodes. So this is really ready for an iTunes or any other feed that you would want, but we want to automate this process a lot more. So we'll keep on working on this.