def login(): username = request.params.username password = request.params.password user = User.get({'username': username}) if user and check_password_hash(user.hash, password): login_user(user) return json({}) else: abort(403)
def create_user(): username, password = request.json.username, request.json.password if not User.get({'username': username}): user = User.create({ 'username': username, 'hash': generate_password_hash(password) }) login_user(user) return json({'username': username}) else: abort(403)
def logout(): logout_user() return json({})
def get_user(username): user = User.get({'username': username}) return json(user.dict())
def get_pin(_id): pin = Pin.get(_id) return json(pin)
def get_pins(): filter = request.params pins = Pin.get_many(filter) return json({'pins': [pin.dict() for pin in pins]})
def delete_pin(_id): Pin.delete({'_id': _id}) return json({})
def update_pin(_id): Pin.update({'_id': _id}, request.json) return json({})
def create_pin(): pin = Pin.create(request.json) return json({'_id': pin._id})
parameter1 = sys.argv[1] except IndexError: parameter1 = 'backup' # oauth检查设置 import get_token get_token.oauth2() import time time = time.strftime("%Y-%m-%d %H:%M:%S") filename = "backup"+time if parameter1 == 'backup': baseUrl = 'http://api.fanfou.com/statuses/user_timeline' page=1 import util #python没有switch语句,所以只能用if语句替代了。 if parameter2 == 'xml': util.xml(page, url=baseUrl+'.xml', filename=filename+'.xml') print '备份文件backup'+time+'.xml成功!' elif parameter2 == 'json': util.json(page, url=baseUrl+'.json', filename=filename+'.json') print '备份文件backup'+time+'.json成功!' else: print '不知道备份成什么格式'
try: parameter2 = sys.argv[2] except IndexError: parameter2 = 'xml' try: parameter1 = sys.argv[1] except IndexError: parameter1 = 'backup' # oauth检查设置 import get_token get_token.oauth2() import time time = time.strftime("%Y-%m-%d %H:%M:%S") filename = "backup" + time if parameter1 == 'backup': baseUrl = 'http://api.fanfou.com/statuses/user_timeline' page = 1 import util #python没有switch语句,所以只能用if语句替代了。 if parameter2 == 'xml': util.xml(page, url=baseUrl + '.xml', filename=filename + '.xml') print '备份文件backup' + time + '.xml成功!' elif parameter2 == 'json': util.json(page, url=baseUrl + '.json', filename=filename + '.json') print '备份文件backup' + time + '.json成功!' else: print '不知道备份成什么格式'