11""" API extras for Cloudflare API"""
22
3+ import datetime
4+
35from bs4 import BeautifulSoup , Comment
46
57API_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
0 commit comments