Skip to content

Commit

Permalink
Setting up the research and news repository with schema and workflows…
Browse files Browse the repository at this point in the history
… for valdiating articles (#1)

* Notebook for validating articles with its json schema

* Schema for a sample article

* Sample article for reference

* Yaml file for validating dispatching articles
  • Loading branch information
KasukabeDefenceForce authored Mar 27, 2024
1 parent 8544e66 commit 3c67c24
Show file tree
Hide file tree
Showing 4 changed files with 295 additions and 0 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Update Group Website

on:
workflow_dispatch:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
Validating_Article:
name: Validate Article
runs-on: ubuntu-latest
steps:
- name: Clone Tardis group data
uses: actions/checkout@v4
with:
repository: tardis-sn/tardis-org-data
path: tardis-org-data
token: ${{ secrets.SITE_TARDIS }}

- name: Clone Research and News Repository
uses: actions/checkout@v4
with:
repository: research_news
path: research_news
token: ${{ secrets.SITE_TARDIS }}

- name: Set up Python3
uses: actions/setup-python@v4
with:
python-version: "3.12"

- name: Update pip and install Jupyter and Pandas
run: |
pip install --upgrade pip jupyter pandas
- name: Run Validator Notebook
run: |
jupyter nbconvert --to python validate.ipynb
python3 validate.py
working-directory: tardis-sn/research_news

- name: Dispatch to Tardis-org-data
run: |
curl -X POST \
-H "Authorization: Bearer ${{ secrets.DISPATCH_VAR }}" \
-H "Accept: application/vnd.github+json" \
-H "Content-Type: application/json" \
-d '{ "event_type": "repo-push" }' \
https://api.github.com/repos/tardis-sn/tardis-org-data/dispatches
32 changes: 32 additions & 0 deletions sample/sample_article.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"title": "title of your article",
"author_id": "author id",
"article_id": "first two or three words of the title separated by underscores and author's first name in end for eg: first_second_third_author",
"display": true,
"date": "MM-DD-YYYY",
"category": "News or research",
"tags": [
"tag1",
"tag2"
],
"platforms": [
"this determines the websites on which you want to display your article",
"Available options are",
"tardis-for tardis website",
"kg-kerzendorf lab",
"dti - deepthought initiative"
],
"short_description": "Summary of your content",
"long_description": "",
"cover_image": "images/**name_of_your_phto_including_extension**",
"content": {
"para1": "content",
"para2": "content"
},
"people_involved_ids": [
"id_of_collaborator1",
"id_of_collaborator2 etc."
],
"links": {},
"twitter": "None"
}
85 changes: 85 additions & 0 deletions schema/article.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"title": {
"type": "string"
},
"short_description": {
"type": "string"
},
"category": {
"type": "string"
},
"tags": {
"type": "array",
"additionalProperties": {
"type": "string"
}
},
"platforms": {
"type": "array",
"additionalProperties": {
"type": "string"
}
},
"long_description": {
"type": "string"
},
"date": {
"type": "string",
"pattern": "^(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])-(\\d{4})$"
},
"cover_image": {
"type": "string"
},
"content": {
"type": "object",
"additionalProperties": {
"type": "string"
},
"propertyNames": {
"pattern": "^(para|img)"
}
},
"people_involved_ids": {
"type": "array",
"items": {
"type": "string"
}
},
"links": {
"type": "object",
"items": {
"type": "string"
}
},
"author_id": {
"type": "string"
},
"article_id": {
"type": "string"
},
"twitter": {
"type": "string"
}
},
"required": [
"title",
"author_id",
"article_id",
"display",
"date",
"category",
"tags",
"platforms",
"short_description",
"long_description",
"cover_image",
"content",
"people_involved_ids",
"links",
"twitter"
],
"additionalProperties": true
}
125 changes: 125 additions & 0 deletions validate.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Validating articles"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Managing Imports"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"import json\n",
"import jsonschema\n",
"from pathlib import Path"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Defining Constants"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"# Defining Colors\n",
"RED = \"\\033[1;31m\"\n",
"YELLOW = \"\\033[0;33m\"\n",
"NOCOLOR = \"\\033[0m\"\n",
"GREEN = \"\\033[0;32m\"\n",
"CYAN = \"\\033[1;36m\"\n",
"\n",
"ARTICLE_SCHEMA = Path(\"schema/article.json\")\n",
"ALL_ARTICLES_DIR = Path(\"articles\")\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Code to validate articles"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[0;32mVALIDATION SUCCESSFUL\u001b[0m for research.\n"
]
}
],
"source": [
"research_validation_failed = False\n",
"for single_article_file in ALL_ARTICLES_DIR.glob(\"*.json\"):\n",
" with open(single_article_file) as fname_article:\n",
" content = json.load(fname_article)\n",
" try:\n",
" with open(ARTICLE_SCHEMA) as schema_f:\n",
" schema_data = json.load(schema_f)\n",
" jsonschema.validate(content, schema_data)\n",
" except (json.JSONDecodeError) as e:\n",
" research_validation_failed = True\n",
" print(\n",
" f\"Please recheck JSON file: {single_article_file} - Error: {str(e)}\"\n",
" )\n",
" except (jsonschema.ValidationError) as e:\n",
" research_validation_failed = True\n",
" print(\n",
" f\"Please recheck JSON file: {single_article_file} - Error: {str(e)}\"\n",
" )\n",
"\n",
"if research_validation_failed:\n",
" print(f\"{RED}VALIDATION FAILED\")\n",
"else:\n",
" print(f\"{GREEN}VALIDATION SUCCESSFUL{NOCOLOR} for research.\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": []
}
],
"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.11.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

0 comments on commit 3c67c24

Please sign in to comment.