Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds python script to convert blogger posts for khata #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/target
**/*.rs.bk
Cargo.lock
conf.json
/output
/posts/
35 changes: 35 additions & 0 deletions blogger_to_khata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import feedparser
import os
import sys

url = sys.argv[1]
feed = feedparser.parse(url)

if len(feed.entries) > 0 and not os.path.isdir('posts'):
os.mkdir('posts')
for entry in feed.entries:
filename = entry.link.split("/")[-1].replace(".html", ".md")
date_parts = entry.published.split(".")
published_date = date_parts[0] + "+" + date_parts[1].split("+")[1]
if "tags" in entry:
tags = ",".join([x.term for x in entry.tags])
else:
tags = ""
post = open('posts/' + filename, "w")
meta_data = "<!--\n\
.. title: {title}\n\
.. slug: {slug}\n\
.. date: {date}\n\
.. tags: {tags}\n\
.. link: \n\
.. description:\n\
.. type: text\n\
-->\n\n".format(
title=entry.title,
slug=filename.replace(".md",""),
date=published_date,
tags=tags
)
post.write(meta_data)
post.write(entry.content[0].value)
post.close()