Skip to content

Commit

Permalink
Issue #20
Browse files Browse the repository at this point in the history
Clean code.
Rename zen.py to zen_lines.py because it rises ImportError.
  • Loading branch information
GomZik committed Aug 11, 2013
1 parent bf5e3a4 commit bbbdb48
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 37 deletions.
10 changes: 7 additions & 3 deletions emergent/base.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# -*- coding: utf-8 -*-

from django.shortcuts import render_to_response
from django.template import RequestContext

from itertools import *
import json
from django.http import HttpResponse

__all__ = (
'render'
)


def render(template):
def renderer(func):
Expand Down
4 changes: 3 additions & 1 deletion emergent/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,7 @@
# 'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
'django_extensions'
'django_extensions',
'emergent',
'zen',
)
3 changes: 1 addition & 2 deletions emergent/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from django.conf import settings
from django.conf.urls import patterns, include, url
from django.views.generic import TemplateView
from views import index, status
from emergent.views import index, status

# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
Expand Down
17 changes: 13 additions & 4 deletions emergent/views.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
from settings import PROJECT_PATH
# -*- coding: utf-8 -*-

from django.conf import settings
from emergent.base import render
import os


__all__ = (
'index',
'status',
)


@render("emergent/index")
def index(request):
import random
price = random.randint(0, 99)
return {"price": price}


@render("emergent/status")
def status(request):
with open(os.path.join(PROJECT_PATH, "status.txt")) as f:
status = f.read();
with open(os.path.join(settings.PROJECT_PATH, "status.txt")) as f:
status = f.read()
return {"status": status}

Empty file modified manage.py
100644 → 100755
Empty file.
16 changes: 13 additions & 3 deletions zen/utils.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
from .settings import MASHAPE_API_KEY, MASHAPE_API_URL
# -*- coding: utf-8 -*-

import requests

headers = {
from zen.settings import MASHAPE_API_KEY, MASHAPE_API_URL


__all__ = (
'yodaize',
)


HEADERS = {
'X-Mashape-Authorization': MASHAPE_API_KEY,
}


def yodaize(message):
data = {
'sentence': message,
}
message = requests.get(MASHAPE_API_URL, params=data, headers=headers)
message = requests.get(MASHAPE_API_URL, params=data, headers=HEADERS)
return message.content
16 changes: 13 additions & 3 deletions zen/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
from django.shortcuts import render
# -*- coding: utf-8 -*-

from random import choice
from .utils import yodaize
from .zen import MESSAGE

from django.shortcuts import render

from zen.utils import yodaize
from zen.zen_lines import MESSAGE


__all__ = (
'index',
)


def index(request):
message = choice(MESSAGE)
Expand Down
21 changes: 0 additions & 21 deletions zen/zen.py

This file was deleted.

28 changes: 28 additions & 0 deletions zen/zen_lines.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-

__all__ = (
'MESSAGE',
)


MESSAGE = (
u"Beautiful is better than ugly.",
u"Explicit is better than implicit.",
u"Simple is better than complex.",
u"Complex is better than complicated.",
u"Flat is better than nested.",
u"Sparse is better than dense.",
u"Readability counts.",
u"Special cases aren't special enough to break the rules.",
u"Although practicality beats purity.",
u"Errors should never pass silently.",
u"Unless explicitly silenced.",
u"In the face of ambiguity, refuse the temptation to guess.",
u"There should be one-- and preferably only one --obvious way to do it.",
u"Although that way may not be obvious at first unless you're Dutch.",
u"Now is better than never.",
u"Although never is often better than *right* now.",
u"If the implementation is hard to explain, it's a bad idea.",
u"If the implementation is easy to explain, it may be a good idea.",
u"Namespaces are one honking great idea -- let's do more of those!",
)

0 comments on commit bbbdb48

Please sign in to comment.