def process_toggle_block_mention(self, minfo, keyword): log.debug(u'process_toggle_block_mention called with keyword: {}'.format(keyword.encode('utf8'))) user = session.query(Follower).filter_by(uniqueid = minfo['id']) try: user = user.one() except NoResultFound: user = session.query(Follower).filter_by(mention_id = minfo['screen_name']) try: user = user.one() except: user = Follower(minfo['screen_name'], minfo['name']) SCRIPT_STOP = u'알았다요. 이제 먼저 말 걸지 않겠다요.. ' SCRIPT_RESUME = u'헤헤 알았다요! 이제 닉시코가 먼저 말을 걸 수도 있다요!' if keyword.split()[1] in (u'중지', u'그만', u'중단'): # if suspend user.is_blocked = 1 log.info(u'사용자 블록 전환: '.format(minfo['screen_name'])) script = Script(SCRIPT_STOP) script.mention(minfo['screen_name']) self.do_tweet(script, minfo['id']) else: # if resume user.is_blocked = 0 log.info(u'사용자 블록 해제: '.format(minfo['screen_name'])) script = Script(SCRIPT_RESUME) script.mention(minfo['screen_name']) self.do_tweet(script, minfo['id']) session.add(user) session.commit() log.debug('toggle_block_mention done')
def process_follower(self, minfo): log.debug('process_follower called') mention_user = session.query(Follower).filter_by(uniqueid=minfo['id']) try: user = mention_user.first() except NoResultFound: mention_user = session.query(Follower).filter_by(mention_id = minfo['screen_name']) try: mention_user = mention_user.one() mention_user.closeness += 1 mention_user.uniqueid = minfo['id'] mention_user.screen_name = minfo['name'] log.debug(u'팔로어: {}, 호감도+1'.format(mention_user.screen_name)) except NoResultFound: mention_user = Follower(minfo['name'], minfo['screen_name']) log.debug(u'팔로어 adding: {}({})'.format(minfo['name'], minfo['screen_name'])) except MultipleResultsFound: log.error(u'중복유저: {}({})'.format(minfo['name'], minfo['screen_name'])) mention_user.modified_at = datetime.datetime.now() try: session.add(mention_user) session.commit() except: log.exception(u'팔로어 학습 실패: {}'.format(repr(mention_user))) raise