def get_post_from_fb(post_id, page_id): url = "%s_%s" % (page_id, post_id) access_token = (BrandMapping.unserialize(BrandMapping.collection().find_one({"facebook.id": page_id}))).facebook[ "access_token" ] print url return GraphAPI(access_token).request(url)
def get_tw_user(user_id, brand_name): dic = TWUser.collection().find_one({"u_id": str(user_id), "brand_name": brand_name}) tw_user = TWUser.unserialize(dic) if dic is not None else None if tw_user is not None: brand_dic = BrandMapping.collection().find_one({"uid": user_id, "brand_name": brand_name}) brand = BrandMapping.unserialize(brand_dic) if brand_dic is not None else None return tw_user, brand.twitter["access_token"]
def get_brand_available_slots(user_id, platform): avail_max_brands = get_max_brands(user_id) dic_list = BrandMapping.collection().find({"uid": user_id}) for d in dic_list: brand = BrandMapping.unserialize(d) avail_max_brands = (avail_max_brands-1) if getattr(brand, platform) is not None else avail_max_brands return avail_max_brands
def get_brand_platform_id(user_id, brand_id, platform): dic = BrandMapping.collection().find_one({"uid": user_id, "_id": coerce_bson_id(brand_id)}) brand = BrandMapping.unserialize(dic) if dic is not None else None return getattr(brand, platform)
def get_brand_mapping(user_id, brand_name): collection = BrandMapping.collection() if user_id is None or brand_name is None: return None dic = collection.find_one({"uid": user_id, "brand_name": brand_name}) return BrandMapping.unserialize(dic) if dic is not None else None