package main

import (
	"flag"
	"fmt"
	"os"
)

func main() {
	//set up the flags for the program to use!
	var city, code, api_key string
	flag.StringVar(&city, "city", "London", "Enter city e.g. London")
	flag.StringVar(&code, "code", "uk", "Enter Code e.g. uk")
	flag.StringVar(&api_key, "api", "none", "Enter you api key here")
	flag.Parse()

	full := "https://api.openweathermap.org/data/2.5/weather?q=" + city + "," + code + "&units=metric" + "&appid=" + api_key + ""

	//read webpage
	html, err := loadWebPage(full)
	if err != nil {
		fmt.Println("4xx error, please try again!")
		os.Exit(1)
	}

	//Create file
	createFile(string(html))

	//Load the file
	data, err := loadJson("weather.json")
	if err != nil {
		fmt.Println("Cannot load weather.json file!")
	}

	//Print the weather!
	printWeather(data)

	//remove the file at the end
	removeFile("weather.json")
}
