-
Notifications
You must be signed in to change notification settings - Fork 5.6k
[Components] meteomatics_weather_api #12541 #13002
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import app from "../../meteomatics_weather_api.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "meteomatics_weather_api-get-weather-data", | ||
| name: "Get Weather Data", | ||
| description: "Retrieve historic, current, and forecast data globally. [See the documentation](https://www.meteomatics.com/en/api/getting-started/)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| app, | ||
| validDateTime: { | ||
| propDefinition: [ | ||
| app, | ||
| "validDateTime", | ||
| ], | ||
| }, | ||
| parameters: { | ||
| propDefinition: [ | ||
| app, | ||
| "parameters", | ||
| ], | ||
| }, | ||
| locations: { | ||
| propDefinition: [ | ||
| app, | ||
| "locations", | ||
| ], | ||
| }, | ||
| format: { | ||
| propDefinition: [ | ||
| app, | ||
| "format", | ||
| ], | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.app.getWeatherData({ | ||
| $, | ||
| validdatetime: this.validDateTime.join("--"), | ||
| parameters: this.parameters.join(","), | ||
| locations: this.locations, | ||
| format: this.format, | ||
| }); | ||
|
|
||
| $.export("$summary", "Successfully retrieved weather data"); | ||
|
|
||
| return response; | ||
| }, | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| export default { | ||
| PARAMETERS: [ | ||
| { | ||
| label: "Instantaneous wind speed at 10m above ground", | ||
| value: "wind_speed_10m:ms", | ||
| }, | ||
| { | ||
| label: "Instantaneous temperature at 2m above ground in degrees Celsius", | ||
| value: "t_2m:C", | ||
| }, | ||
| { | ||
| label: "Precipitation accumulated over the past 24 hours in millimeter (equivalent to litres per square meter)", | ||
| value: "precip_24h:mm", | ||
| }, | ||
| { | ||
| label: "UV index", | ||
| value: "uv:idx", | ||
| }, | ||
| ], | ||
| FORMATS: [ | ||
| "csv", | ||
| "xml", | ||
| "json", | ||
| "png", | ||
| ], | ||
| }; |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,11 +1,60 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { axios } from "@pipedream/platform"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import constants from "./common/constants.mjs"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export default { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type: "app", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| app: "meteomatics_weather_api", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| propDefinitions: {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| propDefinitions: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| validDateTime: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type: "string[]", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| label: "Valid Date Time", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description: "A date or date range to retrieve the weather forecast for, i.e. `2017-05-28T13:00:00Z`", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| parameters: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type: "string[]", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| label: "Parameters", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description: "One or more parameters to be included in this request", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| options: constants.PARAMETERS, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| locations: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type: "string", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| label: "Location", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description: "Geo-coordinates (latitude and longitude) in WGS-84 decimal format, i.e. `47.419708,9.358478`", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| format: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type: "string", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| label: "Format", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description: "The data format of the output", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| options: constants.FORMATS, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| methods: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // this.$auth contains connected account data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| authKeys() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log(Object.keys(this.$auth)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _baseUrl() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return "https://api.meteomatics.com"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async _makeRequest(opts = {}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $ = this, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| path, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| params, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ...otherOpts | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } = opts; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return axios($, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ...otherOpts, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| url: this._baseUrl() + path, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| params: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ...params, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| access_token: `${this.$auth.oauth_access_token}`, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+35
to
+50
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure correct API request handling and error management. The async _makeRequest(opts = {}) {
const {
$ = this,
path,
params,
...otherOpts
} = opts;
try {
return await axios($, {
...otherOpts,
url: this._baseUrl() + path,
params: {
...params,
access_token: `${this.$auth.oauth_access_token}`,
},
});
} catch (error) {
$.export("$summary", `API request failed: ${error.message}`);
throw error;
}
}Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async getWeatherData({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| validdatetime, parameters, locations, format, ...args | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return this._makeRequest({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| path: `/${validdatetime}/${parameters}/${locations}/${format}`, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ...args, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+51
to
+57
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure correct weather data retrieval and error handling. The async getWeatherData({
validdatetime, parameters, locations, format, ...args
}) {
try {
return await this._makeRequest({
path: `/${validdatetime}/${parameters}/${locations}/${format}`,
...args,
});
} catch (error) {
throw new Error(`Failed to retrieve weather data: ${error.message}`);
}
}Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add error handling in the
runmethod.The
runmethod correctly constructs the API call. However, error handling should be added to manage potential API call failures.async run({ $ }) { try { const response = await this.app.getWeatherData({ $, validdatetime: this.validDateTime.join("--"), parameters: this.parameters.join(","), locations: this.locations, format: this.format, }); $.export("$summary", `Successfully retrieved weather data for ${response.data.length} parameters`); return response; } catch (error) { $.export("$summary", `Failed to retrieve weather data: ${error.message}`); throw error; } }Committable suggestion