示例#1
0
# -*- coding: utf-8 -*-
import os

import leancloud
from wsgiref import simple_server

from manage import app

__author__ = 'pan'

APP_ID = os.environ['LC_APP_ID']
MASTER_KEY = os.environ['LC_APP_MASTER_KEY']
PORT = int(os.environ['LC_APP_PORT'])

leancloud.init(APP_ID, master_key=MASTER_KEY)

engine = leancloud.Engine(app)
application = engine

if __name__ == '__main__':
    # 只在本地开发环境执行的代码
    app.debug = True
    server = simple_server.make_server('localhost', PORT, application)
    server.serve_forever()
示例#2
0
# coding: utf-8

from django.core.wsgi import get_wsgi_application
import leancloud
import md5
import time
import sys

reload(sys)
sys.setdefaultencoding("utf-8")
engine = leancloud.Engine(get_wsgi_application())


@engine.define
def create_group(**params):
    print "Create group: {}".format(params["creatorId"])

    # create a conversation
    conversation = leancloud.Conversation()
    conversation.set("name", params["topic"])
    conversation.set("creatorId", params["creatorId"])
    conversation.set("creatorName", params["creatorName"])
    conversation.set("members", [params["creatorId"]])
    conversation.save()

    # create invitations
    Invitation = leancloud.Object.extend("Invitation")
    for uid in params["invitedId"]:
        query = leancloud.Query(leancloud.User)
        if query.get(uid):
            invitation = Invitation()
示例#3
0
import os
import leancloud
from gevent.pywsgi import WSGIServer
from geventwebsocket.handler import WebSocketHandler
from web.httpserver import StaticMiddleware

from app import app

APP_ID = os.environ['LC_APP_ID']
MASTER_KEY = os.environ['LC_APP_MASTER_KEY']
PORT = int(os.environ['LC_APP_PORT'])

leancloud.init(APP_ID, master_key=MASTER_KEY)

engine = app.wsgifunc()
if os.environ.get('LC_HTTPS_ON', 0):
    engine = leancloud.HttpsRedirectMiddleware(engine)
engine = leancloud.Engine(engine)
engine = StaticMiddleware(engine)
application = engine

if __name__ == '__main__':
    # 只在本地开发环境执行的代码
    app.debug = True
    server = WSGIServer(('localhost', PORT),
                        application,
                        handler_class=WebSocketHandler)
    #server = WSGIServer(('localhost', PORT), application)
    server.serve_forever()
示例#4
0

@app.route('/list/save')
def add_list():
    url = bottle.request.query.url
    title = bottle.request.query.title
    lists.save(url, title)
    return 'Url add to list!'


@app.post('/list/delete')
def delete_list():
    lists.delete(bottle.request.params.id)


application = leancloud.Engine(app)


@application.define
def spider_work():
    cloud.spider_work()


@application.define
def clear_old_feed():
    cloud.clear_old_feed()


@app.route('/test/work')
def test_work():
    return cloud.spider_work()