# Path: apps/subscribers/models.py
# class Ticket(models.Model):
#     twid = models.CharField(blank=True, max_length=40)
#     name = models.CharField(max_length=200)
#     display_name = models.CharField(blank=True, max_length=200)
#     created = models.DateTimeField(default=timezone.now)
#     updated = models.DateTimeField(default=timezone.now)
# 
#     # Store the months if there's a substreak (defaults to 1 month).
#     streak = models.IntegerField(default=1)
# 
#     # Is this subscription active?
#     is_active = models.BooleanField(default=True,
#         help_text='Is this subscription active?')
#     is_paid = models.BooleanField(default=True,
#         help_text='Is this a paid subscription? (e.g., Not a bot.)')
# 
#     # Custom manager.
#     objects = TicketManager()
# 
#     class Meta:
#         ordering = ['updated']
#         get_latest_by = 'updated'
# 
#     def __str__(self):
#         return '{}'.format(self.name)
# 
#     def update(self, **kwargs):
#         allowed_attributes = {'twid', 'display_name', 'updated', 'is_active'}
#         for name, value in kwargs.items():
#             assert name in allowed_attributes
#             setattr(self, name, value)
#         self.save()


import logging
import requests
import os
from django.core.management.base import NoArgsCommand
from apps.subscribers.models import Ticket
# -*- coding: utf-8 -*-
logger = logging.getLogger(__name__)





class Command(NoArgsCommand):
    help = 'Loops through all subscribers and marks each ticket appropriately.'

    def handle_noargs(self, **options):
        # Prepare our request.
        headers = {
            'Authorization': 'OAuth %s' % os.environ.get('TWITCH_OAUTH_TOKEN'),
            'Accept': 'application/vnd.twitchtv.v3+json' }
        url = 'https://api.twitch.tv/kraken/channels/avalonstar/subscriptions'

        # Let's not invalidate anything unnecessarily. If we hit an exception
        # with the first request, then bail.

# Path: apps/subscribers/models.py
# class Ticket(models.Model):
#     twid = models.CharField(blank=True, max_length=40)
#     name = models.CharField(max_length=200)
#     display_name = models.CharField(blank=True, max_length=200)
#     created = models.DateTimeField(default=timezone.now)
#     updated = models.DateTimeField(default=timezone.now)
# 
#     # Store the months if there's a substreak (defaults to 1 month).
#     streak = models.IntegerField(default=1)
# 
#     # Is this subscription active?
#     is_active = models.BooleanField(default=True,
#         help_text='Is this subscription active?')
#     is_paid = models.BooleanField(default=True,
#         help_text='Is this a paid subscription? (e.g., Not a bot.)')
# 
#     # Custom manager.
#     objects = TicketManager()
# 
#     class Meta:
#         ordering = ['updated']
#         get_latest_by = 'updated'
# 
#     def __str__(self):
#         return '{}'.format(self.name)
# 
#     def update(self, **kwargs):
#         allowed_attributes = {'twid', 'display_name', 'updated', 'is_active'}
#         for name, value in kwargs.items():
#             assert name in allowed_attributes
#             setattr(self, name, value)
#         self.save()


# Path: apps/subscribers/management/commands/updatetickets.py
import logging
import requests
import os
from django.core.management.base import NoArgsCommand
from apps.subscribers.models import Ticket

# -*- coding: utf-8 -*-
logger = logging.getLogger(__name__)





class Command(NoArgsCommand):
    help = 'Loops through all subscribers and marks each ticket appropriately.'

    def handle_noargs(self, **options):
        # Prepare our request.
        headers = {
            'Authorization': 'OAuth %s' % os.environ.get('TWITCH_OAUTH_TOKEN'),
            'Accept': 'application/vnd.twitchtv.v3+json' }
        url = 'https://api.twitch.tv/kraken/channels/avalonstar/subscriptions'

        # Let's not invalidate anything unnecessarily. If we hit an exception
        # with the first request, then bail.

        try: