mirror of
https://github.com/public-apis/public-apis.git
synced 2025-06-02 19:01:57 +02:00
Migrate JSON logic to api project
This commit is contained in:
parent
19cba58a8d
commit
b0409e8ae2
4 changed files with 1 additions and 102 deletions
|
@ -1,8 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# create json directory if not already present
|
|
||||||
mkdir -p ../json
|
|
||||||
# parse API README and print (minified) JSON to stdout, redirect to /json
|
|
||||||
./md2json.py ../README.md > ../json/entries.min.json
|
|
||||||
# beautify the previously created JSON file, redirect to /json
|
|
||||||
python -m json.tool ../json/entries.min.json > ../json/entries.json
|
|
|
@ -1,23 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
set -o errexit -o nounset
|
|
||||||
|
|
||||||
rev=$(git rev-parse --short HEAD)
|
|
||||||
|
|
||||||
mkdir deploy
|
|
||||||
cd deploy
|
|
||||||
|
|
||||||
git init
|
|
||||||
git config --global user.name $GH_USER
|
|
||||||
git config --global user.email $GH_EMAIL
|
|
||||||
|
|
||||||
git remote add upstream "https://$GH_TOKEN@github.com/toddmotto/public-apis.git"
|
|
||||||
git fetch upstream
|
|
||||||
git reset upstream/master
|
|
||||||
|
|
||||||
mv ../../json .
|
|
||||||
|
|
||||||
git add json/
|
|
||||||
git commit -m "rebuild JSON at ${rev}" -m "[ci skip]"
|
|
||||||
git push upstream HEAD:master
|
|
||||||
|
|
|
@ -8,21 +8,11 @@ if [[ $? != 0 ]]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo "format validation passed!"
|
echo "format validation passed!"
|
||||||
./build.sh
|
|
||||||
if [[ $? != 0 ]]; then
|
|
||||||
echo "JSON build failed!"
|
|
||||||
else
|
|
||||||
echo "JSON build success!"
|
|
||||||
fi
|
|
||||||
if [ "$TRAVIS_BRANCH" == "master" ]
|
|
||||||
then
|
|
||||||
echo "Master build - deploying JSON"
|
|
||||||
./deploy.sh
|
|
||||||
fi
|
|
||||||
if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
|
if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
|
||||||
echo "running on $TRAVIS_BRANCH branch - skipping Pull Request logic"
|
echo "running on $TRAVIS_BRANCH branch - skipping Pull Request logic"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "running on Pull Request #$TRAVIS_PULL_REQUEST"
|
echo "running on Pull Request #$TRAVIS_PULL_REQUEST"
|
||||||
DIFF_URL="https://patch-diff.githubusercontent.com/raw/toddmotto/public-apis/pull/$TRAVIS_PULL_REQUEST.diff"
|
DIFF_URL="https://patch-diff.githubusercontent.com/raw/toddmotto/public-apis/pull/$TRAVIS_PULL_REQUEST.diff"
|
||||||
curl $DIFF_URL > diff.txt
|
curl $DIFF_URL > diff.txt
|
||||||
|
@ -35,16 +25,6 @@ cat additions.txt
|
||||||
echo "------- END ADDITIONS ------"
|
echo "------- END ADDITIONS ------"
|
||||||
LINK_FILE=additions.txt
|
LINK_FILE=additions.txt
|
||||||
|
|
||||||
echo "checking if /json was changed..."
|
|
||||||
if egrep "\+{3}\s.\/json\/" diff.txt > json.txt; then
|
|
||||||
echo "JSON files are auto-generated! Please do not update these files:"
|
|
||||||
cat json.txt
|
|
||||||
exit 1
|
|
||||||
else
|
|
||||||
echo "/json check passed!"
|
|
||||||
rm json.txt
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "running link validation..."
|
echo "running link validation..."
|
||||||
./validate_links.py $LINK_FILE
|
./validate_links.py $LINK_FILE
|
||||||
if [[ $? != 0 ]]; then
|
if [[ $? != 0 ]]; then
|
||||||
|
|
|
@ -1,50 +0,0 @@
|
||||||
#!/usr/bin/env python3
|
|
||||||
|
|
||||||
import json
|
|
||||||
import sys
|
|
||||||
|
|
||||||
|
|
||||||
def markdown_to_json(filename, anchor):
|
|
||||||
"""Convert a Markdown file into a JSON string"""
|
|
||||||
category = ""
|
|
||||||
entries = []
|
|
||||||
with open(filename) as fp:
|
|
||||||
lines = (line.rstrip() for line in fp)
|
|
||||||
lines = list(line for line in lines if line and
|
|
||||||
line.startswith(anchor) or line.startswith('| '))
|
|
||||||
for line in lines:
|
|
||||||
if line.startswith(anchor):
|
|
||||||
category = line.split(anchor)[1].strip()
|
|
||||||
continue
|
|
||||||
chunks = [x.strip() for x in line.split('|')[1:-1]]
|
|
||||||
entry = {
|
|
||||||
'API': chunks[0],
|
|
||||||
'Description': chunks[1],
|
|
||||||
'Auth': None if chunks[2].upper() == 'NO' else chunks[2].strip('`'),
|
|
||||||
'HTTPS': True if chunks[3].upper() == 'YES' else False,
|
|
||||||
'CORS': chunks[4].strip('`'),
|
|
||||||
'Link': chunks[5].replace('[Go!]', '')[1:-1],
|
|
||||||
'Category': category,
|
|
||||||
}
|
|
||||||
entries.append(entry)
|
|
||||||
final = {
|
|
||||||
'count': len(entries),
|
|
||||||
'entries': entries,
|
|
||||||
}
|
|
||||||
return json.dumps(final)
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
num_args = len(sys.argv)
|
|
||||||
if num_args < 2:
|
|
||||||
print("No .md file passed")
|
|
||||||
sys.exit(1)
|
|
||||||
if num_args < 3:
|
|
||||||
anchor = '###'
|
|
||||||
else:
|
|
||||||
anchor = sys.argv[2]
|
|
||||||
print(markdown_to_json(sys.argv[1], anchor))
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
Loading…
Add table
Add a link
Reference in a new issue