py2ls 0.1.10.10__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/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,178 @@ except NameError: | |
| 57 58 | 
             
                pass
         | 
| 58 59 |  | 
| 59 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 | 
            +
             | 
| 95 | 
            +
            # ************* below section: run_when *************
         | 
| 96 | 
            +
            def run_when(when: str = "every 2 min", job=None, wait: int = 60):
         | 
| 97 | 
            +
                if "every" in when.lower():
         | 
| 98 | 
            +
                    when = when.replace("every", "")
         | 
| 99 | 
            +
                    run_every(when=when, job=job, wait=wait)
         | 
| 100 | 
            +
                elif any([i in when.lower() for i in ["at", "@", ":", "am", "pm"]]):
         | 
| 101 | 
            +
                    time_words = ["at", "@", ":", "am", "pm"]
         | 
| 102 | 
            +
                    # 判断'时间词'是否存在
         | 
| 103 | 
            +
                    time_words_bool = [i in when.lower() for i in time_words]
         | 
| 104 | 
            +
                    # 找到'时间词'的位置
         | 
| 105 | 
            +
                    true_indices = [index for index, value in enumerate(time_words_bool) if value]
         | 
| 106 | 
            +
                    time_word = time_words[true_indices[0]]  # 找到第一个'时间词'
         | 
| 107 | 
            +
                    when = when.replace(time_word, "")  # 去除 时间词
         | 
| 108 | 
            +
                    run_at(when=when, job=job, wait=wait)
         | 
| 109 | 
            +
             | 
| 110 | 
            +
             | 
| 111 | 
            +
            def run_every(when: str = None, job=None, wait: int = 60):
         | 
| 112 | 
            +
                """
         | 
| 113 | 
            +
                Schedules a job to run at the given interval.
         | 
| 114 | 
            +
             | 
| 115 | 
            +
                :param when: String specifying the interval, e.g. '2 minutes', '4 hours', '1 day'.
         | 
| 116 | 
            +
                :param job: The function to be scheduled.
         | 
| 117 | 
            +
                """
         | 
| 118 | 
            +
                if job is None:
         | 
| 119 | 
            +
                    print("No job provided!")
         | 
| 120 | 
            +
                    return
         | 
| 121 | 
            +
             | 
| 122 | 
            +
                interval, unit = (
         | 
| 123 | 
            +
                    str2num(when),
         | 
| 124 | 
            +
                    strcmp(when.replace("every", ""), ["seconds", "minutes", "hours", "days"])[0],
         | 
| 125 | 
            +
                )
         | 
| 126 | 
            +
                print(interval, unit)
         | 
| 127 | 
            +
                # Mapping the scheduling based on the unit1
         | 
| 128 | 
            +
                if unit == "seconds":
         | 
| 129 | 
            +
                    schedule.every(interval).seconds.do(job)
         | 
| 130 | 
            +
                elif unit == "minutes":
         | 
| 131 | 
            +
                    schedule.every(interval).minutes.do(job)
         | 
| 132 | 
            +
                elif unit == "hours":
         | 
| 133 | 
            +
                    schedule.every(interval).hours.do(job)
         | 
| 134 | 
            +
                elif unit == "days":
         | 
| 135 | 
            +
                    schedule.every(interval).days.do(job)
         | 
| 136 | 
            +
                else:
         | 
| 137 | 
            +
                    print(f"Invalid time unit: {unit}")
         | 
| 138 | 
            +
                    return
         | 
| 139 | 
            +
             | 
| 140 | 
            +
                print(f"Scheduled job when {interval} {unit}.")
         | 
| 141 | 
            +
             | 
| 142 | 
            +
                # Keep the script running to execute the schedule
         | 
| 143 | 
            +
                while True:
         | 
| 144 | 
            +
                    schedule.run_pending()
         | 
| 145 | 
            +
                    time.sleep(wait)  # in seconds
         | 
| 146 | 
            +
                time.sleep(wait)  # in seconds
         | 
| 147 | 
            +
             | 
| 148 | 
            +
             | 
| 149 | 
            +
            # # usage:
         | 
| 150 | 
            +
            # def job():
         | 
| 151 | 
            +
            #     print("1 sec")
         | 
| 152 | 
            +
            # run_every(when="1 sec", job=job)
         | 
| 153 | 
            +
             | 
| 154 | 
            +
             | 
| 155 | 
            +
            def run_at(when: str, job=None, wait: int = 60):
         | 
| 156 | 
            +
                """
         | 
| 157 | 
            +
                Schedules a job to run at an exact time of the day.
         | 
| 158 | 
            +
             | 
| 159 | 
            +
                :param when: String specifying the time, e.g. '1:30 pm','1.30 am','14:30', '1:30 pm', '8:45 am'.
         | 
| 160 | 
            +
                :param job: The function to be scheduled.
         | 
| 161 | 
            +
                :param wait: The sleep interval between checks in seconds.
         | 
| 162 | 
            +
                """
         | 
| 163 | 
            +
                if job is None:
         | 
| 164 | 
            +
                    print("No job provided!")
         | 
| 165 | 
            +
                    return
         | 
| 166 | 
            +
                when = when.replace("A.M.", "AM").replace("P.M.", "PM")
         | 
| 167 | 
            +
                when = when.replace(".", ":")
         | 
| 168 | 
            +
                when = when.strip()
         | 
| 169 | 
            +
             | 
| 170 | 
            +
                try:
         | 
| 171 | 
            +
                    # Attempt to parse the time in both 24-hour and 12-hour format
         | 
| 172 | 
            +
                    if "am" in when.lower() or "pm" in when.lower():
         | 
| 173 | 
            +
                        scheduled_time = datetime.strptime(
         | 
| 174 | 
            +
                            when, "%I:%M %p"
         | 
| 175 | 
            +
                        ).time()  # 12-hour format with AM/PM
         | 
| 176 | 
            +
                    else:
         | 
| 177 | 
            +
                        scheduled_time = datetime.strptime(when, "%H:%M").time()  # 24-hour format
         | 
| 178 | 
            +
                except ValueError:
         | 
| 179 | 
            +
                    print(
         | 
| 180 | 
            +
                        f"Invalid time format: {when}. Use 'HH:MM' (24-hour) or 'H:MM AM/PM' format."
         | 
| 181 | 
            +
                    )
         | 
| 182 | 
            +
                    return
         | 
| 183 | 
            +
             | 
| 184 | 
            +
                print(f"Job scheduled to run at {scheduled_time}.")
         | 
| 185 | 
            +
             | 
| 186 | 
            +
                # Keep checking the current time
         | 
| 187 | 
            +
                while True:
         | 
| 188 | 
            +
                    now = datetime.now()
         | 
| 189 | 
            +
             | 
| 190 | 
            +
                    # Check if current time matches the scheduled time
         | 
| 191 | 
            +
                    if (
         | 
| 192 | 
            +
                        now.time().hour == scheduled_time.hour
         | 
| 193 | 
            +
                        and now.time().minute == scheduled_time.minute
         | 
| 194 | 
            +
                    ):
         | 
| 195 | 
            +
                        job()  # Run the job
         | 
| 196 | 
            +
                        time.sleep(
         | 
| 197 | 
            +
                            wait
         | 
| 198 | 
            +
                        )  # Sleep for a minute to avoid running the job multiple times in the same minute
         | 
| 199 | 
            +
             | 
| 200 | 
            +
                    time.sleep(wait)  # wait to avoid excessive CPU usage
         | 
| 201 | 
            +
             | 
| 202 | 
            +
             | 
| 203 | 
            +
            # # Example usage:
         | 
| 204 | 
            +
            # def my_job():
         | 
| 205 | 
            +
            #     print("Job executed at the exact time!")
         | 
| 206 | 
            +
            # # Schedule the job at 14:30 when day
         | 
| 207 | 
            +
            # run_at(when="1.30 pm", job=my_job)
         | 
| 208 | 
            +
             | 
| 209 | 
            +
            # ************* above section: run_when *************
         | 
| 210 | 
            +
             | 
| 211 | 
            +
             | 
| 212 | 
            +
            def get_timezone(timezone: str | list):
         | 
| 213 | 
            +
                from pytz import all_timezones
         | 
| 214 | 
            +
                import pytz
         | 
| 215 | 
            +
             | 
| 216 | 
            +
                if isinstance(timezone, str):
         | 
| 217 | 
            +
                    timezone = [timezone]
         | 
| 218 | 
            +
             | 
| 219 | 
            +
                # Extract the part after the "/" in time zones (if exists)
         | 
| 220 | 
            +
                timezones = [ssplit(i, "/")[1] if "/" in i else i for i in all_timezones]
         | 
| 221 | 
            +
             | 
| 222 | 
            +
                # Print all available time zones for debugging purposes
         | 
| 223 | 
            +
                # print(timezones)
         | 
| 224 | 
            +
             | 
| 225 | 
            +
                # Find and return matched time zones using strcmp
         | 
| 226 | 
            +
                matched_timezones = [all_timezones[strcmp(i, timezones)[1]] for i in timezone]
         | 
| 227 | 
            +
                if len(matched_timezones) == 1:
         | 
| 228 | 
            +
                    return pytz.timezone(matched_timezones[0])
         | 
| 229 | 
            +
                else:
         | 
| 230 | 
            +
                    return matched_timezones
         | 
| 231 | 
            +
             | 
| 232 | 
            +
             | 
| 60 233 | 
             
            def is_package_installed(package_name):
         | 
| 61 234 | 
             
                """Check if a package is installed."""
         | 
| 62 235 | 
             
                package_spec = importlib.util.find_spec(package_name)
         | 
| @@ -482,28 +655,29 @@ def str2num(s, *args, **kwargs): | |
| 482 655 | 
             
                        except Exception as e:
         | 
| 483 656 | 
             
                            # Attempt to handle multiple number segments
         | 
| 484 657 | 
             
                            try:
         | 
| 485 | 
            -
                                number_segments =  | 
| 658 | 
            +
                                number_segments = re.findall(r"[-+]?\d*\.\d+|\d+", s)
         | 
| 486 659 | 
             
                                nums = []
         | 
| 487 660 | 
             
                                for segment in number_segments:
         | 
| 488 | 
            -
                                     | 
| 489 | 
            -
                                        nums.append(str2num(segment))
         | 
| 490 | 
            -
                                    except ValueError:
         | 
| 491 | 
            -
                                        continue
         | 
| 661 | 
            +
                                    nums.append(str2num(segment))
         | 
| 492 662 | 
             
                                if len(nums) == 1:
         | 
| 493 663 | 
             
                                    num = nums[0]
         | 
| 494 664 | 
             
                                else:
         | 
| 495 | 
            -
                                     | 
| 496 | 
            -
                                        "Multiple number segments found, cannot determine single numeric value"
         | 
| 497 | 
            -
                                    )
         | 
| 665 | 
            +
                                    num = nums
         | 
| 498 666 | 
             
                            except Exception as e:
         | 
| 499 667 | 
             
                                return None
         | 
| 500 668 |  | 
| 501 669 | 
             
                # Apply rounding if specified
         | 
| 502 670 | 
             
                if round_digits is not None:
         | 
| 503 | 
            -
                     | 
| 504 | 
            -
             | 
| 671 | 
            +
                    if isinstance(num, list):
         | 
| 672 | 
            +
                        num = [round(i + 0.00000000001, round_digits) for i in num]
         | 
| 673 | 
            +
                    else:
         | 
| 674 | 
            +
                        num_adj = num + 0.00000000001  # Ensure precise rounding
         | 
| 675 | 
            +
                        num = round(num_adj, round_digits)
         | 
| 505 676 | 
             
                if round_digits == 0:
         | 
| 506 | 
            -
                     | 
| 677 | 
            +
                    if isinstance(num, list):
         | 
| 678 | 
            +
                        num = [int(i) for i in num]
         | 
| 679 | 
            +
                    else:
         | 
| 680 | 
            +
                        num = int(num)
         | 
| 507 681 | 
             
                # if delimiter is not None:
         | 
| 508 682 | 
             
                #     num_str = f"{num:,}".replace(",", delimiter)
         | 
| 509 683 | 
             
                #     return num_str#s.replace(delimiter, "")
         | 
| @@ -521,21 +695,10 @@ def str2num(s, *args, **kwargs): | |
| 521 695 | 
             
            # print(str2num("12345.6789", " ", 2)) # Output: 12 345.68
         | 
| 522 696 | 
             
            # print(str2num('111113.34555',3,',')) # Output: 111,113.346
         | 
| 523 697 | 
             
            # print(str2num("123.55555 sec miniuets",3)) # Output: 1.3
         | 
| 524 | 
            -
             | 
| 525 | 
            -
             | 
| 526 | 
            -
             | 
| 527 | 
            -
             | 
| 528 | 
            -
                num = []
         | 
| 529 | 
            -
                for s in ssplit(text, by="digital"):
         | 
| 530 | 
            -
                    try:
         | 
| 531 | 
            -
                        if float(s):
         | 
| 532 | 
            -
                            num.append(float(s))
         | 
| 533 | 
            -
                    except:
         | 
| 534 | 
            -
                        pass
         | 
| 535 | 
            -
                if len(num) == 1:
         | 
| 536 | 
            -
                    return num[0]
         | 
| 537 | 
            -
                else:
         | 
| 538 | 
            -
                    return num
         | 
| 698 | 
            +
            # print(str2num("every 3,300.55 hours and 5.045555 min", sep=",", round=1))
         | 
| 699 | 
            +
            # print(str2num("five hundred fourty one"), str2num(
         | 
| 700 | 
            +
            #     "this is 5.9435 euros for 10.04499 killograme", round=3
         | 
| 701 | 
            +
            # )[0])
         | 
| 539 702 |  | 
| 540 703 |  | 
| 541 704 | 
             
            def num2str(num, *args, **kwargs):
         | 
| @@ -572,11 +735,13 @@ def num2str(num, *args, **kwargs): | |
| 572 735 |  | 
| 573 736 |  | 
| 574 737 | 
             
            # Examples
         | 
| 575 | 
            -
            # print(num2str(123),type(num2str(123))) | 
| 576 | 
            -
            # print(num2str(123.456, 2),type(num2str(123.456, 2))) | 
| 577 | 
            -
            # print(num2str(7000.125,  | 
| 578 | 
            -
            # print( | 
| 579 | 
            -
            # | 
| 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"
         | 
| 580 745 | 
             
            def sreplace(*args, **kwargs):
         | 
| 581 746 | 
             
                """
         | 
| 582 747 | 
             
                sreplace(text, by=None, robust=True)
         | 
| @@ -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=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. | 
| 219 | 
            -
            py2ls-0.1.10. | 
| 220 | 
            -
            py2ls-0.1.10. | 
| 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,,
         | 
| 
            File without changes
         |