Created
September 20, 2010 10:39
-
-
Save maplpro/587723 to your computer and use it in GitHub Desktop.
cherrypy simple example and config file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cherrypy | |
from jinja2 import Environment, Template, FileSystemLoader | |
env = Environment( loader = FileSystemLoader('./templates') ) | |
class Root: | |
@cherrypy.expose | |
def index(self): | |
return env.get_template( "index.html" ).render( months = [ '2010-01', '2010-02', '2010-03', '2010-04', '2010-05', '2010-06' ] ) | |
@cherrypy.expose | |
def cloud(self, data): | |
import simplejson | |
res = simplejson.loads( data ) | |
return str( len( res[ 'data' ][ 'items' ] ) ) | |
@cherrypy.expose | |
def search(self, month): | |
import urllib2 | |
cherrypy.response.headers[ "Content-Type" ] = "applcation/json" | |
url = "http://www.googleapis.com/buzz/v1/activities/search?alt=json&max-results=1000&q=from:Mikhael%20Plavskiy%20date:" + month | |
res = urllib2.urlopen( url ) | |
cherrypy.log( url ) | |
return res.read() | |
app = cherrypy.quickstart( Root(), config = "config.txt" ) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[global] | |
server.socket_host: '0.0.0.0' | |
log.error_file: 'site.log' | |
[/] | |
tools.staticdir.root = os.getcwd() | |
[/static] | |
tools.staticdir.on = True | |
tools.staticdir.dir = "static" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
shouldn't the config file be ini, config.ini instead of config.txt