|
3 | 3 | from selenium.webdriver.support.select import Select |
4 | 4 | from selenium.webdriver.common.action_chains import ActionChains |
5 | 5 | from apscheduler.schedulers.blocking import BlockingScheduler |
| 6 | +from webdriver_manager.microsoft import EdgeChromiumDriverManager |
6 | 7 | import random, time, re, toml, os, sys |
7 | 8 | import requests |
8 | 9 | import datetime |
9 | 10 | from datetime import timedelta |
10 | 11 | from dateutil import parser |
11 | 12 | from ask_users_options import ask_users_options |
12 | 13 |
|
13 | | -if not os.path.exists("msedgedriver.exe"): |
| 14 | +if not os.path.exists("./msedgedriver.exe"): |
14 | 15 | print("請下載Microsoft Edge Webdriver並放在與此檔案同目錄") |
15 | 16 | input("按Enter 結束...") |
16 | 17 | sys.exit() |
|
30 | 31 | RETAKE = data["Retake"] |
31 | 32 | KEYWORDS = data["Keywords"] |
32 | 33 |
|
33 | | -MOCK = True |
| 34 | +MOCK = False |
34 | 35 |
|
35 | 36 | def information_validation(): |
36 | 37 | # Regular expressions |
@@ -62,35 +63,28 @@ def information_validation(): |
62 | 63 | input("請按Enter繼續...") |
63 | 64 | sys.exit() |
64 | 65 |
|
65 | | -def get_latest_sign_date_in_mingguo(): |
66 | | - # Fetch the current time for Taiwan from worldtimeapi.org |
67 | | - response = requests.get("http://worldtimeapi.org/api/timezone/Asia/Taipei") |
68 | | - data = response.json() |
69 | | - |
70 | | - # Extract the datetime string from the response |
71 | | - datetime_str = data['datetime'] |
72 | | - |
73 | | - # Parse the datetime string using dateutil.parser |
74 | | - taiwan_time = parser.isoparse(datetime_str) |
| 66 | +from datetime import datetime, timedelta |
| 67 | +from zoneinfo import ZoneInfo # Python 3.9+ |
75 | 68 |
|
76 | | - # Get the current local time and make it offset-aware |
77 | | - local_time = datetime.datetime.now(datetime.timezone.utc).astimezone(taiwan_time.tzinfo) |
78 | | - |
79 | | - # Calculate the difference in minutes |
80 | | - time_difference = abs((taiwan_time - local_time).total_seconds() / 60) |
| 69 | +def get_latest_sign_date_in_mingguo(): |
| 70 | + # Get the current time in Asia/Taipei timezone |
| 71 | + taiwan_tz = ZoneInfo("Asia/Taipei") |
| 72 | + taiwan_time = datetime.now(taiwan_tz) |
81 | 73 |
|
82 | | - # Allow a 1-minute error margin |
83 | | - assert time_difference <= 1, f"本地時間錯誤,有{time_difference:.0f}分鐘誤差。" |
| 74 | + # Optional: Verify local time offset difference if needed (skipped here because no API) |
84 | 75 |
|
85 | 76 | # Calculate the date 30 days from now |
86 | 77 | future_date = taiwan_time + timedelta(days=30) |
87 | 78 |
|
88 | | - # Format the future date |
| 79 | + # Format the future date in YYYYMMDD |
89 | 80 | formatted_future_date = future_date.strftime("%Y%m%d") |
90 | | - formatted_future_date_mingguo = str(int(formatted_future_date[:4]) - 1911) + formatted_future_date[4:] |
91 | 81 |
|
92 | | - return formatted_future_date_mingguo |
| 82 | + # Convert Gregorian year to Minguo year (Taiwan year) |
| 83 | + # Minguo year = Gregorian year - 1911 |
| 84 | + minguo_year = int(formatted_future_date[:4]) - 1911 |
| 85 | + formatted_future_date_minguo = str(minguo_year) + formatted_future_date[4:] |
93 | 86 |
|
| 87 | + return formatted_future_date_minguo |
94 | 88 |
|
95 | 89 | def driver_license_speedrun(): |
96 | 90 | options = webdriver.EdgeOptions() |
|
0 commit comments