Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gør APIerne tilgængeligt i et API #95

Open
NoahBohme opened this issue May 1, 2023 · 10 comments
Open

Gør APIerne tilgængeligt i et API #95

NoahBohme opened this issue May 1, 2023 · 10 comments
Assignees
Labels

Comments

@NoahBohme
Copy link
Collaborator

Bare for at være super meta-meta bør vi lave et API-Danmark API.

@mauran
Copy link
Owner

mauran commented May 3, 2023

Haha. Det kunne være sjovt. Markdown dokumentet kan snildt parses, men jeg tror sgu jeg må overlade den opgave til en anden 😉

@Tanddant
Copy link
Collaborator

Bør APIet så teknisk set også blive en del af APIet selv? - APIception? 🤯

@LasseRafn
Copy link
Contributor

Sounds like a job for ChatGPT! -- fed ide, men ja er enig det er nok ikke arbejdet værd at bygge 😄

CleanShot 2023-06-09 at 15 12 19

Resultat:

function parseMarkdownTables($content)
{
	$lines = explode("\n", $content);
	$tables = [];
	$currentTable = null;

	foreach ($lines as $line) {
		if (preg_match('/^##\s+(.*)$/', $line, $matches)) {
			$currentTable = $matches[1];
		} elseif (preg_match('/^\|(.*)\|$/', $line, $matches)) {
			if ($currentTable !== null) {
				$tableRow = explode('|', trim($matches[1]));
				$tableRow = array_map('trim', $tableRow);

				// Skip the second row (separator row)
				if (!empty($tables[$currentTable])) {
					$tables[$currentTable][] = array_combine($tables[$currentTable][0], $tableRow);
				} else {
					$tables[$currentTable][] = $tableRow;
				}
			}
		}
	}

	return array_map(function($entry) {
		return array_slice($entry, 2);
	}, $tables);
}

JSON encoded output:

{"Betalingsl\u00f8sninger":[{"API":"[Clearhaus](http:\/\/docs.gateway.clearhaus.com\/)","Type":"JSON","Tilg\u00e6ngelighed":"Private"},{"API":"[ePay](https:\/\/epay.bambora.com\/da\/betalingswebservice)","Type":"JSON","Tilg\u00e6ngelighed":"Private"},{"API":"[MobilePay](https:\/\/developer.mobilepay.dk)","Type":"JSON","Tilg\u00e6ngelighed":"Public"},{"API":"[Paylike](https:\/\/github.com\/paylike\/api-docs)","Type":"JSON","Tilg\u00e6ngelighed":"Private"},{"API":"[QuickPay](https:\/\/learn.quickpay.net\/tech-talk\/api\/#introduction)","Type":"JSON","Tilg\u00e6ngelighed":"Private"},{"API":"[OnPay](https:\/\/manage.onpay.io\/docs\/)","Type":"JSON","Tilg\u00e6ngelighed":"Private"},{"API":"[DIBS](http:\/\/tech.dibspayment.com\/D2\/API)","Type":"JSON","Tilg\u00e6ngelighed":"Private"},{"API":"[Reepay](https:\/\/docs.reepay.com\/api\/)","Type":"JSON","Tilg\u00e6ngelighed":"Private"},{"API":"[AltaPay](https:\/\/altapay.com\/technology\/integration-manuals#download)","Type":"JSON","Tilg\u00e6ngelighed":"Private"},{"API":"[Scanpay](https:\/\/docs.scanpay.dk)","Type":"JSON","Tilg\u00e6ngelighed":"Private"},{"API":"[FarPay](https:\/\/www.farpay.io\/api\/)","Type":"JSON","Tilg\u00e6ngelighed":"Private"},{"API":"[Nets Netaxept](https:\/\/developers.nets.eu\/netaxept\/en-EU\/docs\/)","Type":"XML","Tilg\u00e6ngelighed":"Private"},{"API":"[Pensopay](https:\/\/docs.pensopay.com\/reference\/getting-started-with-your-api)","Type":"JSON","Tilg\u00e6ngelighed":"Private"}],"COVID-19":[{"API":"[Statens Serum Institut](https:\/\/covid19.ssi.dk\/overvagningsdata\/ugentlige-opgorelser-med-overvaagningsdata)","Type":"ZIP\/CSV","Tilg\u00e6ngelighed":"Public"}],"Detail & webshops":[{"API":"[Coop](https:\/\/developerdemo.cl.coop.dk\/docs\/services)","Type":"JSON","Tilg\u00e6ngelighed":"Private"},{"API":"[Salling Group](https:\/\/developer.sallinggroup.com\/api-reference)","Type":"JSON","Tilg\u00e6ngelighed":"Private"}],"Historie":[{"API":"[Dansk Kultur Arv](http:\/\/www.danskkulturarv.dk\/api\/)","Type":"XML","Tilg\u00e6ngelighed":"Private"},{"API":"[Historisk Atlas](http:\/\/api.historiskatlas.dk\/)","Type":"JSON","Tilg\u00e6ngelighed":"Public"}],"Hosting":[{"API":"[HostedShop](https:\/\/help.hostedshop.dk\/integration-via-api) (Wannafind, Curanet & ScanNet)","Type":"SOAP","Tilg\u00e6ngelighed":"Private"},{"API":"[DanDomain Webshop](https:\/\/shoppartner.dandomain.dk\/dokumentation\/api-documentation\/)","Type":"JSON","Tilg\u00e6ngelighed":"Private"},{"API":"[Simply.com](https:\/\/www.simply.com\/dk\/docs\/api\/)","Type":"JSON","Tilg\u00e6ngelighed":"Private"},{"API":"[Curanet (DNS)](https:\/\/api.curanet.dk\/dns\/swagger\/index.html)","Type":"JSON","Tilg\u00e6ngelighed":"Private"},{"API":"[Curanet (Mail)](https:\/\/api.curanet.dk\/mail\/swagger\/index.html)","Type":"JSON","Tilg\u00e6ngelighed":"Private"}],"Medier":[{"API":"[DR](http:\/\/www.dr.dk\/mu-online\/)","Type":"JSON","Tilg\u00e6ngelighed":"Private"}],"Vejr":[{"API":"[DMI Vejr](https:\/\/confluence.govcloud.dk\/display\/FDAPI) - Vejr-, klima- og observationsdata","Type":"GeoJSON\/JSON","Tilg\u00e6ngelighed":"Public"},{"API":"[Vejret i din by](http:\/\/vejr.eu\/pages\/api-documentation)","Type":"JSON","Tilg\u00e6ngelighed":"Public"}],"Milj\u00f8data":[{"API":"[Ressource](https:\/\/miljoeportal.dk\/it-systemer-udvikling-og-webservices\/udvikler\/)","Type":"Webservice","Tilg\u00e6ngelighed":"Public"}],"Offentlige":[{"API":"[Beredskabsstyrelsen](http:\/\/www.odin.dk\/RSS\/) - Seneste beredskabsinformation","Type":"RSS","Tilg\u00e6ngelighed":"Public"},{"API":"[Danmarks Adressers Web API - DAWA](https:\/\/dawa.aws.dk\/)","Type":"JSON","Tilg\u00e6ngelighed":"Public"},{"API":"[Datafordeler.dk - Din indgang til offentlige grunddata fra danmarks myndigheder](https:\/\/datafordeler.dk)","Type":"JSON","Tilg\u00e6ngelighed":"Public"},{"API":"[Domsdatabasen](https:\/\/domsdatabasen.dk\/sporgsmal-og-svar\/api-adgang-til-domsdatabasen\/) - fortrinsvis civile sager. Deruover historiske civile sager og straffesager","Type":"REST API","Tilg\u00e6ngelighed":"Private"},{"API":"[Folketinget](https:\/\/www.ft.dk\/da\/dokumenter\/aabne_data)","Type":"JSON\/XML","Tilg\u00e6ngelighed":"Public"},{"API":"[Frekvenser](http:\/\/frekvens.erhvervsstyrelsen.dk\/OffentligtAPI.pdf)","Type":"JSON","Tilg\u00e6ngelighed":"Public"},{"API":"[Geografiske fagdata i GeoDanmark (GeoFA)](https:\/\/www.geodanmark.dk\/home\/vejledninger\/geofa\/hent-geofa\/)","Type":"GeoJSON\/GML\/WMS\/WFS","Tilg\u00e6ngelighed":"Public"},{"API":"[HvemStemmerHvad](http:\/\/www.hvemstemmerhvad.dk\/api\/api.php) - information om politikere","Type":"XML","Tilg\u00e6ngelighed":"Public"},{"API":"[Kommunernes og Regionernes L\u00f8ndatakontor](https:\/\/krl.dk\/#\/apibeta\/description)","Type":"JSON\/CSV","Tilg\u00e6ngelighed":"Public"},{"API":"[Mastedatabasen](https:\/\/mastedatabasen.dk\/Viskort\/ContentPages\/DataFraDatabasen.aspx?callingapp=mastedb#webapi)","Type":"JSON\/XML\/KML","Tilg\u00e6ngelighed":"Public"},{"API":"[Min Uddannelse](https:\/\/api.minuddannelse.net\/metadata)","Type":"JSON\/CSV","Tilg\u00e6ngelighed":"Private"},{"API":"**[OpenData.dk](https:\/\/opendata.dk)** - f\u00e6llesoffentlig forening for udbredelse af \u00e5bne data","Type":"Forskelligt","Tilg\u00e6ngelighed":"Public"},{"API":"[UNI-LOGIN \/ Grundskolerne](https:\/\/viden.stil.dk\/display\/INFRA2\/Unilogin+SkoleGrunddata+BPI-webservices)","Type":"JSON\/XML","Tilg\u00e6ngelighed":"Private"},{"API":"[Retsinformation](https:\/\/api.retsinformation.dk\/index.html)","Type":"JSON","Tilg\u00e6ngelighed":"Public"},{"API":"[Statstidende](https:\/\/api.statstidende.dk\/docs\/index.html)","Type":"JSON","Tilg\u00e6ngelighed":"Private"},{"API":"[Skattestyrelsen, API-l\u00f8sning til momsindberetning](https:\/\/skat.dk\/data.aspx?oid=2291926)","Type":"SOAP","Tilg\u00e6ngelighed":"Private"},{"API":"API","Type":"Type","Tilg\u00e6ngelighed":"Tilg\u00e6ngelighed"},{"API":"-----------------------------------------------------","Type":":-----------:","Tilg\u00e6ngelighed":":--------------:"},{"API":"[K\u00f8benhavns kommune data bank](http:\/\/data.kk.dk\/)","Type":"Forskelligt","Tilg\u00e6ngelighed":"Public"},{"API":"[K\u00f8benhavns solutionlab](http:\/\/portal.opendata.dk)","Type":"Forskelligt","Tilg\u00e6ngelighed":"Public"},{"API":"[\u00c5bne data fra Aarhus kommune](https:\/\/www.odaa.dk)","Type":"Forskelligt","Tilg\u00e6ngelighed":"Public"}],"Pakker & logistisk":[{"API":"[Bring Developer](http:\/\/developer.bring.com)","Type":"JSON\/XML\/SOAP","Tilg\u00e6ngelighed":"Public"},{"API":"[CoolRunner](https:\/\/docs.coolrunner.dk)","Type":"JSON","Tilg\u00e6ngelighed":"Private"},{"API":"[GLS Pakkeshops](http:\/\/www.gls.dk\/webservices_v2\/wsPakkeshop.asmx?WSD)","Type":"SOAP","Tilg\u00e6ngelighed":"Public"},{"API":"[GLS Parcel Processing](http:\/\/api.gls.dk\/ws\/)","Type":"JSON\/XML","Tilg\u00e6ngelighed":"Private"},{"API":"[Shipmondo](https:\/\/app.shipmondo.com\/api\/public\/v3\/specification)","Type":"JSON","Tilg\u00e6ngelighed":"Private"},{"API":"[PostNord Developer](https:\/\/developer.postnord.com)","Type":"JSON","Tilg\u00e6ngelighed":"Private"},{"API":"[UPS](https:\/\/www.ups.com\/upsdeveloperkit?loc=da_DK)","Type":"JSON\/XML\/Webservice","Tilg\u00e6ngelighed":"Private"},{"API":"[Unifaun](https:\/\/www.unifaunonline.se\/rs-docs\/)","Type":"JSON","Tilg\u00e6ngelighed":"Private"},{"API":"[Webshipr](https:\/\/webshipr.docs.apiary.io)","Type":"JSON","Tilg\u00e6ngelighed":"Private"},{"API":"[Lagersystem.dk](https:\/\/api.lagersystem.dk)","Type":"JSON","Tilg\u00e6ngelighed":"Private"}],"Regnskabsprogrammer":[{"API":"[Billy](https:\/\/www.billy.dk\/api)","Type":"JSON","Tilg\u00e6ngelighed":"Private"},{"API":"[Dinero](https:\/\/api.dinero.dk\/docs)","Type":"JSON","Tilg\u00e6ngelighed":"Private"},{"API":"[e-conomic](https:\/\/restdocs.e-conomic.com)","Type":"JSON","Tilg\u00e6ngelighed":"Private"},{"API":"[DynAccount](https:\/\/dynaccount.dk\/funktioner\/api-integration\/)","Type":"JSON","Tilg\u00e6ngelighed":"Private"},{"API":"[Uniconta](http:\/\/www.uniconta.com\/da\/uniconta-api\/)","Type":".NET","Tilg\u00e6ngelighed":"Private"},{"API":"[Visma](https:\/\/developer.vismaonline.com\/)","Type":"JSON","Tilg\u00e6ngelighed":"Private"}],"L\u00f8nsystemer":[{"API":"[Zenegy](https:\/\/developers.zenegy.com\/)","Type":"JSON","Tilg\u00e6ngelighed":"Private"},{"API":"[Salary](https:\/\/api.salary.dk\/docs)","Type":"JSON","Tilg\u00e6ngelighed":"Private"},{"API":"[DataL\u00f8n](https:\/\/dataloen-api.zendesk.com\/hc\/da)","Type":"JSON","Tilg\u00e6ngelighed":"Private"}],"Reklamer":[{"API":"[eTilbudsavis](https:\/\/etilbudsavis.dk\/developers)","Type":"JSON","Tilg\u00e6ngelighed":"Private"}],"SMS Gateways":[{"API":"[Txty.dk](http:\/\/api.txty.dk\/4\/)","Type":"JSON","Tilg\u00e6ngelighed":"Private"},{"API":"[SMS.dk.dk](https:\/\/docs.sms.dk\/)","Type":"JSON","Tilg\u00e6ngelighed":"Private"},{"API":"[SMS1919.dk](http:\/\/www.sms1919.dk\/api\/)","Type":"XML","Tilg\u00e6ngelighed":"Private"},{"API":"[GatewayAPI.com](https:\/\/gatewayapi.com\/docs\/)","Type":"JSON\/SOAP","Tilg\u00e6ngelighed":"Private"},{"API":"[CPSMS.dk](https:\/\/api.cpsms.dk\/documentation\/)","Type":"JSON","Tilg\u00e6ngelighed":"Private"}],"E-mail marketing":[{"API":"[Heyloyalty](https:\/\/support.heyloyalty.com\/hc\/en-us\/articles\/115001593169-3-8-API)","Type":"JSON","Tilg\u00e6ngelighed":"Private"},{"API":"[Ubivox](https:\/\/support.ubivox.dk\/artikler\/introduktion-til-integration-i-ubivox\/)","Type":"Forskellige","Tilg\u00e6ngelighed":"Private"},{"API":"[eMailPlatform](http:\/\/mailmailmail.net\/xmlguide\/)","Type":"XML","Tilg\u00e6ngelighed":"Private"}],"Statistisk":[{"API":"[Danmarks Statistik](https:\/\/www.dst.dk\/da\/Statistik\/brug-statistikken\/muligheder-i-statistikbanken\/api)","Type":"JSON\/XML","Tilg\u00e6ngelighed":"Public"},{"API":"[B\u00f8rne- og Undervisningsministeriet](https:\/\/api.uddannelsesstatistik.dk\/)","Type":"JSON","Tilg\u00e6ngelighed":"Private"}],"Telefoni":[{"API":"[Flexfone](https:\/\/cdn.rawgit.com\/mauran\/API-Danmark\/e35d562\/assets\/flexfone.pdf)","Type":"JSON\/XML","Tilg\u00e6ngelighed":"Private"},{"API":"[Relatel](https:\/\/dev.relatel.dk\/api-v2\/)","Type":"JSON","Tilg\u00e6ngelighed":"Private"},{"API":"[ipnordic](https:\/\/apidocs.ipnordic.dk\/)","Type":"JSON","Tilg\u00e6ngelighed":"Private"}],"Transport":[{"API":"[DSB feeds](https:\/\/www.dsb.dk\/dsb-labs\/feeds)","Type":"RSS","Tilg\u00e6ngelighed":"Public"},{"API":"[Rejseplanen Labs](https:\/\/help.rejseplanen.dk\/hc\/da\/categories\/201728005)","Type":"JSON\/XML","Tilg\u00e6ngelighed":"Private"},{"API":"[Synsbasen API](https:\/\/api.synsbasen.dk)","Type":"JSON","Tilg\u00e6ngelighed":"Public"}],"Virksomhedsdata":[{"API":"[CVRAPI](http:\/\/cvrapi.dk)","Type":"JSON","Tilg\u00e6ngelighed":"Public"},{"API":"[Digitale regnskaber](https:\/\/data.virk.dk\/datakatalog\/erhvervsstyrelsen\/system-til-system-adgang-til-regnskabsdata)","Type":"JSON","Tilg\u00e6ngelighed":"Public"},{"API":"[CVR-data (Erhvervsstyrelsen)](https:\/\/data.virk.dk\/datakatalog\/erhvervsstyrelsen\/system-til-system-adgang-til-cvr-data).","Type":"JSON","Tilg\u00e6ngelighed":"Public"},{"API":"[eniro](https:\/\/api.eniro.com)","Type":"JSON","Tilg\u00e6ngelighed":"Private"},{"API":"[EAN API](https:\/\/eanapi.dk\/)","Type":"JSON","Tilg\u00e6ngelighed":"Private"},{"API":"[cvr.dev](https:\/\/cvr.dev)","Type":"JSON","Tilg\u00e6ngelighed":"Public"},{"API":"[APICVR (Public Beta)](https:\/\/apicvr.dk)","Type":"JSON","Tilg\u00e6ngelighed":"Public"}],"POS":[{"API":"[Customers 1st](https:\/\/api-docs.c1st.com).","Type":"JSON","Tilg\u00e6ngelighed":"Private"},{"API":"[OnlinePOS](https:\/\/speca.io\/SimonOnlinePOS\/external-api-v2?key=41502b8375f30e56b210877ef797b7e4)","Type":"JSON","Tilg\u00e6ngelighed":"Private"}],"Diverse":[{"API":"[Berlingske Meningsm\u00e5lninger](http:\/\/www.b.dk\/upload\/webred\/bmsandbox\/opinion_poll\/2015\/pollofpolls.xml) (fra 2015)","Type":"SOAP","Tilg\u00e6ngelighed":"Public"},{"API":"[Circle K](https:\/\/www.circlek.dk\/priser)","Type":"CSV","Tilg\u00e6ngelighed":"Public"},{"API":"[Det Danske Filminstitut](https:\/\/www.dfi.dk\/viden-om-film\/filmdatabasen\/abne-data)","Type":"XML","Tilg\u00e6ngelighed":"Public"},{"API":"[KortereLink](https:\/\/korterelink.dk\/api)","Type":"JSON","Tilg\u00e6ngelighed":"Public"},{"API":"[MadOpskrifter.nu](http:\/\/start.madopskrifter.nu\/MadopskrifternuAPI.aspx)","Type":"JSON","Tilg\u00e6ngelighed":"Public"},{"API":"[Trustpilot](https:\/\/developers.trustpilot.com\/)","Type":"JSON","Tilg\u00e6ngelighed":"Private"},{"API":"[TimeLog](http:\/\/api.timelog.com\/)","Type":"XML","Tilg\u00e6ngelighed":"Public"},{"API":"[Ordrestyring.dk](https:\/\/graphql.ordrestyring.dk\/docs)","Type":"JSON","Tilg\u00e6ngelighed":"Private"},{"API":"[eloverblik.dk](https:\/\/api.eloverblik.dk\/CustomerApi\/swagger\/index.html)","Type":"JSON","Tilg\u00e6ngelighed":"Private"},{"API":"[Energi Data Service](https:\/\/www.energidataservice.dk\/datasets)","Type":"JSON","Tilg\u00e6ngelighed":"Public"},{"API":"[SallingGroup (helligdage m.m)](https:\/\/developer.sallinggroup.com\/api-reference#apis-holidays)","Type":"JSON","Tilg\u00e6ngelighed":"Public"},{"API":"[Statens Museum for Kunst](https:\/\/www.smk.dk\/article\/smk-api\/)","Type":"JSON","Tilg\u00e6ngelighed":"Public"},{"API":"[GuideDenmark](https:\/\/api.guidedanmark.org\/Help)","Type":"JSON","Tilg\u00e6ngelighed":"Private"},{"API":"[Previsto](https:\/\/docs.previsto.com\/help\/api\/introduction-to-api)","Type":"JSON","Tilg\u00e6ngelighed":"Private"},{"API":"[MotorAPI](https:\/\/motorapi.dk\/)","Type":"JSON","Tilg\u00e6ngelighed":"Public"},{"API":"[Pollental](https:\/\/www.astma-allergi.dk\/pollenservices\/pollenfeed\/)","Type":"JSON","Tilg\u00e6ngelighed":"Private"},{"API":"[Penneo](https:\/\/penneo.readme.io\/)","Type":"JSON","Tilg\u00e6ngelighed":"Private"},{"API":"[GetAccept](https:\/\/app.getaccept.com\/api\/)","Type":"JSON","Tilg\u00e6ngelighed":"Private"}],"Finans":[{"API":"[Saxobank OpenAPI](https:\/\/www.developer.saxo\/openapi\/learn)","Type":"JSON","Tilg\u00e6ngelighed":"Private"},{"API":"[Nationalbankens valutakurser](https:\/\/www.nationalbanken.dk\/valutakurser)","Type":"XML","Tilg\u00e6ngelighed":"Public"},{"API":"[Nordnet API](https:\/\/www.nordnet.dk\/externalapi\/docs\/api)","Type":"JSON","Tilg\u00e6ngelighed":"Private"},{"API":"[Nordigen PSD2 adgang til bank konti](https:\/\/nordigen.com\/en\/account_information_documenation\/api-documention\/overview\/)","Type":"JSON","Tilg\u00e6ngelighed":"Public"}]}

@NoahBohme
Copy link
Collaborator Author

NoahBohme commented Jun 9, 2023

@LasseRafn jeg har prøvet ChatGPT, men synes at rende ind i samme issue hver gang. Den kan ikke rigtig parse det rigtigt og får en masse gris med - Hvis nogle er bedre til PHP og Regex end ChatGPT og jeg (det må der være), så giv gerne jeres besyv.

ChatGPTs kode:

<?php

function parseMarkdownTables($content)
{
    $lines = explode("\n", $content);
    $tables = [];
    $currentTable = null;

    foreach ($lines as $line) {
        if (preg_match('/^##\s+(.*)$/', $line, $matches)) {
            $currentTable = $matches[1];
        } elseif (preg_match('/^\|(.*)\|$/', $line, $matches)) {
            if ($currentTable !== null) {
                $tableRow = explode('|', trim($matches[1]));
                $tableRow = array_map('trim', $tableRow);

                // Skip the second row (separator row)
                if (!empty($tables[$currentTable])) {
                    $tables[$currentTable][] = array_combine($tables[$currentTable][0], $tableRow);
                } else {
                    $tables[$currentTable][] = $tableRow;
                }
            }
        }
    }

    return $tables;
}

// Read the content of README.md
$content = file_get_contents('README.md');

// Function to convert parsed tables to JSON
function convertToJSON($tables)
{
    $result = [];

    foreach ($tables as $table => $rows) {
        foreach ($rows as $row) {
            $name = preg_replace('/\[([^\]]+)\]/', '$1', $row['API']);
            $name = trim(preg_replace('/\(.*?\)/', '', $name));
            $endpoint = trim(preg_replace('/\[.*?\]/', '', $row['API']));
            $type = $row['Type'];
            $availability = $row['Tilgængelighed'];

            $result[$table][] = [
                "name" => $name,
                "endpoint" => $endpoint,
                "type" => $type,
                "availability" => $availability
            ];
        }
    }

    return $result;
}

// Parse markdown tables
$tables = parseMarkdownTables($content);

// Convert tables to JSON
$jsonData = convertToJSON($tables);

// Convert JSON data to string
$jsonString = json_encode($jsonData, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);

// Save JSON data to info.json file
file_put_contents('info.json', $jsonString);

// Print success message
echo "JSON data saved to info.json file." . PHP_EOL;

Output:
billede

@hojlund123
Copy link

api.json

@mauran
Copy link
Owner

mauran commented May 30, 2024

@hojlund123 Så mangler vi bare et script der kan parse README's og lave det output, så er vi der 😄

@hojlund123
Copy link

@hojlund123 Så mangler vi bare et script der kan parse README's og lave det output, så er vi der 😄

import json
import re

def extract_information():
    return {
        "Information": {
            "Tilgængelighed": {
                "Public": "Det er gratis at bruge API'et, også selvom det kræver login etc.",
                "Private": "Du skal have en 'relation' til firmaet der udstiller API'et, betalt eller ej."
            }
        }
    }

def parse_table_lines(table_lines):
    headers = [header.strip() for header in table_lines[0].split('|')[1:-1]]
    api_list = []

    for row in table_lines[2:]:
        columns = [col.strip() for col in row.split('|')[1:-1]]
        api_info = dict(zip(headers, columns))
        
        name_match = re.match(r'\[(.*?)\]\((.*?)\)', api_info['API'])
        if name_match:
            api_info['name'] = name_match.group(1)
            api_info['url'] = name_match.group(2)
        
        api_info['type'] = api_info.pop('Type')
        api_info['availability'] = api_info.pop('Tilgængelighed')
        del api_info['API']
        
        api_list.append(api_info)
    
    return api_list

def parse_readme_content(content):
    api_data = extract_information()
    api_data["APIs"] = {}

    categories = re.split(r'##\s+', content)
    exclude_categories = {"Information", "Tilgængelighed", "Public", "Private"}
    
    for category in categories[1:]:
        category_lines = category.splitlines()
        category_name = category_lines[0].strip()
        if category_name in exclude_categories:
            continue
        
        table_lines = [line for line in category_lines[1:] if line.startswith('|')]
        if table_lines:
            api_list = parse_table_lines(table_lines)
            api_data["APIs"][category_name] = api_list

    return api_data

def main():
    file_path = 'README.md'
    
    with open(file_path, 'r', encoding='utf-8') as file:
        content = file.read()

    api_json = parse_readme_content(content)
    
    output_path = 'api.json'
    with open(output_path, 'w', encoding='utf-8') as json_file:
        json.dump(api_json, json_file, ensure_ascii=False, indent=4)
        
    print("API data has been converted to JSON and saved as 'api.json'.")

if __name__ == "__main__":
    main()

@boserup
Copy link
Collaborator

boserup commented May 30, 2024

@hojlund123 Hvis du er rigtig god, så laver du en Github Action ;)

@hojlund123
Copy link

hojlund123 commented May 30, 2024

@hojlund123 Hvis du er rigtig god, så laver du en Github Action ;)

name: Convert README to JSON

on:
  push:
    paths:
      - 'README.md'
  workflow_dispatch:

jobs:
  convert:
    runs-on: ubuntu-latest

    steps:
    - name: Checkout repository
      uses: actions/checkout@v3

    - name: Set up Python
      uses: actions/setup-python@v4
      with:
        python-version: '3.11'

    - name: Run parser
      run: |
        import json
        import re

        def extract_information():
            return {
                "Information": {
                    "Tilgængelighed": {
                        "Public": "Det er gratis at bruge API'et, også selvom det kræver login etc.",
                        "Private": "Du skal have en 'relation' til firmaet der udstiller API'et, betalt eller ej."
                    }
                }
            }

        def parse_table_lines(table_lines):
            headers = [header.strip() for header in table_lines[0].split('|')[1:-1]]
            api_list = []

            for row in table_lines[2:]:
                columns = [col.strip() for col in row.split('|')[1:-1]]
                api_info = dict(zip(headers, columns))
                
                name_match = re.match(r'\[(.*?)\]\((.*?)\)', api_info['API'])
                if name_match:
                    api_info['name'] = name_match.group(1)
                    api_info['url'] = name_match.group(2)
                
                api_info['type'] = api_info.pop('Type')
                api_info['availability'] = api_info.pop('Tilgængelighed')
                del api_info['API']
                
                api_list.append(api_info)
            
            return api_list

        def parse_readme_content(content):
            api_data = extract_information()
            api_data["APIs"] = {}

            categories = re.split(r'##\s+', content)
            exclude_categories = {"Information", "Tilgængelighed", "Public", "Private"}
            
            for category in categories[1:]:
                category_lines = category.splitlines()
                category_name = category_lines[0].strip()
                if category_name in exclude_categories:
                    continue
                
                table_lines = [line for line in category_lines[1:] if line.startswith('|')]
                if table_lines:
                    api_list = parse_table_lines(table_lines)
                    api_data["APIs"][category_name] = api_list

            return api_data

        def main():
            file_path = 'README.md'
            
            with open(file_path, 'r', encoding='utf-8') as file:
                content = file.read()

            api_json = parse_readme_content(content)
            
            output_path = 'api.json'
            with open(output_path, 'w', encoding='utf-8') as json_file:
                json.dump(api_json, json_file, ensure_ascii=False, indent=4)
                
            print("API data has been converted to JSON and saved as 'api.json'.")

        if __name__ == "__main__":
            main()

    - name: Commit and push changes
      run: |
        git config --global user.name 'github-actions'
        git config --global user.email '[email protected]'
        git add api.json
        git commit -m 'Automatically update api.json'
        git push
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

@mauran
Copy link
Owner

mauran commented Nov 4, 2024

Har først set det nu 😄 - Hvor effektivt funker det?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants