# import arrow
# import json

# utc = arrow.get('1997-01-31')
# print(utc.timestamp)

# date = arrow.get(865641600)
# print(date.format('MMMM DD, YYYY'))

# local = utc.to('US/Pacific')
# print(local.timestamp)

# val = arrow.get(1573783610)
# print(val.format())

# today = arrow.get(datetime.datetime.now())
# print(today)

# past = arrow.now().shift(hours=-1)
# print(past.humanize())

# present = arrow.now()
# future = present.shift(hours=2)
# print(future.humanize(present))

# with open('class_record.json', 'r') as json_file:
#     json_reader = json.load(json_file)
#     today = arrow.now()
#     dick = {}
#     dictionary = []
#     with open('classv2.json', 'w') as json_writer:
#         for line in json_reader['birthdays']:
#             ts = arrow.get(line['bday_timestamp'])
#             formatted = ts.format('MMMM DD, YYYY')
#             age = today.year - ts.year - ((today.month, today.day) < (ts.month, ts.day))
#             line['age'] = age
#             line['birthday'] = formatted
#             res = json.dumps(line)
#             dictionary.append(line)
            
#         dick['birthdays'] = dictionary
#          # print(res)
#         json.dump(dick, json_writer, indent=2)

# events = [
#     "December 8, 1941, the Japanese invades the Philippines hours after bombing Pear Harbor in Hawaii.",
#     "March 31, 1521, The first Catholic mass was held in Limasawa, an island in the south of Leyte.",
#     "July 7, 1892, Jose Rizal was captured and exiled to Dapitan in Mindanao. There he served as a doctor, a scientist and"
#     "a teacher to the locals", 
#     "August 19, 1896, The spaniards learned the Katipunan movement that resulted to a massive capture of many Filipinos.",
#     "March 17, 1764, The british surrendered the country to Spain after losing a battle during the seven-year war between them."
# ]

# for line in events:
#     res = line.split(',')
#     result = res[0] + res[1]
#     date = arrow.get(result, 'MMMM D YYYY')
#     result = date.humanize()
#     print(result + ', ' + ' '.join(line.split(' ')[3:]))

import arrow
import json
from enum import Enum

ruling_planet = {
    'Aries': ['Mars'], 'Taurus': ['Venus'], 'Gemini': ['Mercury'],
    'Cancer': ['Moon'], 'Leo': ['Sun'], 'Virgo': ['Mercury'],
    'Libra': ['Venus'], 'Scorpio': ['Pluto', 'Mars'],
    'Sagittarius': ['Jupiter'], ' Capricorn': ['Saturn'],
    'Aquarius': ['Uranus', 'Saturn'], 'Pisces': ['Neptune', 'Jupiter']
}


class Signs(Enum):
    December = ('Sagittarius', 22, 'Capricorn')
    January = ('Capricorn', 20, 'Aquarius')
    February = ('Aquarius', 19, 'Pisces')
    March = ('Pisces', 21, 'Aries')
    April = ('Aries', 20, 'Taurus')
    May = ('Taurus', 21, 'Gemini')
    June = ('Gemini', 21, 'Cancer')
    July = ('Cancer', 23, 'Leo')
    August = ('Leo', 23, 'Virgo')
    September = ('Virgo', 23, 'Libra')
    October = ('Libra', 23, 'Scorpio')
    November = ('Scorpio', 22, 'Sagittarius')

    @classmethod
    def get_sign(cls, month, day):
        _signs = cls[month].value
        if int(day) < _signs[1]:
            return _signs[0]
        else:
            return _signs[2]


def birthday(x):
    date_fmt = arrow.get(x['bday_timestamp'])
    bday = date_fmt.format('MMMM DD, YYYY')

    m, d = bday.split(',')[0].split()
    sign = Signs.get_sign(m, d)

    x['birthday'] = bday
    x['zodiac_sign'] = sign
    x['ruling_planet'] = ', '.join(ruling_planet[sign])
    return x


with open('classv2.json') as json_f:
    data = json.load(json_f)['birthdays']
    data = [birthday(x) for x in data]

with open('birthdays_output.json', 'w') as json_fw:
    data = json.dumps(data, indent=4)
    json_fw.write(data)

print(data)
