# This Python file uses the following encoding: utf-8
# !/usr/bin/env python
import os

import django

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "proj_hkcm.settings")
django.setup()

import pytz
from hkcm.models import Crimemapinfo, Cmdata
from datetime import datetime

if __name__ == "__main__":

    crimemapinfo_list = Crimemapinfo.objects.all()

    for x in crimemapinfo_list:
        issuetime = datetime.strptime(x.issuetime, '%Y-%m-%d %H:%M')
        issuetime = pytz.utc.localize(issuetime)
        # location = x.location.encode('unicode_escape')
        # crime = x.crime.encode('unicode_escape')
        # crimecat = x.crimecat
        # latitude = x.latitude
        # longitude = x.longitude
        # title = x.title.encode('unicode_escape')
        # url = x.url
        location = x.location
        crime = x.crime
        crimecat = x.crimecat
        latitude = x.latitude
        longitude = x.longitude
        title = x.title
        url = x.url

        record = Cmdata(issuetime=issuetime,
                        location=location,
                        crime=crime,
                        crimecat=crimecat,
                        latitude=latitude,
                        longitude=longitude,
                        title=title,
                        URL=url)
        record.save()
    # # for x in crimemapinfo_list:
    # x = crimemapinfo_list[0]
    # issuetime = datetime.strptime(x.issuetime, '%Y-%m-%d %H:%M')
    # issuetime = pytz.utc.localize(issuetime)
    # # location = x.location.encode('unicode_escape')
    # # crime = x.crime.encode('unicode_escape')
    # # crimecat = x.crimecat
    # # latitude = x.latitude
    # # longitude = x.longitude
    # # title = x.title.encode('unicode_escape')
    # # url = x.url
    # location = x.location
    # print(type(location))
    # crime = x.crime
    # crimecat = x.crimecat
    # latitude = x.latitude
    # longitude = x.longitude
    # title = x.title
    # url = x.url
    #
    # record = Cmdata(issuetime=issuetime,
    #                 location=location,
    #                 crime=crime,
    #                 crimecat=crimecat,
    #                 latitude=latitude,
    #                 longitude=longitude,
    #                 title=title,
    #                 URL=url)
    # # sec_record = HongKongDistricts(location=location,)
    # record.save()
    # # sec_record.save()
