|
| 1 | +# check https://api.plenigo.com/ website, parse the html and check the version of the openapi spec |
| 2 | +# the version looks something like this as text: plenigo API v3 (API.241015-MAJOR) |
| 3 | +# and this as html:<h1 class="sc-fujyAs sc-dFRpbK bpZWeL fdKBSs">plenigo API v3<!-- --> <span>(<!-- -->API.241015-MAJOR<!-- -->)</span></h1> |
| 4 | +# the file containing the openapi spec can be found in the html: <p>Download OpenAPI specification<!-- -->:<a download="openapi.json" target="_blank" class="sc-bsatvv gidAUi" href="blob:https://api.plenigo.com/34a50f04-3802-4d2d-8bb9-7b1e12f1246e">Download</a></p> |
| 5 | + |
| 6 | +import requests |
| 7 | +from bs4 import BeautifulSoup |
| 8 | +import json |
| 9 | +import os |
| 10 | +import sys |
| 11 | + |
| 12 | +url = 'https://api.plenigo.com/' |
| 13 | +response = requests.get(url) |
| 14 | +soup = BeautifulSoup(response.text, 'html.parser') |
| 15 | +version = soup.find('h1').text |
| 16 | +# get words inside the parenthesis |
| 17 | +version = version.split('(')[1].split(')')[0] |
| 18 | + |
| 19 | +# list the files in the openapi_specs folder |
| 20 | +# open the fist folder and check the version |
| 21 | +# if the version is different, print a message |
| 22 | +latest_folder_path = "./openapi_specs/latest" |
| 23 | +files = os.listdir(latest_folder_path) |
| 24 | +file_path = os.path.join(latest_folder_path, files[0]) |
| 25 | +with open(file_path, 'r') as file: |
| 26 | + openapi_spec = json.load(file) |
| 27 | +current_prod_version = openapi_spec['info']['version'] |
| 28 | +if version != current_prod_version: |
| 29 | + print(f"Version mismatch: Current version is {current_prod_version} while the website version is {version}") |
| 30 | + sys.exit(1) |
| 31 | +else: |
| 32 | + print("We are currently using the latest version") |
| 33 | + sys.exit(0) |
| 34 | + |
| 35 | + |
| 36 | + |
0 commit comments