py2ls 0.1.10.10__py3-none-any.whl → 0.1.10.11__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
py2ls/batman.py
CHANGED
py2ls/ips.py
CHANGED
@@ -16,6 +16,7 @@ import importlib.util
|
|
16
16
|
import time
|
17
17
|
from dateutil import parser
|
18
18
|
from datetime import datetime
|
19
|
+
import schedule
|
19
20
|
|
20
21
|
from PIL import Image, ImageEnhance, ImageOps, ImageFilter
|
21
22
|
from rembg import remove, new_session
|
@@ -57,6 +58,143 @@ except NameError:
|
|
57
58
|
pass
|
58
59
|
|
59
60
|
|
61
|
+
# ************* below section: run_when *************
|
62
|
+
def run_when(when: str = "every 2 min", job=None, sleep: int = 1):
|
63
|
+
if "every" in when.lower():
|
64
|
+
when = when.replace("every", "")
|
65
|
+
run_every(when=when, job=job, sleep=sleep)
|
66
|
+
elif any([i in when.lower() for i in ["at", "@", ":", "am", "pm"]]):
|
67
|
+
time_words = ["at", "@", ":", "am", "pm"]
|
68
|
+
# 判断'时间词'是否存在
|
69
|
+
time_words_bool = [i in when.lower() for i in time_words]
|
70
|
+
# 找到'时间词'的位置
|
71
|
+
true_indices = [index for index, value in enumerate(time_words_bool) if value]
|
72
|
+
time_word = time_words[true_indices[0]] # 找到第一个'时间词'
|
73
|
+
when = when.replace(time_word, "") # 去除 时间词
|
74
|
+
run_at(when=when, job=job, sleep=sleep)
|
75
|
+
|
76
|
+
|
77
|
+
def run_every(when: str = None, job=None, sleep: int = 1):
|
78
|
+
"""
|
79
|
+
Schedules a job to run at the given interval.
|
80
|
+
|
81
|
+
:param when: String specifying the interval, e.g. '2 minutes', '4 hours', '1 day'.
|
82
|
+
:param job: The function to be scheduled.
|
83
|
+
"""
|
84
|
+
if job is None:
|
85
|
+
print("No job provided!")
|
86
|
+
return
|
87
|
+
|
88
|
+
interval, unit = (
|
89
|
+
str2num(when),
|
90
|
+
strcmp(when.replace("every", ""), ["seconds", "minutes", "hours", "days"])[0],
|
91
|
+
)
|
92
|
+
print(interval, unit)
|
93
|
+
# Mapping the scheduling based on the unit1
|
94
|
+
if unit == "seconds":
|
95
|
+
schedule.every(interval).seconds.do(job)
|
96
|
+
elif unit == "minutes":
|
97
|
+
schedule.every(interval).minutes.do(job)
|
98
|
+
elif unit == "hours":
|
99
|
+
schedule.every(interval).hours.do(job)
|
100
|
+
elif unit == "days":
|
101
|
+
schedule.every(interval).days.do(job)
|
102
|
+
else:
|
103
|
+
print(f"Invalid time unit: {unit}")
|
104
|
+
return
|
105
|
+
|
106
|
+
print(f"Scheduled job when {interval} {unit}.")
|
107
|
+
|
108
|
+
# Keep the script running to execute the schedule
|
109
|
+
while True:
|
110
|
+
schedule.run_pending()
|
111
|
+
time.sleep(sleep) # in seconds
|
112
|
+
|
113
|
+
|
114
|
+
# # usage:
|
115
|
+
# def job():
|
116
|
+
# print("1 sec")
|
117
|
+
# run_every(when="1 sec", job=job)
|
118
|
+
|
119
|
+
|
120
|
+
def run_at(when: str, job=None, sleep: int = 60):
|
121
|
+
"""
|
122
|
+
Schedules a job to run at an exact time of the day.
|
123
|
+
|
124
|
+
:param when: String specifying the time, e.g. '1:30 pm','1.30 am','14:30', '1:30 pm', '8:45 am'.
|
125
|
+
:param job: The function to be scheduled.
|
126
|
+
:param sleep: The sleep interval between checks in seconds.
|
127
|
+
"""
|
128
|
+
if job is None:
|
129
|
+
print("No job provided!")
|
130
|
+
return
|
131
|
+
when = when.replace("A.M.", "AM").replace("P.M.", "PM")
|
132
|
+
when = when.replace(".", ":")
|
133
|
+
when = when.strip()
|
134
|
+
|
135
|
+
try:
|
136
|
+
# Attempt to parse the time in both 24-hour and 12-hour format
|
137
|
+
if "am" in when.lower() or "pm" in when.lower():
|
138
|
+
scheduled_time = datetime.strptime(
|
139
|
+
when, "%I:%M %p"
|
140
|
+
).time() # 12-hour format with AM/PM
|
141
|
+
else:
|
142
|
+
scheduled_time = datetime.strptime(when, "%H:%M").time() # 24-hour format
|
143
|
+
except ValueError:
|
144
|
+
print(
|
145
|
+
f"Invalid time format: {when}. Use 'HH:MM' (24-hour) or 'H:MM AM/PM' format."
|
146
|
+
)
|
147
|
+
return
|
148
|
+
|
149
|
+
print(f"Job scheduled to run at {scheduled_time}.")
|
150
|
+
|
151
|
+
# Keep checking the current time
|
152
|
+
while True:
|
153
|
+
now = datetime.now()
|
154
|
+
|
155
|
+
# Check if current time matches the scheduled time
|
156
|
+
if (
|
157
|
+
now.time().hour == scheduled_time.hour
|
158
|
+
and now.time().minute == scheduled_time.minute
|
159
|
+
):
|
160
|
+
job() # Run the job
|
161
|
+
time.sleep(
|
162
|
+
60
|
163
|
+
) # Sleep for a minute to avoid running the job multiple times in the same minute
|
164
|
+
|
165
|
+
time.sleep(sleep) # Sleep to avoid excessive CPU usage
|
166
|
+
|
167
|
+
|
168
|
+
# # Example usage:
|
169
|
+
# def my_job():
|
170
|
+
# print("Job executed at the exact time!")
|
171
|
+
# # Schedule the job at 14:30 when day
|
172
|
+
# run_at(when="1.30 pm", job=my_job)
|
173
|
+
|
174
|
+
# ************* above section: run_when *************
|
175
|
+
|
176
|
+
|
177
|
+
def get_timezone(timezone: str | list):
|
178
|
+
from pytz import all_timezones
|
179
|
+
import pytz
|
180
|
+
|
181
|
+
if isinstance(timezone, str):
|
182
|
+
timezone = [timezone]
|
183
|
+
|
184
|
+
# Extract the part after the "/" in time zones (if exists)
|
185
|
+
timezones = [ssplit(i, "/")[1] if "/" in i else i for i in all_timezones]
|
186
|
+
|
187
|
+
# Print all available time zones for debugging purposes
|
188
|
+
# print(timezones)
|
189
|
+
|
190
|
+
# Find and return matched time zones using strcmp
|
191
|
+
matched_timezones = [all_timezones[strcmp(i, timezones)[1]] for i in timezone]
|
192
|
+
if len(matched_timezones) == 1:
|
193
|
+
return pytz.timezone(matched_timezones[0])
|
194
|
+
else:
|
195
|
+
return matched_timezones
|
196
|
+
|
197
|
+
|
60
198
|
def is_package_installed(package_name):
|
61
199
|
"""Check if a package is installed."""
|
62
200
|
package_spec = importlib.util.find_spec(package_name)
|
@@ -482,28 +620,29 @@ def str2num(s, *args, **kwargs):
|
|
482
620
|
except Exception as e:
|
483
621
|
# Attempt to handle multiple number segments
|
484
622
|
try:
|
485
|
-
number_segments =
|
623
|
+
number_segments = re.findall(r"[-+]?\d*\.\d+|\d+", s)
|
486
624
|
nums = []
|
487
625
|
for segment in number_segments:
|
488
|
-
|
489
|
-
nums.append(str2num(segment))
|
490
|
-
except ValueError:
|
491
|
-
continue
|
626
|
+
nums.append(str2num(segment))
|
492
627
|
if len(nums) == 1:
|
493
628
|
num = nums[0]
|
494
629
|
else:
|
495
|
-
|
496
|
-
"Multiple number segments found, cannot determine single numeric value"
|
497
|
-
)
|
630
|
+
num = nums
|
498
631
|
except Exception as e:
|
499
632
|
return None
|
500
633
|
|
501
634
|
# Apply rounding if specified
|
502
635
|
if round_digits is not None:
|
503
|
-
|
504
|
-
|
636
|
+
if isinstance(num, list):
|
637
|
+
num = [round(i + 0.00000000001, round_digits) for i in num]
|
638
|
+
else:
|
639
|
+
num_adj = num + 0.00000000001 # Ensure precise rounding
|
640
|
+
num = round(num_adj, round_digits)
|
505
641
|
if round_digits == 0:
|
506
|
-
|
642
|
+
if isinstance(num, list):
|
643
|
+
num = [int(i) for i in num]
|
644
|
+
else:
|
645
|
+
num = int(num)
|
507
646
|
# if delimiter is not None:
|
508
647
|
# num_str = f"{num:,}".replace(",", delimiter)
|
509
648
|
# return num_str#s.replace(delimiter, "")
|
@@ -521,6 +660,7 @@ def str2num(s, *args, **kwargs):
|
|
521
660
|
# print(str2num("12345.6789", " ", 2)) # Output: 12 345.68
|
522
661
|
# print(str2num('111113.34555',3,',')) # Output: 111,113.346
|
523
662
|
# print(str2num("123.55555 sec miniuets",3)) # Output: 1.3
|
663
|
+
# print(str2num("every 3,300.55 hours and 5.045555 min", sep=",", round=1))
|
524
664
|
|
525
665
|
|
526
666
|
def text2num(text):
|
@@ -172,7 +172,7 @@ py2ls/.gitignore,sha256=y7GvbD_zZkjPVVIue8AyiuFkDMuUbvMaV65Lgu89To8,2763
|
|
172
172
|
py2ls/LICENSE,sha256=UOZ1F5fFDe3XXvG4oNnkL1-Ecun7zpHzRxjp-XsMeAo,11324
|
173
173
|
py2ls/README.md,sha256=CwvJWAnSXnCnrVHlnEbrxxi6MbjbE_MT6DH2D53S818,11572
|
174
174
|
py2ls/__init__.py,sha256=Nn8jTIvySX7t7DMJ8VNRVctTStgXGjHldOIdZ35PdW8,165
|
175
|
-
py2ls/batman.py,sha256=
|
175
|
+
py2ls/batman.py,sha256=U5FcWkq4kgwvFKur0wsqe0jBdq1hQjwpSUKSRzQWeCM,7509
|
176
176
|
py2ls/brain_atlas.py,sha256=w1o5EelRjq89zuFJUNSz4Da8HnTCwAwDAZ4NU4a-bAY,5486
|
177
177
|
py2ls/chat.py,sha256=Yr22GoIvoWhpV3m4fdwV_I0Mn77La346_ymSinR-ORA,3793
|
178
178
|
py2ls/correlators.py,sha256=RbOaJIPLCHJtUm5SFi_4dCJ7VFUPWR0PErfK3K26ad4,18243
|
@@ -206,7 +206,7 @@ py2ls/doc.py,sha256=xN3g1OWfoaGUhikbJ0NqbN5eKy1VZVvWwRlhHMgyVEc,4243
|
|
206
206
|
py2ls/export_requirements.py,sha256=x2WgUF0jYKz9GfA1MVKN-MdsM-oQ8yUeC6Ua8oCymio,2325
|
207
207
|
py2ls/freqanalysis.py,sha256=F4218VSPbgL5tnngh6xNCYuNnfR-F_QjECUUxrPYZss,32594
|
208
208
|
py2ls/ich2ls.py,sha256=3E9R8oVpyYZXH5PiIQgT3CN5NxLe4Dwtm2LwaeacE6I,21381
|
209
|
-
py2ls/ips.py,sha256=
|
209
|
+
py2ls/ips.py,sha256=v4ef1W0FbT8TaW9E7VrU9AcwcmMtASFkMEroI3_y-Po,140434
|
210
210
|
py2ls/netfinder.py,sha256=_stenzqRZsB4m5FDE7YsSkC2jvkmrUOsq48BRQB2mPM,55369
|
211
211
|
py2ls/ocr.py,sha256=T1C589yPF07lJ6EFpGgKq5Dw0vLIZ_-ffH_WZZVIz5o,31026
|
212
212
|
py2ls/plot.py,sha256=J8hRKLpQXHQRG_xE_nmT0mQvc1IxCMJ21tJmKsUKFl4,96155
|
@@ -215,6 +215,6 @@ py2ls/sleep_events_detectors.py,sha256=bQA3HJqv5qnYKJJEIhCyhlDtkXQfIzqksnD0YRXso
|
|
215
215
|
py2ls/stats.py,sha256=fJmXQ9Lq460StOn-kfEljE97cySq7876HUPTnpB5hLs,38123
|
216
216
|
py2ls/translator.py,sha256=zBeq4pYZeroqw3DT-5g7uHfVqKd-EQptT6LJ-Adi8JY,34244
|
217
217
|
py2ls/wb_detector.py,sha256=7y6TmBUj9exCZeIgBAJ_9hwuhkDh1x_-yg4dvNY1_GQ,6284
|
218
|
-
py2ls-0.1.10.
|
219
|
-
py2ls-0.1.10.
|
220
|
-
py2ls-0.1.10.
|
218
|
+
py2ls-0.1.10.11.dist-info/METADATA,sha256=mcWlOaiPcY_cMz41gTwAJaxvXvlmR3XO2L7REagrdps,19791
|
219
|
+
py2ls-0.1.10.11.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
|
220
|
+
py2ls-0.1.10.11.dist-info/RECORD,,
|
File without changes
|