Skip to content

Commit

Permalink
feat: add script and GitHub action to generate CSV fr GPT
Browse files Browse the repository at this point in the history
  • Loading branch information
aleron75 committed Jun 2, 2024
1 parent 9e971e2 commit f9cc9d3
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/update-extensions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Update extensions_generated_for_gpt.csv
on: [workflow_dispatch, push, pull_request]
jobs:
update-readme:
name: Update extensions_generated_for_gpt.csv
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Run csv generator
run: |
php csv2gpt.php resources.csv extensions_generated_for_gpt.csv
git config user.name "GitHub Actions"
git config user.email github-actions@github.com
if [[ `git status --porcelain` ]]; then git add . && git commit -m "extensions.csv updated by action" && git push; fi
50 changes: 50 additions & 0 deletions csv2gpt.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php declare(strict_types=1);

/**
* This script generates a CSV containing just the Extensions to feed GPT
*/
if (!isset($argv[2])) {
echo "Usage: php csv2gpt.php input_file output_file.csv" . PHP_EOL;
exit(1);
}

$csv = $argv[1];
if (!file_exists($csv)) {
echo "File not found: $csv" . PHP_EOL;
exit(1);
}

$outfile = $argv[2];
if ($csv == $outfile) {
echo "Cannot write on input file!" . PHP_EOL;
exit(1);
}

$contents = [
['Extension name', 'Extension URL', 'Extension Description']
];
$topic = '';
$prevtopic = '';
if (($handle = fopen($csv, "r")) !== false) {
while (($data = fgetcsv($handle, 1000, ",")) !== false) {
list($topic, $_, $name, $url, $description) = $data;

if ($topic !== 'Extensions' ) {
continue;
}

$contents[] = [
$name,
$url,
$description,
];
}
fclose($handle);
}
#print_r($contents);

$handle = fopen($outfile, 'w');
foreach ($contents as $content) {
fputcsv($handle, $content);
}
fclose($handle);

0 comments on commit f9cc9d3

Please sign in to comment.