-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4ndyWeather.js
187 lines (174 loc) · 5.22 KB
/
4ndyWeather.js
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
class FourndyWeather {
constructor() {
this.apiUrl = 'https://api.weatherapi.com/v1/current.json?key=52f0b34b8177490893613729250401&q=';
}
getInfo() {
return {
id: '4ndyWeather',
name: '4ndy Weather',
blocks: [
{
opcode: 'getTemperature',
blockType: Scratch.BlockType.REPORTER,
text: 'get temperature of [LOCATION]',
arguments: {
LOCATION: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'London'
}
}
},
{
opcode: 'getCondition',
blockType: Scratch.BlockType.REPORTER,
text: 'get weather condition of [LOCATION]',
arguments: {
LOCATION: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'London'
}
}
},
{
opcode: 'getHumidity',
blockType: Scratch.BlockType.REPORTER,
text: 'get humidity of [LOCATION]',
arguments: {
LOCATION: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'London'
}
}
},
{
opcode: 'getWindSpeed',
blockType: Scratch.BlockType.REPORTER,
text: 'get wind speed of [LOCATION]',
arguments: {
LOCATION: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'London'
}
}
},
{
opcode: 'getWeatherIcon',
blockType: Scratch.BlockType.REPORTER,
text: 'get weather icon of [LOCATION]',
arguments: {
LOCATION: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'London'
}
}
},
{
opcode: 'getAirQualityIndex',
blockType: Scratch.BlockType.REPORTER,
text: 'get air quality index (AQI) of [LOCATION]',
arguments: {
LOCATION: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'London'
}
}
},
{
opcode: 'getPressure',
blockType: Scratch.BlockType.REPORTER,
text: 'get air pressure of [LOCATION]',
arguments: {
LOCATION: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'London'
}
}
},
{
opcode: 'getFeelsLike',
blockType: Scratch.BlockType.REPORTER,
text: 'get feels like temperature of [LOCATION]',
arguments: {
LOCATION: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'London'
}
}
},
{
opcode: 'getUVIndex',
blockType: Scratch.BlockType.REPORTER,
text: 'get UV index of [LOCATION]',
arguments: {
LOCATION: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'London'
}
}
},
{
opcode: 'getCloudCoverage',
blockType: Scratch.BlockType.REPORTER,
text: 'get cloud coverage of [LOCATION]',
arguments: {
LOCATION: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'London'
}
}
}
]
};
}
async getTemperature(args) {
const response = await fetch(`${this.apiUrl}${args.LOCATION}&aqi=yes`);
const data = await response.json();
return data.current.temp_c;
}
async getCondition(args) {
const response = await fetch(`${this.apiUrl}${args.LOCATION}&aqi=yes`);
const data = await response.json();
return data.current.condition.text;
}
async getHumidity(args) {
const response = await fetch(`${this.apiUrl}${args.LOCATION}&aqi=yes`);
const data = await response.json();
return data.current.humidity;
}
async getWindSpeed(args) {
const response = await fetch(`${this.apiUrl}${args.LOCATION}&aqi=yes`);
const data = await response.json();
return data.current.wind_kph;
}
async getWeatherIcon(args) {
const response = await fetch(`${this.apiUrl}${args.LOCATION}&aqi=yes`);
const data = await response.json();
return data.current.condition.icon;
}
async getAirQualityIndex(args) {
const response = await fetch(`${this.apiUrl}${args.LOCATION}&aqi=yes`);
const data = await response.json();
return data.current.air_quality.pm2_5;
}
async getPressure(args) {
const response = await fetch(`${this.apiUrl}${args.LOCATION}&aqi=yes`);
const data = await response.json();
return data.current.pressure_mb;
}
async getFeelsLike(args) {
const response = await fetch(`${this.apiUrl}${args.LOCATION}&aqi=yes`);
const data = await response.json();
return data.current.feelslike_c;
}
async getUVIndex(args) {
const response = await fetch(`${this.apiUrl}${args.LOCATION}&aqi=yes`);
const data = await response.json();
return data.current.uv;
}
async getCloudCoverage(args) {
const response = await fetch(`${this.apiUrl}${args.LOCATION}&aqi=yes`);
const data = await response.json();
return data.current.cloud;
}
}
Scratch.extensions.register(new FourndyWeather());