summaryrefslogtreecommitdiff
path: root/app/backend/weekdays.py
blob: 547f6b248d12d3b366defcf0d9965d72381c8ecf (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
import json
import os
import urllib

from lxml import etree


def main():
    week_day_config = {}

    supplemental_data = etree.fromstring(
        urllib.urlopen(
            'http://unicode.org/repos/cldr/trunk/common/supplemental/' +
            'supplementalData.xml'
        ).read())
    for first_day in supplemental_data.xpath('weekData/firstDay[not(@alt)]'):
        day = first_day.get('day')
        territories = first_day.get('territories').split()
        for territory in territories:
            week_day_config[territory] = day

    json.dump(week_day_config,
              file(os.path.join(
                  os.environ['PYTHONPATH'],
                  'config',
                  'weekdays.json'), 'w'),
              sort_keys=True,
              indent=4,
              separators=(',', ': '))

if __name__ == '__main__':
    main()