def post(): try: # authenticate user user = User.validate_auth_key(username=request.form.get("username"), api_key=request.form.get("api_key")) if user is None: return "API Auth Failed: Post" # decode the json payload data = json.loads(request.form.get("ebooks")) except KeyError: return "Bad Request" # stats log the upload Log.create(user.id, "CONNECT", request.form.get("total"), request.form.get("api_key")) # update the library ds = DataStore(user) new_ebook_count = ds.update_library(data) Log.create(user.id, "NEW", new_ebook_count, request.form.get("api_key")) # handle badge and reputation changes r = Reputation(user) r.new_ebooks(new_ebook_count) r.earn_badges() msgs = r.get_new_badges() # query books missing from S3 and supply back to the client rs = ds.find_missing_books() return json.dumps({'ebooks_to_upload': rs, 'messages': msgs})
def lb(ebook_id): from ogreserver.models.datastore import DataStore ds = DataStore(app.config, logger=None) ebook = ds.load_ebook(ebook_id) # if no ebook_id supplied, check if supplied param is file_hash if ebook is None: ebook = ds.load_ebook_by_file_hash(ebook_id, match=True) if ebook is None: print 'Not found' return for v in ebook['versions']: v['date_added'] = v['date_added'].isoformat() del(v['ebook_id']) for f in v['formats']: del(f['version_id']) # decode ReQL date objects for JSON encode decode_rql_dates(ebook) # pretty print json with colorized ebook_id/file_hash print json.dumps(ebook, indent=2).replace( ebook_id, '\033[92m{}\033[0m'.format(ebook_id) )
def store_ebook(user_id, sdbkey, filehash, fmt): user = User.query.get(user_id) filepath = "%s/%s%s" % (app.config['UPLOADED_EBOOKS_DEST'], filehash, fmt) print "store_ebook: %s %s%s" % (sdbkey, filehash, fmt) # store the file into S3 ds = DataStore(user) ds.store_ebook(sdbkey, filehash, filepath) # handle badge and reputation changes r = Reputation(user) r.earn_badges()
def post(): try: # authenticate user user = User.validate_auth_key( username=request.form.get("username"), api_key=request.form.get("api_key") ) if user is None: return "API Auth Failed: Post" # decode the json payload data = json.loads(request.form.get("ebooks")) except KeyError: return "Bad Request" # stats log the upload Log.create(user.id, "CONNECT", request.form.get("total"), request.form.get("api_key")) # update the library ds = DataStore(user) new_ebook_count = ds.update_library(data) Log.create(user.id, "NEW", new_ebook_count, request.form.get("api_key")) # handle badge and reputation changes r = Reputation(user) r.new_ebooks(new_ebook_count) r.earn_badges() msgs = r.get_new_badges() # query books missing from S3 and supply back to the client rs = ds.find_missing_books() return json.dumps({ 'ebooks_to_upload': rs, 'messages': msgs })