Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
wwwanlingxiao
public-apis
Commits
b0409e8a
Commit
b0409e8a
authored
Feb 03, 2018
by
davemachado
Browse files
Migrate JSON logic to api project
parent
19cba58a
Changes
4
Hide whitespace changes
Inline
Side-by-side
build/build.sh
deleted
100755 → 0
View file @
19cba58a
#!/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
build/deploy.sh
deleted
100755 → 0
View file @
19cba58a
#!/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
build/main.sh
View file @
b0409e8a
...
...
@@ -8,21 +8,11 @@ if [[ $? != 0 ]]; then
exit
1
fi
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
echo
"running on
$TRAVIS_BRANCH
branch - skipping Pull Request logic"
exit
0
fi
echo
"running on Pull Request #
$TRAVIS_PULL_REQUEST
"
DIFF_URL
=
"https://patch-diff.githubusercontent.com/raw/toddmotto/public-apis/pull/
$TRAVIS_PULL_REQUEST
.diff"
curl
$DIFF_URL
>
diff.txt
...
...
@@ -35,16 +25,6 @@ cat additions.txt
echo
"------- END ADDITIONS ------"
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..."
./validate_links.py
$LINK_FILE
if
[[
$?
!=
0
]]
;
then
...
...
build/md2json.py
deleted
100755 → 0
View file @
19cba58a
#!/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
()
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment