{ "cells": [ { "cell_type": "code", "execution_count": null, "id": "5726d887", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Temperature: 22.7 °C\n", "Humidity: 54 %\n", "Wind speed: 3.6 km/h\n", "{'time': '2026-06-08T21:45', 'interval': 900, 'temperature_2m': 22.7, 'relative_humidity_2m': 54, 'wind_speed_10m': 3.6}\n" ] } ], "source": [ "import requests\n", "\n", "# Coordinates for Marseille\n", "lat = 43.2965\n", "lon = 5.3698\n", "\n", "url = (\n", " \"https://api.open-meteo.com/v1/forecast\"\n", " f\"?latitude={lat}&longitude={lon}\"\n", " \"¤t=temperature_2m,relative_humidity_2m,wind_speed_10m\"\n", ")\n", "\n", "data = requests.get(url).json()\n", "\n", "current = data[\"current\"]\n", "\n", "print(\"Temperature:\", current[\"temperature_2m\"], \"°C\")\n", "print(\"Humidity:\", current[\"relative_humidity_2m\"], \"%\")\n", "print(\"Wind speed:\", current[\"wind_speed_10m\"], \"km/h\")\n" ] }, { "cell_type": "code", "execution_count": 5, "id": "eda4c3a6", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Chance of rain tomorrow: 35%\n", "☀️ Rain unlikely tomorrow\n" ] } ], "source": [ "# check if it rains tommorrow\n", "from datetime import datetime, timedelta\n", "\n", "LATITUDE = 43.2965\n", "LONGITUDE = 5.3698\n", "\n", "url = (\n", " \"https://api.open-meteo.com/v1/forecast\"\n", " f\"?latitude={LATITUDE}\"\n", " f\"&longitude={LONGITUDE}\"\n", " \"&daily=precipitation_probability_max\"\n", " \"&timezone=auto\"\n", ")\n", "\n", "data = requests.get(url, timeout=10).json()\n", "\n", "tomorrow = (datetime.now() + timedelta(days=1)).strftime(\"%Y-%m-%d\")\n", "\n", "dates = data[\"daily\"][\"time\"]\n", "probs = data[\"daily\"][\"precipitation_probability_max\"]\n", "\n", "idx = dates.index(tomorrow)\n", "prob = probs[idx]\n", "\n", "print(f\"Chance of rain tomorrow: {prob}%\")\n", "\n", "if prob >= 50:\n", " print(\"🌧️ Likely to rain tomorrow\")\n", "else:\n", " print(\"☀️ Rain unlikely tomorrow\")" ] }, { "cell_type": "code", "execution_count": 8, "id": "c806be1c", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "False\n", "True\n", "False\n" ] } ], "source": [ "from datetime import date, datetime\n", "def did_or_will_rain(\n", " target_date,\n", " latitude,\n", " longitude,\n", " forecast_threshold=50,\n", "):\n", " \"\"\"\n", " Returns True if:\n", " - it rained on a past date\n", " - rain is forecast on a future date above the threshold\n", "\n", " Parameters\n", " ----------\n", " target_date : str | date | datetime\n", " Date to check (\"YYYY-MM-DD\" or date object)\n", " latitude : float\n", " longitude : float\n", " forecast_threshold : int\n", " Minimum rain probability (%) for future dates\n", "\n", " Returns\n", " -------\n", " bool\n", " \"\"\"\n", "\n", " # Normalize date\n", " if isinstance(target_date, str):\n", " target_date = datetime.strptime(target_date, \"%Y-%m-%d\").date()\n", " elif isinstance(target_date, datetime):\n", " target_date = target_date.date()\n", "\n", " today = date.today()\n", "\n", " # Historical date\n", " if target_date < today:\n", " url = (\n", " \"https://archive-api.open-meteo.com/v1/archive\"\n", " f\"?latitude={latitude}\"\n", " f\"&longitude={longitude}\"\n", " f\"&start_date={target_date}\"\n", " f\"&end_date={target_date}\"\n", " \"&daily=precipitation_sum\"\n", " \"&timezone=auto\"\n", " )\n", "\n", " data = requests.get(url, timeout=10).json()\n", "\n", " rain_mm = data[\"daily\"][\"precipitation_sum\"][0]\n", " return rain_mm > 0\n", "\n", " # Today / future date\n", " else:\n", " url = (\n", " \"https://api.open-meteo.com/v1/forecast\"\n", " f\"?latitude={latitude}\"\n", " f\"&longitude={longitude}\"\n", " \"&daily=precipitation_probability_max,precipitation_sum\"\n", " \"&forecast_days=16\"\n", " \"&timezone=auto\"\n", " )\n", "\n", " data = requests.get(url, timeout=10).json()\n", "\n", " dates = data[\"daily\"][\"time\"]\n", "\n", " target_date_str = target_date.isoformat()\n", "\n", " if target_date_str not in dates:\n", " raise ValueError(\"Date outside forecast range\")\n", "\n", " idx = dates.index(target_date_str)\n", "\n", " probability = data[\"daily\"][\"precipitation_probability_max\"][idx]\n", " precipitation = data[\"daily\"][\"precipitation_sum\"][idx]\n", "\n", " return (\n", " probability >= forecast_threshold\n", " or precipitation > 0\n", " )\n", " \n", "# Marseille\n", "LAT = 43.2965\n", "LON = 5.3698\n", "\n", "# Did it rain yesterday?\n", "print(did_or_will_rain(\"2026-06-03\", LAT, LON))\n", "\n", "# Will it rain tomorrow?\n", "print(did_or_will_rain(\"2026-06-04\", LAT, LON))\n", "\n", "# Require at least 70% confidence\n", "print(\n", " did_or_will_rain(\n", " \"2026-06-05\",\n", " LAT,\n", " LON,\n", " forecast_threshold=70,\n", " ))" ] }, { "cell_type": "code", "execution_count": null, "id": "34b8844f", "metadata": {}, "outputs": [], "source": [ "from plant import Plant\n", "p = Plant(\"Ficus\")\n", "print(p)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.14.5" } }, "nbformat": 4, "nbformat_minor": 5 }