def get_excerpt_dictionary(): # Authenticate the user user_profile = verify_auth_token() if user_profile is None: return json_result({ 'success': 0, 'error' : 'authentication failed', }) try: # Read the parameters lang = request.form['lang'] except KeyError: # Return failure if the arguments don't exist return json_result({ 'success': 0, 'error' : 'invalid parameters', }) email = user_profile['email'] excerpts = mongo.db.excerpts.find({ 'lang': lang, 'email': email }) phrase_ids = [] for excerpt in excerpts: phrase_ids += excerpt['phrase_ids'] print len(set(phrase_ids)) coll = mongo.db["phrases_%s" % lang] d = {} for phrase_id_chunk in dbutils.chunk_list(phrase_ids, 1000): cursor = coll.find({ '_id': { '$in': phrase_id_chunk } }) d.update(dictionary.create_dictionary_from_cursor(lang, cursor)) print len(set(d.keys())) return json_result({ 'success': 1, 'result' : d, })
restrictions['trad'] = { '$exists': 0 } cursor = coll.find(restrictions).sort('rank', pymongo.ASCENDING) coll.update( { }, { '$set': { 'in_plan': 0, }, }, multi=True, upsert=True, ) d = dictionary.create_dictionary_from_cursor(args.lang, cursor) for h in d.values(): coll.update( { 'base': h['base'], }, { '$set': { 'in_plan': 1, }, }, multi=True, upsert=True, )