Skip to content

Commit

Permalink
Implement HTML output and deployment to GitHub Pages
Browse files Browse the repository at this point in the history
* Add first version of HTML template

* feat: added html export

added html export based on jinja according to hte inputed template

* fix: imporved readme

* feat: documentation for workflow

* fix: fixed table header

Co-authored-by: Marián Hlaváč <[email protected]>
  • Loading branch information
safrataxyz and marianhlavac committed Aug 3, 2022
1 parent a855a4b commit 6c0c64e
Show file tree
Hide file tree
Showing 10 changed files with 432 additions and 65 deletions.
171 changes: 118 additions & 53 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,80 +7,145 @@ on:
branches: [master]

permissions:
contents: read
contents: write
pages: write
deployments: write
id-token: write

jobs:
convert_and_release:
name: Convert CSV to files
convert_to_json:
name: Convert CSV to JSON files
runs-on: ubuntu-latest
steps:
- name: checkout repo content
uses: actions/checkout@v2 # checkout the repository content to github runner.

- name: setup python
uses: actions/setup-python@v2
with:
python-version: "3.10"

- name: execute py script # run the run.py to get the latest data
run: |
python convertors/json_convertor.py
- name: Upload converted files # Upload 3 JSON files outputted from py script
uses: actions/upload-artifact@v1
with:
name: json
path: ./out

convert_to_html:
name: Convert CSV to HTML template
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: checkout repo content
uses: actions/checkout@v2 # checkout the repository content to github runner.

- name: setup python
uses: actions/setup-python@v2
with:
python-version: "3.10"

- name: Install Jinja2 # For putting data into HTML template
run: |
pip install Jinja2
- name: execute py script # run the run.py to get the latest data
run: |
python convertors/convertor.py
# - name: Get current date
# id: date
# run: echo "::set-output name=date::$(date +'%Y%m%d-%H%M')"
# - name: Release
# uses: actions/create-release@v1
# id: create_release
# with:
# draft: false
# prerelease: false
# release_name: ${{ steps.date.outputs.date }}
# tag_name: ${{ steps.date.outputs.date }}
# body: "Expanded drone manufacturer and drone models database"
# env:
# GITHUB_TOKEN: ${{ github.token }}

# - name: Upload manufacturers artifact
# uses: actions/upload-release-asset@v1
# env:
# GITHUB_TOKEN: ${{ github.token }}
# with:
# upload_url: ${{ steps.create_release.outputs.upload_url }}
# asset_path: ./out/manufacturers.json
# asset_name: manufacturers.json
# asset_content_type: application/json

# - name: Upload manufacturers with models artifacts
# uses: actions/upload-release-asset@v1
# env:
# GITHUB_TOKEN: ${{ github.token }}
# with:
# upload_url: ${{ steps.create_release.outputs.upload_url }}
# asset_path: ./out/manufacturersWithModels.json
# asset_name: manufacturersWithModels.json
# asset_content_type: application/json

# - name: Upload models artifacts
# uses: actions/upload-release-asset@v1
# env:
# GITHUB_TOKEN: ${{ github.token }}
# with:
# upload_url: ${{ steps.create_release.outputs.upload_url }}
# asset_path: ./out/models.json
# asset_name: models.json
# asset_content_type: application/json
python convertors/html_convertor.py
- name: Upload converted files # Upload html and CSS + fonts outputted from py script
uses: actions/upload-artifact@v1
with:
name: html
path: ./out

release:
name: Create a release
needs: [convert_to_html, convert_to_json]
runs-on: ubuntu-latest
steps:
- name: Download JSON artifact
uses: actions/download-artifact@v3
with:
name: json
path: ./json

- name: Get current date # Get formatted date for release tag creation
id: date
run: echo "::set-output name=date::$(date +'%Y%m%d-%H%M')"

- name: Release # Create a release
uses: actions/create-release@v1
id: create_release
with:
draft: false
prerelease: false
release_name: ${{ steps.date.outputs.date }}
tag_name: ${{ steps.date.outputs.date }}
env:
GITHUB_TOKEN: ${{ github.token }}

- name: Upload manufacturers artifact # Attach manufacturers JSON to release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ github.token }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./json/manufacturers.json
asset_name: manufacturers.json
asset_content_type: application/json

- name: Upload manufacturers with models artifacts # Attach manufacturers with models JSON to release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ github.token }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./json/manufacturersWithModels.json
asset_name: manufacturersWithModels.json
asset_content_type: application/json

- name: Upload models artifacts # Attach models JSON to release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ github.token }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./json/models.json
asset_name: models.json
asset_content_type: application/json

deploy:
name: Deploy to Github pages
needs: [convert_to_html, convert_to_json]
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Download JSON artifact # Download JSON out file
uses: actions/download-artifact@v3
with:
name: json
path: ./json
- name: Download HTML artifact # Download HTML out file
uses: actions/download-artifact@v3
with:
name: html
path: ./html
- name: Merge artifacts for upload # Merging the two artifacts into one, which is then uploaded to pages
run: |
mkdir out
cp -a ./json/. ./out/
cp -a ./html/. ./out/
- name: Upload converted files
uses: actions/[email protected]
with:
name: github-pages
path: ./out
- name: Deploy Github Pages
- name: Deploy Github Pages # Deploy to pages
uses: actions/deploy-pages@v1
id: deployment
with:
Expand Down
49 changes: 37 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,50 @@
# opendronelist
# OpenDroneList

Opendronelist is a public open-source community-driven list of drones and their common properties.
OpenDroneList is a public open-source community-driven list of drones and their common properties.

## What is **opendronelist** good for?
## What is **OpenDroneList** good for?

Thanks to various output formats, including the human-readable HTML table, or computer-readable CSV, JSONs and others, the list can be used for developing your own applications or to use for your data analysis or other projects.

We, [authors](https://dronetag.cz), use opendronelist in many systems and user interfaces requiring the same or similar data — for example when you pick pre-defined drone in our mobile app or when using [Dronald](https://dronald.cz), we always query the latest data from the opendronelist to show a list of known drones and their properties.

## Available properties

* Drone model/product name, vendor
* Drone weight
* Drone endurance
* Used for authoritative processes in U-space
* Year of manufacture (?)
* TODO
## Currently available properties

- **Manufacturer & Model Name**
- The commercial name of the drone
- **Class**
- UAV Class label designated for the drone (labels such as C0, C1, ...)
- **Weight**
- The nominal weight of the drone from the manufacturer specifications
- in grams
- **Max. takeoff weight**
- The maximum allowed takeoff weight of the drone
- Usually used to determine the drone's weight category
- in grams
- **Endurance**
- The nominal maximum flight time of the drone
- in minutes
- **Has Camera?**
- Determines if the drone is equipped with a camera
- **Is Toy?**
- Determines if the drone is classified as a toy
- Drones are regarded as a toy if the drone documentation allows the use of the drone for children below 14 years of age according to Directive 2009/48/ES

## Formats available

The list is avilable in CSV file which is then converted into three JSON files - found [here](https://github.com/dronetag/opendronelist/releases/latest)
The list is avilable in following output formats:

- [CSV Format](./list.csv)
- JSON Format
- Manufacturers
- Isolated array of unique manufacturers specified in the CSV
- Download [here](https://github.com/dronetag/opendronelist/releases/latest/download/manufacturers.json)
- Models
- An array of models, with data about the models - (manufacturer, name, weight, ...)
- Download [here](https://github.com/dronetag/opendronelist/releases/latest/download/models.json)
- Manufacturers with Models
- An array of unique manufacturers and all of their models which are specified in the CSV
- Download [here](https://github.com/dronetag/opendronelist/releases/latest/download/manufacturersWithModels.json)

## Guaranties & Liability

Expand Down
56 changes: 56 additions & 0 deletions convertors/html_convertor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import csv
import os
from jinja2 import Environment, PackageLoader
import shutil

env = Environment(loader=PackageLoader('html_convertor', 'templates'))

template = env.get_template("template.html.jinja")

dir_path = 'out'

os.makedirs(dir_path, exist_ok=True)
with open('list.csv') as csv_file:
# Read csv - maybe input as a arg
csv_reader = csv.reader(csv_file, delimiter=',')
line_count = 0 # For iterating through lines
manufacturers = dict() # Initialize manufacturers as a Dict
models = list() # Initialize models as a list
parameters = dict() # Initialize parameters as a dict

for row in csv_reader:
for param in row: # only first row with parameters is necessary
parameters[param] = row.index(param)
break

# Reset for second iteration
line_count = 0
csv_file.seek(0)

# Second iteration of CSV for two JSON
for row in csv_reader:
if line_count == 0:
line_count += 1
continue

manufacturer = row[parameters.get('manufacturer')]
name = row[parameters.get('name')]
uas_class = row[parameters.get('class')]
weight = row[parameters.get('weight')]
max_takeoff = row[parameters.get('max_takeoff')]
endurance = row[parameters.get('endurance')]
has_camera = row[parameters.get('has_camera')]
is_toy = row[parameters.get('is_toy')]

models.append({'manufacturer': manufacturer, 'name': name, 'uas_class': uas_class,
"weight": weight, 'max_takeoff': max_takeoff, 'endurance': endurance, 'has_camera': has_camera, 'is_toy': is_toy})

line_count += 1

with open(os.path.join(dir_path, 'index.html'), 'w') as outfile:
outfile.write(template.render(models=models))
try: # throws an error of file being in the folder, even in case of empty folder, nevertheless, the files are copied
shutil.copy('templates/styles.css', 'out/styles.css')
shutil.copytree('templates/fonts', 'out/fonts')
except:
pass
File renamed without changes.
Loading

0 comments on commit 6c0c64e

Please sign in to comment.