# Geocoded Weather Extractor (`scraping_samurai/geocoded-weather-extractor`) Actor

Provide a location and choose hourly, daily, or weekly output; the actor resolves coordinates, fetches forecasts for selected variables (e.g., temperature_2m, precipitation, wind), and writes an overview JSON plus normalized rows to a Dataset.

- **URL**: https://apify.com/scraping_samurai/geocoded-weather-extractor.md
- **Developed by:** [Scraping Samurai](https://apify.com/scraping_samurai) (community)
- **Categories:** Automation, Developer tools, Travel
- **Features:** Full permissions
- **Stats:** 4 total users, 0 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

Pay per usage

This Actor is paid per platform usage. The Actor is free to use, and you only pay for the Apify platform usage, which gets cheaper the higher subscription plan you have.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-usage

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Geocoded Weather Extractor (Actor/Fetcher)

A simple, fast, and privacy‑aware weather data fetcher you can run as an Actor or locally.\
Give it a location and choose **hourly**, **daily**, or **weekly (aggregated)** output.\
Designed for business use: clean outputs, predictable schemas, and vendor‑neutral messaging.

***

### ✨ Features

- **Three granularities**: hourly, daily, or weekly (derived from daily via ISO‑week aggregation).
- **Pick your variables**: choose exactly which fields you want included.
- **Timezone‑aware**: set a specific IANA timezone or use automatic inference.
- **Structured outputs**: overview JSON + normalized rows in the Dataset.
- **Drop‑in for analytics**: consistent schemas for easy ingestion to BI tools or warehouses.
- **Production‑ready**: typed code, input schema validation, and clear logging.

***

### 🧠 How it works (high level)

1. The actor resolves the provided free‑text **location** to coordinates.
2. It fetches a **forecast** for the requested variables and timeframe.
3. It writes:
   - An **`OUTPUT`** JSON summarizing the run (resolved location, coordinates, timezone, variables, etc.).
   - A **Dataset** with one row per timestamp (hour/day) or **per ISO week** when using weekly mode.

***

### 📥 Input

The actor accepts the following JSON input (also defined in `.actor/input_schema.json`).

```json
{
  "location": "Prague, CZ",
  "mode": "hourly",
  "hourly": ["temperature_2m", "precipitation"],
  "daily": ["temperature_2m_max", "temperature_2m_min", "precipitation_sum"],
  "timezone": "auto",
  "forecastDays": 3
}
```

#### Fields

| Field | Type | Required | Description |
|---|---|---:|---|
| `location` | string | ✅ | Free‑text place (e.g., `"Prague"` or `"Prague, CZ"`). |
| `mode` | `"hourly" \| "daily" \| "weekly"` |  | Data granularity; weekly aggregates daily values by ISO week. Default: `"hourly"`. |
| `hourly` | string\[] |  | Hourly variables to include when `mode = "hourly"`. |
| `daily` | string\[] |  | Daily variables to include when `mode = "daily"` or `"weekly"`. |
| `timezone` | string |  | `"auto"` to infer from coordinates, or any IANA name (e.g., `"Europe/Prague"`). |
| `forecastDays` | integer (1–7) |  | Number of days to fetch. |

> Tip: You can safely omit `hourly` or `daily` if they are not relevant to your chosen `mode`.

***

### 📤 Outputs

#### Key‑value store (`OUTPUT`)

```json
{
  "input_location": "Prague, CZ",
  "resolved_name": "Prague, Hlavni mesto Praha, Czechia",
  "latitude": 50.08,
  "longitude": 14.43,
  "timezone": "Europe/Prague",
  "timezone_abbreviation": "CEST",
  "elevation": 194,
  "mode": "hourly",
  "variables": ["temperature_2m", "precipitation"],
  "fetched_at": "2025-09-21T10:11:12.345Z"
}
```

#### Dataset

- **Hourly mode**: one item per `time` (ISO datetime).
- **Daily mode**: one item per `date` (ISO date).
- **Weekly mode**: one item per `iso_week` (e.g., `2025-W38`) with `start_date`, `end_date`, and aggregated metrics.

Example (hourly row):

```json
{
  "mode": "hourly",
  "time": "2025-09-21T12:00:00Z",
  "input_location": "Prague, CZ",
  "resolved_name": "Prague, Hlavni mesto Praha, Czechia",
  "latitude": 50.08,
  "longitude": 14.43,
  "temperature_2m": 23.1,
  "precipitation": 0.0
}
```

Example (weekly row):

```json
{
  "mode": "weekly",
  "iso_week": "2025-W38",
  "input_location": "Prague, CZ",
  "resolved_name": "Prague, Hlavni mesto Praha, Czechia",
  "latitude": 50.08,
  "longitude": 14.43,
  "start_date": "2025-09-15",
  "end_date": "2025-09-21",
  "days_in_week": 7,
  "temperature_2m_max": 26.4,
  "temperature_2m_min": 12.2,
  "precipitation_sum": 4.6
}
```

***

### 🧮 Weekly aggregation rules

When `mode = "weekly"`, the actor aggregates daily series by ISO week:

- Variables ending in `_sum` (and `precipitation_sum`): **sum**
- Variables ending in `_max`: **max**
- Variables ending in `_min`: **min**
- All other numeric series: **average**

Non‑numeric or missing values are ignored in the aggregation. Weeks are labeled using ISO format (`YYYY-Www`).

***

### 🧩 Example inputs

**Hourly forecast (2 variables, 24 hours default window depending on source):**

```json
{
  "location": "Berlin, DE",
  "mode": "hourly",
  "hourly": ["temperature_2m", "precipitation"],
  "timezone": "Europe/Berlin",
  "forecastDays": 1
}
```

**Daily forecast (5 days):**

```json
{
  "location": "Lisbon, PT",
  "mode": "daily",
  "daily": ["temperature_2m_max", "temperature_2m_min", "precipitation_sum"],
  "timezone": "auto",
  "forecastDays": 5
}
```

**Weekly aggregates from daily:**

```json
{
  "location": "Prague, CZ",
  "mode": "weekly",
  "daily": ["temperature_2m_max", "temperature_2m_min", "precipitation_sum"],
  "timezone": "Europe/Prague",
  "forecastDays": 7
}
```

***

### 🏷️ Data dictionary (selected variables)

- `temperature_2m` — Near‑surface air temperature (°C).
- `precipitation` / `precipitation_sum` — Precipitation amount (mm).
- `relative_humidity_2m` — Relative humidity (%).
- `apparent_temperature` — Feels‑like temperature (°C).
- `pressure_msl` — Mean sea‑level pressure (hPa).
- `wind_speed_10m`, `wind_gusts_10m` — Wind speed/gusts at 10 m (m/s).
- `cloud_cover` — Total cloud cover (%).
- `temperature_2m_max`, `temperature_2m_min` — Daily extrema (°C).
- `rain_sum`, `snowfall_sum` — Daily totals (mm).

> The available variables depend on your chosen mode. Provide only the ones you need.

***

### 🧰 Troubleshooting

- **No results for location**: Try a more specific place name (e.g., `"City, Country"`).
- **Timezone mismatch**: Set a specific IANA timezone instead of `"auto"`.
- **Empty dataset**: Ensure your selected variables exist for the chosen mode.
- **Rate‑limits**: If running many jobs, space them out or batch your locations to avoid upstream throttling.

# Actor input Schema

## `location` (type: `string`):

Free-text place to look up (e.g., "Prague" or "Prague, CZ").

## `mode` (type: `string`):

Choose data granularity. 'Weekly' aggregates daily values by ISO week.

## `hourly` (type: `array`):

Used when mode = hourly. Select the hourly fields to include.

## `daily` (type: `array`):

Used when mode = daily or weekly. Select the daily fields to include.

## `timezone` (type: `string`):

Use "auto" to infer from coordinates, or specify an IANA TZ like "Europe/Prague".

## `forecastDays` (type: `integer`):

Number of days to fetch (1–7).

## Actor input object example

```json
{
  "location": "Prague",
  "mode": "daily",
  "hourly": [
    "temperature_2m",
    "precipitation"
  ],
  "daily": [
    "temperature_2m_max",
    "temperature_2m_min",
    "precipitation_sum"
  ],
  "timezone": "auto"
}
```

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "location": "Prague",
    "hourly": [
        "temperature_2m",
        "precipitation"
    ],
    "daily": [
        "temperature_2m_max",
        "temperature_2m_min",
        "precipitation_sum"
    ],
    "timezone": "auto"
};

// Run the Actor and wait for it to finish
const run = await client.actor("scraping_samurai/geocoded-weather-extractor").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "location": "Prague",
    "hourly": [
        "temperature_2m",
        "precipitation",
    ],
    "daily": [
        "temperature_2m_max",
        "temperature_2m_min",
        "precipitation_sum",
    ],
    "timezone": "auto",
}

# Run the Actor and wait for it to finish
run = client.actor("scraping_samurai/geocoded-weather-extractor").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "location": "Prague",
  "hourly": [
    "temperature_2m",
    "precipitation"
  ],
  "daily": [
    "temperature_2m_max",
    "temperature_2m_min",
    "precipitation_sum"
  ],
  "timezone": "auto"
}' |
apify call scraping_samurai/geocoded-weather-extractor --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,scraping_samurai/geocoded-weather-extractor"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/j2425Uk7WyQuzqS68/builds/fHlxmwhDMKbLWxcef/openapi.json
