async def add_QQUser(qq_id, nickname, group_id=None, group_card=None, sex=None, group_role=None, **kw): session = DBSession() qqUser = session.query(QQUser).filter(QQUser.qq_id == qq_id).first() if qqUser: qqUser.nickname = nickname if (group_id): qqUser.group_id = group_id qqUser.group_role = group_role qqUser.sex = sex session.merge(qqUser) session.commit() session.close() return 1 else: qqUser = QQUser(qq_id=qq_id, group_id=group_id, nickname=nickname, group_card=group_card, sex=sex, group_role=group_role, join_time=datetime.now()) session.add(qqUser) session.commit() session.close() return 0
async def add_homework_info(group_id, subject_name, content, end_date, assign_for=None, added_date=None, add_by=None): if added_date is None: added_date = date.today() homework = Homework(group_id=group_id, subject_name=subject_name, content=content, end_date=end_date, assign_for=assign_for, added_date=added_date, add_by=add_by) session = DBSession() session.add(homework) session.commit() homework = session.query(Homework).filter( Homework.group_id == group_id, Homework.subject_name == subject_name, Homework.content == content, Homework.assign_for == assign_for, Homework.added_date == added_date, Homework.add_by == add_by).first() session.close() return homework
async def add_group_info(group_id, group_name, last_weather_notify=None, is_morningcall_on=False, is_curriculumschedule_on=True, is_weather_notify_on=False, is_homework_daily_on=False): session = DBSession() group = session.query(GroupInfo).filter( GroupInfo.group_id == group_id).first() if group: group.group_id = group_id group.group_name = group_name session.merge(group) session.commit() session.close() return 1 else: group = GroupInfo(group_id=group_id, group_name=group_name, last_weather_notify=last_weather_notify, is_morningcall_on=is_morningcall_on, is_curriculumschedule_on=is_curriculumschedule_on, is_weather_notify_on=is_weather_notify_on, is_homework_daily_on=is_homework_daily_on) session.add(group) session.commit() session.close() return 0
async def add_item(item_name, item_info, seller_id, type='sell', from_group_id=None, add_time=None, **kw): if add_time is None: add_time = datetime.now() item = SellItem(item_name=item_name, item_info=item_info, seller_id=seller_id, from_group_id=from_group_id, add_time=add_time, type=type, is_onsell=True) session = DBSession() session.add(item) session.commit() item = session.query(SellItem).filter( SellItem.seller_id == seller_id, SellItem.item_name == item_name, SellItem.item_info == item_info, ).first() session.close() return item
async def init_user_invite(qq_id, nickname): session = DBSession() user_invite = session.query(User_invite).filter( User_invite.qq_id == qq_id).first() if user_invite: session.close() return else: user_invite = User_invite(qq_id=qq_id, nickname=nickname, join_time=datetime.now()) session.add(user_invite) session.commit() session.close()
async def join_event(user_id, nickname, sex): session = DBSession() dbuser = session.query(CPuser).filter(CPuser.qq_id == user_id).first() if dbuser: session.close() return False cpuser = CPuser(qq_id=user_id, user_name=nickname, user_sex=sex, is_paired=False) session.add(cpuser) session.commit() session.close() session = DBSession() cpuser = session.query(CPuser).filter(CPuser.qq_id == user_id).first() session.close() return cpuser