Skip to main content

检测正在运行的 Python 脚本,并按地区打开对应视频。

Project description

nbpl

安装 nbpl 后,不需要在任何脚本中导入它。它会通过 Python 的 sitecustomize 启动钩子,在该环境中每次常规启动 Python 解释器时,自动使用系统默认浏览器打开一个视频:

公网 IP 所在国家/地区代码 打开的链接
CN(中国大陆) https://www.bilibili.com/video/BV1GJ411x7h7
其他代码,或定位失败 https://www.youtube.com/watch?v=dQw4w9WgXcQ

地区查询使用 https://ipapi.co/json/。本包仅会发起一次 IP 地理位置查询;不会上传脚本路径。

安装

pip install nbpl

也可以直接从本仓库安装:

pip install git+https://github.com/hekuo5310/nbpl.git

自动使用

安装后,以下常规 Python 启动方式都会自动触发:

python app.py
python -m 包名
python -c "print('hello')"
python

同样包含运行 .pyw、.pyc 文件和 Python 测试/工具启动器。自动行为只在安装了 nbpl 的 Python 环境中生效。

独立监控器

如果只想作为独立监控器使用,仍可运行:

nbpl

独立监控器默认每秒检查一次;发现其他 Python 脚本后打开对应链接并退出。修改检查间隔:

nbpl --interval 2

本地测试时可跳过 IP 查询,直接指定地区:

nbpl --country-code CN

临时关闭自动触发

为避免自动打开浏览器,可在运行命令前设置环境变量:

NBPL_DISABLE_AUTO_OPEN=1 python app.py

Windows PowerShell:

$env:NBPL_DISABLE_AUTO_OPEN = "1"; python app.py

Python 的 -S 参数会禁止加载 sitecustomize,因此此启动方式不会自动触发。

Python API

from nbpl import run_once, watch

run_once()  # 仅当已有其他 Python 脚本在运行时才打开链接
watch(interval=1.0)  # 等待脚本出现,打开链接后返回

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nbpl-0.1.2.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nbpl-0.1.2-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file nbpl-0.1.2.tar.gz.

File metadata

  • Download URL: nbpl-0.1.2.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for nbpl-0.1.2.tar.gz
Algorithm Hash digest
SHA256 ffdc0e933e6403a581ae408c222a4adac84482deb78f500e78c022b31becc7d0
MD5 e8618c157e9dc7565ddd8e902c33f84c
BLAKE2b-256 a6b6ee2afbf9222eeb72d27435738bc77b74a8ac2225a426d68ec8d476fd527a

See more details on using hashes here.

Provenance

The following attestation bundles were made for nbpl-0.1.2.tar.gz:

Publisher: publish.yml on hekuo5310/nbpl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nbpl-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: nbpl-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for nbpl-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d4f02335e277c03b7fe88fb4da3d5e6f1a47604bcd6256a1bc49e7b24faaa7de
MD5 49f29ea237cff444ef8f6687593f6ff4
BLAKE2b-256 042a7a271a2263ef648cd93baf5ce44e0c23e171c58b85fd5991e358c196eb1d

See more details on using hashes here.

Provenance

The following attestation bundles were made for nbpl-0.1.2-py3-none-any.whl:

Publisher: publish.yml on hekuo5310/nbpl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page