-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
60 lines (37 loc) · 1.4 KB
/
Program.cs
File metadata and controls
60 lines (37 loc) · 1.4 KB
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
54
55
56
57
58
59
60
using System;
using System.Text;
using System.Collections.Generic;
using System.Net.Http;
using System.IO;
using Newtonsoft.Json.Linq;
using System.Threading.Tasks;
namespace APIWeatherProject
{
class Program
{
static void Main(string[] args)
{
#if DEBUG
string key = File.ReadAllText("appsettings.debug.json");
#else
string key = File.ReadAllText("appsettings.release.json");
#endif
var httpclient = new HttpClient();
Console.WriteLine("Enter Zip Code");
int zip = int.Parse(Console.ReadLine());
Console.WriteLine("Enter your Country Code (Ex. US, CA etc...)");
string countrycode = Console.ReadLine();
JObject jObject = JObject.Parse(key);
JToken token = jObject["ApiKey"];
string apikey = token.ToString();
string url = $"https://api.openweathermap.org/data/2.5/weather?zip={zip},{countrycode}&appid={apikey}";
Task<string> response = httpclient.GetStringAsync(url);
string newresponse = response.Result;
JObject jObject1 = JObject.Parse(newresponse);
var temp = jObject1["main"]["temp"].ToString();
var tempconversion = double.Parse(temp) * 9 / 5 - 459.67;
tempconversion = Math.Round(tempconversion, 1);
Console.WriteLine($"Temp is {tempconversion}");
}
}
}