Skip to content

Integrate UNEP Environmental Data API#33

Merged
GYFX35 merged 1 commit intofeat/initial-project-structurefrom
integrate-unep-api-13134788857640065043
Feb 7, 2026
Merged

Integrate UNEP Environmental Data API#33
GYFX35 merged 1 commit intofeat/initial-project-structurefrom
integrate-unep-api-13134788857640065043

Conversation

@GYFX35
Copy link
Owner

@GYFX35 GYFX35 commented Feb 7, 2026

Integrated UNEP environmental data by leveraging the UN SDG API. Added backend endpoints to fetch recycling rates and protected areas coverage, and a new frontend page with interactive charts to display this information. Verified the changes with backend tests and frontend screenshots.


PR created automatically by Jules for task 13134788857640065043 started by @GYFX35

Summary by Sourcery

Integrate UNEP SDG environmental indicators into the app with backend APIs and a new frontend visualization page.

New Features:

  • Add backend API endpoints to expose UNEP recycling rate and protected areas coverage data derived from the UN SDG API.
  • Introduce a dedicated UNEP data page with charts visualizing top countries for recycling rates and protected areas coverage, linked from the main navigation.

Enhancements:

  • Style the new UNEP data page with dedicated layout and chart presentation for better readability.

This change adds two new backend routes that fetch data for SDG indicators
where UNEP is the custodian (recycling rate and protected areas).
It also adds a new frontend page to visualize this data using Chart.js.

- Added `/api/unep_recycling` and `/api/unep_protected_areas` in `app.py`.
- Created `unep.html`, `unep.js`, and `unep.css` in `static/`.
- Updated `index.html` with a link to the new page.
- Added timeouts to the new backend API requests.

Co-authored-by: GYFX35 <134739293+GYFX35@users.noreply.github.com>
@google-labs-jules
Copy link
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Feb 7, 2026

Deploying success with  Cloudflare Pages  Cloudflare Pages

Latest commit: 0ee4f9a
Status: ✅  Deploy successful!
Preview URL: https://69f4c7ba.success-a2i.pages.dev
Branch Preview URL: https://integrate-unep-api-131347888.success-a2i.pages.dev

View logs

@sourcery-ai
Copy link

sourcery-ai bot commented Feb 7, 2026

Reviewer's Guide

Adds backend UNEP-powered SDG endpoints for recycling rates and protected areas coverage, and a new frontend UNEP page that visualizes the top 10 countries for each indicator using Chart.js, linked from the main index page.

Sequence diagram for fetching UNEP SDG data and rendering charts

sequenceDiagram
    actor User
    participant Browser
    participant FlaskBackend
    participant UN_SDG_API

    User->>Browser: Open unep.html
    Browser->>FlaskBackend: GET /api/unep_recycling
    FlaskBackend->>UN_SDG_API: GET /sdg/Series/Data?seriesCode=EN_MWT_RCYR
    UN_SDG_API-->>FlaskBackend: JSON series data
    FlaskBackend->>FlaskBackend: Extract latest per country
    FlaskBackend->>FlaskBackend: Sort and select top 10
    FlaskBackend-->>Browser: JSON top_10_recycling
    Browser->>Browser: renderChart(recyclingChart, top_10_recycling)

    Browser->>FlaskBackend: GET /api/unep_protected_areas
    FlaskBackend->>UN_SDG_API: GET /sdg/Series/Data?seriesCode=ER_PTD_TERR
    UN_SDG_API-->>FlaskBackend: JSON series data
    FlaskBackend->>FlaskBackend: Extract latest per country
    FlaskBackend->>FlaskBackend: Sort and select top 10
    FlaskBackend-->>Browser: JSON top_10_protected_areas
    Browser->>Browser: renderChart(protectedAreasChart, top_10_protected_areas)
Loading

File-Level Changes

Change Details Files
Expose UNEP / UN SDG-based recycling rate data via a new backend API endpoint.
  • Add /api/unep_recycling Flask route calling the UN SDG API series EN_MWT_RCYR with a 10s timeout
  • Aggregate raw series data into latest-per-country entries, converting year and value to numeric types
  • Sort countries by recycling rate, return the top 10 as JSON, and handle empty data with 404 responses
  • Log success and error cases with structured logger metadata for this endpoint
eco_project/backend/app.py
Expose UNEP / UN SDG-based protected areas coverage data via a new backend API endpoint.
  • Add /api/unep_protected_areas Flask route calling the UN SDG API series ER_PTD_TERR with a 10s timeout
  • Aggregate raw series data into latest-per-country entries, converting year and value to numeric types
  • Sort countries by protected area coverage, return the top 10 as JSON, and handle empty data with 404 responses
  • Log success and error cases with structured logger metadata for this endpoint
eco_project/backend/app.py
Introduce a new UNEP data page with charts and link it from the main site navigation.
  • Add a navigation link from the Community section to unep.html in the main index page
  • Create unep.html with intro copy about UNEP and SDGs and two canvas elements for the indicators, loading Chart.js from a CDN and unep.js for behavior
  • Implement unep.js to fetch data from the new backend endpoints, handle basic error responses, and render bar charts via Chart.js with fixed 0–100 y-axis scales
  • Style the UNEP page with unep.css, including card-like sections, responsive canvases, and highlighted intro section styling
eco_project/backend/static/index.html
eco_project/backend/static/unep.html
eco_project/backend/static/unep.js
eco_project/backend/static/unep.css

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • The two UNEP backend endpoints contain nearly identical request/transform/sort logic; consider extracting a shared helper function that takes series code and logging metadata to reduce duplication and make future indicator additions easier.
  • In both UNEP endpoints, handle non-2xx responses explicitly (e.g., via response.raise_for_status() or checking response.ok) before calling response.json() so that upstream HTTP errors are surfaced more clearly and consistently.
  • On the frontend, the fetch helpers in unep.js assume response.json() will succeed; you may want to guard against non-JSON or error status responses (e.g., by checking response.ok and logging or showing a simple user-facing message) to make failures easier to debug.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The two UNEP backend endpoints contain nearly identical request/transform/sort logic; consider extracting a shared helper function that takes series code and logging metadata to reduce duplication and make future indicator additions easier.
- In both UNEP endpoints, handle non-2xx responses explicitly (e.g., via `response.raise_for_status()` or checking `response.ok`) before calling `response.json()` so that upstream HTTP errors are surfaced more clearly and consistently.
- On the frontend, the fetch helpers in `unep.js` assume `response.json()` will succeed; you may want to guard against non-JSON or error status responses (e.g., by checking `response.ok` and logging or showing a simple user-facing message) to make failures easier to debug.

## Individual Comments

### Comment 1
<location> `eco_project/backend/app.py:749-753` </location>
<code_context>
+                year = entry['timePeriodStart']
+                value = entry['value']
+
+                if value is not None and (country not in latest_data or year > latest_data[country]['year']):
+                    latest_data[country] = {
+                        'country': country,
+                        'year': int(year),
+                        'value': float(value)
+                    }
+
</code_context>

<issue_to_address>
**issue (bug_risk):** Comparison between `year` (string) and stored `year` (int) will raise a TypeError.

`year` comes directly from the API as a string, while `latest_data[country]['year']` is stored as `int(year)`. On subsequent iterations this makes `year > latest_data[country]['year']` a string-vs-int comparison in Python 3. Convert `year` once (e.g. `year_int = int(year)`) and use `year_int` both in the comparison and when storing it.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +749 to +753
if value is not None and (country not in latest_data or year > latest_data[country]['year']):
latest_data[country] = {
'country': country,
'year': int(year),
'value': float(value)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Comparison between year (string) and stored year (int) will raise a TypeError.

year comes directly from the API as a string, while latest_data[country]['year'] is stored as int(year). On subsequent iterations this makes year > latest_data[country]['year'] a string-vs-int comparison in Python 3. Convert year once (e.g. year_int = int(year)) and use year_int both in the comparison and when storing it.

@GYFX35 GYFX35 merged commit a43056e into feat/initial-project-structure Feb 7, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant