summaryrefslogtreecommitdiffstats
path: root/pytzdata/commands/zones.py
blob: ef3e33a56ca6345c0a114d8f761458845625862f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# -*- coding: utf-8 -*-

import os
import pprint
import pytzdata

from cleo import Command


class ZonesCommand(Command):
    """
    Dumps available timezones to the _timezone.py file.

    zones:dump
    """

    TEMPLATE = """# -*- coding: utf-8 -*-

timezones = {}
"""

    def handle(self):
        zones = pytzdata.get_timezones()

        tz_file = os.path.join(
            os.path.dirname(__file__),
            '..',
            '_timezones.py'
        )

        with open(tz_file, 'w') as fd:
            fd.write(
                self.TEMPLATE.format(pprint.pformat(zones))
            )

        self.info('Dumped <comment>{}</> timezones'.format(len(zones)))