@@ -42,33 +42,45 @@ def detect_environment():
42
42
43
43
def update_notice ():
44
44
"""
45
- Checks for a newer version of the package and displays an update notice .
45
+ Checks for newer versions of vnstock and vnai packages and displays update notices .
46
46
"""
47
+ packages = ["vnstock" , "vnai" ]
48
+
47
49
try :
48
- installed_version = get_version ("vnstock" )
49
- response = requests .get ("https://pypi.org/pypi/vnstock/json" , timeout = 5 )
50
- response .raise_for_status ()
51
- latest_version = response .json ().get ("info" , {}).get ("version" )
50
+ environment = detect_environment ()
51
+
52
+ for package in packages :
53
+ try :
54
+ installed_version = get_version (package )
55
+ response = requests .get (f"https://pypi.org/pypi/{ package } /json" , timeout = 5 )
56
+ response .raise_for_status ()
57
+ latest_version = response .json ().get ("info" , {}).get ("version" )
52
58
53
- if latest_version and version .parse (installed_version ) < version .parse (latest_version ):
54
- message = (
55
- f"Phiên bản Vnstock { latest_version } đã có mặt, vui lòng cập nhật với câu lệnh : `pip install vnstock --upgrade`.\n "
56
- f"Lịch sử phiên bản: https://vnstocks.com/docs/tai-lieu/lich-su-phien-ban\n "
57
- f"Phiên bản hiện tại { installed_version } "
58
- )
59
+ if latest_version and version .parse (installed_version ) < version .parse (latest_version ):
60
+ package_name = package .capitalize ()
61
+ # Customize URL based on package
62
+ history_url = "https://vnstocks.com/docs/tai-lieu/lich-su-phien-ban" if package == "vnstock" else "https://pypi.org/project/vnai/#history"
63
+
64
+ message = (
65
+ f"Phiên bản { package_name } { latest_version } đã có mặt, vui lòng cập nhật với câu lệnh : `pip install { package } --upgrade`.\n "
66
+ f"Lịch sử phiên bản: { history_url } \n "
67
+ f"Phiên bản hiện tại { installed_version } "
68
+ )
59
69
60
- environment = detect_environment ()
61
-
62
- if environment in ["Jupyter" , "Google Colab" ] and ipython_available :
63
- display (Markdown (message )) # Display as markdown in Jupyter or Google Colab
64
- else :
65
- warnings .simplefilter ("always" , UserWarning )
66
- warnings .warn (
67
- message .replace ("**" , "" ), # Remove markdown styling for non-notebook environments
68
- UserWarning ,
69
- stacklevel = 2
70
- )
71
- except requests .exceptions .RequestException :
70
+ if environment in ["Jupyter" , "Google Colab" ] and ipython_available :
71
+ display (Markdown (message )) # Display as markdown in Jupyter or Google Colab
72
+ else :
73
+ warnings .simplefilter ("always" , UserWarning )
74
+ warnings .warn (
75
+ message .replace ("**" , "" ), # Remove markdown styling for non-notebook environments
76
+ UserWarning ,
77
+ stacklevel = 2
78
+ )
79
+ except (requests .exceptions .RequestException , ImportError , pkg_resources .DistributionNotFound ):
80
+ # Skip this package if it's not installed or can't be checked
81
+ pass
82
+ except Exception :
83
+ # Ensure the entire update check doesn't break the user's code
72
84
pass
73
85
74
86
# Customizing the warnings output format for non-notebook environments
0 commit comments