Skip to content

Commit 0ad51da

Browse files
authored
Merging pull request #17700
Actions - Get Location Key - Get Current Conditions - Get Daily Forecast - Get Hourly Forecast - Get Historical Weather
1 parent 14b4359 commit 0ad51da

File tree

9 files changed

+290
-9
lines changed

9 files changed

+290
-9
lines changed
Lines changed: 66 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,73 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "accuweather",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
locationKey: {
8+
type: "string",
9+
label: "Location Key",
10+
description: "The location key for the desired location. You can get this using the 'Get Location Key' action.",
11+
},
12+
},
513
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
14+
_baseUrl() {
15+
return "http://dataservice.accuweather.com";
16+
},
17+
_params(params = {}) {
18+
return {
19+
apikey: `${this.$auth.api_key}`,
20+
...params,
21+
};
22+
},
23+
_makeRequest({
24+
$ = this, params, path, ...opts
25+
}) {
26+
return axios($, {
27+
url: this._baseUrl() + path,
28+
params: this._params(params),
29+
...opts,
30+
});
31+
},
32+
searchLocation(opts = {}) {
33+
return this._makeRequest({
34+
path: "/locations/v1/search",
35+
...opts,
36+
});
37+
},
38+
getCurrentConditions({
39+
locationKey, ...opts
40+
}) {
41+
return this._makeRequest({
42+
path: `/currentconditions/v1/${locationKey}`,
43+
...opts,
44+
});
45+
},
46+
getDailyForecast({
47+
days, locationKey, ...opts
48+
}) {
49+
return this._makeRequest({
50+
path: `/forecasts/v1/daily/${days}day/${locationKey}`,
51+
...opts,
52+
});
53+
},
54+
getHourlyForecast({
55+
hours, locationKey, ...opts
56+
}) {
57+
return this._makeRequest({
58+
path: `/forecasts/v1/hourly/${hours}hour/${locationKey}`,
59+
...opts,
60+
});
61+
},
62+
getHistoricalWeather({
63+
locationKey, time, ...opts
64+
}) {
65+
return this._makeRequest({
66+
path: `/currentconditions/v1/${locationKey}/historical${time === 24
67+
? "/24"
68+
: ""}`,
69+
...opts,
70+
});
971
},
1072
},
1173
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import accuweather from "../../accuweather.app.mjs";
2+
3+
export default {
4+
key: "accuweather-get-current-conditions",
5+
name: "Get Current Conditions",
6+
description: "Retrieve current weather conditions for a specific location using its location key. [See the documentation](https://developer.accuweather.com/accuweather-current-conditions-api/apis/get/currentconditions/v1/%7BlocationKey%7D)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
accuweather,
11+
locationKey: {
12+
propDefinition: [
13+
accuweather,
14+
"locationKey",
15+
],
16+
},
17+
},
18+
async run({ $ }) {
19+
const response = await this.accuweather.getCurrentConditions({
20+
$,
21+
locationKey: this.locationKey,
22+
});
23+
$.export("$summary", `Retrieved current conditions for location key: ${this.locationKey}`);
24+
return response;
25+
},
26+
};
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import accuweather from "../../accuweather.app.mjs";
2+
import { FORECAST_DAYS_OPTIONS } from "../../common/constants.mjs";
3+
4+
export default {
5+
key: "accuweather-get-daily-forecast",
6+
name: "Get Daily Forecast",
7+
description: "Get daily weather forecast for a specific location with temperature, precipitation, and conditions. [See the documentation](https://developer.accuweather.com/accuweather-forecast-api/apis)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
accuweather,
12+
locationKey: {
13+
propDefinition: [
14+
accuweather,
15+
"locationKey",
16+
],
17+
},
18+
forecastDays: {
19+
type: "integer",
20+
label: "Forecast Days",
21+
description: "Number of days to forecast",
22+
options: FORECAST_DAYS_OPTIONS,
23+
},
24+
},
25+
async run({ $ }) {
26+
const response = await this.accuweather.getDailyForecast({
27+
$,
28+
locationKey: this.locationKey,
29+
days: this.forecastDays,
30+
params: {
31+
details: true,
32+
},
33+
});
34+
35+
$.export("$summary", `Retrieved forecast for ${this.forecastDays} day${this.forecastDays === 1
36+
? ""
37+
: "s"}`);
38+
39+
return response;
40+
},
41+
};
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import accuweather from "../../accuweather.app.mjs";
2+
import { HISTORICAL_TIME_OPTIONS } from "../../common/constants.mjs";
3+
4+
export default {
5+
key: "accuweather-get-historical-weather",
6+
name: "Get Historical Weather",
7+
description: "Retrieve historical weather data for a specific location and date range. [See the documentation](https://developer.accuweather.com/accuweather-current-conditions-api/apis)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
accuweather,
12+
locationKey: {
13+
propDefinition: [
14+
accuweather,
15+
"locationKey",
16+
],
17+
},
18+
historicalTime: {
19+
type: "integer",
20+
label: "Historical Time",
21+
description: "Historical time for weather data",
22+
options: HISTORICAL_TIME_OPTIONS,
23+
},
24+
},
25+
async run({ $ }) {
26+
const response = await this.accuweather.getHistoricalWeather({
27+
$,
28+
locationKey: this.locationKey,
29+
time: this.historicalTime,
30+
});
31+
32+
$.export("$summary", `Retrieved historical weather data for ${this.historicalTime} hours`);
33+
return response;
34+
},
35+
};
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import accuweather from "../../accuweather.app.mjs";
2+
import { FORECAST_HOURS_OPTIONS } from "../../common/constants.mjs";
3+
4+
export default {
5+
key: "accuweather-get-hourly-forecast",
6+
name: "Get Hourly Forecast",
7+
description: "Retrieve hourly weather forecast (1-12 hours) for a specific location with detailed weather data. [See the documentation](https://developer.accuweather.com/accuweather-forecast-api/apis)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
accuweather,
12+
locationKey: {
13+
propDefinition: [
14+
accuweather,
15+
"locationKey",
16+
],
17+
},
18+
forecastHours: {
19+
type: "integer",
20+
label: "Forecast Hours",
21+
description: "Number of hours to forecast",
22+
options: FORECAST_HOURS_OPTIONS,
23+
},
24+
},
25+
async run({ $ }) {
26+
const response = await this.accuweather.getHourlyForecast({
27+
$,
28+
locationKey: this.locationKey,
29+
hours: this.forecastHours,
30+
params: {
31+
details: true,
32+
},
33+
});
34+
35+
$.export("$summary", `Retrieved forecast for ${this.forecastHours} hour${this.forecastHours === 1
36+
? ""
37+
: "s"}`);
38+
39+
return response;
40+
},
41+
};
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import accuweather from "../../accuweather.app.mjs";
2+
3+
export default {
4+
key: "accuweather-get-location-key",
5+
name: "Get Location Key",
6+
description: "Search for a location and retrieve its unique location key required for weather API calls. [See the documentation](https://developer.accuweather.com/accuweather-locations-api/apis/get/locations/v1/search)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
accuweather,
11+
locationQuery: {
12+
type: "string",
13+
label: "Location Query",
14+
description: "Search query for location (e.g., 'New York', 'London', 'Tokyo').",
15+
},
16+
},
17+
async run({ $ }) {
18+
const response = await this.accuweather.searchLocation({
19+
$,
20+
params: {
21+
q: this.locationQuery,
22+
},
23+
});
24+
25+
let summary = `Successfully found ${response.length} location${response.length === 1
26+
? ""
27+
: "s"}`;
28+
29+
if (response.length === 0) {
30+
summary = `No location found for query: ${this.locationQuery}`;
31+
}
32+
33+
$.export("$summary", summary);
34+
return response;
35+
},
36+
};
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
export const FORECAST_DAYS_OPTIONS = [
2+
{
3+
label: "1 Day",
4+
value: 1,
5+
},
6+
{
7+
label: "5 Days",
8+
value: 5,
9+
},
10+
];
11+
12+
export const FORECAST_HOURS_OPTIONS = [
13+
{
14+
label: "1 Hour",
15+
value: 1,
16+
},
17+
{
18+
label: "12 Hours",
19+
value: 12,
20+
},
21+
];
22+
23+
export const HISTORICAL_TIME_OPTIONS = [
24+
{
25+
label: "6 Hours",
26+
value: 6,
27+
},
28+
{
29+
label: "24 Hours",
30+
value: 24,
31+
},
32+
];

components/accuweather/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/accuweather",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream AccuWeather Components",
55
"main": "accuweather.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.1.0"
1417
}
15-
}
18+
}

pnpm-lock.yaml

Lines changed: 8 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)