GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - luminoso/weather-collector: Python 'service' that pulls web API results, in this case weather from IPMA

This repository was archived by the owner on Oct 26, 2026. It is now read-only.
BranchesTags
Open more actions menu

Latest commit

 

History

43 Commits
43 Commits

Folders and files

NameName
Last commit message
Last commit date
doc
doc
 
 
outputs
outputs
 
 
sources
sources
 
 
utils
utils
 
 
.gitignore
.gitignore
 
 
Dockerfile
Dockerfile
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
config.yaml
config.yaml
 
 
docker-compose.yml
docker-compose.yml
 
 
requirements.txt
requirements.txt
 
 
weather-collector.py
weather-collector.py
 
 

Repository files navigation

IPMA weather-collector

'weather-collector' is a very simple API collector from various sources and sends the results to different outputs.

This collector exercised as pull service for IPMA (Instituto Português do Mar e da Atmosfera) public APIs, where each source is queried, processed, and flattened. It can be extended to other weather-sources or any other web API.

For each different API response change, the script tries to calculate the incremental differences and sends only incremental changes since the first run.

Main structure guideline:

  • Config file (sources and output initialization, pull time, etc)
  • Each source is a class that defines what web API to call and how to process it
  • Output definition: where to push the changes (e.g.: file system, kafka server, console, etc)
  • weather-collector.py: main loop

Basic architecture:

1. New source example

  1. Let's assume we want to collect IPMA available weather locations available at http://api.ipma.pt/open-data/distrits-islands.json

  2. Create a code snippet that extends GenericSource and implement the API peculiarities if any.

class ipma_globalIds(GenericSource):
    def __init__(self, enabled=True):
        super().__init__()
        self.url = 'http://api.ipma.pt/open-data/distrits-islands.json'

    def refresh_source(self):
        # clear latest result
        self.data = []

        if req := self.fetch_url(self.url):
            
            # globalIds API returns data within 'data' payload
            for data in req['data']:
                # flatten the metadata to the inner payload
                self.append_ipma_metadata(req, data)
                self.data.append(data)
  1. Add new source configuration to config.yaml
sources:
  ipma:
    ipma_globalIds:
  1. Define an effortless output, for example, write to a file:
def write_to_file(source: GenericSource):

    filename = f'{source.name}.txt'

    logging.debug(f'Writing {len(source)} messages to file {filename}')

    for msg in source:
        with open(filename, "a") as myfile:
            myfile.write(str(msg))

        with open(filename, "a") as myfile:
            myfile.write('\n')
  1. Build and run Dockerfile
$ docker build -t foo . && docker run -it foo

2. I just want to see it working

By default, the service pulls everything and writes to files

  1. Build and the docker file
$ docker build -t foo . && docker run -it foo

3. Included IPMA data sources

This repo includes two types of (weather) API sources.

Official

Official sources are APIs available at the IPMA API webpage. It is expected that they're somewhat reliable and its structure not to change.

id Description
ipma_globalIds Lookup table containing available weather locations
ipma_5days_local 5 day forecast for each globalId
ipma_3days_day 3 day forecast for each globalId
ipma_seismicity Detected seismicity
ipma_weatherIds Lookup table for weather forecast classes
ipma_windClasses Lookup table for weather wind classes

Unofficial

Unofficial sources are sources found when parsing IPMA website. They may change anytime, and it isn't expected any reliability.

id Description
ipma_dea Descargas elétricas atmosféricas [DEA's]
ipma_hourly Hourly predictions for available globalIds
ipma_sto_hourly Hourly report of last 24 hours for each weather station
ipma_sto_daily Daily report of last 24 hours for each weather station
ipma_stations Available weather stations list
ipma_warnings Weather warnings
ipma_locations Locations list
ipma_districts Districts list
ipma_wwis World Weather Information Service (WWIS) report

4. License

MIT

About

Python 'service' that pulls web API results, in this case weather from IPMA

Topics

ipmaweather-data

Resources

Readme
MIT license
Activity

Stars

2 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.