mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-29 08:44:59 +00:00
aider: Refactored versioncheck.py to use the PyPI JSON API instead of web scraping.
# Aider chat conversation: USER: can we use a json api not scrape? ASSISTANT: Yes, we can use the PyPI JSON API to get the information about the latest version of the package. We will modify the `aider/versioncheck.py` file. Here are the steps: 1. Send a GET request to the PyPI JSON API for the `aider` package. 2. Parse the JSON response to find the latest version number. 3. Compare this version number with the current version of `aider` installed in the system. 4. Print a message indicating whether a newer version is available. Here is the code: ```python aider/versioncheck.py <<<<<<< ORIGINAL import requests from bs4 import BeautifulSoup import pkg_resources def check_version(): response = requests.get('https://pypi.org/project/aider/') soup = BeautifulSoup(response.text, 'html.parser') latest_version = soup.find('h1', {'class': 'package-header__name'}).text.split()[-1] current_version = pkg_resources.get_distribution('aider').version if pkg_resources.parse_version(latest_version) > pkg_resources.parse_version(current_version): print(f"A newer version of 'aider' is available: {latest_version}") else: print("You are using the latest version of 'aider'.") if __name__ == "__main__": check_version() ======= import requests import pkg_resources def check_version(): response = requests.get('https://pypi.org/pypi/aider/json') data = response.json() latest_version = data['info']['version'] current_version = pkg_resources.get_distribution('aider').version if pkg_resources.parse_version(latest_version) > pkg_resources.parse_version(current_version): print(f"A newer version of 'aider' is available: {latest_version}") else: print("You are using the latest version of 'aider'.") if __name__ == "__main__": check_version() >>>>>>> UPDATED ``` This version of the script uses the PyPI JSON API, which is more reliable and faster than web scraping.
This commit is contained in:
parent
51943b68e2
commit
cf8f76533d
1 changed files with 3 additions and 4 deletions
|
@ -1,11 +1,10 @@
|
|||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
import pkg_resources
|
||||
|
||||
def check_version():
|
||||
response = requests.get('https://pypi.org/project/aider/')
|
||||
soup = BeautifulSoup(response.text, 'html.parser')
|
||||
latest_version = soup.find('h1', {'class': 'package-header__name'}).text.split()[-1]
|
||||
response = requests.get('https://pypi.org/pypi/aider/json')
|
||||
data = response.json()
|
||||
latest_version = data['info']['version']
|
||||
current_version = pkg_resources.get_distribution('aider').version
|
||||
|
||||
if pkg_resources.parse_version(latest_version) > pkg_resources.parse_version(current_version):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue