語音轉文字
cmd
whisper test.mp3 --model medium --language Chinese --device cuda --fp16 False --task transcribe --initial_prompt "以下內容為佛教講經,包含佛經原文、法師開示、佛學專有名詞,如:末學、蓮友、大德、阿彌陀、述要、菩提、般若、涅槃、阿賴耶識、因果、空性、佛說無量壽經、解行並進、信願行、資糧。請依原文逐字轉寫,不翻譯、不簡化。"
medium 好像比 large 好
tiny/base/small/medium/large
ubuntu + python + google maps
# ubuntu 20.04.6 + gtk 為基底
# python 3.8.10
# cpu 是 intel 系列
import gi
gi.require_version('Gtk', '3.0')
gi.require_version('WebKit2', '4.0')
from gi.repository import Gtk, WebKit2, Gdk, GLib
import random
# ----------------------------
# 截圖函式
# ----------------------------
def take_screenshot(webview):
window = webview.get_window()
if window:
width, height = webview.get_allocated_width(), webview.get_allocated_height()
pb = Gdk.pixbuf_get_from_window(window, 0, 0, width, height)
if pb:
pb.savev("screenshot.png", "png", [], [])
print("截圖完成,存檔為 screenshot.png")
Gtk.main_quit()
# ----------------------------
# 抓 DOM 函式
# ----------------------------
def grab_dom(webview):
js_code = "document.getElementsByClassName('tUEI8e')[0].textContent;"
def js_callback(webview, result, user_data):
value = webview.run_javascript_finish(result).get_js_value()
print("抓到網頁 title:", value.to_string())
# 等 DOM 取完再截圖
take_screenshot(webview)
webview.run_javascript(js_code, None, js_callback, None)
# ----------------------------
# 網頁載入完成 callback
# ----------------------------
def on_load_changed(webview, event, user_data=None):
if event == WebKit2.LoadEvent.FINISHED:
print("網頁載入完成")
# 延遲 20~25 秒再抓 DOM,不阻塞主迴圈
delay = random.randint(20, 25)*1000
GLib.timeout_add(delay, lambda: grab_dom(webview))
# ----------------------------
# 主程式
# ----------------------------
win = Gtk.Window()
win.set_default_size(1920, 1080)
win.set_title("GTK WebView 非阻塞延遲範例")
webview = WebKit2.WebView()
win.add(webview)
win.show_all()
webview.connect("load-changed", on_load_changed)
webview.load_uri("https://www.google.com/maps/dir/嘉里醫藥烏日倉/台中榮民總醫院")
Gtk.main()
import subprocess
# 呼叫另一個 Python 腳本
result = subprocess.run(["python3", "other.py"], capture_output=True, text=True)
# 等待 other.py 執行完畢後再繼續
print("other.py 執行完畢")
print("輸出結果:")
print(result.stdout)
raspberry pi 4
sudo apt install python3-webview
sudo apt install python3-pyqt5
sudo apt install gir1.2-webkit2-4.0 libwebkit2gtk-4.0-37
import webview
import threading
urls = [
"https://www.google.com/maps/dir/嘉里醫藥烏日倉/台中榮民總醫院",
"https://www.google.com/maps/dir/嘉里醫藥烏日倉/盛雲藥品股份有限公司",
"https://www.google.com/maps/dir/嘉里醫藥烏日倉/彰化基督教醫院"
]
def started():
def switch():
for url in urls:
print("切換到:", url)
window.load_url(url)
threading.Event().wait(30) # 每頁停 30 秒
distance=window.evaluate_js("document.getElementsByClassName('tUEI8e')[0].textContent")
print(distance)
threading.Event().wait(5) # 每頁停 5 秒
threading.Thread(target=switch, daemon=True).start()
window = webview.create_window("Demo", urls[0])
webview.start(started)
python 查詢網站 ssl 的憑證到期日
import ssl
import socket
from datetime import datetime
def get_ssl_expiry_date(hostname, port=443):
context = ssl.create_default_context()
with socket.create_connection((hostname, port)) as sock:
with context.wrap_socket(sock, server_hostname=hostname) as ssock:
cert = ssock.getpeercert()
# 取得過期日期並轉為 datetime 格式
expiry_str = cert['notAfter']
expiry_date = datetime.strptime(expiry_str, '%b %d %H:%M:%S %Y %Z')
return expiry_date
# 測試
hostname = 'tw.yahoo.com'
expiry_date = get_ssl_expiry_date(hostname)
print(f"{hostname} 的 SSL 憑證到期日是:{expiry_date}")
https://www.google.com/maps/search/23.882309,+120.702162?coh=277533&entry=tts&g_ep=EgoyMDI2MDExOS4wIPu8ASoKLDEwMDc5MjA2OUgBUAM%3D&skid=756a1055-ea44-48e1-a836-e420089f41be