Skip to content

Commit 159c993

Browse files
committedFeb 17, 2022
third commit
1 parent 6ec5673 commit 159c993

File tree

63 files changed

+886
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+886
-0
lines changed
 

‎Action.cs

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
5+
namespace MyAlarm // Note: actual namespace depends on the project name.
6+
{
7+
public abstract class Action
8+
{
9+
public static String TYPE_SPEAK= "speak";
10+
public static String TYPE_METEO= "meteo";
11+
public static String TYPE_URL= "url";
12+
13+
protected String type;
14+
15+
protected String [] args;
16+
17+
public Action(String type, String[] args){
18+
this.type= type;
19+
this.args= args;
20+
}
21+
22+
public abstract void execute();
23+
}
24+
}

‎ActionMeteo.cs

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using Newtonsoft.Json;
5+
6+
7+
namespace MyAlarm // Note: actual namespace depends on the project name.
8+
{
9+
public class ActionMeteo : Action
10+
{
11+
12+
private String url="http://api.weatherstack.com/current?";
13+
private String key;
14+
private String location;
15+
public ActionMeteo(string[] args) : base(Action.TYPE_METEO, args)
16+
{
17+
key= args[0];
18+
location= args[1];
19+
}
20+
21+
public override async void execute()
22+
{
23+
HttpClient client = new HttpClient();
24+
HttpResponseMessage response = await client.GetAsync($"{url}access_key={key}&query={location}");
25+
response.EnsureSuccessStatusCode();
26+
string responseBody = await response.Content.ReadAsStringAsync();
27+
JsonTextReader reader = new JsonTextReader(new StringReader(responseBody));
28+
String currentParameter="";
29+
String[] texts= new string[2];
30+
while (reader.Read()){
31+
if (reader.Value != null)
32+
{
33+
if(reader.TokenType.ToString().Equals("PropertyName")){
34+
currentParameter= reader.Value.ToString();
35+
}else if(currentParameter.Equals("temperature")
36+
&&reader.TokenType.ToString().Equals("Integer")){
37+
texts[0]= $"La température est de {reader.Value.ToString()}°C.";
38+
}
39+
}
40+
}
41+
texts[1]="Voici la page des données météo.";
42+
ActionSpeak speak= new ActionSpeak(texts);
43+
speak.execute();
44+
ActionUrl pageMeteo= new ActionUrl(new string[]{$"https://www.google.com/search?q=meteo+{location}"});
45+
pageMeteo.execute();
46+
}
47+
}
48+
}

0 commit comments

Comments
 (0)
Please sign in to comment.