Commit af89df7c authored by Nicolas Steinmetz's avatar Nicolas Steinmetz

Add requirements.txt, Add slugify for filename, save html as file, update ReadMe

parent 09233444
......@@ -6,9 +6,10 @@ Migration tool to migrate from a RSS/Atom Feed to [Hugo](https://gohugo.io/) sta
* Python 3+ (not tested with Python 2)
* Feedparser
* Slugigy
```
pip install feedparser
pip install -r requirements.txt
```
## Usage
......@@ -18,4 +19,17 @@ Run :
```
python feed2hugo.py -f <url_or_path_to_feed> -t <hugo_root_path> [-c post]
```
Specify value for `-c` only if your content type is not `post`.
Examples:
```
python feed2hugo.py -f http://www.domain.com/blog/feed -t /home/user/path/to/hugo
```
or:
```
python feed2hugo.py -f http://www.domain.com/blog/feed -t /home/user/path/to/hugo -c blogpost
```
\ No newline at end of file
import feedparser
import os, sys
from argparse import ArgumentParser
from slugify import slugify
def main():
#
......@@ -77,17 +78,21 @@ def main():
tags.append(tag['term'])
content = entry.content[0].value
contenttype = DEFAULT_CONTENT_TYPE
filetitle = "%s.html" % link.split('/')[-1:][0]
print(filetitle)
print('---')
print('date: %s' % date)
print('title: %s' % title)
print('url: %s' % link)
print('tags: [%s]' % '", "'.join(tags))
print('lastmod: %s' % lastmod)
print('type: %s' % contenttype)
print('---')
print(content)
filetitle = "%s.html" % slugify(entry.title)
full_dest_path = "%s/%s" % (dest_path, filetitle)
output = open(full_dest_path, 'w')
output.write('---\n')
output.write('date: %s\n' % date)
output.write('title: "%s"\n' % title.replace('"','\''))
output.write('author: %s\n' % author)
output.write('previous_url: %s\n' % link)
output.write('tags: ["%s"] \n' % '", "'.join(tags))
output.write('lastmod: %s\n' % lastmod)
output.write('type: %s\n' % contenttype)
output.write('---\n')
output.write(content)
output.close()
#
## RSS Case - to implement ?
......
python-slugify
feedparser
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment