Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Publish the article to either Blogger or Medium
# Should read in Article title, tags from the md file
# Call the modifications file and do it on the output html
# Publish to Blogger but as a draft
import sys, os, re
import blogger_publish, medium_publish
import CommentParser
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. Article to publish")
html_file = sys.argv[1]
# Handle user's mistake by taking care of file extensions for him
# If md file was given when html was intended
if html_file.endswith(".md"):
html_file = html_file[:-2] + "html"
elif not html_file.endswith(".html"):
html_file = html_file + ".html"
if not os.path.exists(html_file):
print('File', html_file, 'does not exist. Exiting.')
with open(html_file) as file:
html_file_contents =
re_comments = re.compile('\s*<!--(.*)-->', re.DOTALL)
comments_text =
comments_parser = CommentParser.parse_comments(comments_text)
if comments_parser.destination.lower() == 'blogger':
blogger_publish.publish(html_file, comments_parser.title, comments_parser.labels, comments_parser.post_id)
elif comments_parser.destination.lower() == 'medium':
medium_publish.publish(html_file, comments_parser.title, comments_parser.labels)
'Unknown destination: ' + comments_parser.destination + '. Supported destinations are Blogger and Medium.')
if __name__ == '__main__':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment