from schematics.models import Model from schematics.types import StringType, FloatType import redis, uuid, json from pwitter import config from textblob import TextBlob _r = redis.StrictRedis( host=config.get('DB_ADDRESS'), port=int(config.get('DB_PORT')), db=0 ) class Entity(Model): KEY_PREFIX = 'entity' def __init__(self, *args, **kwargs): Model.__init__(self, *args, **kwargs) self.ID = str(uuid.uuid1()) @property def key(self): return ':'.join([self.KEY_PREFIX, str( self.ID )]) def save(self): # using hashes # http://redis.io/commands#hash _r.hmset(self.key, self.to_primitive()) self.on_save() def on_save(self):
return jsonify(body) @app.route('/pweets/count', methods=['GET']) def count(): return jsonify({'count': Pweet.count()}) @app.route('/pweets', methods=['POST']) def post(): ''' This expects a Pweet and stores it to database ''' pweet = Pweet(request.form) pweet.validate() pweet.save() return jsonify(pweet.serialize()), 201 @app.errorhandler(ValidationError) @app.errorhandler(ConversionError) def handle_validation_error(error): resp = jsonify({'message': error.message}) resp.status_code = 400 return resp if __name__ == '__main__': app.run( debug=True, host=config.get('WEB_ADDRESS'), port=int(config.get('WEB_PORT')) )