aboutsummaryrefslogtreecommitdiff
path: root/main.py
blob: 3fbf3e79769c7a8ade56857ec25efa31c98b041a (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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python3
import json, requests, datetime, argparse, pytz

import library

def parse_args():
    parser = argparse.ArgumentParser()
    parser.add_argument('-d', '--days', type=int)
    parser.add_argument('-H', '--hours', type=int)
    parser.add_argument('-l', '--location', type=str, required=True)
    return parser.parse_args()


def hourly_forecast(args, raw_data):

    init_time = library.get_current_rounded_time()
    if args.hours is not None:
        delta = datetime.timedelta(hours=args.hours)
    elif args.days is not None:
        delta = datetime.timedelta(days=args.days)
    else:
        delta = datetime.timedelta(hours=(24-init_time.hour))
    end_time = init_time + delta

    hourly_data = library.get_hourly_data(raw_data, end_time)

    for point in hourly_data:
        print(point["time"].strftime("%a %x %I:%M %p"))
        print(f'\t Temperature - { point["temp"] }°F')
        print(f'\t Humidity - { point["humidity"] }%')
        print(f'\t Chance of Precipitation - { point["precip_chance"] }%')
        print(f'\t Precipitation Amount - { point["precip_amount"] } in')
        print(f'\t Wind Speed - { point["wind_speed"] } MPH')
        print(f'\t Wind Direction - { point["wind_direction"] }')
        print('\n')



def daily_forecast(raw_data):
    pass


def main():
    args = parse_args()
    latitude, longitude = library.get_lat_long(args.location)
    grid_data = library.get_grid_data(latitude, longitude)
    raw_data = library.get_raw_data(grid_data["grid_id"], grid_data["grid_x"], grid_data["grid_y"])
    hourly_forecast(args, raw_data)



if __name__ == '__main__':
    main()