# Path: telostats/stations/tasks.py
# def measure(log_tempodb=True):
#     logging.info('Measuring stations...')
#     timestamp = datetime.datetime.utcnow().replace(tzinfo=utc)
#     stations = parse_stations(scrape_stations())
#     store_stations(stations)
#     if log_tempodb:
#         log_data(timestamp, stations)
#     else:
#         logging.debug('Skipping logging measurements to TempoDB...')
#     logging.info('Measured {} stations.'.format(len(stations)))
#     # TODO: periodically write more metadata about stations to the tempo series?


import logging
from django.core.management.base import BaseCommand
from optparse import make_option
from telostats.stations.tasks import measure


logging.basicConfig(level=logging.DEBUG)


class Command(BaseCommand):
    help = 'Scrape station data from the Tel-o-fun website.'
    option_list = BaseCommand.option_list + (
        make_option('-n', '--no-log',
            action='store_false',
            dest='log_tempodb',
            default=True,
            help='Do not log measurements to Tempo DB (use this in local env)'),
    )

    def handle(self, *args, **options):

# Path: telostats/stations/tasks.py
# def measure(log_tempodb=True):
#     logging.info('Measuring stations...')
#     timestamp = datetime.datetime.utcnow().replace(tzinfo=utc)
#     stations = parse_stations(scrape_stations())
#     store_stations(stations)
#     if log_tempodb:
#         log_data(timestamp, stations)
#     else:
#         logging.debug('Skipping logging measurements to TempoDB...')
#     logging.info('Measured {} stations.'.format(len(stations)))
#     # TODO: periodically write more metadata about stations to the tempo series?


# Path: telostats/stations/management/commands/measure_stations.py
import logging
from django.core.management.base import BaseCommand
from optparse import make_option
from telostats.stations.tasks import measure



logging.basicConfig(level=logging.DEBUG)


class Command(BaseCommand):
    help = 'Scrape station data from the Tel-o-fun website.'
    option_list = BaseCommand.option_list + (
        make_option('-n', '--no-log',
            action='store_false',
            dest='log_tempodb',
            default=True,
            help='Do not log measurements to Tempo DB (use this in local env)'),
    )

    def handle(self, *args, **options):

        measure(log_tempodb=options['log_tempodb'])