py2ls 0.1.10.11__py3-none-any.whl → 0.1.10.12__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/ips.py CHANGED
@@ -58,11 +58,45 @@ except NameError:
58
58
  pass
59
59
 
60
60
 
61
+ def unique(lst, ascending=None):
62
+ """
63
+ 移除列表中的重复元素,同时可以选择按升序或降序排序。
64
+
65
+ 参数:
66
+ lst (list): 输入的列表,其中可能包含重复的元素。
67
+ ascending (bool, 可选): 如果为 True,则按升序排序;如果为 False,则按降序排序;如果为 None,则不排序,只移除重复元素。
68
+
69
+ 返回:
70
+ list: 一个列表,其中的元素是唯一的,顺序根据参数 `ascending` 进行排序。
71
+ """
72
+ if ascending is not None:
73
+ # 移除重复项
74
+ unique_items = list(set(lst))
75
+ # 统一元素类型(例如,转换为字符串)
76
+ try:
77
+ unique_items = sorted(
78
+ unique_items, key=lambda x: str(x), reverse=not ascending
79
+ )
80
+ except TypeError:
81
+ # 如果排序失败(例如,元素类型不一致),返回原始去重列表
82
+ return unique_items
83
+ return unique_items
84
+ else:
85
+ # 移除重复项同时保持原始顺序
86
+ seen = set() # 用于记录已见的元素
87
+ result = [] # 用于存储结果
88
+ for item in lst:
89
+ if item not in seen:
90
+ seen.add(item) # 记录该元素
91
+ result.append(item) # 添加到结果列表中
92
+ return result
93
+
94
+
61
95
  # ************* below section: run_when *************
62
- def run_when(when: str = "every 2 min", job=None, sleep: int = 1):
96
+ def run_when(when: str = "every 2 min", job=None, wait: int = 60):
63
97
  if "every" in when.lower():
64
98
  when = when.replace("every", "")
65
- run_every(when=when, job=job, sleep=sleep)
99
+ run_every(when=when, job=job, wait=wait)
66
100
  elif any([i in when.lower() for i in ["at", "@", ":", "am", "pm"]]):
67
101
  time_words = ["at", "@", ":", "am", "pm"]
68
102
  # 判断'时间词'是否存在
@@ -71,10 +105,10 @@ def run_when(when: str = "every 2 min", job=None, sleep: int = 1):
71
105
  true_indices = [index for index, value in enumerate(time_words_bool) if value]
72
106
  time_word = time_words[true_indices[0]] # 找到第一个'时间词'
73
107
  when = when.replace(time_word, "") # 去除 时间词
74
- run_at(when=when, job=job, sleep=sleep)
108
+ run_at(when=when, job=job, wait=wait)
75
109
 
76
110
 
77
- def run_every(when: str = None, job=None, sleep: int = 1):
111
+ def run_every(when: str = None, job=None, wait: int = 60):
78
112
  """
79
113
  Schedules a job to run at the given interval.
80
114
 
@@ -108,7 +142,8 @@ def run_every(when: str = None, job=None, sleep: int = 1):
108
142
  # Keep the script running to execute the schedule
109
143
  while True:
110
144
  schedule.run_pending()
111
- time.sleep(sleep) # in seconds
145
+ time.sleep(wait) # in seconds
146
+ time.sleep(wait) # in seconds
112
147
 
113
148
 
114
149
  # # usage:
@@ -117,13 +152,13 @@ def run_every(when: str = None, job=None, sleep: int = 1):
117
152
  # run_every(when="1 sec", job=job)
118
153
 
119
154
 
120
- def run_at(when: str, job=None, sleep: int = 60):
155
+ def run_at(when: str, job=None, wait: int = 60):
121
156
  """
122
157
  Schedules a job to run at an exact time of the day.
123
158
 
124
159
  :param when: String specifying the time, e.g. '1:30 pm','1.30 am','14:30', '1:30 pm', '8:45 am'.
125
160
  :param job: The function to be scheduled.
126
- :param sleep: The sleep interval between checks in seconds.
161
+ :param wait: The sleep interval between checks in seconds.
127
162
  """
128
163
  if job is None:
129
164
  print("No job provided!")
@@ -159,10 +194,10 @@ def run_at(when: str, job=None, sleep: int = 60):
159
194
  ):
160
195
  job() # Run the job
161
196
  time.sleep(
162
- 60
197
+ wait
163
198
  ) # Sleep for a minute to avoid running the job multiple times in the same minute
164
199
 
165
- time.sleep(sleep) # Sleep to avoid excessive CPU usage
200
+ time.sleep(wait) # wait to avoid excessive CPU usage
166
201
 
167
202
 
168
203
  # # Example usage:
@@ -661,21 +696,9 @@ def str2num(s, *args, **kwargs):
661
696
  # print(str2num('111113.34555',3,',')) # Output: 111,113.346
662
697
  # print(str2num("123.55555 sec miniuets",3)) # Output: 1.3
663
698
  # print(str2num("every 3,300.55 hours and 5.045555 min", sep=",", round=1))
664
-
665
-
666
- def text2num(text):
667
- # extract the digital nums from a text
668
- num = []
669
- for s in ssplit(text, by="digital"):
670
- try:
671
- if float(s):
672
- num.append(float(s))
673
- except:
674
- pass
675
- if len(num) == 1:
676
- return num[0]
677
- else:
678
- return num
699
+ # print(str2num("five hundred fourty one"), str2num(
700
+ # "this is 5.9435 euros for 10.04499 killograme", round=3
701
+ # )[0])
679
702
 
680
703
 
681
704
  def num2str(num, *args, **kwargs):
@@ -712,11 +735,13 @@ def num2str(num, *args, **kwargs):
712
735
 
713
736
 
714
737
  # Examples
715
- # print(num2str(123),type(num2str(123))) # Output: "123"
716
- # print(num2str(123.456, 2),type(num2str(123.456, 2))) # Output: "123.46"
717
- # print(num2str(7000.125, 2),type(num2str(7000.125, 2))) # Output: "7000.13"
718
- # print(num2str(12345.6789, ","),type(num2str(12345.6789, ","))) # Output: "12,345.6789"
719
- # print(num2str(7000.00, ","),type(num2str(7000.00, ","))) # Output: "7,000.00"
738
+ # print(num2str(123), type(num2str(123))) # Output: "123"
739
+ # print(num2str(123.456, round=2), type(num2str(123.456, 2))) # Output: "123.46"
740
+ # print(num2str(7000.125, round=1), type(num2str(7000.125, 2))) # Output: "7000.13"
741
+ # print(
742
+ # num2str(12345333.6789, sep=","), type(num2str(12345.6789, ","))
743
+ # ) # Output: "12,345.6789"
744
+ # print(num2str(7000.00, sep=","), type(num2str(7000.00, ","))) # Output: "7,000.00"
720
745
  def sreplace(*args, **kwargs):
721
746
  """
722
747
  sreplace(text, by=None, robust=True)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: py2ls
3
- Version: 0.1.10.11
3
+ Version: 0.1.10.12
4
4
  Summary: py(thon)2(too)ls
5
5
  Author: Jianfeng
6
6
  Author-email: Jianfeng.Liu0413@gmail.com
@@ -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=v4ef1W0FbT8TaW9E7VrU9AcwcmMtASFkMEroI3_y-Po,140434
209
+ py2ls/ips.py,sha256=gL00NltT6GTwuuT-QQ9wVm7qtnMGF6DGm1aMZ6i6R4o,141608
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.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,,
218
+ py2ls-0.1.10.12.dist-info/METADATA,sha256=ms-f5xVUXSTNZTyvCyj_KbQdkgh7dV-x6NpBLjAqi40,19791
219
+ py2ls-0.1.10.12.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
220
+ py2ls-0.1.10.12.dist-info/RECORD,,