# Path: apps/broadcasts/models.py
# class Broadcast(models.Model):
#     # Metadata.
#     number = models.IntegerField(blank=True, null=True)
#     airdate = models.DateField(default=timezone.now)
#     status = models.CharField(blank=True, max_length=200,
#         help_text='Loosely related to Twitch\'s status field. Does not need to match. Will display on overlays.')
#     notes = models.TextField(blank=True)
# 
#     # Connections.
#     games = models.ManyToManyField(Game, related_name='appears_on')
#     series = models.ForeignKey(Series, blank=True, null=True, related_name='broadcasts',
#         help_text='Is this episode part of an ongoing series (i.e., "Whatever Wednesdays", etc.)?')
# 
#     # Statuses.
#     is_charity = models.BooleanField('is for charity?', default=False,
#         help_text='Is a charity fundraiser involved in this episode?')
#     is_marathon = models.BooleanField('is a marathon?', default=False,
#         help_text='Is this a marathon episode (longer than 12 hours)?')
# 
#     class Meta:
#         get_latest_by = 'airdate'
#         ordering = ['-airdate']
# 
#     def __str__(self):
#         return 'Episode {}'.format(self.number)
# 
#     def get_absolute_url(self):
#         return reverse('broadcast-detail', kwargs={'slug': self.number})
# 
# Path: apps/live/utils.py
# def fetch_stream():
#     endpoint = 'https://api.twitch.tv/kraken/streams/avalonstar'
#     json = requests.get(endpoint).json()
#     return json.get('stream', {})
# 
# def is_episodic():
#     # Let's use the stream's title to determine if a stream is an episode
#     # or not. We use the stream's status to determine this as follows:
#     #
#     #   - "A☆###": A numbered episode.
#     #   - (Anything else.): A casual episode.
#     #
#     # Because Python is weird, it doesn't detect the white star. We're not
#     # going to bother looking for it.
#     pattern = r'^A.\d{3}'
#     status = fetch_status()
#     return bool(re.match(pattern, status, re.UNICODE))


from django.views.generic import View
from braces.views import JSONResponseMixin
from apps.broadcasts.models import Broadcast
from .utils import fetch_stream, is_episodic
# -*- coding: utf-8 -*-





class StatusView(JSONResponseMixin, View):
    def get(self, request, *args, **kwargs):
        broadcast = Broadcast.objects.latest()
        context = {
            'is_episodic': is_episodic(),

# Path: apps/broadcasts/models.py
# class Broadcast(models.Model):
#     # Metadata.
#     number = models.IntegerField(blank=True, null=True)
#     airdate = models.DateField(default=timezone.now)
#     status = models.CharField(blank=True, max_length=200,
#         help_text='Loosely related to Twitch\'s status field. Does not need to match. Will display on overlays.')
#     notes = models.TextField(blank=True)
# 
#     # Connections.
#     games = models.ManyToManyField(Game, related_name='appears_on')
#     series = models.ForeignKey(Series, blank=True, null=True, related_name='broadcasts',
#         help_text='Is this episode part of an ongoing series (i.e., "Whatever Wednesdays", etc.)?')
# 
#     # Statuses.
#     is_charity = models.BooleanField('is for charity?', default=False,
#         help_text='Is a charity fundraiser involved in this episode?')
#     is_marathon = models.BooleanField('is a marathon?', default=False,
#         help_text='Is this a marathon episode (longer than 12 hours)?')
# 
#     class Meta:
#         get_latest_by = 'airdate'
#         ordering = ['-airdate']
# 
#     def __str__(self):
#         return 'Episode {}'.format(self.number)
# 
#     def get_absolute_url(self):
#         return reverse('broadcast-detail', kwargs={'slug': self.number})
# 
# Path: apps/live/utils.py
# def fetch_stream():
#     endpoint = 'https://api.twitch.tv/kraken/streams/avalonstar'
#     json = requests.get(endpoint).json()
#     return json.get('stream', {})
# 
# def is_episodic():
#     # Let's use the stream's title to determine if a stream is an episode
#     # or not. We use the stream's status to determine this as follows:
#     #
#     #   - "A☆###": A numbered episode.
#     #   - (Anything else.): A casual episode.
#     #
#     # Because Python is weird, it doesn't detect the white star. We're not
#     # going to bother looking for it.
#     pattern = r'^A.\d{3}'
#     status = fetch_status()
#     return bool(re.match(pattern, status, re.UNICODE))


# Path: apps/live/views.py
from django.views.generic import View
from braces.views import JSONResponseMixin
from apps.broadcasts.models import Broadcast
from .utils import fetch_stream, is_episodic

# -*- coding: utf-8 -*-





class StatusView(JSONResponseMixin, View):
    def get(self, request, *args, **kwargs):
        broadcast = Broadcast.objects.latest()
        context = {
            'is_episodic': is_episodic(),

            'is_live': bool(fetch_stream()),