<s> import pymongo <EOL> import bson <EOL> connection = pymongo . Connection ( ) <EOL> database = connection . mobsq_db <EOL> def get_user ( user_id ) : <EOL> """<STR_LIT>""" <EOL> return database . profiles . find_one ( { "<STR_LIT>" : bson . objectid . ObjectId ( user_id ) } ) <EOL> def get_or_create_location_by_id ( location_id ) : <EOL> """<STR_LIT>""" <EOL> location_data = database . location . find_one ( { "<STR_LIT>" : location_id } ) <EOL> if location_data is None : <EOL> location_data = { "<STR_LIT>" : location_id , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : None , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : None <EOL> } <EOL> database . location . save ( location_data , safe = True ) <EOL> return location_data <EOL> def get_locations ( location_ids ) : <EOL> """<STR_LIT>""" <EOL> locations = { } <EOL> for location in database . location . find ( { "<STR_LIT>" : { "<STR_LIT>" : location_ids } } ) : <EOL> locations [ location [ "<STR_LIT>" ] ] = location <EOL> return locations <EOL> def save_profile ( profile ) : <EOL> """<STR_LIT>""" <EOL> return database . profiles . save ( profile , safe = True ) <EOL> def save_location ( location ) : <EOL> """<STR_LIT>""" <EOL> return database . location . save ( location , safe = True ) <EOL> def save_inventory ( inventory ) : <EOL> """<STR_LIT>""" <EOL> return database . inventory . save ( inventory , safe = True ) <EOL> def get_inventory_for_user ( user ) : <EOL> """<STR_LIT>""" <EOL> inventory = database . inventory . find_one ( { "<STR_LIT>" : user [ "<STR_LIT:id>" ] } ) <EOL> if inventory is None : <EOL> inventory = { "<STR_LIT>" : user [ "<STR_LIT:id>" ] , <EOL> "<STR_LIT>" : { } , <EOL> "<STR_LIT>" : { } , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : items . STARTING_MONEY <EOL> } <EOL> return inventory </s>
