Skip to content

Instantly share code, notes, and snippets.

@Bankq
Created November 28, 2011 20:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bankq/1401992 to your computer and use it in GitHub Desktop.
Save Bankq/1401992 to your computer and use it in GitHub Desktop.
Blog post script
#! /usr/bin/env python -tt
# Author: Bank
# 1. ask for draft file path: default -> ./draft
# 2. add info at the front of new file
# 3. add draft at the end of the file
# 4. git add [filename]
# 5. git commit -m [filename]
# 6. git push site
import sys
import os
import datetime
def get_draft():
if sys.argv.__len__ == 2:
path = sys.argv[1]
else:
path = 'path/to/your/draft'
return path
def generate_file(draft_path):
now = datetime.datetime.now()
file_format = now.strftime("%Y-%m-%d")
link_prefix = now.strftime("/%Y/%m/")
display = now.strftime("%B %d, %Y")
layout = raw_input("Please choose a layout:(e.g. post):")
title = raw_input("Pleas input title:")
link_title = title.replace(' ','-')
permalink = link_prefix + link_title
file_str = '_posts/' +file_format + '-' + link_title + '.markdown'
file = open(file_str, 'w')
file.write('---\n')
file.write('layout: ' + layout + '\n')
file.write('title: ' + title + '\n')
file.write('permalink: ' + permalink + '\n')
file.write('---\n')
draft = open(draft_path,'r')
for line in draft:
file.write(line)
draft.close()
file.close()
os.system('git add '+file_str)
os.system('git commit -m \'new post: ' + file_str + '\'')
os.system('git push site')
if __name__ == '__main__':
draft_path = get_draft()
generate_file(draft_path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment