Skip to content

Instantly share code, notes, and snippets.



Last active Dec 12, 2015
What would you like to do?
Gist to test out conundrum, a webframework agnostic simple blogging plugin in Python -->

Hello, World!

Test post #1 for testing conundrum, a webframework agnostic blogging plugin.

Lets test syntax highliting


print 'Code with shebang, and numbered lines

from markdown import markdown
from yaml import load, dump
from sys import path, argv
from datetime import datetime
from requests import get, post
from json import loads, dumps
import os

base= os.path.dirname(os.path.realpath(__file__))+'/posts/'

def fetch(id, name, user):
    gist= get(''+id, headers={'user-agent': 'conundrum-blog-framework'})
    content= loads(gist.content)
    if user!= content['user']['login'] or gist.status_code!=200:
        return False
    data= {'date':'%B %d, %Y')}
    data['description']= content['description']
    for f in content['files']:
        if content['files'][f]['language']=='Markdown':
            data['post']= content['files'][f]['content']
            data['url']= content['files'][f]['raw_url']
            data['title']= content['files'][f]['filename']
            data['author']= content['user']['login']
    with open(base+name+'.yaml', 'w') as post:
        dump(data, post)
    with open(base+'first', 'w') as f:
    with open(base+'', 'a') as archive:
        line= ' - [{0}]({1})   ({2})\n'.format(data['title'], name, data['date'])
    return True

def update(name):
        with open(base+name+'.yaml', 'r') as f:
            data= load(f)
    except IOError:
        return False
    post= get(data['url'], headers={'user-agent': 'conundrum-blog-engine'})
    if post.status_code!=200:
        return False
    data['post']= post.text
    with open(base+name+'.yaml', 'w') as f:
        dump(data, f)
    return True

Switching things up a bit


print 'No shebang, but numbered lines.'

def blog(name):
        if name is None:
            with open(base+'first', 'w') as f:
        with open(base+name+'.yaml', 'r') as f:
            data= load(f)
    except IOError:
        return False
    post= markdown(data['post'], ['codehilite'])
    return post, data['date']

def archive():
        with open(base+'', 'r') as f:
            data= f.readlines()
        arch= ''.join(data[::-1])
        return markdown(arch)
    except IOError:
        return False

And finally


print 'No shebang, no line numbers'
def operate(*args):
    opts= ['-p' , '-u']
    keys= ['title', 'id', 'auth']
    headers= {'User-Agent': 'conundrum-operator', 'Content-Type': 'application/json'}
    if args[0] not in opts:
        print 'Invalid options'
        return False
    payload= {}
    for key, value in zip(keys, args[2:]):
        payload[key]= value
    body= dumps(payload)
    req= post(args[1], data= body, headers= headers)
    print req.status_code

if __name__=='__main__':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.