podcast-rss-md 0.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- podcast_rss_md-0.0.1/.gitignore +10 -0
- podcast_rss_md-0.0.1/LICENSE +19 -0
- podcast_rss_md-0.0.1/PKG-INFO +99 -0
- podcast_rss_md-0.0.1/README.md +71 -0
- podcast_rss_md-0.0.1/pyproject.toml +64 -0
- podcast_rss_md-0.0.1/src/podcast_rss_md/__about__.py +1 -0
- podcast_rss_md-0.0.1/src/podcast_rss_md/__init__.py +0 -0
- podcast_rss_md-0.0.1/src/podcast_rss_md/__main__.py +6 -0
- podcast_rss_md-0.0.1/src/podcast_rss_md/cli.py +10 -0
- podcast_rss_md-0.0.1/src/podcast_rss_md/podcast_rss_md.py +188 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) 2026 Paul E Cooley
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
SOFTWARE.
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: podcast_rss_md
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Reads an RSS feed with enclosures and creates Hugo static markdown files with their content.
|
|
5
|
+
Author-email: Paul E Cooley <paul@shadowpublications.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Classifier: Operating System :: OS Independent
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
12
|
+
Requires-Python: >=3.14
|
|
13
|
+
Requires-Dist: beautifulsoup4
|
|
14
|
+
Requires-Dist: feedparser
|
|
15
|
+
Requires-Dist: feedparser-sgmllib
|
|
16
|
+
Requires-Dist: iniconfig
|
|
17
|
+
Requires-Dist: jinja2
|
|
18
|
+
Requires-Dist: markdownify
|
|
19
|
+
Requires-Dist: markupsafe
|
|
20
|
+
Requires-Dist: packaging
|
|
21
|
+
Requires-Dist: pluggy
|
|
22
|
+
Requires-Dist: pygments
|
|
23
|
+
Requires-Dist: pytest
|
|
24
|
+
Requires-Dist: soupsieve
|
|
25
|
+
Requires-Dist: typer
|
|
26
|
+
Requires-Dist: typing-extensions
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
# Podcast RSS MD Converter
|
|
30
|
+
A simple utility to create Markdown files from an RSS feed, which typically has podcast enclosures for audio.
|
|
31
|
+
The converter rips through each entry in an RSS Feed using [FeedParser](https://github.com/kurtmckee/feedparser) and populates an object with the details of that entry. The object is then passed to a [Jinja2](https://jinja.palletsprojects.com/en/stable/) template to create a properly formatted Markdown file. Any HTML in the summary/description fields are then converted from HTML into Markdown compatible code using [Markdownify](https://github.com/matthewwithanm/python-markdownify).
|
|
32
|
+
|
|
33
|
+
## Installation
|
|
34
|
+
The converter is easily installed from the source code using [pipx](https://pipx.pypa.io/stable/). The source code contains a sample template designed for using with the [Hugo](https://gohugo.io/documentation/) static site generator. While the utility was originally designed for Hugo, the system can use any Jinja2 template and provide it with the fields for an entry.
|
|
35
|
+
|
|
36
|
+
## Fields
|
|
37
|
+
The following fields are populated by the converter:
|
|
38
|
+
* `published`: Date/time the RSS entry was originally published
|
|
39
|
+
* `title`: The RSS entry's title
|
|
40
|
+
* `enclosure`: The URL pointing to the audio file used in the entry.
|
|
41
|
+
* `author`: The entry's author field
|
|
42
|
+
* `summary`: The summary field typically has HTML tags which are converted into Markdown.
|
|
43
|
+
|
|
44
|
+
These are by no means the entire set of fields available via the FeedParser library, but are sufficient for most needs. You are more than welcome to add more fields and logic into the converter.
|
|
45
|
+
|
|
46
|
+
## Usage
|
|
47
|
+
### Running from source
|
|
48
|
+
Download the github repository. With pipx installed, run the following command in the project root:
|
|
49
|
+
|
|
50
|
+
`pipx run --no-cache --spec . podcast_rss_md [feedURL] [templateFile] [outputdir]`
|
|
51
|
+
|
|
52
|
+
### Validation
|
|
53
|
+
The converter requires all three arguments (*feedURL*, *templateFile*, and *outputdir*).
|
|
54
|
+
It expects that the *templateFile* exists and is valid, as well as the *outputdir*.
|
|
55
|
+
The *feedURL* should be a URL pointing to a file on the internet, or a `file:///` pointing to a local file.
|
|
56
|
+
|
|
57
|
+
### Local installation
|
|
58
|
+
From the project root directory, run:
|
|
59
|
+
|
|
60
|
+
`pipx install .`
|
|
61
|
+
|
|
62
|
+
This will created a command called `podcast_rss_md` which you can then run at the command line.
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
## Testing and Sample RSS Feed
|
|
66
|
+
Rather than pointing to an RSS Feed located online and thus requiring network access, the `tests` directory includes a sample RSS file, `rss_test.xml`, containing two entries with enclosures. The pair of entries are *real* in the sense that they were taken directly from an existing RSS feed.
|
|
67
|
+
|
|
68
|
+
## Caveats
|
|
69
|
+
While [FeedParser](https://feedparser.readthedocs.io/en/latest/reference/) will provide the caller with dozens of entries, the converter makes use of only a small subset. Therefore, it would be preferable to have the converter provide all of the fields for a template, regardless of whether or not it needs them. Perhaps in the future, one will provide a simple text file containing the fields to populate from FeedParser's API.
|
|
70
|
+
|
|
71
|
+
## Room for improvement
|
|
72
|
+
The converter doesn't currently handle Hugo's [taxonomy](https://gohugo.io/content-management/taxonomies/). I didn't want to make the entire utility specific for Hugo, but it's quite simple to add logic into the base converter to populate the taxonomies based on elements in the RSS Entry. In the case of Shadowpublications.com, I used simple parsing rules to populate these tags.
|
|
73
|
+
|
|
74
|
+
`book_names = [
|
|
75
|
+
"An Ancient Trap",
|
|
76
|
+
"Sacculina",
|
|
77
|
+
"Neptune Scars",
|
|
78
|
+
"Kill Shelter",
|
|
79
|
+
"The Black",
|
|
80
|
+
"The Black: Arrival",
|
|
81
|
+
"The Black: Outbreak",
|
|
82
|
+
"The Black: Evolution",
|
|
83
|
+
"The Black: Oceania"
|
|
84
|
+
]`
|
|
85
|
+
|
|
86
|
+
`...`
|
|
87
|
+
|
|
88
|
+
`for x in book_names:
|
|
89
|
+
if post.title.find(x) != -1:
|
|
90
|
+
temp["tags"] = [x]
|
|
91
|
+
`
|
|
92
|
+
|
|
93
|
+
Again, these are simple rules, but were sufficient for my needs.
|
|
94
|
+
|
|
95
|
+
## Why this utility exists
|
|
96
|
+
After deciding to abandon WordPress for Hugo, I needed a mechanism to create static pages from every entry in my RSS Feeds.
|
|
97
|
+
Rather than attempting to manually create an entry for each RSS entry (my original feeds contain several hundred podcast entries), I wanted something I could use again and again to repopulate my site files.
|
|
98
|
+
|
|
99
|
+
This utility, in one form or another, was used to create [Shadowpublications.com](https://shadowpublications.com) and [Dead Robots' Society](https://deadrobotssociety.com). Each markdown file was then processed in batch by Hugo during site creation.
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# Podcast RSS MD Converter
|
|
2
|
+
A simple utility to create Markdown files from an RSS feed, which typically has podcast enclosures for audio.
|
|
3
|
+
The converter rips through each entry in an RSS Feed using [FeedParser](https://github.com/kurtmckee/feedparser) and populates an object with the details of that entry. The object is then passed to a [Jinja2](https://jinja.palletsprojects.com/en/stable/) template to create a properly formatted Markdown file. Any HTML in the summary/description fields are then converted from HTML into Markdown compatible code using [Markdownify](https://github.com/matthewwithanm/python-markdownify).
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
The converter is easily installed from the source code using [pipx](https://pipx.pypa.io/stable/). The source code contains a sample template designed for using with the [Hugo](https://gohugo.io/documentation/) static site generator. While the utility was originally designed for Hugo, the system can use any Jinja2 template and provide it with the fields for an entry.
|
|
7
|
+
|
|
8
|
+
## Fields
|
|
9
|
+
The following fields are populated by the converter:
|
|
10
|
+
* `published`: Date/time the RSS entry was originally published
|
|
11
|
+
* `title`: The RSS entry's title
|
|
12
|
+
* `enclosure`: The URL pointing to the audio file used in the entry.
|
|
13
|
+
* `author`: The entry's author field
|
|
14
|
+
* `summary`: The summary field typically has HTML tags which are converted into Markdown.
|
|
15
|
+
|
|
16
|
+
These are by no means the entire set of fields available via the FeedParser library, but are sufficient for most needs. You are more than welcome to add more fields and logic into the converter.
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
### Running from source
|
|
20
|
+
Download the github repository. With pipx installed, run the following command in the project root:
|
|
21
|
+
|
|
22
|
+
`pipx run --no-cache --spec . podcast_rss_md [feedURL] [templateFile] [outputdir]`
|
|
23
|
+
|
|
24
|
+
### Validation
|
|
25
|
+
The converter requires all three arguments (*feedURL*, *templateFile*, and *outputdir*).
|
|
26
|
+
It expects that the *templateFile* exists and is valid, as well as the *outputdir*.
|
|
27
|
+
The *feedURL* should be a URL pointing to a file on the internet, or a `file:///` pointing to a local file.
|
|
28
|
+
|
|
29
|
+
### Local installation
|
|
30
|
+
From the project root directory, run:
|
|
31
|
+
|
|
32
|
+
`pipx install .`
|
|
33
|
+
|
|
34
|
+
This will created a command called `podcast_rss_md` which you can then run at the command line.
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
## Testing and Sample RSS Feed
|
|
38
|
+
Rather than pointing to an RSS Feed located online and thus requiring network access, the `tests` directory includes a sample RSS file, `rss_test.xml`, containing two entries with enclosures. The pair of entries are *real* in the sense that they were taken directly from an existing RSS feed.
|
|
39
|
+
|
|
40
|
+
## Caveats
|
|
41
|
+
While [FeedParser](https://feedparser.readthedocs.io/en/latest/reference/) will provide the caller with dozens of entries, the converter makes use of only a small subset. Therefore, it would be preferable to have the converter provide all of the fields for a template, regardless of whether or not it needs them. Perhaps in the future, one will provide a simple text file containing the fields to populate from FeedParser's API.
|
|
42
|
+
|
|
43
|
+
## Room for improvement
|
|
44
|
+
The converter doesn't currently handle Hugo's [taxonomy](https://gohugo.io/content-management/taxonomies/). I didn't want to make the entire utility specific for Hugo, but it's quite simple to add logic into the base converter to populate the taxonomies based on elements in the RSS Entry. In the case of Shadowpublications.com, I used simple parsing rules to populate these tags.
|
|
45
|
+
|
|
46
|
+
`book_names = [
|
|
47
|
+
"An Ancient Trap",
|
|
48
|
+
"Sacculina",
|
|
49
|
+
"Neptune Scars",
|
|
50
|
+
"Kill Shelter",
|
|
51
|
+
"The Black",
|
|
52
|
+
"The Black: Arrival",
|
|
53
|
+
"The Black: Outbreak",
|
|
54
|
+
"The Black: Evolution",
|
|
55
|
+
"The Black: Oceania"
|
|
56
|
+
]`
|
|
57
|
+
|
|
58
|
+
`...`
|
|
59
|
+
|
|
60
|
+
`for x in book_names:
|
|
61
|
+
if post.title.find(x) != -1:
|
|
62
|
+
temp["tags"] = [x]
|
|
63
|
+
`
|
|
64
|
+
|
|
65
|
+
Again, these are simple rules, but were sufficient for my needs.
|
|
66
|
+
|
|
67
|
+
## Why this utility exists
|
|
68
|
+
After deciding to abandon WordPress for Hugo, I needed a mechanism to create static pages from every entry in my RSS Feeds.
|
|
69
|
+
Rather than attempting to manually create an entry for each RSS entry (my original feeds contain several hundred podcast entries), I wanted something I could use again and again to repopulate my site files.
|
|
70
|
+
|
|
71
|
+
This utility, in one form or another, was used to create [Shadowpublications.com](https://shadowpublications.com) and [Dead Robots' Society](https://deadrobotssociety.com). Each markdown file was then processed in batch by Hugo during site creation.
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling >= 1.26"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[tool.setuptools.packages.find]
|
|
6
|
+
where = ["src/"]
|
|
7
|
+
include = ["podcast_rss_md"]
|
|
8
|
+
|
|
9
|
+
[tool.hatch.version]
|
|
10
|
+
path = "src/podcast_rss_md/__about__.py"
|
|
11
|
+
|
|
12
|
+
[tool.hatch.build]
|
|
13
|
+
path="src/"
|
|
14
|
+
|
|
15
|
+
[tool.hatch.build.targets.sdist]
|
|
16
|
+
include = [
|
|
17
|
+
"src/"
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
[tool.hatch.build.targets.wheel]
|
|
21
|
+
packages = [
|
|
22
|
+
"src/podcast_rss_md"
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
[project]
|
|
26
|
+
name = "podcast_rss_md"
|
|
27
|
+
dynamic = ["version"]
|
|
28
|
+
authors = [
|
|
29
|
+
{ name="Paul E Cooley", email="paul@shadowpublications.com" },
|
|
30
|
+
]
|
|
31
|
+
description = "Reads an RSS feed with enclosures and creates Hugo static markdown files with their content."
|
|
32
|
+
readme = "README.md"
|
|
33
|
+
requires-python = ">=3.14"
|
|
34
|
+
classifiers = [
|
|
35
|
+
"Programming Language :: Python :: 3",
|
|
36
|
+
"Operating System :: OS Independent",
|
|
37
|
+
"Programming Language :: Python :: 3",
|
|
38
|
+
"Programming Language :: Python :: 3.14",
|
|
39
|
+
"Programming Language :: Python :: 3.15",
|
|
40
|
+
]
|
|
41
|
+
license = "MIT"
|
|
42
|
+
license-files = ["LICEN[CS]E*"]
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
dependencies = [
|
|
47
|
+
"beautifulsoup4",
|
|
48
|
+
"feedparser",
|
|
49
|
+
"feedparser-sgmllib",
|
|
50
|
+
"iniconfig",
|
|
51
|
+
"Jinja2",
|
|
52
|
+
"markdownify",
|
|
53
|
+
"MarkupSafe",
|
|
54
|
+
"packaging",
|
|
55
|
+
"pluggy",
|
|
56
|
+
"Pygments",
|
|
57
|
+
"pytest",
|
|
58
|
+
"soupsieve",
|
|
59
|
+
"typing_extensions",
|
|
60
|
+
"typer"
|
|
61
|
+
]
|
|
62
|
+
|
|
63
|
+
[project.scripts]
|
|
64
|
+
podcast_rss_md = "podcast_rss_md.cli:main"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
VERSION = "0.0.1"
|
|
File without changes
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Copyright (c) 2026 Paul E Cooley
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
SOFTWARE.
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
import re
|
|
24
|
+
import unicodedata
|
|
25
|
+
from pathlib import Path
|
|
26
|
+
from typing import Annotated
|
|
27
|
+
from urllib.parse import urlparse
|
|
28
|
+
|
|
29
|
+
import feedparser
|
|
30
|
+
from jinja2 import Template
|
|
31
|
+
from markdownify import markdownify as md
|
|
32
|
+
from typer import Argument
|
|
33
|
+
|
|
34
|
+
RSS_ENTRY_FIELDS = [
|
|
35
|
+
"title",
|
|
36
|
+
"link",
|
|
37
|
+
"published",
|
|
38
|
+
"author",
|
|
39
|
+
"summary",
|
|
40
|
+
"enclosure", # podcast specific field
|
|
41
|
+
"tags",
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class BadInitArgumentException(Exception):
|
|
46
|
+
def __init__(self, *args):
|
|
47
|
+
super().__init__(*args)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class InvalidRSSFeedException(BadInitArgumentException):
|
|
51
|
+
pass
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class InvalidTemplatePathException(BadInitArgumentException):
|
|
55
|
+
pass
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
class InvalidOutputDirectoryException(BadInitArgumentException):
|
|
59
|
+
pass
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class PodcastRSSMDConverter:
|
|
63
|
+
def __init__(self, rss_feed, jinja_template_file, output_dir):
|
|
64
|
+
self.rss_feed = rss_feed
|
|
65
|
+
self.jinja_template_file = jinja_template_file
|
|
66
|
+
self.output_dir = output_dir
|
|
67
|
+
|
|
68
|
+
url = urlparse(self.rss_feed)
|
|
69
|
+
result = all([url.scheme, url.path])
|
|
70
|
+
if not result:
|
|
71
|
+
raise InvalidRSSFeedException(
|
|
72
|
+
"Feed url is not valid. Check argument and try again."
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
template_path = Path(self.jinja_template_file)
|
|
76
|
+
if not template_path.exists() or not template_path.is_file():
|
|
77
|
+
raise InvalidTemplatePathException("Template file must exist.")
|
|
78
|
+
|
|
79
|
+
output_path = Path(self.output_dir)
|
|
80
|
+
if not output_path.exists() or not output_path.is_dir():
|
|
81
|
+
raise InvalidOutputDirectoryException(
|
|
82
|
+
"Output path must exist and be a directory. Create directory and try again."
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
self.template = self.get_template()
|
|
86
|
+
|
|
87
|
+
def get_template(self) -> Template:
|
|
88
|
+
with open(self.jinja_template_file) as file_:
|
|
89
|
+
return Template(file_.read())
|
|
90
|
+
|
|
91
|
+
def create_file_name(self, post):
|
|
92
|
+
# need to create a file name from the title.
|
|
93
|
+
# meaning it needs to be escaped.
|
|
94
|
+
"""
|
|
95
|
+
Convert to ASCII if 'allow_unicode' is False. Convert spaces or repeated
|
|
96
|
+
dashes to single dashes. Remove characters that aren't alphanumerics,
|
|
97
|
+
underscores, or hyphens. Convert to lowercase. Also strip leading and
|
|
98
|
+
trailing whitespace, dashes, and underscores.
|
|
99
|
+
The following code borrowed from django/utils/text.py
|
|
100
|
+
"""
|
|
101
|
+
value = post["title"]
|
|
102
|
+
value = (
|
|
103
|
+
unicodedata.normalize("NFKD", value)
|
|
104
|
+
.encode("ascii", "ignore")
|
|
105
|
+
.decode("ascii")
|
|
106
|
+
)
|
|
107
|
+
value = re.sub(r"[^\w\s-]", "", value.lower())
|
|
108
|
+
value = re.sub(r"[-\s]+", "-", value).strip("-_")
|
|
109
|
+
value = f"{value}.md"
|
|
110
|
+
return value
|
|
111
|
+
|
|
112
|
+
def process_posts(self, posts):
|
|
113
|
+
for post in posts:
|
|
114
|
+
outputText = self.template.render(item=post)
|
|
115
|
+
file_name = self.create_file_name(post)
|
|
116
|
+
with open(f"{self.output_dir}/{file_name}", "w") as f:
|
|
117
|
+
f.writelines(outputText)
|
|
118
|
+
|
|
119
|
+
def get_posts_details(self):
|
|
120
|
+
"""
|
|
121
|
+
Take link of rss feed as argument
|
|
122
|
+
"""
|
|
123
|
+
if self.rss_feed is not None:
|
|
124
|
+
# parsing blog feed
|
|
125
|
+
rss_feed_posts = feedparser.parse(self.rss_feed)
|
|
126
|
+
|
|
127
|
+
post_list = []
|
|
128
|
+
|
|
129
|
+
# iterating over individual posts
|
|
130
|
+
for entry in rss_feed_posts.entries:
|
|
131
|
+
temp = {}
|
|
132
|
+
|
|
133
|
+
# if any post doesn't have information then throw error.
|
|
134
|
+
try:
|
|
135
|
+
for field in RSS_ENTRY_FIELDS:
|
|
136
|
+
temp[field] = getattr(entry, field, "")
|
|
137
|
+
if field == "summary":
|
|
138
|
+
temp[field] = md(temp[field]) # markdownify the description
|
|
139
|
+
elif field == "enclosure":
|
|
140
|
+
temp[field] = entry.enclosures[0].href
|
|
141
|
+
|
|
142
|
+
except (ValueError, TypeError) as e:
|
|
143
|
+
print("Error", e)
|
|
144
|
+
post_list.append(temp)
|
|
145
|
+
|
|
146
|
+
return post_list
|
|
147
|
+
else:
|
|
148
|
+
raise ValueError("Can't parse an empty URL. Please provide a valid URL.")
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def main(
|
|
152
|
+
rss_feed: Annotated[
|
|
153
|
+
str,
|
|
154
|
+
Argument(
|
|
155
|
+
help="The RSS Feed with 'enclosure' elements to parse.",
|
|
156
|
+
),
|
|
157
|
+
],
|
|
158
|
+
jinja_template_file: Annotated[
|
|
159
|
+
Path,
|
|
160
|
+
Argument(
|
|
161
|
+
help="Jinja2 template to use for generating markdown.",
|
|
162
|
+
file_okay=True,
|
|
163
|
+
dir_okay=False,
|
|
164
|
+
exists=True,
|
|
165
|
+
),
|
|
166
|
+
],
|
|
167
|
+
output_dir: Annotated[
|
|
168
|
+
Path,
|
|
169
|
+
Argument(
|
|
170
|
+
help="Existing directory to store generated markdown files.",
|
|
171
|
+
file_okay=False,
|
|
172
|
+
dir_okay=True,
|
|
173
|
+
exists=True,
|
|
174
|
+
),
|
|
175
|
+
],
|
|
176
|
+
):
|
|
177
|
+
|
|
178
|
+
try:
|
|
179
|
+
prc = PodcastRSSMDConverter(rss_feed, jinja_template_file, output_dir)
|
|
180
|
+
print(f"Creating markdown files from:\t {rss_feed}")
|
|
181
|
+
print(f"Using jinja2 template:\t {jinja_template_file}")
|
|
182
|
+
print(f"Saving markdown files to:\t {output_dir}")
|
|
183
|
+
posts = prc.get_posts_details()
|
|
184
|
+
print(f"Processing {len(posts)} posts")
|
|
185
|
+
prc.process_posts(posts=posts)
|
|
186
|
+
print("...finished.")
|
|
187
|
+
except BadInitArgumentException as e:
|
|
188
|
+
print("Couldn't start run\n".join(e.args))
|