Skip to content
This repository was archived by the owner on Nov 22, 2024. It is now read-only.

Commit 5aba7f0

Browse files
committed
improve deprecated code - add dates, check expire, improve parse of api webpage
1 parent 5ca2b6f commit 5aba7f0

File tree

3 files changed

+37
-6
lines changed

3 files changed

+37
-6
lines changed

CloudFlare/api_decode_from_web.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
""" API extras for Cloudflare API"""
22

3+
import datetime
4+
35
from bs4 import BeautifulSoup, Comment
46

57
API_TYPES = ['GET', 'POST', 'PATCH', 'PUT', 'DELETE']
@@ -10,9 +12,31 @@ def do_section(section):
1012
cmds = []
1113
# look for deprecated first in section
1214
deprecated = False
15+
deprecated_date = ''
16+
deprecated_already = False
1317
for tag2 in section.find_all('h3'):
18+
# <h3 class="text-warning" data-reactid="13490">Deprecation Warning</h3>
1419
if 'Deprecation Warning' in str(tag2):
1520
deprecated = True
21+
break
22+
for tag2 in section.find_all('p'):
23+
# <p class="deprecation-date" data-reactid="13491">End of life Date: November 2, 2020</p>
24+
if 'End of life Date:' in str(tag2):
25+
for child in tag2.children:
26+
deprecated_date = str(child).replace('End of life Date:','').strip()
27+
try:
28+
# clean up date
29+
d = datetime.datetime.strptime(deprecated_date, '%B %d, %Y')
30+
if d <= datetime.datetime.now():
31+
# already done!
32+
deprecated_already = True
33+
deprecated_date = d.strftime('%Y-%m-%d')
34+
except ValueError:
35+
# Lets not worry about all the date formats that could show-up. Leave as a string
36+
pass
37+
break
38+
if deprecated_date != '':
39+
break
1640
# look for all API calls in section
1741
for tag2 in section.find_all('pre'):
1842
cmd = []
@@ -29,7 +53,7 @@ def do_section(section):
2953
cmd = ''.join(cmd[1:])
3054
if cmd[0] == '/':
3155
cmd = cmd[1:]
32-
v = {'deprecated': deprecated, 'action': action, 'cmd': cmd}
56+
v = {'action': action, 'cmd': cmd, 'deprecated': deprecated, 'deprecated_date': deprecated_date, 'deprecated_already': deprecated_already}
3357
cmds.append(v)
3458
return cmds
3559

Makefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,14 @@ lint:
7979
api:
8080
@tmp=/tmp/_$$$$_ ; \
8181
python -m cli4 --dump | sed -e 's/^\///' | sort > $$tmp.1 ; \
82-
python -m cli4 --api | sed -e 's/.* //' -e 's/\/:[^:\/]*//g' -e 's/^\///' | sort | uniq > $$tmp.2 ; \
82+
python -m cli4 --api | sed -e 's/^[A-Z][A-Z]* *//' -e 's/\/:[a-z_]*//g' -e 's/^\///' | sort | uniq > $$tmp.2 ; \
83+
egrep -v '; deprecated' < $$tmp.2 | diff $$tmp.1 - > $$tmp.3 ; \
8384
echo "In code:" ; \
84-
diff $$tmp.1 $$tmp.2 | egrep '< ' | sed -e 's/< / /' | sort ; \
85+
egrep '< ' < $$tmp.3 | sed -e 's/< / /' | sort | tee $$tmp.4 ; \
8586
echo "In docs:" ; \
86-
diff $$tmp.1 $$tmp.2 | egrep '> ' | sed -e 's/> / /' | sort ; \
87+
egrep '> ' < $$tmp.3 | sed -e 's/> / /' | sort ; \
88+
echo "Deprecated:" ; \
89+
egrep '; deprecated' < $$tmp.2 | while read cmd x depricated depricated_date ; do egrep "$$cmd" $$tmp.4 | sed -e "s/$$/ ; depricated $$depricated_date/" ; done | sort | uniq ; \
8790
rm $$tmp.?
8891

8992
clean:

cli4/cli4.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,12 @@ def dump_commands_from_web():
2929
w = cf.api_from_web()
3030
for r in w:
3131
if r['deprecated']:
32-
continue
33-
sys.stdout.write('%-6s %s\n' % (r['action'], r['cmd']))
32+
if r['deprecated_already']:
33+
sys.stdout.write('%-6s %s ; deprecated %s - expired!\n' % (r['action'], r['cmd'], r['deprecated_date']))
34+
else:
35+
sys.stdout.write('%-6s %s ; deprecated %s\n' % (r['action'], r['cmd'], r['deprecated_date']))
36+
else:
37+
sys.stdout.write('%-6s %s\n' % (r['action'], r['cmd']))
3438

3539
def run_command(cf, method, command, params=None, content=None, files=None):
3640
"""run the command line"""

0 commit comments

Comments
 (0)