Skip to content

Commit

Permalink
Added migration notice
Browse files Browse the repository at this point in the history
  • Loading branch information
thinh-vu committed Aug 11, 2024
1 parent 8b38754 commit 96ddd99
Show file tree
Hide file tree
Showing 16 changed files with 145 additions and 3 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<div align="center">

[![python_course_6](https://course.learn-anything.vn/wp-content/uploads/2024/06/Python-Course-7-Phan-tich-du-lieu-va-giao-dich-chung-khoan.png)
<!-- [![python_course_8](https://github.com/thinh-vu/vnstock/blob/legacy/docs/docs/assets/images/Python_course_8_Phan_tich_du_lieu_bot_chung_khoan.png?raw=true) -->

[![migrate_to_vnstock3](https://github.com/thinh-vu/vnstock/blob/legacy/docs/docs/assets/images/vnstock3-migration-notice.png?raw=true)](https://vnstocks.com/docs/tai-lieu/migration-chuyen-doi-sang-vnstock3)


</div>

Expand Down
41 changes: 41 additions & 0 deletions dev/cleanup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import os
import shutil
import fnmatch

def delete_dirs(dirs):
for dir in dirs:
for root, dirnames, filenames in os.walk('.'):
for dirname in fnmatch.filter(dirnames, dir):
dir_path = os.path.join(root, dirname)
try:
shutil.rmtree(dir_path)
print(f"Deleted directory: {dir_path}")
except FileNotFoundError:
print(f"Directory not found: {dir_path}")
except Exception as e:
print(f"Error while deleting directory: {dir_path}. Error: {str(e)}")

def delete_files(files):
for file in files:
for root, dirnames, filenames in os.walk('.'):
for filename in fnmatch.filter(filenames, file):
file_path = os.path.join(root, filename)
try:
os.remove(file_path)
print(f"Deleted file: {file_path}")
except FileNotFoundError:
print(f"File not found: {file_path}")
except Exception as e:
print(f"Error while deleting file: {file_path}. Error: {str(e)}")

# List of directories to delete
dirs_to_delete = ["__pycache__", "build", "*.egg-info", "dist"]

# List of files to delete
files_to_delete = ["*.tmp"]

# Delete directories
delete_dirs(dirs_to_delete)

# Delete files
delete_files(files_to_delete)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/docs/assets/images/vnstock3-migration-notice.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ requires = [
"requests",
"bs4",
"pandas",
"openpyxl"
"openpyxl",
"packaging>=20.0",
"importlib-metadata>=1.0",
"ipython>=7.0"
]
build-backend = "setuptools.build_meta"
# dependencies = []
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = vnstock
version = 0.2.9.0
version = 0.2.9.2.2
author = Thinh Vu
author_email = [email protected]
description = Vietnam Stock Market Data
Expand Down
3 changes: 3 additions & 0 deletions vnstock/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@
from .integration import *
from .funds import *
# from .ocr import *

update_notice()

Binary file removed vnstock/__pycache__/config.cpython-310.pyc
Binary file not shown.
Binary file removed vnstock/__pycache__/derivative.cpython-310.pyc
Binary file not shown.
Binary file removed vnstock/__pycache__/fundamental.cpython-310.pyc
Binary file not shown.
Binary file removed vnstock/__pycache__/funds.cpython-310.pyc
Binary file not shown.
Binary file removed vnstock/__pycache__/integration.cpython-310.pyc
Binary file not shown.
Binary file removed vnstock/__pycache__/market.cpython-310.pyc
Binary file not shown.
Binary file removed vnstock/__pycache__/technical.cpython-310.pyc
Binary file not shown.
Binary file removed vnstock/__pycache__/trading.cpython-310.pyc
Binary file not shown.
92 changes: 92 additions & 0 deletions vnstock/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,95 @@ def get_path_delimiter():
Detect the running OS and return the appropriate file path delimiter.
"""
return '\\' if os.name == 'nt' else '/'

# UPDATE NOTICE

import warnings
import requests
from packaging import version
from importlib.metadata import version as get_version
from IPython.display import display, Markdown, HTML
import sys
import os
import uuid

def detect_environment():
"""
Detects the running environment (Jupyter, Google Colab, etc.) and returns a string identifier.
"""
try:
from IPython import get_ipython
if 'IPKernelApp' not in get_ipython().config:
if sys.stdout.isatty():
return "Terminal"
else:
return "Other" # Non-interactive environment (e.g., script executed from an IDE)
else:
if 'google.colab' in sys.modules:
return "Google Colab"
return "Jupyter"
except (ImportError, AttributeError):
if sys.stdout.isatty():
return "Terminal"
else:
return "Other"

def detect_hosting_service():
"""
Detects if the code is running in a cloud environment (Google Colab, Kaggle, etc.)
"""
try:
if 'google.colab' in sys.modules:
return "Google Colab"
elif 'CODESPACE_NAME' in os.environ:
return "Github Codespace"
elif 'GITPOD_WORKSPACE_CLUSTER_HOST' in os.environ:
return "Gitpod"
elif 'REPLIT_USER' in os.environ:
return "Replit"
elif 'KAGGLE_CONTAINER_NAME' in os.environ:
return "Kaggle"
elif 'SPACE_HOST' in os.environ and '.hf.space' in os.environ['SPACE_HOST']:
return "Hugging Face Spaces"
else:
return "Local or Unknown"
except:
return "Local or Unknown"

def update_notice():
"""
Checks for a newer version of the package and displays an update notice.
"""
try:
installed_version = get_version("vnstock")
response = requests.get("https://pypi.org/pypi/vnstock3/json", timeout=5)
response.raise_for_status()
latest_version = response.json().get("info", {}).get("version")

if latest_version and version.parse(installed_version) < version.parse(latest_version):
message = (
f"**Vui lòng chuyển đổi sang Vnstock3** thế hệ mới ({latest_version}) với câu lệnh: `pip install vnstock3 --upgrade`.\n"
"**Từ 1/1/2025, vnstock3 sẽ được cài đặt khi sử dụng cú pháp** `pip install vnstock` **thay cho Vnstock Legacy** hiện tại.\n"
"Xem chi tiết [chuyển đổi sang vnstock3](https://vnstocks.com/docs/tai-lieu/migration-chuyen-doi-sang-vnstock3).\n"
f"Phiên bản **Vnstock Legacy ({installed_version})** bạn đang sử dụng **sẽ không được nâng cấp thêm.**\n"
)

environment = detect_environment()

if environment in ["Jupyter", "Google Colab"]:
display(Markdown(message)) # Display as markdown in Jupyter or Google Colab
else:
warnings.simplefilter("always", UserWarning)
warnings.warn(
message.replace("**", ""), # Remove markdown styling for non-notebook environments
UserWarning,
stacklevel=2
)
except requests.exceptions.RequestException:
pass

# Customizing the warnings output format for non-notebook environments
def custom_formatwarning(message, category, filename, lineno, line=None):
return f"{message}\n"

warnings.formatwarning = custom_formatwarning

0 comments on commit 96ddd99

Please sign in to comment.