Skip to content

Instantly share code, notes, and snippets.

Last active March 14, 2023 08:35
Show Gist options
  • Save durgaswaroop/78c51da2d74944d9e5a936cd18733f85 to your computer and use it in GitHub Desktop.
Save durgaswaroop/78c51da2d74944d9e5a936cd18733f85 to your computer and use it in GitHub Desktop.
Script to create md and html files with the given title
import sys
import subprocess
import os.path
import inflect
# alias blog="python ~\Desktop\30DaysOfBlogging\"
# Run the script with `blog <title>`
def main():
# One argument, which is the name of the to be created markdown file
if len(sys.argv) is not 2:
print("ERROR: One and only one argument needed. Title of the article")
title = sys.argv[1]
md_file = title + ".md"
# If file already exists, just exit
if os.path.exists(md_file):
print("ERROR: Markdown file '" + md_file + "' already exists. Opening that.")['C:/Program Files (x86)/Vim/vim80/gvim.exe', '+10', md_file])
article_title = title.replace("_", " ").title()
# Create the markdown file and add the title
f = open(md_file, "w+")
f.write(article_title) # Replace underscores and title case it
f.write("-" * len(title))
# Now, create the html file
html_file = title + ".html"
open(html_file, "w").close()
# Start vim with the markdown file open on line #10['C:/Program Files (x86)/Vim/vim80/gvim.exe', '+10', md_file])
# The comments to be put on top of the file
def generate_comments_header(title):
comments = f'''<!--
Title : {title}
Destination: Blogger
return comments
# Generates the standard footer text, I'm using for my series
def generate_footer_text():
part1 = '''
That is all for this article.
For more programming articles, checkout [Freblogg]({.bodyclass} TODO:// Insert some more here as appropriate:
TODO:// Keep only for automation
Some articles on automation:
[Web Scraping For Beginners with Python]({.bodyclass}
[My semi automated workflow for blogging]({.bodyclass}
[Publish articles to Blogger automatically]({.bodyclass}
[Publish articles to Medium automatically]({.bodyclass}
part2 = get_twitter_footer()
part3 = '''
If you are interested in contributing to any open source projects and haven't found the right project or if you were unsure on how to begin, I would like to suggest my own project, [Delorean]({.bodyclass} which is a Distributed Version control system, built from scratch in scala. You can contribute not only in the form of code, but also with usage documentation and also by identifying any bugs in its functionality.
Thanks for reading. See you again in the next article.'''
return part1 + part2 + part3
def get_twitter_footer():
days_since_challenge_started = get_days_since_challenge_started()
e = inflect.engine()
# 1 -> 1st, 2 -> 2nd ...
ordinal = e.ordinal(days_since_challenge_started)
# 22 -> Twenty two, 18 -> Eighteen ..
days_still_left_in_words = e.number_to_words(30 - days_since_challenge_started).capitalize().replace("-", " ")
test = f'''This is the {ordinal} article as part of my twitter challenge [#30DaysOfBlogging]({{.bodyclass}}. {days_still_left_in_words} more articles on various topics, including but not limited to, [Java]({{.bodyclass}}, [Git]({{.bodyclass}}, [Vim]({{.bodyclass}}, [Software Development]({{.bodyclass}}, [Python]({{.bodyclass}}, to come.
If you are interested in this, make sure to follow me on Twitter [\@durgaswaroop]({{.bodyclass}}. While you're at it, Go ahead and subscribe [here on medium]({{.bodyclass}} and my [other blog]({{.bodyclass}} as well.
return test
def get_days_since_challenge_started():
from datetime import date
start = date(2017, 12, 23)
today =
return (today - start).days + 1 # adding 1 as the 23rd December was Day #1 and not Day #0
if __name__ == '__main__':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment