-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add script and GitHub action to generate CSV fr GPT
- Loading branch information
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |