Skip to content

iqfareez/astros-api

Repository files navigation

Warning

Deprecation notice

This API server codebase is now abandoned. Please visit latest implementation at https://github.com/iqfareez/astros-api-v2


Python NodeJS GitHub Actions

astros-api

Fetch the data and host the JSON-Server website. This project contains two parts:

  • Python part: Fetches the latest astros data
  • Node JS part: Hosts the JSON-Server website

Get started

Get Azure key

image

We use the Bing Search API to get astronauts' profile images. Create a new Bing Resource instance. Take the primary and secondary keys and save them in the .env file (see .env.example for an example).

Get the latest astros data

Prerequisites: Node & Python 3.x

Install required packages:

pip install -r requirements.txt

Run the fetcher:

py fetcher.py

Start local server

npm install

Then

npm start

How does it work?

flowchart TD
    subgraph "External API"
    A(OpenNotifyAPI) & B(Bing API)
    end
    B <--> C
    A <--> C
    subgraph fetcher.py
    C[[Fetch latest astros data]] --> D[(db.json)] & E[(log.json)] --> F(Commit & push)
    end
    F -->|Railway build triggered| G[Deployed to Railway]
Loading

Fetch and deploy

db.json contains the actual astronauts' database. log.json stores the date & time of the fetcher run.

The fetcher.py script is scheduled to run automatically via a GitHub action. The frequency is defined in the fetcher.yml script.

Usage

Fetch db.json file from the GitHub:

curl https://raw.githubusercontent.com/iqfareez/astros-api/refs/heads/master/db.json

Basic example to retrieve the data using Dart:

import 'dart:convert';
import 'package:http/http.dart' as http;

void main() async {
  final response = await http.get(Uri.parse(
      'https://raw.githubusercontent.com/iqfareez/astros-api/refs/heads/master/db.json'));
  if (response.statusCode != 200) {
    throw Exception('Failed to load astros. StatusCode ${response.statusCode}');
  }

  final result = jsonDecode(response.body)["data"];
  final totalPeopleInSpace = result['number'];
  final peoples = result['people'];

  print('Total people in space is $totalPeopleInSpace:\n');

  for (final people in peoples) {
    print(people['name']);
  }
}

Honorable mentions

  1. http://open-notify.org/Open-Notify-API/People-In-Space/
  2. https://www.microsoft.com/en-us/bing/apis/bing-image-search-api
  3. Website template

About

An extension to the famous People In Space API by http://open-notify.org/Open-Notify-API/People-In-Space/

Topics

Resources

Stars

Watchers

Forks

Contributors 2

  •  
  •