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
from flask import Flask | |
app = Flask(__name__) | |
@app.route("/") | |
def hello(): | |
return "Hello World!" | |
if __name__ == "__main__": | |
app.run() |
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
# http://flask.pocoo.org/docs/api/#url-route-registrations | |
@app.route('/') | |
def index(): | |
pass | |
@app.route('/<username>') | |
def show_user(username): | |
pass |
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
@app.route('/') | |
def index(): | |
return "" | |
@app.route('/<username>') | |
def show_user(username): | |
return username | |
@app.route('/post/<int:post_id>') | |
def show_post(post_id): |
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
from flask import request | |
@app.route("/reverse") | |
def reverse(): | |
message = request.values["message"] | |
return "".join(reversed(message)) |
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
# from http://flask.pocoo.org/docs/quickstart/#sessions | |
from flask import Flask, session, redirect, url_for, escape, request | |
app = Flask(__name__) | |
@app.route('/') | |
def index(): | |
if 'username' in session: | |
return 'Logged in as %s' % escape(session['username']) |
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
# from http://flask.pocoo.org/docs/quickstart/#rendering-templates | |
from flask import render_template | |
@app.route('/hello/') | |
@app.route('/hello/<name>') | |
def hello(name=None): | |
return render_template('hello.html', name=name) |
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
# http://docs.python.org/library/asyncore.html#asyncore-example-basic-http-client | |
import asyncore, socket | |
class HTTPClient(asyncore.dispatcher): | |
def __init__(self, host, path): | |
asyncore.dispatcher.__init__(self) | |
self.create_socket(socket.AF_INET, socket.SOCK_STREAM) | |
self.connect( (host, 80) ) | |
self.buffer = 'GET %s HTTP/1.0\r\n\r\n' % path |
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
# 페이스북 계정들을 가져와서 반복하면서 | |
for account in FacebookAccount.query: | |
account.update() #FQL을 보내자. |
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 eventlet | |
eventlet.monkey_patch() #표준 라이브러리를 변환 | |
# 여러가지 import를 하고... | |
pool = eventlet.GreenPool() | |
# 페이스북 계정들을 가져와서 반복하면서 | |
for account in FacebookAccount.query: | |
# 코루틴들에게 떠넘기자. |
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
# from eventlet/pathcer.py | |
def monkey_patch(**on): | |
"""Globally patches certain system modules to be greenthread-friendly. | |
The keyword arguments afford some control over which modules are patched. | |
If no keyword arguments are supplied, all possible modules are patched. | |
If keywords are set to True, only the specified modules are patched. E.g., | |
``monkey_patch(socket=True, select=True)`` patches only the select and | |
socket modules. Most arguments patch the single module of the same name |