Skip to content

Commit da0451a

Browse files
committed
Update Edge Driver executable and calculate MingGuo date locally
1 parent 30f2389 commit da0451a

5 files changed

Lines changed: 20 additions & 22 deletions

File tree

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*.pyc
2+
build
3+
dist
4+
*.spec
-14.4 MB
Binary file not shown.

Driver License Sign Up Speedrun.py

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
from selenium.webdriver.support.select import Select
44
from selenium.webdriver.common.action_chains import ActionChains
55
from apscheduler.schedulers.blocking import BlockingScheduler
6+
from webdriver_manager.microsoft import EdgeChromiumDriverManager
67
import random, time, re, toml, os, sys
78
import requests
89
import datetime
910
from datetime import timedelta
1011
from dateutil import parser
1112
from ask_users_options import ask_users_options
1213

13-
if not os.path.exists("msedgedriver.exe"):
14+
if not os.path.exists("./msedgedriver.exe"):
1415
print("請下載Microsoft Edge Webdriver並放在與此檔案同目錄")
1516
input("按Enter 結束...")
1617
sys.exit()
@@ -30,7 +31,7 @@
3031
RETAKE = data["Retake"]
3132
KEYWORDS = data["Keywords"]
3233

33-
MOCK = True
34+
MOCK = False
3435

3536
def information_validation():
3637
# Regular expressions
@@ -62,35 +63,28 @@ def information_validation():
6263
input("請按Enter繼續...")
6364
sys.exit()
6465

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+
7568

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)
8173

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)
8475

8576
# Calculate the date 30 days from now
8677
future_date = taiwan_time + timedelta(days=30)
8778

88-
# Format the future date
79+
# Format the future date in YYYYMMDD
8980
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:]
9181

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:]
9386

87+
return formatted_future_date_minguo
9488

9589
def driver_license_speedrun():
9690
options = webdriver.EdgeOptions()

msedgedriver.exe

547 KB
Binary file not shown.

requirements.txt

1012 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)