qrpa 1.0.9__py3-none-any.whl → 1.0.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.

Potentially problematic release.


This version of qrpa might be problematic. Click here for more details.

qrpa/time_utils.py CHANGED
@@ -11,44 +11,44 @@ from typing import Optional, Tuple, List, Union
11
11
 
12
12
  class TimeUtils:
13
13
  """时间工具类,提供各种时间相关的静态方法"""
14
-
14
+
15
15
  # ==================== 当前时间获取 ====================
16
-
16
+
17
17
  @staticmethod
18
18
  def get_current_date() -> str:
19
19
  """获取当前日期,格式为 YYYYMMDD"""
20
20
  return datetime.now().strftime('%Y%m%d')
21
-
21
+
22
22
  @staticmethod
23
23
  def get_current_datetime() -> str:
24
24
  """获取当前日期时间,格式为 YYYYMMDDHHMMSS"""
25
25
  return datetime.now().strftime('%Y%m%d%H%M%S')
26
-
26
+
27
27
  @staticmethod
28
28
  def current_datetime() -> str:
29
29
  """获取当前日期时间,格式为 YYYY-MM-DD HH:MM:SS"""
30
30
  return datetime.now().strftime('%Y-%m-%d %H:%M:%S')
31
-
31
+
32
32
  @staticmethod
33
33
  def today_date() -> str:
34
34
  """获取今天的日期,格式为 YYYY-MM-DD"""
35
35
  return datetime.now().strftime('%Y-%m-%d')
36
-
36
+
37
37
  @staticmethod
38
38
  def today_date_hour() -> str:
39
39
  """获取今天的日期和小时,格式为 YYYY-MM-DD_HH"""
40
40
  return datetime.now().strftime('%Y-%m-%d_%H')
41
-
41
+
42
42
  @staticmethod
43
43
  def get_current_year() -> int:
44
44
  """获取当前年份"""
45
45
  return datetime.now().year
46
-
46
+
47
47
  @staticmethod
48
48
  def get_current_month() -> int:
49
49
  """获取当前月份(1-12)"""
50
50
  return datetime.now().month
51
-
51
+
52
52
  @staticmethod
53
53
  def get_current_year_range() -> Tuple[str, str]:
54
54
  """获取当前年份的开始和结束日期"""
@@ -56,9 +56,9 @@ class TimeUtils:
56
56
  start_date = datetime(current_year, 1, 1).strftime('%Y-%m-%d')
57
57
  end_date = datetime(current_year, 12, 31).strftime('%Y-%m-%d')
58
58
  return start_date, end_date
59
-
59
+
60
60
  # ==================== 相对日期获取 ====================
61
-
61
+
62
62
  @staticmethod
63
63
  def get_yesterday(dt: Optional[str] = None) -> str:
64
64
  """
@@ -76,28 +76,28 @@ class TimeUtils:
76
76
  dt = datetime.strptime(dt, "%Y%m%d")
77
77
  yesterday = dt - timedelta(days=1)
78
78
  return yesterday.strftime("%Y-%m-%d")
79
-
79
+
80
80
  @staticmethod
81
81
  def before_yesterday() -> str:
82
82
  """获取前天的日期"""
83
83
  return (datetime.now().date() - timedelta(days=2)).strftime("%Y-%m-%d")
84
-
84
+
85
85
  @staticmethod
86
86
  def tomorrow_date() -> str:
87
87
  """获取明天的日期"""
88
88
  return (datetime.now().date() + timedelta(days=1)).strftime("%Y-%m-%d")
89
-
89
+
90
90
  @staticmethod
91
91
  def get_last_month() -> int:
92
92
  """获取上个月的月份"""
93
93
  today = datetime.today()
94
94
  last_month = today.month - 1 if today.month > 1 else 12
95
95
  return last_month
96
-
96
+
97
97
  # ==================== 日期范围计算 ====================
98
-
98
+
99
99
  @staticmethod
100
- def get_past_7_days_range(start_from: Optional[str] = None) -> Tuple[str, str]:
100
+ def get_past_7_days_range(start_from: Optional[str] = None, format_str: str = '%Y-%m-%d') -> Tuple[str, str,]:
101
101
  """
102
102
  获取过去7天的日期范围(包括结束日,共7天)
103
103
 
@@ -122,8 +122,8 @@ class TimeUtils:
122
122
  end_date = base_date - timedelta(days=1) # 默认昨天为结束
123
123
  start_date = end_date - timedelta(days=6) # 往前推6天为开始
124
124
 
125
- return start_date.strftime('%Y-%m-%d'), end_date.strftime('%Y-%m-%d')
126
-
125
+ return start_date.strftime(format_str), end_date.strftime(format_str)
126
+
127
127
  @staticmethod
128
128
  def get_past_7_days_range_format(start_from: Optional[str] = None, format_str: str = '%Y-%m-%d') -> Tuple[str, str]:
129
129
  """
@@ -148,9 +148,9 @@ class TimeUtils:
148
148
  start_date = end_date - timedelta(days=6) # 往前推6天为开始
149
149
 
150
150
  return start_date.strftime(format_str), end_date.strftime(format_str)
151
-
151
+
152
152
  @staticmethod
153
- def get_past_nth_day(n: int, start_from: Optional[str] = None) -> str:
153
+ def get_past_nth_day(n: int, start_from: Optional[str] = None, format_str: str = '%Y-%m-%d') -> str:
154
154
  """
155
155
  获取过去第n天的日期
156
156
 
@@ -174,8 +174,8 @@ class TimeUtils:
174
174
  base_date = datetime.today()
175
175
 
176
176
  past_date = base_date - timedelta(days=n)
177
- return past_date.strftime('%Y-%m-%d')
178
-
177
+ return past_date.strftime(format_str)
178
+
179
179
  @staticmethod
180
180
  def get_past_n_days_list(n: int, start_from: Optional[str] = None) -> List[str]:
181
181
  """
@@ -204,7 +204,7 @@ class TimeUtils:
204
204
  (base_date - timedelta(days=i)).strftime('%Y-%m-%d')
205
205
  for i in range(1, n + 1)
206
206
  ]
207
-
207
+
208
208
  @staticmethod
209
209
  def get_past_7_days_list(start_from: Optional[str] = None) -> List[str]:
210
210
  """
@@ -228,7 +228,7 @@ class TimeUtils:
228
228
  (base_date - timedelta(days=i)).strftime('%Y-%m-%d')
229
229
  for i in range(1, 8)
230
230
  ]
231
-
231
+
232
232
  @staticmethod
233
233
  def date_range(start_date: str, end_date: str) -> List[str]:
234
234
  """
@@ -257,7 +257,7 @@ class TimeUtils:
257
257
  current_date += timedelta(days=1)
258
258
 
259
259
  return date_list
260
-
260
+
261
261
  @staticmethod
262
262
  def get_dates_from_first_of_month_to_yesterday() -> List[str]:
263
263
  """获取从本月第一天到昨天的日期列表"""
@@ -273,9 +273,9 @@ class TimeUtils:
273
273
  current_date += timedelta(days=1)
274
274
 
275
275
  return date_list
276
-
276
+
277
277
  # ==================== 月份相关 ====================
278
-
278
+
279
279
  @staticmethod
280
280
  def get_last_month_range() -> Tuple[str, str]:
281
281
  """获取上个月的第一天和最后一天"""
@@ -287,7 +287,7 @@ class TimeUtils:
287
287
  last_day = datetime(year, last_month, calendar.monthrange(year, last_month)[1])
288
288
 
289
289
  return first_day.strftime("%Y-%m-%d"), last_day.strftime("%Y-%m-%d")
290
-
290
+
291
291
  @staticmethod
292
292
  def get_last_month_range_time_str() -> Tuple[str, str]:
293
293
  """获取上个月第一天和最后一天的时间字符串"""
@@ -302,7 +302,7 @@ class TimeUtils:
302
302
  end_time_str = last_day.strftime("%Y-%m-%d %H:%M:%S")
303
303
 
304
304
  return start_time_str, end_time_str
305
-
305
+
306
306
  @staticmethod
307
307
  def get_last_month_range_time() -> Tuple[int, int]:
308
308
  """获取上个月第一天和最后一天的毫秒级时间戳"""
@@ -317,7 +317,7 @@ class TimeUtils:
317
317
  end_timestamp = int(last_day.timestamp() * 1000)
318
318
 
319
319
  return start_timestamp, end_timestamp
320
-
320
+
321
321
  @staticmethod
322
322
  def is_in_month(time_str: str, month: int, fmt: str = "%Y-%m-%d") -> bool:
323
323
  """
@@ -336,16 +336,16 @@ class TimeUtils:
336
336
  return dt.month == month
337
337
  except ValueError:
338
338
  return False
339
-
339
+
340
340
  # ==================== 星期相关 ====================
341
-
341
+
342
342
  @staticmethod
343
343
  def get_week_num() -> int:
344
344
  """获取当前是第几周"""
345
345
  today = date.today()
346
346
  week_num = today.isocalendar()[1] # 返回 (year, week_num, weekday)
347
347
  return week_num
348
-
348
+
349
349
  @staticmethod
350
350
  def get_chinese_weekday(date_str: str) -> str:
351
351
  """
@@ -368,16 +368,16 @@ class TimeUtils:
368
368
  return weekday_cn[weekday_num]
369
369
  except ValueError as e:
370
370
  raise ValueError(f"日期格式错误,请输入'YYYY-MM-DD'格式的日期字符串。错误详情: {str(e)}")
371
-
371
+
372
372
  @staticmethod
373
373
  def get_weekday_name(date_str: str) -> str:
374
374
  """获取中文星期名称(简短格式)"""
375
375
  weekdays = ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
376
376
  date_obj = datetime.strptime(date_str, '%Y-%m-%d')
377
377
  return weekdays[date_obj.weekday()]
378
-
378
+
379
379
  # ==================== 时间段相关 ====================
380
-
380
+
381
381
  @staticmethod
382
382
  def get_period() -> str:
383
383
  """获取当前时间段(上午/下午/晚上)"""
@@ -388,16 +388,16 @@ class TimeUtils:
388
388
  return "下午"
389
389
  else:
390
390
  return "晚上"
391
-
391
+
392
392
  @staticmethod
393
393
  def get_period2() -> str:
394
394
  """获取当前时间段(AM/PM)"""
395
395
  now = datetime.now()
396
396
  period = now.strftime("%p") # 返回AM或者PM
397
397
  return period
398
-
398
+
399
399
  # ==================== 时间戳转换 ====================
400
-
400
+
401
401
  @staticmethod
402
402
  def convert_timestamp_to_str(timestamp_ms: Optional[int]) -> str:
403
403
  """
@@ -414,7 +414,7 @@ class TimeUtils:
414
414
  timestamp_s = int(timestamp_ms) / 1000
415
415
  dt = datetime.fromtimestamp(timestamp_s)
416
416
  return dt.strftime('%Y-%m-%d %H:%M:%S')
417
-
417
+
418
418
  @staticmethod
419
419
  def convert_timestamp_to_date(timestamp_ms: Union[int, float]) -> str:
420
420
  """
@@ -429,7 +429,7 @@ class TimeUtils:
429
429
  timestamp_s = timestamp_ms / 1000
430
430
  dt = datetime.fromtimestamp(timestamp_s)
431
431
  return dt.strftime('%Y-%m-%d')
432
-
432
+
433
433
  @staticmethod
434
434
  def get_start_timestamps(date_str: str) -> int:
435
435
  """
@@ -443,7 +443,7 @@ class TimeUtils:
443
443
  """
444
444
  start_of_day = datetime.strptime(date_str, "%Y-%m-%d")
445
445
  return int(start_of_day.timestamp() * 1000)
446
-
446
+
447
447
  @staticmethod
448
448
  def get_end_timestamps(date_str: str) -> int:
449
449
  """
@@ -458,9 +458,9 @@ class TimeUtils:
458
458
  start_of_day = datetime.strptime(date_str, "%Y-%m-%d")
459
459
  end_of_day = start_of_day + timedelta(days=1) - timedelta(milliseconds=1)
460
460
  return int(end_of_day.timestamp() * 1000)
461
-
461
+
462
462
  # ==================== 日期格式转换 ====================
463
-
463
+
464
464
  @staticmethod
465
465
  def convert_datetime_to_date(datetime_str: str) -> str:
466
466
  """
@@ -482,7 +482,7 @@ class TimeUtils:
482
482
  except ValueError:
483
483
  print(f"输入的时间字符串格式错误,需要 'YYYY-MM-DD HH:MM:SS' 格式,但得到: {datetime_str}")
484
484
  return datetime_str
485
-
485
+
486
486
  @staticmethod
487
487
  def date_trans(d_t: str) -> str:
488
488
  """
@@ -495,7 +495,7 @@ class TimeUtils:
495
495
  格式为 YYYYMMDD 的日期字符串
496
496
  """
497
497
  return datetime.strptime(d_t, "%Y-%m-%d").strftime("%Y%m%d")
498
-
498
+
499
499
  @staticmethod
500
500
  def format_date_cross_platform(date_str: str) -> str:
501
501
  """
@@ -513,9 +513,9 @@ class TimeUtils:
513
513
  return date_obj.strftime("%Y/%#m/%#d")
514
514
  else: # Linux, macOS等
515
515
  return date_obj.strftime("%Y/%-m/%-d")
516
-
516
+
517
517
  # ==================== 日期比较和判断 ====================
518
-
518
+
519
519
  @staticmethod
520
520
  def is_date_greater_or_equal(date_str: str) -> bool:
521
521
  """
@@ -535,7 +535,7 @@ class TimeUtils:
535
535
  except ValueError:
536
536
  print("日期格式不正确,请使用YYYY-MM-DD格式")
537
537
  return False
538
-
538
+
539
539
  @staticmethod
540
540
  def is_yesterday(create_time_str: str, dt: Optional[str] = None) -> bool:
541
541
  """
@@ -559,7 +559,7 @@ class TimeUtils:
559
559
 
560
560
  yesterday = dt - timedelta(days=1)
561
561
  return create_time.date() == yesterday.date()
562
-
562
+
563
563
  @staticmethod
564
564
  def is_yesterday_date(date_str: str) -> bool:
565
565
  """
@@ -579,9 +579,9 @@ class TimeUtils:
579
579
 
580
580
  yesterday = dt - timedelta(days=1)
581
581
  return create_time.date() == yesterday.date()
582
-
582
+
583
583
  # ==================== 文件时间相关 ====================
584
-
584
+
585
585
  @staticmethod
586
586
  def get_file_mtime(file_path: str, to_str: bool = True, tz_offset: int = 8) -> Union[str, datetime]:
587
587
  """
@@ -833,11 +833,11 @@ if __name__ == "__main__":
833
833
  print(f"当前周数: {get_week_num()}")
834
834
  print(f"当前时间段: {get_period()}")
835
835
  print(f"中文星期: {get_chinese_weekday(today_date())}")
836
-
836
+
837
837
  # 测试日期范围
838
838
  start, end = get_past_7_days_range()
839
839
  print(f"过去7天范围: {start} 到 {end}")
840
-
840
+
841
841
  # 测试时间戳转换
842
842
  current_ts = int(datetime.now().timestamp() * 1000)
843
843
  print(f"当前时间戳: {current_ts}")
qrpa/wxwork.py CHANGED
@@ -18,7 +18,6 @@ import base64
18
18
  import requests
19
19
  from requests_toolbelt import MultipartEncoder
20
20
 
21
-
22
21
  # 通过企微群机器人发送消息
23
22
  class WxWorkBot:
24
23
  def __init__(self, key):
@@ -59,7 +58,7 @@ class WxWorkBot:
59
58
  media_id = self.upload_media(file_path)
60
59
  data = {
61
60
  "msgtype": "file",
62
- "file": {
61
+ "file" : {
63
62
  "media_id": media_id
64
63
  }
65
64
  }
@@ -75,7 +74,7 @@ class WxWorkBot:
75
74
  """
76
75
  data = {
77
76
  "msgtype": "text",
78
- "text": {
77
+ "text" : {
79
78
  "content": content
80
79
  }
81
80
  }
@@ -93,7 +92,7 @@ class WxWorkBot:
93
92
  :return:
94
93
  """
95
94
  data = {
96
- "msgtype": "markdown",
95
+ "msgtype" : "markdown",
97
96
  "markdown": {
98
97
  "content": content
99
98
  }
@@ -109,9 +108,9 @@ class WxWorkBot:
109
108
  """
110
109
  data = {
111
110
  "msgtype": "image",
112
- "image": {
111
+ "image" : {
113
112
  "base64": self.img_to_base64(img_path),
114
- "md5": self.img_to_md5(img_path)
113
+ "md5" : self.img_to_md5(img_path)
115
114
  }
116
115
  }
117
116
  self.send_msg(data)
@@ -127,13 +126,13 @@ class WxWorkBot:
127
126
  """
128
127
  data = {
129
128
  "msgtype": "news",
130
- "news": {
129
+ "news" : {
131
130
  "articles": [
132
131
  {
133
- "title": title,
132
+ "title" : title,
134
133
  "description": description,
135
- "url": url,
136
- "picurl": picurl
134
+ "url" : url,
135
+ "picurl" : picurl
137
136
  }
138
137
  ]
139
138
  }
@@ -172,7 +171,6 @@ class WxWorkBot:
172
171
  image_data = image_file.read()
173
172
  return base64.b64encode(image_data).decode('utf-8')
174
173
 
175
-
176
174
  # 通过企微应用发送消息
177
175
  class WxWorkAppBot:
178
176
  def __init__(self, corpid, corpsecret, agentid):
@@ -256,7 +254,7 @@ class WxWorkAppBot:
256
254
  url = "https://qyapi.weixin.qq.com/cgi-bin/media/get"
257
255
  params = {
258
256
  "access_token": self.access_token,
259
- "media_id": media_id
257
+ "media_id" : media_id
260
258
  }
261
259
  response = requests.get(url=url, params=params)
262
260
  if response.status_code == 200:
@@ -271,4 +269,4 @@ class WxWorkAppBot:
271
269
  print("HTTP Error:", response.status_code)
272
270
  return None
273
271
  except Exception as err:
274
- raise Exception("get media error", err)
272
+ raise Exception("get media error", err)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: qrpa
3
- Version: 1.0.9
3
+ Version: 1.0.11
4
4
  Summary: qsir's rpa library
5
5
  Author: QSir
6
6
  Author-email: QSir <1171725650@qq.com>
@@ -0,0 +1,16 @@
1
+ qrpa/RateLimitedSender.py,sha256=hqvb1qspDFaW4RsLuVufylOrefkMgixANKeBaGEqYb4,1421
2
+ qrpa/__init__.py,sha256=OSN1T20XRX3uadTfmYrTbqETA6Y_tOca2bDodllnSkc,632
3
+ qrpa/db_migrator.py,sha256=2VmhzcMsU0MKpl-mNCwKyV8tLTqyEysSpP27-S_rQZ8,21862
4
+ qrpa/fun_base.py,sha256=W_owEa8-yuGG18n9kX3remm9YTzym69ztQjtYCNMTw4,3308
5
+ qrpa/fun_excel.py,sha256=aVSLcE3UJYnxvGi1XULM9qTbziUT7xlOcd2grnP6F3I,103615
6
+ qrpa/fun_file.py,sha256=BInN-Iuxi8sYiJ031gXI_DzO_n170RsOf7fnpkl_etM,7100
7
+ qrpa/fun_web.py,sha256=5QLQorAhRzMOGMRh4eCJ2UH8ZhVHvxkHwobWhmgU5qM,6286
8
+ qrpa/fun_win.py,sha256=-LnTeocdTt72NVH6VgLdpAT9_C5oV9okeudXG6CftMA,8034
9
+ qrpa/shein_ziniao.py,sha256=nSqqcEPh4nVQtUxUnIRzeZfTLyXywGPjPZn5pP-w57U,18309
10
+ qrpa/time_utils.py,sha256=ef0hhbN_6b-gcnz5ETIVOoxemIMvcxGVGGIRnHnGaBo,29564
11
+ qrpa/time_utils_example.py,sha256=shHOXKKF3QSzb0SHsNc34M61wEkkLuM30U9X1THKNS8,8053
12
+ qrpa/wxwork.py,sha256=IeJq-1LwKCsCt_AdMSLvYrQJWNoQp_wqVtk6iqwJqf4,9200
13
+ qrpa-1.0.11.dist-info/METADATA,sha256=TYJZ4HTibjVUL7-V67k_waJYRlohGYGVSbCWRVU3n-U,231
14
+ qrpa-1.0.11.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
15
+ qrpa-1.0.11.dist-info/top_level.txt,sha256=F6T5igi0fhXDucPPUbmmSC0qFCDEsH5eVijfVF48OFU,5
16
+ qrpa-1.0.11.dist-info/RECORD,,
@@ -1,13 +0,0 @@
1
- qrpa/__init__.py,sha256=bktAIMgoTJNYrhnDVEKP0qMy8mqvPWZLQ6G5bHRj3dU,454
2
- qrpa/db_migrator.py,sha256=2VmhzcMsU0MKpl-mNCwKyV8tLTqyEysSpP27-S_rQZ8,21862
3
- qrpa/fun_base.py,sha256=9bbtyfQsqyBXF-AU4wR5wPvr3qeqKU1ml5KS1ZODpLA,1229
4
- qrpa/fun_file.py,sha256=BInN-Iuxi8sYiJ031gXI_DzO_n170RsOf7fnpkl_etM,7100
5
- qrpa/fun_win.py,sha256=mPvojBYYvAcoXIGh_IXaNcA6x1qZAPGTRzwRvDb-WSU,1223
6
- qrpa/shein_ziniao.py,sha256=LjOCHUB5nPDnGta0Nq2sdy7_gtbwiFquLS2r7wh6J4c,17979
7
- qrpa/time_utils.py,sha256=NJHDoEiEv8oM7hIQAXZJ9YpbupS3WMSIwrzsytblMAg,29707
8
- qrpa/time_utils_example.py,sha256=shHOXKKF3QSzb0SHsNc34M61wEkkLuM30U9X1THKNS8,8053
9
- qrpa/wxwork.py,sha256=jJ6hOYvSRVo0pf37H845e0-DQnyC6-6qLtxy7-yh2Co,9163
10
- qrpa-1.0.9.dist-info/METADATA,sha256=IuwRcY8pQ49WV4iV0mnt3__WrBTNVMLFoJYW62HKt5E,230
11
- qrpa-1.0.9.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
12
- qrpa-1.0.9.dist-info/top_level.txt,sha256=F6T5igi0fhXDucPPUbmmSC0qFCDEsH5eVijfVF48OFU,5
13
- qrpa-1.0.9.dist-info/RECORD,,
File without changes