예제 #1
0
    def handle_event(self, event):
        self.logger.info('Handling new event: %s' % event.id)
        settings = self.get_site_settings()
        url = self.generate_slack_msg()
        event_dict = protolib.ToDict(event, full=True)
        msg = self.generate_slack_msg(settings, event_dict)
        if 'image' in event_dict:
            image_file = self.get_image_file(event_dict['image']['url'])

        if post:
            with SuppressTaskErrors(self.logger):
                tasks.slack_post.delay(url, post)
예제 #2
0
    def _schedule_tweet(self, tweet, profile, image_url=None):
        if not profile:
            self.logger.warning('Empty profile, skipping tweet.')
            return
        self.logger.info('Scheduling tweet on @%s: %s' %
                         (profile.get('twitter_name'), repr(tweet)))
        consumer_key, consumer_secret = self.get_credentials()
        oauth_token = profile.get(KEY_OAUTH_TOKEN)
        oauth_token_secret = profile.get(KEY_OAUTH_TOKEN_SECRET)

        with SuppressTaskErrors(self.logger):
            tasks.send_tweet.delay(consumer_key, consumer_secret, oauth_token,
                                   oauth_token_secret, tweet, image_url)
예제 #3
0
 def handle_event(self, event):
     self.logger.info('Handling new event: %s' % event.id)
     settings = self.get_site_settings()
     event_dict = protolib.ToDict(event, full=True)
     msg = self.generate_slack_msg(settings, event_dict)
     #import ipdb; ipdb.set_trace()
     try:
         url = event_dict['drink']['images'][0]['original_url']
     except:
         url = None
     if url:
         image_file = '/home/federico/kegbot-data/' + url.split('/', 3)[3]
     else:
         image_file = ''
     with SuppressTaskErrors(self.logger):
         tasks.slack_post(self.slack_config(), msg, image_file)
예제 #4
0
    def handle_new_events(self, events):
        for event in events:
            self.logger.info('Handling new event: %s' % event.id)
            user = event.user

            if event.kind != event.DRINK_POURED:
                self.logger.info('Ignoring event: not %s.' %
                                 event.DRINK_POURED)
                return

            if user.is_guest():
                self.logger.info('Ignoring event: guest.')
                return

            if util.is_stale(event.time):
                self.logger.info('Ignoring event: stale.')
                return

            token = self.get_user_token(user)
            if not token:
                self.logger.info('Ignoring event: no token for user %s.' %
                                 user.username)
                return

            settings = self.get_user_settings(user)
            if not settings or not settings.get('enable_checkins'):
                self.logger.info('Ignoring event: not enabled.')
                return

            venue_id = self.get_venue_id()
            if not venue_id:
                self.logger.info('Ignoring event: no venue id.')
                return

            with SuppressTaskErrors(self.logger):
                tasks.foursquare_checkin.delay(token, venue_id)
예제 #5
0
def schedule_checkin(force=False):
    """Schedules a checkin if needed and allowed.

    Args
        force: if True, ignore last checkin time.

    Returns
        True if a checkin was scheduled.
    """
    kbsite = models.KegbotSite.get()
    if not kbsite.check_for_updates:
        LOGGER.debug('schedule_checkin: not scheduling: checkin disabled')
        return False

    last_checkin_time, last_checkin_data = get_last_checkin()
    now = timezone.now()
    if not last_checkin_time or (
            now - last_checkin_time) > CHECKIN_INTERVAL or force:
        with SuppressTaskErrors(LOGGER):
            LOGGER.info('schedule_checkin: scheduling checkin')
            core_checkin_task.delay()
            return True

    return False
예제 #6
0
    def handle_event(self, event):
        self.logger.info('Handling new event: %s' % event)
        user = event.user

        if event.kind != event.DRINK_POURED:
            self.logger.info('Ignoring event: %s' % event.kind)
            return

        if user.is_guest():
            self.logger.info('Ignoring event: anonymous.')
            return

        if plugin_util.is_stale(event.time):
            self.logger.info('Ignoring event: stale.')
            return

        token = self.get_user_token(user)
        if not token:
            self.logger.info('Ignoring event: no token for user %s.' %
                             user.username)
            return

        settings = self.get_user_settings(user)
        if not settings or not settings.get('enable_checkins'):
            self.logger.info('Ignoring event: not enabled.')
            return

        beer_id = event.drink.keg.type.untappd_beer_id
        if not beer_id:
            self.logger.info('Ignoring event: no untappd beer id.')
            return

        shout = None
        if event.drink.shout:
            shout = event.drink.shout

        foursquare_venue_id = foursquare_client_id = foursquare_client_secret = None
        foursquare = self.plugin_registry.get('foursquare')
        if foursquare:
            foursquare_client_id, foursquare_client_secret = foursquare.get_credentials(
            )
            foursquare_venue_id = foursquare.get_venue_id()
            if foursquare_venue_id:
                self.logger.info(
                    'Adding location info, foursquare venue id: {}'.format(
                        foursquare_venue_id))
            else:
                self.logger.info(
                    'No Foursquare venue id, not adding location info.')
        else:
            self.logger.info(
                'Foursquare not available, not adding location info.')

        timezone_name = timezone.get_current_timezone_name()

        with SuppressTaskErrors(self.logger):
            tasks.untappd_checkin.delay(
                token,
                beer_id,
                timezone_name,
                shout=shout,
                foursquare_client_id=foursquare_client_id,
                foursquare_client_secret=foursquare_client_secret,
                foursquare_venue_id=foursquare_venue_id)
예제 #7
0
 def build_backup(self):
     """Builds backup file for Kegbot Site."""
     with SuppressTaskErrors(self._logger):
         tasks.build_backup.delay()
예제 #8
0
 def build_stats(self, since_drink_id):
     """Rebuilds statistics starting with this drink."""
     assert since_drink_id is not None, 'No drink id.'
     with SuppressTaskErrors(self._logger):
         tasks.build_stats.delay(since_drink_id=since_drink_id)