qrpa 1.0.96__py3-none-any.whl → 1.0.98__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.
Potentially problematic release.
This version of qrpa might be problematic. Click here for more details.
- qrpa/feishu_client.py +410 -410
- qrpa/feishu_logic.py +1443 -1443
- qrpa/fun_excel.py +1 -0
- qrpa/fun_web.py +65 -7
- qrpa/shein_excel.py +131 -14
- qrpa/shein_lib.py +47 -0
- qrpa/shein_mysql.py +62 -62
- qrpa/shein_ziniao.py +1 -1
- qrpa/time_utils.py +30 -43
- qrpa/wxwork.py +318 -318
- {qrpa-1.0.96.dist-info → qrpa-1.0.98.dist-info}/METADATA +1 -1
- {qrpa-1.0.96.dist-info → qrpa-1.0.98.dist-info}/RECORD +14 -14
- {qrpa-1.0.96.dist-info → qrpa-1.0.98.dist-info}/WHEEL +0 -0
- {qrpa-1.0.96.dist-info → qrpa-1.0.98.dist-info}/top_level.txt +0 -0
qrpa/time_utils.py
CHANGED
|
@@ -8,7 +8,6 @@ import calendar
|
|
|
8
8
|
from datetime import date, datetime, timedelta, timezone
|
|
9
9
|
from typing import Optional, Tuple, List, Union
|
|
10
10
|
|
|
11
|
-
|
|
12
11
|
class TimeUtils:
|
|
13
12
|
"""时间工具类,提供各种时间相关的静态方法"""
|
|
14
13
|
|
|
@@ -94,6 +93,17 @@ class TimeUtils:
|
|
|
94
93
|
last_month = today.month - 1 if today.month > 1 else 12
|
|
95
94
|
return last_month
|
|
96
95
|
|
|
96
|
+
@staticmethod
|
|
97
|
+
def get_last_two_month() -> int:
|
|
98
|
+
"""获取上上个月的月份"""
|
|
99
|
+
today = datetime.today()
|
|
100
|
+
# 计算上上个月:当前月份减2
|
|
101
|
+
last_two_month = today.month - 2
|
|
102
|
+
# 处理跨年情况
|
|
103
|
+
if last_two_month < 1:
|
|
104
|
+
last_two_month += 12
|
|
105
|
+
return last_two_month
|
|
106
|
+
|
|
97
107
|
# ==================== 日期范围计算 ====================
|
|
98
108
|
|
|
99
109
|
@staticmethod
|
|
@@ -285,6 +295,7 @@ class TimeUtils:
|
|
|
285
295
|
current_date += timedelta(days=1)
|
|
286
296
|
|
|
287
297
|
return date_list
|
|
298
|
+
|
|
288
299
|
# ==================== 月份相关 ====================
|
|
289
300
|
|
|
290
301
|
@staticmethod
|
|
@@ -299,6 +310,24 @@ class TimeUtils:
|
|
|
299
310
|
|
|
300
311
|
return first_day.strftime("%Y-%m-%d"), last_day.strftime("%Y-%m-%d")
|
|
301
312
|
|
|
313
|
+
@staticmethod
|
|
314
|
+
def get_last_two_month_range() -> Tuple[str, str]:
|
|
315
|
+
"""获取上上个月的第一天和最后一天"""
|
|
316
|
+
today = datetime.today()
|
|
317
|
+
# 计算上上个月
|
|
318
|
+
last_two_month = today.month - 2
|
|
319
|
+
year = today.year
|
|
320
|
+
|
|
321
|
+
# 处理跨年情况
|
|
322
|
+
if last_two_month < 1:
|
|
323
|
+
last_two_month += 12
|
|
324
|
+
year -= 1
|
|
325
|
+
|
|
326
|
+
first_day = datetime(year, last_two_month, 1)
|
|
327
|
+
last_day = datetime(year, last_two_month, calendar.monthrange(year, last_two_month)[1])
|
|
328
|
+
|
|
329
|
+
return first_day.strftime("%Y-%m-%d"), last_day.strftime("%Y-%m-%d")
|
|
330
|
+
|
|
302
331
|
@staticmethod
|
|
303
332
|
def get_last_month_range_time_str() -> Tuple[str, str]:
|
|
304
333
|
"""获取上个月第一天和最后一天的时间字符串"""
|
|
@@ -618,7 +647,6 @@ class TimeUtils:
|
|
|
618
647
|
|
|
619
648
|
return mtime_dt.strftime('%Y-%m-%d %H:%M:%S') if to_str else mtime_dt
|
|
620
649
|
|
|
621
|
-
|
|
622
650
|
# ==================== 便捷函数 ====================
|
|
623
651
|
# 为了保持向后兼容,提供一些便捷函数
|
|
624
652
|
|
|
@@ -626,197 +654,158 @@ def get_current_date() -> str:
|
|
|
626
654
|
"""获取当前日期,格式为 YYYYMMDD"""
|
|
627
655
|
return TimeUtils.get_current_date()
|
|
628
656
|
|
|
629
|
-
|
|
630
657
|
def get_current_datetime() -> str:
|
|
631
658
|
"""获取当前日期时间,格式为 YYYYMMDDHHMMSS"""
|
|
632
659
|
return TimeUtils.get_current_datetime()
|
|
633
660
|
|
|
634
|
-
|
|
635
661
|
def current_datetime() -> str:
|
|
636
662
|
"""获取当前日期时间,格式为 YYYY-MM-DD HH:MM:SS"""
|
|
637
663
|
return TimeUtils.current_datetime()
|
|
638
664
|
|
|
639
|
-
|
|
640
665
|
def today_date() -> str:
|
|
641
666
|
"""获取今天的日期,格式为 YYYY-MM-DD"""
|
|
642
667
|
return TimeUtils.today_date()
|
|
643
668
|
|
|
644
|
-
|
|
645
669
|
def today_date_hour() -> str:
|
|
646
670
|
"""获取今天的日期和小时,格式为 YYYY-MM-DD_HH"""
|
|
647
671
|
return TimeUtils.today_date_hour()
|
|
648
672
|
|
|
649
|
-
|
|
650
673
|
def get_yesterday(dt: Optional[str] = None) -> str:
|
|
651
674
|
"""获取昨天的日期"""
|
|
652
675
|
return TimeUtils.get_yesterday(dt)
|
|
653
676
|
|
|
654
|
-
|
|
655
677
|
def tomorrow_date() -> str:
|
|
656
678
|
"""获取明天的日期"""
|
|
657
679
|
return TimeUtils.tomorrow_date()
|
|
658
680
|
|
|
659
|
-
|
|
660
681
|
def before_yesterday() -> str:
|
|
661
682
|
"""获取前天的日期"""
|
|
662
683
|
return TimeUtils.before_yesterday()
|
|
663
684
|
|
|
664
|
-
|
|
665
685
|
def get_current_year() -> int:
|
|
666
686
|
"""获取当前年份"""
|
|
667
687
|
return TimeUtils.get_current_year()
|
|
668
688
|
|
|
669
|
-
|
|
670
689
|
def get_current_month() -> int:
|
|
671
690
|
"""获取当前月份"""
|
|
672
691
|
return TimeUtils.get_current_month()
|
|
673
692
|
|
|
674
|
-
|
|
675
693
|
def get_last_month() -> int:
|
|
676
694
|
"""获取上个月的月份"""
|
|
677
695
|
return TimeUtils.get_last_month()
|
|
678
696
|
|
|
679
|
-
|
|
680
697
|
def get_week_num() -> int:
|
|
681
698
|
"""获取当前是第几周"""
|
|
682
699
|
return TimeUtils.get_week_num()
|
|
683
700
|
|
|
684
|
-
|
|
685
701
|
def get_period() -> str:
|
|
686
702
|
"""获取当前时间段(上午/下午/晚上)"""
|
|
687
703
|
return TimeUtils.get_period()
|
|
688
704
|
|
|
689
|
-
|
|
690
705
|
def get_period2() -> str:
|
|
691
706
|
"""获取当前时间段(AM/PM)"""
|
|
692
707
|
return TimeUtils.get_period2()
|
|
693
708
|
|
|
694
|
-
|
|
695
709
|
def get_chinese_weekday(date_str: str) -> str:
|
|
696
710
|
"""根据输入的日期字符串返回中文星期几"""
|
|
697
711
|
return TimeUtils.get_chinese_weekday(date_str)
|
|
698
712
|
|
|
699
|
-
|
|
700
713
|
def get_weekday_name(date_str: str) -> str:
|
|
701
714
|
"""获取中文星期名称(简短格式)"""
|
|
702
715
|
return TimeUtils.get_weekday_name(date_str)
|
|
703
716
|
|
|
704
|
-
|
|
705
717
|
def is_in_month(time_str: str, month: int, fmt: str = "%Y-%m-%d") -> bool:
|
|
706
718
|
"""判断时间字符串是否在指定月份"""
|
|
707
719
|
return TimeUtils.is_in_month(time_str, month, fmt)
|
|
708
720
|
|
|
709
|
-
|
|
710
721
|
def date_trans(d_t: str) -> str:
|
|
711
722
|
"""无斜杠日期转成有斜杠日期"""
|
|
712
723
|
return TimeUtils.date_trans(d_t)
|
|
713
724
|
|
|
714
|
-
|
|
715
725
|
def is_date_greater_or_equal(date_str: str) -> bool:
|
|
716
726
|
"""比较指定日期是否大于或等于今天的日期"""
|
|
717
727
|
return TimeUtils.is_date_greater_or_equal(date_str)
|
|
718
728
|
|
|
719
|
-
|
|
720
729
|
def is_yesterday(create_time_str: str, dt: Optional[str] = None) -> bool:
|
|
721
730
|
"""判断给定的时间字符串是否是昨天"""
|
|
722
731
|
return TimeUtils.is_yesterday(create_time_str, dt)
|
|
723
732
|
|
|
724
|
-
|
|
725
733
|
def is_yesterday_date(date_str: str) -> bool:
|
|
726
734
|
"""判断给定的日期字符串是否是昨天"""
|
|
727
735
|
return TimeUtils.is_yesterday_date(date_str)
|
|
728
736
|
|
|
729
|
-
|
|
730
737
|
def get_file_mtime(file_path: str, to_str: bool = True, tz_offset: int = 8) -> Union[str, datetime]:
|
|
731
738
|
"""获取文件的修改时间"""
|
|
732
739
|
return TimeUtils.get_file_mtime(file_path, to_str, tz_offset)
|
|
733
740
|
|
|
734
|
-
|
|
735
741
|
def convert_timestamp_to_str(timestamp_ms: Optional[int]) -> str:
|
|
736
742
|
"""将毫秒时间戳转换为字符串"""
|
|
737
743
|
return TimeUtils.convert_timestamp_to_str(timestamp_ms)
|
|
738
744
|
|
|
739
|
-
|
|
740
745
|
def convert_timestamp_to_date(timestamp_ms: Union[int, float]) -> str:
|
|
741
746
|
"""将毫秒时间戳转换为日期字符串"""
|
|
742
747
|
return TimeUtils.convert_timestamp_to_date(timestamp_ms)
|
|
743
748
|
|
|
744
|
-
|
|
745
749
|
def convert_datetime_to_date(datetime_str: str) -> str:
|
|
746
750
|
"""将格式为 'YYYY-MM-DD HH:MM:SS' 的时间字符串转换为 'YYYY-MM-DD' 格式的日期字符串"""
|
|
747
751
|
return TimeUtils.convert_datetime_to_date(datetime_str)
|
|
748
752
|
|
|
749
|
-
|
|
750
753
|
def get_current_year_range() -> Tuple[str, str]:
|
|
751
754
|
"""获取当前年份的开始和结束日期"""
|
|
752
755
|
return TimeUtils.get_current_year_range()
|
|
753
756
|
|
|
754
|
-
|
|
755
757
|
def get_start_timestamps(date_str: str) -> int:
|
|
756
758
|
"""获取指定日期的开始毫秒时间戳(00:00:00.000)"""
|
|
757
759
|
return TimeUtils.get_start_timestamps(date_str)
|
|
758
760
|
|
|
759
|
-
|
|
760
761
|
def get_end_timestamps(date_str: str) -> int:
|
|
761
762
|
"""获取指定日期的结束毫秒时间戳(23:59:59.999)"""
|
|
762
763
|
return TimeUtils.get_end_timestamps(date_str)
|
|
763
764
|
|
|
764
|
-
|
|
765
765
|
def format_date_cross_platform(date_str: str) -> str:
|
|
766
766
|
"""跨平台格式化日期"""
|
|
767
767
|
return TimeUtils.format_date_cross_platform(date_str)
|
|
768
768
|
|
|
769
|
-
|
|
770
769
|
def get_past_7_days_range(start_from: Optional[str] = None) -> Tuple[str, str]:
|
|
771
770
|
"""获取过去7天的日期范围(包括结束日,共7天)"""
|
|
772
771
|
return TimeUtils.get_past_7_days_range(start_from)
|
|
773
772
|
|
|
774
|
-
|
|
775
773
|
def get_past_7_days_range_format(start_from: Optional[str] = None, format_str: str = '%Y-%m-%d') -> Tuple[str, str]:
|
|
776
774
|
"""获取过去7天的日期范围(包括结束日,共7天),支持自定义格式"""
|
|
777
775
|
return TimeUtils.get_past_7_days_range_format(start_from, format_str)
|
|
778
776
|
|
|
779
|
-
|
|
780
777
|
def get_past_nth_day(n: int, start_from: Optional[str] = None) -> str:
|
|
781
778
|
"""获取过去第n天的日期"""
|
|
782
779
|
return TimeUtils.get_past_nth_day(n, start_from)
|
|
783
780
|
|
|
784
|
-
|
|
785
781
|
def get_past_n_days_list(n: int, start_from: Optional[str] = None) -> List[str]:
|
|
786
782
|
"""获取过去n天的日期列表,从最旧到最近的日期"""
|
|
787
783
|
return TimeUtils.get_past_n_days_list(n, start_from)
|
|
788
784
|
|
|
789
|
-
|
|
790
785
|
def get_past_7_days_list(start_from: Optional[str] = None) -> List[str]:
|
|
791
786
|
"""获取过去7天的日期列表(不包含 start_from 当天),共7天"""
|
|
792
787
|
return TimeUtils.get_past_7_days_list(start_from)
|
|
793
788
|
|
|
794
|
-
|
|
795
789
|
def date_range(start_date: str, end_date: str) -> List[str]:
|
|
796
790
|
"""生成两个日期之间的日期列表"""
|
|
797
791
|
return TimeUtils.date_range(start_date, end_date)
|
|
798
792
|
|
|
799
|
-
|
|
800
793
|
def get_dates_from_first_of_month_to_yesterday() -> List[str]:
|
|
801
794
|
"""获取从本月第一天到昨天的日期列表"""
|
|
802
795
|
return TimeUtils.get_dates_from_first_of_month_to_yesterday()
|
|
803
796
|
|
|
804
|
-
|
|
805
797
|
def get_last_month_range() -> Tuple[str, str]:
|
|
806
798
|
"""获取上个月的第一天和最后一天"""
|
|
807
799
|
return TimeUtils.get_last_month_range()
|
|
808
800
|
|
|
809
|
-
|
|
810
801
|
def get_last_month_range_time_str() -> Tuple[str, str]:
|
|
811
802
|
"""获取上个月第一天和最后一天的时间字符串"""
|
|
812
803
|
return TimeUtils.get_last_month_range_time_str()
|
|
813
804
|
|
|
814
|
-
|
|
815
805
|
def get_last_month_range_time() -> Tuple[int, int]:
|
|
816
806
|
"""获取上个月第一天和最后一天的毫秒级时间戳"""
|
|
817
807
|
return TimeUtils.get_last_month_range_time()
|
|
818
808
|
|
|
819
|
-
|
|
820
809
|
# 为了向后兼容,保留一些旧函数名
|
|
821
810
|
def get_past_7_days_range_old() -> Tuple[str, str]:
|
|
822
811
|
"""获取过去7天的日期范围(旧版本)"""
|
|
@@ -824,7 +813,6 @@ def get_past_7_days_range_old() -> Tuple[str, str]:
|
|
|
824
813
|
start_date = end_date - timedelta(days=6) # 往前推6天为开始日期
|
|
825
814
|
return start_date.strftime('%Y-%m-%d'), end_date.strftime('%Y-%m-%d')
|
|
826
815
|
|
|
827
|
-
|
|
828
816
|
def get_past_7_days_list_old() -> List[str]:
|
|
829
817
|
"""获取过去7天的日期列表(旧版本)"""
|
|
830
818
|
today = datetime.today()
|
|
@@ -833,7 +821,6 @@ def get_past_7_days_list_old() -> List[str]:
|
|
|
833
821
|
for i in range(1, 8)
|
|
834
822
|
]
|
|
835
823
|
|
|
836
|
-
|
|
837
824
|
if __name__ == "__main__":
|
|
838
825
|
# 测试示例
|
|
839
826
|
print(f"当前日期: {today_date()}")
|