-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathWeatherParam.cs
More file actions
81 lines (70 loc) · 2.09 KB
/
WeatherParam.cs
File metadata and controls
81 lines (70 loc) · 2.09 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using MSEvangelism.OpenWeatherMap;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using Microsoft.Bot.Builder.Dialogs;
namespace MyBot
{
[Serializable]
public enum Measurement { Temp = 1, Humidity = 2, Pressure = 4, None = 0 };
[Serializable]
public class WeatherParam
{
public string Location { get; set; }
public DateTime When { get; set; }
public Measurement MeasurementType { get; set; }
public WeatherParam()
{
When = DateTime.Now;
MeasurementType = Measurement.Temp;
Location = "Moscow";
}
public void Today()
{
When = DateTime.Now;
}
public void Tomorrow()
{
When = DateTime.Now.AddDays(1);
}
public void AlsoMeasure(Measurement M)
{
MeasurementType |= M;
}
public bool Measure(Measurement M)
{
return (M & MeasurementType) > 0;
}
public int Offset
{
get
{
return (int)(((float)(When - DateTime.Now).Hours) / 24.0 + 0.5) ;
}
}
public async Task<string> BuildResult()
{
WeatherClient OWM = new WeatherClient(Config.OpenWeatherMapAPIKey);
var res = await OWM.Forecast(Location);
var r = res[Offset];
StringBuilder sb = new StringBuilder();
if (Measure(Measurement.Temp))
{
sb.Append($"The temperature on {r.Date} in {Location} is {r.Temp}\r\n");
}
if (Measure(Measurement.Pressure))
{
sb.Append($"The pressure on {r.Date} in {Location} is {r.Pressure}\r\n");
}
if (Measure(Measurement.Humidity))
{
sb.Append($"Humidity on {r.Date} in {Location} is {r.Humidity}\r\n");
}
if (sb.Length == 0) return "I do not understand";
else return sb.ToString();
}
}
}