#!/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()