def _update_status(self):
        app.logger.info("Updating status for {}".format(self))

        # add channel to streamer table if it's needed and fix if it's needed
        streamer = Streamer.query.filter_by(twitch_channel=self.channel).first()
        # if there is streamer with this channel
        if streamer:
            self.streamer = streamer
        elif self.streamer is not None:
            # if self.streamer has no tc and didn't ever checked profile
            if self.streamer.twitch_channel is None and\
                    not self.streamer.checked:
                self.streamer.twitch_channel = self.channel
            else:
                self.streamer = None

        r = requests_get_with_retries("https://api.twitch.tv/kraken/streams/{}".format(self.channel))
        r.raise_for_status()

        stream = r.json()['stream']
        if stream is not None:
            self._go_live()
            if 'status' in stream['channel']:
                self.title = stream['channel']['status']
            self.current_viewers = stream['viewers']
            self.last_time_live = datetime.utcnow()
            if self.actual_start_time is None:
                self.actual_start_time = self.last_time_live
        else:
            if self.status == 'live':
                # this is workaround for situations like stream going offline shortly
                if datetime.utcnow() - self.last_time_live > timedelta(minutes=12):
                    self.status = 'completed'
                    self.current_viewers = None

            if self.status == 'upcoming':
                self._update_title_from_channel()
dataset/ETHPy150Open WatchPeopleCode/WatchPeopleCode/wpc/models.py/TwitchStream._update_status/original