bot_ins_110100.py
83.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
# -*- coding: utf-8 -*-
import time
import re
import os
import datetime
from lxml import etree
import win32api
from win32.lib import win32con
from sibot.common import constant
from sibot.worker.bot.bot import Bot as RootBot
from selenium.webdriver.support.select import Select
from sibot.common.bot_log import BotLogger
from sibot.common import waclient
from sibot.common.utils import check_id_num
logger = BotLogger(os.path.basename(__file__), logname=2).getLogger()
class Bot(RootBot):
"""
北京地区社保缴纳机器人
"""
def __init__(self, job):
super(Bot, self).__init__(job)
self.login_url = "http://fuwu.rsj.beijing.gov.cn/csibiz/csirp/login.jsp"
self.login_url1 = "https://yzt.beijing.gov.cn/am/UI/Login?module=BjzwCert&goto=https%3A%2F%2Fyzt.beijing.gov.cn%2Fam%2Foauth2%2Fauthorize%3Fservice%3DbjzwService%26response_type%3Dcode%26client_id%3D688350606_02%26scope%3Dcn%2Buid%2BidCardNumber%2BextProperties%2BcredenceClass%26redirect_uri%3Dhttp%253A%252F%252Ffuwu.rsj.beijing.gov.cn%252Funitplatform%252FYZTAuth%26encoded%3Dfalse%26encoded%3Dfalse&lackFlag=NA"
# self.login_url = "https://yzt.beijing.gov.cn/am/UI/Login?module=BjzwCert&lackFlag=NA"
self.driver.implicitly_wait(30)
def login(self):
"""北京社保网站登录操作"""
for i in range(5):
try:
logger.info('start login beijing ----------')
self.driver.get(self.login_url1) # 登陆窗口
self.driver.implicitly_wait(30) # 隐式等待30秒
time.sleep(3)
# 旧登录方式抓取登陆错误方法
# sound_code = self.driver.page_source
# if '本月系统维护' in sound_code:
# message = etree.HTML(sound_code).xpath('/html/body/table/tbody/tr[1]/td/text()')
# message = message[0].replace('\n\t', '') + message[1].replace('\n\t', '').replace(' ', '')
# logger.error(message)
# return False
# 判断数字证书是否成功加载
# if not self.driver.find_elements_by_xpath('//*[@id="UserList"]/option'):
# logger.errors("证书加载失败")
# self.driver.refresh()
# continue
# 输入帐号密码等信息
# js = 'document.getElementById("wrapper").style.display="none";'
# self.driver.execute_script(js)
# js = 'document.getElementsByClassName("pop")[0].style.display="none";'
# self.driver.execute_script(js)
# time.sleep(1)
# self.driver.find_element_by_id('popButton1').click() # 选择北京市统一身份认证平台登录
# time.sleep(1)
# self.driver.find_element_by_id('popButton4').click() # 否
# time.sleep(8)
#
# self.driver.switch_to_frame('header') # 进入 frame表单
# self.driver.find_element_by_xpath('/html/body/div/div[1]/p/a[2]').click() # 点击法人登录
# self.driver.switch_to_default_content() # 退出 frame表单
time.sleep(2)
# current_window = self.driver.current_window_handle # 存储当前窗口的id
# all_windows = self.driver.window_handles # 获取打开的全部窗口
# for window in all_windows: # 循环全部窗口 直到有新的窗口
# if window != current_window:
# self.driver.switch_to.window(window) # switch_to.window 切换窗口
self.driver.maximize_window() # 新打开窗口全屏
time.sleep(2)
# self.driver.find_element_by_xpath('//*[@id="userId"]/ul/li[1]/a').click() # 点击证书登录
# time.sleep(4)
self.driver.find_element_by_id('password').send_keys(self.job.usb_cert_pwd) # usb_cert_pwd 证书密码
self.driver.find_element_by_xpath('//*[@id="cert_div"]/div[6]/input').click() # 点击登陆
self.driver.find_element_by_xpath('//*[@id="cert_div"]/div[6]/input').click() # 点击登陆
time.sleep(8)
# 旧登录方式抓取登陆错误方法
# try:
# alert_text = self.driver.switch_to_alert().text
# if '口令错误' in alert_text:
# logger.error('alert_text: {}'.format(alert_text))
# self.driver.switch_to_alert().accept()
# return False
# if '过期' in alert_text:
# logger.error('alert_text: {}'.format(alert_text))
# self.driver.switch_to_alert().accept()
# except Exception as e:
# logger.error(str(e))
# try:
# source_code = self.driver.page_source
# time.sleep(1)
# if '认证失败,请检查登录凭证是否正确' in source_code or '点击返回首页' in source_code:
# logger.error("发现并处理错误页面")
# return False
# except Exception as e:
# logger.error(str(e))
# 新的登陆方式抓取登陆错误方法
# 弹出框
# alert(一个按钮),confirm(两个按钮),prompt(两个按钮+输入框)
# driver.switch_to.alert.text # 获取弹出框的文本信息
# driver.switch_to.alert.accept() # 确认
# driver.switch_to.alert.dismiss() # 取消
try:
alert_text = self.driver.switch_to_alert().text # 获取弹出框 的文本
if '校验证书密码失败' in alert_text:
logger.error('alert_text: {}'.format(alert_text))
self.driver.switch_to_alert().accept() # 在弹出框上 点击确认
return False
if '输入证书密码' in alert_text:
logger.error('alert_text: {}'.format(alert_text))
self.driver.switch_to_alert().accept()
continue
if '过期' in alert_text:
logger.error('alert_text: {}'.format(alert_text))
self.driver.switch_to_alert().accept()
time.sleep(2)
sound_code = self.driver.page_source # 获取页面的数据/源码
time.sleep(1)
if '请检查登录凭证是否正确' in sound_code or '点击返回首页' in sound_code:
logger.error('页面错误,重新加载')
self.driver.refresh() # 刷新浏览器
continue
except Exception as e:
logger.error(str(e))
for j in range(1, 100): # 有问题
declare_xpath = \
self.driver.find_element_by_xpath('/html/body/div[3]/div/div[2]/ul/li[' + str(j) + ']/a')
declare_text = declare_xpath.text
if declare_text == '社会保险网上申报':
declare_xpath.click()
time.sleep(5)
break # 跳出整个循环
return True
except Exception as e:
logger.error(str(e))
self.driver.refresh()
continue # 跳出本次循环
return False
def __increase(self):
# 获取增员类型办理任务
# __get_tasks:获取指定条件的任务函数 constant:常量文件 OP_TYPE_INCREASE:增员 STATUS_INIT:状态初始化
tasks = self.__get_tasks(constant.OP_TYPE_INCREASE, constant.STATUS_INIT)
if not tasks:
return
self.close_notice() # 关闭页面悬浮div弹框
for task in tasks:
# waclient:请求sass平台文件 get_si_task:更新社保公积金待办任务
task_detail, err_code = waclient.get_si_task(self.ctx, task['id'])
if err_code != 200:
break
# 下载新参保人员证件照
if 'person_attachments' in task_detail:
attachs = task['person_attachments'] # 有问题
if attachs is not None and len(attachs) > 0:
file_object = attachs[0]
local_file_path, status_code = waclient.download_file(self.ctx, file_object) # download_file:获取云平台对象文件
if status_code == 200:
task_detail['idphoto'] = local_file_path # 有问题
response = self.do_increase(task_detail) # do_increase:北京社保增员操作
ins = self.get_all_ins(task_detail)
if not ins:
ins = ['医疗保险', '生育保险', '养老保险', '失业保险', '工伤保险']
result = self.return_ins_result(ins=ins, status=constant.STATUS_CONFORMING)
if not self.is_once_submit_increase():
hhr_type = ''
comment = response[1]
if self.is_once_submit():
return_status = constant.STATUS_SUCCESS
else:
return_status = constant.STATUS_CONFORMING
comment_list = response[1].split('#')
if len(comment_list) >= 2:
comment = comment_list[0]
hhr_type = comment_list[1]
print('---***---')
print(response)
print(comment)
print(return_status)
print(comment_list)
print(hhr_type)
# logger.info('---***---')
# logger.info(response)
# logger.info(comment)
# logger.info(return_status)
# logger.info(comment_list)
# logger.info(hhr_type)
if response[0] != constant.STATUS_INIT:
if not response[0]:
return_status = constant.STATUS_FAIL
result = self.return_ins_result(ins=ins, status=constant.STATUS_FAIL)
else:
return_status = constant.STATUS_INIT
result = self.return_ins_result(ins=ins, status=constant.STATUS_INIT)
if comment.isdigit():
return_status = constant.STATUS_SUCCESS
result = self.return_ins_result(ins=ins, status=constant.STATUS_SUCCESS)
if '不能进行转入人员增加' in comment:
return_status = constant.STATUS_SUCCESS
result = self.return_ins_result(ins=ins, status=constant.STATUS_SUCCESS)
response = waclient.update_si_task(self.ctx, task['id'], return_status, comment, hhr_type=hhr_type, result=result)
if response[1] != 200:
logger.error("Task Status Update Fail: " + str(task['id']))
if 'idphoto' in task_detail.keys():
self.del_batch_file(task_detail['idphoto'])
def do_increase(self, task):
"""北京社保增员操作"""
if task['handle_type'] == "0":
return self.new_ginseng(task) # 北京地区社保新参保
elif task['handle_type'] == "1": # 北京社保转入人员参保
return self.transfer_staff(task)
def new_ginseng(self, task):
"""北京地区社保新参保"""
id_num = task['insured_id_num']
name = task['insured_name']
# id_type = task['insured_id_type']
timestamp = task['start_month'] # 获取时间戳
payers = task['huji_type'] # 缴费人员类别
tel = task['insured_mobile']
wage = task['base']
nation = '汉族'
photo = ''
if 'idphoto' in task.keys():
photo = task['idphoto']
# 判断身份证号码的有效性
id_num = id_num.upper().replace(' ', '') # upper() 字符串小写转大写
if not check_id_num(id_num=id_num): # check_id_num:验证身份证号的正确性
return False, '请输入正确的身份证号: {}'.format(id_num)
if photo == '':
return False, '未上传证件照附件'
# 判断必须字段是否为空
if not name:
return False, '姓名为空'
if not photo:
return False, '电子照片为空'
if not timestamp:
return False, '参保工作日期有误'
if not payers:
return False, '缴费人员类别有误'
if not tel or len(tel) != 11 or not re.findall('^\d*$', tel):
return False, '手机号有误'
if not wage:
return False, '月均工资数据有误'
if payers == '外地农村':
payers = '外埠农村劳动力'
elif payers == '外地城镇':
payers = '外埠场镇职工'
elif payers == '本地城镇':
payers = '本地城镇职工'
elif payers == '本地农村':
payers = '本地农村劳动力'
time_local = time.localtime(timestamp)
work_date = time.strftime("%Y-%m-%d", time_local) # 将时间戳转换成格式时间
ext_infos = task['ext_info'] # ext_infos 里面包含了 非被填字段
per_nation = '工人' # 个人身份
hukou_address = '' # 户口所在地地址
hukou_code = '' # 户口所在地邮政编码
now_address = '' # 居住地联系地址
now_address_code = '' # 居住地联系邮政编码
bill_way = '网上查询' # 对账单方式
education = '大学' # 文化程度
bank_name = '' # 委托代发银行名称
bank_num = '' # 委托代发银行账号
medical1 = '' # 定点医疗机构1
medical2 = '' # 定点医疗机构2
medical3 = '' # 定点医疗机构3
medical4 = '' # 定点医疗机构4
medical5 = '' # 定点医疗机构5
four_save_reason = '其它新参统' # 四险个人缴费原因
# 开始对每个扩展字段进行查询和赋值
staff_type = '' # 员工类型
uniform_code = '' # 统一社会信用代码
uniform = '' # 用工单位
work_post = '' # 岗位
salary = '' # 合同约定工资薪金
laborStartDate = '' # 劳动合同开始时间
laborEndDate = '' # 劳动合同结束时间
contract_type = '固定期限劳动合同'
singed_contract = ''
# 开始对每个扩展字段进行查询和赋值 # 有问题
for ext_info in ext_infos:
if ext_info['name'] == '个人身份':
per_nation = ext_info['value']
if ext_info['name'] == '户口所在地地址':
hukou_address = ext_info['value']
if ext_info['name'] == '户口所在地邮政编码':
hukou_code = ext_info['value'].replace(' ', '')
if ext_info['name'] == '居住地(联系)地址':
now_address = ext_info['value']
if ext_info['name'] == '居住地(联系)邮政编码':
now_address_code = ext_info['value']
if '对账单方式' in ext_info['name']:
bill_way = ext_info['value']
if ext_info['name'] == '文化程度':
education = ext_info['value']
if ext_info['name'] == '委托代发银行名称':
bank_name = ext_info['value']
if bank_name == "北京银行" or bank_name == "农商银行" or bank_name == "广发银行":
bank_name += "(只限本市)"
if ext_info['name'] == '委托代发银行账号':
bank_num = ext_info['value'].replace(' ', '')
if ext_info['name'] == '定点医疗机构1':
medical1 = ext_info['value'].replace(' ', '')
if ext_info['name'] == '定点医疗机构2':
medical2 = ext_info['value'].replace(' ', '')
if ext_info['name'] == '定点医疗机构3':
medical3 = ext_info['value'].replace(' ', '')
if ext_info['name'] == '定点医疗机构4':
medical4 = ext_info['value'].replace(' ', '')
if ext_info['name'] == '定点医疗机构5':
medical5 = ext_info['value'].replace(' ', '')
if ext_info['name'] == '民族':
nation = ext_info['value']
if '族' not in nation:
nation += '族'
if '四险个人缴费原因' in ext_info['name']:
four_save_reason = ext_info['value'].replace(' ', '')
if ext_info['name'] == '员工类型':
staff_type = ext_info['value']
if ext_info['name'] == '统一社会信用代码':
uniform_code = ext_info['value']
if ext_info['name'] == '用工单位':
uniform = ext_info['value']
if ext_info['name'] == '岗位':
work_post = ext_info['value']
if ext_info['name'] == '劳动合同约定工资':
salary = ext_info['value']
if ext_info['name'] == '劳动合同起止时间':
laborStartDate = ext_info['value']
if ext_info['name'] == '劳动合同结束时间':
laborEndDate = ext_info['value']
if ext_info['name'] == '是否已签订电子劳动合同':
singed_contract = ext_info['value']
# 判断用户扩展字段的完整性
if not hukou_address:
return False, '户口所在地地址为空' # 有问题
if not hukou_code:
return False, '户口所在地邮政编码为空'
if not now_address:
now_address = hukou_address
if not now_address_code:
now_address_code = hukou_code
if not bank_name:
return False, '委托代发银行名称为空'
if not bank_num:
return False, '委托代发银行账号为空'
if not medical1:
return False, '定点医疗机构1为空'
if not medical2:
return False, '定点医疗机构2为空'
if per_nation not in ['工人', '干部']:
return False, '个人身份数据有误'
if not task['insurances']:
return False, '参加险种为空'
if not contract_type:
contract_type = '固定期限劳动合同'
if not education:
education = '大学'
if not singed_contract:
singed_contract = '否'
# 判断区分人力资源账户和单立户
if self.job.mark == '人力资源':
if not staff_type:
staff_type = '本单位员工'
# return False, '员工类型为空'
if not uniform_code:
return False, '统一社会信用代码为空'
if not work_post:
return False, '岗位为空'
if not salary:
salary = wage
# return False, '合同约定工资薪金为空'
if not laborStartDate:
return False, '劳动合同起止时间'
if not laborEndDate:
return False, '劳动合同结束时间为空'
comment = '网络或服务器繁忙,请稍后再试'
for i in range(3):
status, comment = self.check_nav_show(div_id='level:1', one_id='link000', two_id='link002') # check_nav_show:检查左侧导航是否显示二级导航
if not status:
return constant.STATUS_INIT, comment
self.driver.switch_to.default_content()
try:
self.driver.find_element_by_xpath('/html/body/div[last()]/div[@class="popup_top"]/h2/a').click()
except Exception as e:
logger.info('没有提示')
logger.error(str(e))
time.sleep(2)
try:
self.driver.find_element_by_xpath('/html/body/div[@class="popwrap"]/div/h2/a').click()
except Exception as e:
logger.info('没有提示')
logger.error(str(e))
self.driver.switch_to.default_content()
self.driver.switch_to.frame('center')
self.driver.switch_to.frame('mainFrame')
try:
self.driver.find_element_by_id('idcard').send_keys(id_num) # 输入身份证号
self.driver.find_element_by_id('name').send_keys(name) # 输入姓名
select = Select(self.driver.find_element_by_id("cardType")) # 证件类型
select.select_by_visible_text('居民身份证') # select_by_visible_text 下拉框的文本值
time.sleep(1)
self.driver.find_element_by_id('reg').click() # 确定
time.sleep(1)
# self.driver.switch_to.default_content()
# self.driver.switch_to.frame('center')
# try:
# self.driver.find_element_by_xpath('/html/body/div[@class="popwrap"]/div/h2/a').click()
# except Exception as e:
# logger.info('没有提示')
# logger.error(str(e))
try: # 有问题
# '/html/body/table[2]/tbody/tr/td/table[1]/tbody/tr/td/font/ul/li/span').text
source_text = self.driver.page_source
# if '系统提示' in source_text:
# js_ad = "var aa=document.getElementsByClassName('popup_top')[0];aa.parentNode.removeChild(aa)"
# self.driver.execute_script(js_ad)
# else:
# logger.info('没有广告')
if re.findall('业务系统中已有该身份证号', source_text):
return False, "业务系统中已有该身份证号"
elif re.findall('个人信息登记业务中已存在', source_text):
# 点击【编辑按钮】
lists = self.driver.find_elements_by_xpath('//*[@id="allform"]/table[1]/tbody/tr')[1:]
for k in range(len(lists)):
try:
count = k + 2
xpath1 = "//*[@id='allform']/table[1]/tbody/tr[" + str(count) + "]/td[2]/div[1]/input[2]"
card_num = self.driver.find_element_by_xpath(xpath1).get_attribute('value')
if id_num in card_num:
xpath2 = "//*[@id='allform']/table[1]/tbody/tr[" + str(count) + "]/td[9]/div/a"
self.driver.find_element_by_xpath(xpath2).click()
break
except Exception as e:
logger.error(str(e))
except Exception as e:
logger.error(str(e))
time.sleep(2)
# is_selected
ylbx_check = self.driver.find_element_by_id('kinds-1')
if not ylbx_check.is_selected():
ylbx_check.click()
sybx_check = self.driver.find_element_by_id('kinds-2')
if not sybx_check.is_selected():
sybx_check.click()
gsbx_check = self.driver.find_element_by_id('kinds-3')
if not gsbx_check.is_selected():
gsbx_check.click()
syubx_check = self.driver.find_element_by_id('kinds-4')
if not syubx_check.is_selected():
syubx_check.click()
jbylbx_check = self.driver.find_element_by_id('kinds-5')
if not jbylbx_check.is_selected():
jbylbx_check.click()
# self.driver.find_element_by_id('name').clear()
# self.driver.find_element_by_id('name').send_keys(name) # 姓名
select = Select(self.driver.find_element_by_id("psnstatus")) # 个人身份
select.select_by_visible_text(per_nation) #定位 select 下拉框
self.driver.find_element_by_id('workdate').clear()
self.driver.find_element_by_id('workdate').send_keys(work_date) # 工作日期
js = "document.getElementById('photo').setAttribute('onchange',' ')" # 去除弹窗
self.driver.execute_script(js)
self.driver.find_element_by_id('photo').send_keys(photo) # 上传照片
time.sleep(1)
self.driver.find_element_by_id('photobutton').click() # 上传
time.sleep(3)
select_nation = Select(self.driver.find_element_by_id('nation')) # 设置名族
select_nation.select_by_visible_text(nation)
select = Select(self.driver.find_element_by_id("feepsntype")) # 缴费人员类别
select.select_by_index(0) # 下拉框的索引
time.sleep(0.5)
select.select_by_visible_text(payers)
self.driver.find_element_by_id('residentaddr').clear()
self.driver.find_element_by_id('residentaddr').send_keys(hukou_address) # 籍贯
self.driver.find_element_by_id('residentzip').clear()
self.driver.find_element_by_id('residentzip').send_keys(hukou_code) # 籍贯邮编
self.driver.find_element_by_id("address").clear() # 清除输入框内容
self.driver.find_element_by_id('address').send_keys(now_address) # 现住址
self.driver.find_element_by_id('zip').clear()
self.driver.find_element_by_id('zip').send_keys(now_address_code) # 现住址邮编
select = Select(self.driver.find_element_by_id('getBillMethod')) # 对账单方式
select.select_by_visible_text(bill_way)
select = Select(self.driver.find_element_by_id('education')) # 文化程度
select.select_by_visible_text(education)
self.driver.find_element_by_id('tel').clear()
self.driver.find_element_by_id('tel').send_keys(tel) # 手机号
self.driver.find_element_by_id('cellphone').clear()
self.driver.find_element_by_id('cellphone').send_keys(tel)
self.driver.find_element_by_id('salary').clear()
self.driver.find_element_by_id('salary').send_keys(wage)
bank_list = self.driver.find_elements_by_xpath('//*[@id="deputybank"]/option')
select = Select(self.driver.find_element_by_id('deputybank')) # 委托代发银行名称
for item in bank_list:
if item.text in bank_name:
select.select_by_visible_text(item.text)
break
self.driver.find_element_by_id('deputybankaccount').clear()
self.driver.find_element_by_id('deputybankaccount').send_keys(bank_num) # 银行卡号
# 配置定点医疗机构1
self.driver.find_element_by_id('set1').click() # 配置定点医疗机构1
self.driver.switch_to.frame('hosp1Frame') # 切换到frame下寻找元素
self.driver.find_element_by_id('personInfoReg_search').send_keys(medical1) # 输入医院1
self.driver.find_elements_by_tag_name('input')[2].click()
time.sleep(1)
tds = self.driver.find_elements_by_tag_name('td')
if len(tds) <= 4:
return False, '定点医疗机构1不存在'
# 选择查询到的医疗机构1
inputs = self.driver.find_elements_by_tag_name('input')
for item in inputs:
if item.get_attribute('value') == '选择':
item.click()
break
self.driver.switch_to.default_content() # 退出frame
self.driver.switch_to.frame('center')
self.driver.switch_to.frame('mainFrame') # 切换到frame下寻找元素
time.sleep(1)
# 配置定点医疗机构2
self.driver.find_element_by_id('set2').click() # 配置定点医疗机构1
self.driver.switch_to.frame('hosp2Frame') # 切换到frame下寻找元素
self.driver.find_element_by_id('personInfoReg_search').send_keys(medical2) # 输入医院2
self.driver.find_elements_by_tag_name('input')[2].click()
time.sleep(1)
tds = self.driver.find_elements_by_tag_name('td')
if len(tds) <= 4:
return False, '定点医疗机构2不存在'
# 选择查询到的医疗机构1
inputs = self.driver.find_elements_by_tag_name('input')
for j in inputs:
if j.get_attribute('value') == '选择':
j.click()
break
self.driver.switch_to.default_content() # 退出frame
self.driver.switch_to.frame('center')
self.driver.switch_to.frame('mainFrame') # 切换到frame下寻找元素
time.sleep(1)
# 配置定点医疗机构3
if medical3:
self.__select_medical('set3', 'hosp3Frame', medical3)
# 配置定点医疗机构4
if medical4:
self.__select_medical('set4', 'hosp4Frame', medical4)
# 配置定点医疗机构5
if medical5:
self.__select_medical('set5', 'hosp5Frame', medical5)
select = Select(self.driver.find_element_by_id('hosReason')) # 医保个人缴费原因
select.select_by_visible_text('新参统')
select = Select(self.driver.find_element_by_id('fourReason')) # 四险个人缴费原因
select.select_by_visible_text(four_save_reason)
# 新增中新加字段
if self.job.mark == '人力资源':
# js_val = 'document.getElementById("staffType").value="劳务外包员工"'
select = Select(self.driver.find_element_by_id("staffType")) # 员工类型
select.select_by_visible_text(staff_type)
# self.driver.execute_script(js_val)
# time.sleep(1)
# self.driver.find_element_by_id('staffType').send_keys('劳务外包员工')
time.sleep(1)
# js = "document.getElementById('photo').setAttribute('onchange',' ')" # 去除弹窗
# self.driver.execute_script(js)
if staff_type == '劳务外包员工':
time.sleep(3)
self.new_system_prompt()
# js_cl1 = "document.getElementsByTagName('div')[1].style.display='none'"
# self.driver.execute_script(js_cl1)
# time.sleep(2)
# js = "document.getElementById('coverTop').style.display='none'"
# self.driver.execute_script(js)
# self.left_click(1259, 357)
time.sleep(1)
if staff_type != '本单位员工':
self.driver.find_element_by_id('employerUscc').send_keys(uniform_code) # 输入社会统一信用代码
# TODO 统一信用代码输入错误处理
js = "document.getElementById('employerDeptName').removeAttribute('readonly')" # 删除元素
self.driver.execute_script(js)
time.sleep(1)
self.driver.find_element_by_id('employerDeptName').send_keys(uniform) # 填写用工单位名称
# 设置合同开始时间
try:
time.sleep(1)
js_start = 'document.getElementById("laborStartDate").value="%s";' % (laborStartDate) #
self.driver.execute_script(js_start)
time.sleep(2)
js_end = 'document.getElementById("laborEndDate").value="%s";' % (laborEndDate) #
self.driver.execute_script(js_end)
# self.driver.switch_to_default_content()
# self.driver.switch_to.frame('center')
# self.driver.switch_to.frame('mainFrame')
# self.driver.find_element_by_id('laborStartDate').clear()
# self.driver.find_element_by_id('laborStartDate').send_keys(laborStartDate) # 输入劳动合同开始时间
# self.driver.switch_to.frame(0)
# self.driver.find_element_by_id('dpTodayInput').click() # 点击日期窗口的今天按钮
except Exception as e:
logger.error(str(e))
self.driver.refresh()
continue
time.sleep(1)
# 设置合同结束时间
# try:
# # self.driver.switch_to_default_content()
# # self.driver.switch_to.frame('center')
# # self.driver.switch_to.frame('mainFrame')
# # year, month, day = self.__date()
# js = "document.getElementById('laborEndDate').removeAttribute('readonly')" # 删除元素
# self.driver.execute_script(js)
# # endDay = str(year) + '-' + str(month) + '-' + str(day)
# self.driver.find_element_by_id('laborEndDate').send_keys(laborEndDate) # 输入合同结束时间
# self.driver.find_element_by_xpath(
# '//*[@id="newform"]/table[1]/tbody/tr/td/table/tbody/tr[9]/td[1]/strong').click()
# time.sleep(1)
# except Exception as e:
# logger.error(str(e))
# self.driver.refresh()
# continue
time.sleep(2)
# 劳动合同类型
select = Select(self.driver.find_element_by_id("laborContractType"))
select.select_by_visible_text(contract_type)
time.sleep(2)
if singed_contract in '否':
self.driver.find_element_by_id('signElectronicLabor0').click()
else:
self.driver.find_element_by_id('signElectronicLabor1').click()
time.sleep(2)
# self.driver.find_element_by_xpath(
# '//*[@id="newform"]/table[1]/tbody/tr/td/table/tbody/tr[9]/td[1]/strong').click()
# self.driver.find_element_by_id('employerDeptName').click() # 带出用工单位名称
select = Select(self.driver.find_element_by_id("workPost")) # 岗位
select.select_by_visible_text(work_post)
self.driver.find_element_by_id('contractSalary').send_keys(salary) # 合同约定工资薪金
time.sleep(1)
time.sleep(2)
self.driver.find_element_by_id('submitshow').click() # 提交按钮
try:
time.sleep(1)
self.driver.switch_to_alert().accept() # 弹窗处理
except Exception as e:
logger.error(str(e))
try:
time.sleep(1)
self.new_system_prompt()
except Exception as e:
logger.error(str(e))
time.sleep(2)
for _ in range(3):
try:
# 确认用户信息悬浮框
time.sleep(3)
self.driver.find_element_by_xpath('//*[@id="newDiv"]/button[1]').click()
break
except Exception as e:
logger.error(str(e))
time.sleep(2)
continue
for m in range(3):
# 处理操作业务成功的逻辑
try:
msg = self.driver.find_element_by_xpath('/html/body/div[2]/form[1]/table[1]/tbody/tr[1]/td[1]/div[1]/span').text
if '业务导入失败' in msg:
logger.error(msg)
return True, msg
elif '业务导入成功' in msg:
logger.info(msg)
gov_ids = re.findall('\d{16}', msg)
if gov_ids:
gov_id = gov_ids[0].strip()
return True, gov_id
except Exception as e:
logger.error(str(e))
return True, "等待查询反馈"
except Exception as e:
logger.error(str(e))
self.driver.refresh()
continue
return constant.STATUS_INIT, comment
def transfer_staff(self, task):
"""北京社保转入人员参保"""
id_num = task['insured_id_num']
name = task['insured_name']
wage = task['base']
id_num = id_num.upper().replace(' ', '')
if not check_id_num(id_num=id_num):
logger.error('请输入正确的身份证号: {}'.format(id_num))
return False, '请输入正确的身份证号: {}'.format(id_num)
ext_infos = task['ext_info']
staff_type = '' # 员工类型
uniform_code = '' # 统一社会信用代码
uniform = '' # 用工单位
work_post = '' # 岗位
salary = '' # 合同约定工资薪金
laborStartDate = '' # 劳动合同开始时间
laborEndDate = '' # 劳动合同结束时间
contract_type = ''
singed_contract = ''
for ext_info in ext_infos:
if ext_info['name'] == '员工类型':
staff_type = ext_info['value']
if ext_info['name'] == '统一社会信用代码':
uniform_code = ext_info['value']
if ext_info['name'] == '用工单位':
uniform = ext_info['value']
if ext_info['name'] == '岗位':
work_post = ext_info['value']
if ext_info['name'] == '合同约定工资薪金':
salary = ext_info['value']
if ext_info['name'] == '劳动合同开始时间':
laborStartDate = ext_info['value']
if ext_info['name'] == '劳动合同结束时间':
laborEndDate = ext_info['value']
if ext_info['name'] == '劳动合同类型':
contract_type = ext_info['value']
if ext_info['name'] == '是否已签订电子劳动合同':
singed_contract = ext_info['value']
# 判断区分人力资源账户和单立户
if self.job.mark == '人力资源':
if not staff_type:
staff_type = '本单位员工'
# return False, '员工类型为空'
if not uniform_code:
return False, '统一社会信用代码为空'
if not work_post:
return False, '岗位为空'
if not salary:
salary = wage
# return False, '合同约定工资薪金为空'
if not laborStartDate:
return False, '劳动合同开始时间为空'
if not laborEndDate:
return False, '劳动合同结束时间为空'
if not contract_type:
contract_type = '固定期限劳动合同'
if not singed_contract:
singed_contract = '否'
comment = '网络或服务器繁忙,请稍后再试'
for i in range(3):
status, comment = self.check_nav_show(div_id='level:1', one_id='link000', two_id='link003')
if not status:
return constant.STATUS_INIT, comment
self.system_prompt()
try:
time.sleep(1)
self.driver.find_element_by_xpath('//*[@id="Layer2"]/table/tbody/tr[1]/td[2]/a').click() # 点击关闭
except Exception as e:
logger.error(str(e))
self.driver.switch_to.default_content()
try:
# self.driver.find_element_by_xpath('/html/body/div[@class="popwrap"]/div/h2/a').click()
self.driver.find_element_by_xpath('/html/body/div[last()]/div[@class="popup_top"]/h2/a').click()
except Exception as e:
logger.info('没有提示')
logger.error(str(e))
time.sleep(2)
try:
self.driver.find_element_by_xpath('/html/body/div[@class="popwrap"]/div/h2/a').click()
except Exception as e:
logger.info('没有提示')
logger.error(str(e))
self.driver.switch_to.default_content()
self.driver.switch_to.frame('center')
self.driver.switch_to.frame('mainFrame')
try:
time.sleep(1)
self.driver.find_element_by_id('button').click() # 点击普通增员
except Exception as e:
logger.error(str(e))
self.driver.refresh()
continue
try:
time.sleep(1)
self.driver.find_element_by_xpath('//*[@id="Layer2"]/table/tbody/tr[1]/td[2]/a').click() # 点击关闭
except Exception as e:
logger.error(str(e))
try:
self.driver.find_element_by_id('dataNormalAdd.idCard').send_keys(id_num) # 输入身份证号
self.driver.find_element_by_id('dataNormalAdd.personName').send_keys(name) # 输入姓名
self.driver.find_element_by_xpath('//*[@id="newform"]/table[1]/tbody/tr/td/table/tbody/tr[2]/td[2]/label[2]/input').click() # 点击查询
time.sleep(1)
# 判断该人员是否可以正常转入
card_text = self.driver.find_element_by_xpath("//*[@id='listzone']/table[2]/tbody/tr[1]/td[1]/table[1]/tbody/tr[2]/td[2]").text
if id_num not in card_text:
cause = self.driver.find_element_by_xpath("//*[@id='messages']/ul[1]/li[1]/span").text
if '查询结果为空' in cause or '不能进行转入人员增加' in cause:
return False, cause
return True, cause
person_type = self.driver.find_element_by_xpath('//*[@id="listzone"]/table[2]/tbody/tr/td/table/tbody/tr[5]/td[2]').text
person_type = person_type.replace(' ', '').replace('\n', '').replace('\t', '')
hhr_type = person_type # 转入人员必须返回户籍类型
logger.info("转入户籍类型:" + str(hhr_type))
if person_type == '自由职业人员':
person_type = '本市城镇职工'
elif person_type == '本市农村劳动力(24号文)':
person_type = '本市农村劳动力(养24号文)'
elif person_type == '灵活就业':
logger.info('户籍类型:灵活就业')
return False, person_type
select = Select(self.driver.find_element_by_id('personType')) # 缴费人员类别
select.select_by_visible_text(person_type)
self.driver.find_element_by_id('pay').send_keys(wage) # 申报月工资收入
# logger.info('备注字段:{}'.format(self.job.mark))
if self.job.mark in '人力资源':
print(self.job.mark)
time.sleep(2)
select = Select(self.driver.find_element_by_id("staffType")) # 员工类型
select.select_by_visible_text(staff_type)
time.sleep(1)
# 设置合同开始时间
try:
time.sleep(1)
js_start = 'document.getElementById("laborStartDate").value="%s";' % (laborStartDate) #
self.driver.execute_script(js_start)
time.sleep(2)
js_end = 'document.getElementById("laborEndDate").value="%s";' % (laborEndDate) #
self.driver.execute_script(js_end)
# self.driver.switch_to_default_content()
# self.driver.switch_to.frame('center')
# self.driver.switch_to.frame('mainFrame')
# self.driver.find_element_by_id('laborStartDate').clear()
# self.driver.find_element_by_id('laborStartDate').send_keys(laborStartDate) # 输入劳动合同开始时间
# self.driver.switch_to.frame(0)
# self.driver.find_element_by_id('dpTodayInput').click() # 点击日期窗口的今天按钮
except Exception as e:
logger.error(str(e))
self.driver.refresh()
continue
time.sleep(1)
# 设置合同结束时间
# try:
# # self.driver.switch_to_default_content()
# # self.driver.switch_to.frame('center')
# # self.driver.switch_to.frame('mainFrame')
# # year, month, day = self.__date()
# js = "document.getElementById('laborEndDate').removeAttribute('readonly')" # 删除元素
# self.driver.execute_script(js)
# # endDay = str(year) + '-' + str(month) + '-' + str(day)
# self.driver.find_element_by_id('laborEndDate').send_keys(laborEndDate) # 输入合同结束时间
# self.driver.find_element_by_xpath('//*[@id="newform"]/table[1]/tbody/tr/td/table/tbody/tr[9]/td[1]/strong').click()
# time.sleep(1)
# except Exception as e:
# logger.error(str(e))
# self.driver.refresh()
# continue
# 劳动合同类型
select = Select(self.driver.find_element_by_id("laborContractType"))
select.select_by_visible_text(contract_type)
time.sleep(2)
# 签订劳动合同时间
# self.driver.find_element_by_id('laborSignDate').clear()
# self.driver.find_element_by_id('laborSignDate').send_keys(laborStartDate)
# self.driver.switch_to_default_content()
# self.driver.switch_to.frame('center')
# self.driver.switch_to.frame('mainFrame')
time.sleep(2)
if staff_type == '劳务外包员工':
self.system_prompt()
if staff_type != '本单位员工':
self.driver.find_element_by_id('employerUscc').send_keys(uniform_code) # 输入社会统一信用代码
# TODO 统一信用代码输入错误处理
js = "document.getElementById('employerDeptName').removeAttribute('readonly')" # 删除元素
self.driver.execute_script(js)
time.sleep(1)
# self.driver.find_element_by_id('employerDeptName').send_keys(uniform) # 填写用工单位名称
self.driver.find_element_by_id('employerDeptName').click() # 填写用工单位名称
# self.driver.find_element_by_xpath(
# '//*[@id="newform"]/table[1]/tbody/tr/td/table/tbody/tr[9]/td[1]/strong').click()
# self.driver.find_element_by_id('employerDeptName').click() # 带出用工单位名称
select = Select(self.driver.find_element_by_id("workPost")) # 岗位
select.select_by_visible_text(work_post)
self.driver.find_element_by_id('contractSalary').send_keys(salary) # 合同约定工资薪金
time.sleep(2)
# 是否已签订电子劳动合同
if singed_contract in '否':
time.sleep(2)
self.driver.find_element_by_id('signElectronicLabor0').click()
else:
time.sleep(2)
self.driver.find_element_by_id('signElectronicLabor1').click()
else:
try:
time.sleep(1) #
js_start = 'document.getElementById("laborStartDate").value="%s";' % (laborStartDate) #
self.driver.execute_script(js_start)
time.sleep(2)
js_end = 'document.getElementById("laborEndDate").value="%s";' % (laborEndDate) #
self.driver.execute_script(js_end)
except Exception as e:
logger.error(str(e))
self.driver.refresh()
continue
time.sleep(1)
# 劳动合同类型
select = Select(self.driver.find_element_by_id("laborContractType"))
select.select_by_visible_text(contract_type)
time.sleep(2)
select = Select(self.driver.find_element_by_id("workPost")) # 岗位
select.select_by_visible_text(work_post)
time.sleep(2)
self.driver.find_element_by_id('contractSalary').send_keys(salary) # 合同约定工资薪金
time.sleep(2)
# 是否已签订电子劳动合同
if singed_contract in '否':
time.sleep(2)
self.driver.find_element_by_id('signElectronicLabor0').click()
else:
time.sleep(2)
self.driver.find_element_by_id('signElectronicLabor1').click()
time.sleep(1)
# return True, '等待查询反馈'
self.driver.find_element_by_id('submitButton').click() # 点击【提交】
# 判断弹窗错误信息
try:
alert_text = self.driver.switch_to_alert().text
logger.error('{}'.format(alert_text))
self.driver.switch_to_alert().accept()
return False, alert_text
except Exception as e:
logger.error(str(e))
for k in range(4):
time.sleep(2)
sound_code = self.driver.page_source
if '人员已处于正常缴费状态' in sound_code:
return True, '等待查询反馈' + '#' + hhr_type
elif '业务操作失败' in sound_code:
logger.error('业务操作失败')
cause = self.driver.find_element_by_xpath('//*[@id="0"]/td/table/tbody/tr[3]/td/span/span').text
return True, cause + '#' + hhr_type
elif '业务操作成功' in sound_code:
gov_id = self.driver.find_element_by_xpath('//*[@id="0"]/td/table/tbody/tr[2]/td/span/span').text
logger.info("转入流水号:" + str(gov_id))
if gov_id:
gov_id = gov_id.replace(' ', '')
return True, gov_id + '#' + hhr_type
return True, '等待查询反馈'
except Exception as e:
logger.error(str(e))
self.driver.refresh()
continue
return constant.STATUS_INIT, comment
def __decrease(self): # 有问题
logger.info('start decrease ')
tasks = self.__get_tasks(constant.OP_TYPE_DECREASE, constant.STATUS_INIT)
if not tasks:
return
try:
self.close_notice()
except Exception as e:
logger.info(str(e))
for task in tasks:
task_detail, err_code = waclient.get_si_task(self.ctx, task['id'])
if err_code != 200:
break
response = self.do_decrease(task_detail)
comment = response[1]
# logger.info(('---***---'))
# logger.info(response)
# logger.info(comment)
ins = self.get_all_ins(task_detail)
if not ins:
ins = ['医疗保险', '生育保险', '养老保险', '失业保险', '工伤保险']
result = self.return_ins_result(ins=ins, status=constant.STATUS_CONFORMING)
if self.is_once_submit():
return_status = constant.STATUS_SUCCESS
result = self.return_ins_result(ins=ins, status=constant.STATUS_SUCCESS)
else:
return_status = constant.STATUS_CONFORMING
# if response[0] != constant.STATUS_INIT:
# if not response[0]:
# return_status = constant.STATUS_FAIL
# result = self.return_ins_result(ins=ins, status=constant.STATUS_FAIL)
# else:
# return_status = constant.STATUS_INIT
# result = self.return_ins_result(ins=ins, status=constant.STATUS_INIT)
print('---***--')
print(return_status)
print(comment)
print(result)
if '等待查询反馈' in comment:
return_status = constant.STATUS_CONFORMING
if comment.isdigit(): # 减员成功
return_status = constant.STATUS_SUCCESS
result = self.return_ins_result(ins=ins, status=constant.STATUS_SUCCESS)
if '无权查看此人信息' in comment:
return_status = constant.STATUS_SUCCESS
result = self.return_ins_result(ins=ins, status=constant.STATUS_FAIL)
if '[养老缴费(中断)转出未转入] [失业缴费(中断)转出未转入] [工伤缴费(中断)转出未转入] [医保缴费 (暂停)缴费]' in comment:
return_status = constant.STATUS_SUCCESS
result = self.return_ins_result(ins=ins, status=constant.STATUS_SUCCESS)
if '人员已处于中断缴费状态,不允许重复减员' in comment:
return_status = constant.STATUS_SUCCESS
result = self.return_ins_result(ins=ins, status=constant.STATUS_SUCCESS)
response = waclient.update_si_task(self.ctx, task['id'], return_status, comment, result=result)
if response[1] != 200:
logger.error("Task Status Update Fail: " + task['id'])
def do_decrease(self, task):
"""北京社保减员操作"""
logger.info('statr do decrease')
id_num = task['insured_id_num']
name = task['insured_name']
ext_infos = task['ext_info']
decrease_reason = '' # 个人停止缴费原因
for ext_info in ext_infos:
if ext_info['name'] == '个人停止缴费原因':
decrease_reason = ext_info['value']
if not decrease_reason:
decrease_reason = '本人意愿解除劳动合同'
# return False, '请输入正确的个人停止缴费原因'
if decrease_reason not in ['劳动合同期满', '非本人意愿解除劳动合同', '本人意愿解除劳动合同']:
return False, '请输入正确的个人停止缴费原因: {}'.format(decrease_reason)
if not check_id_num(id_num=id_num):
logger.error('请输入正确的身份证号: {}'.format(id_num))
return False, '请输入正确的身份证号: {}'.format(id_num)
comment = '网络或服务器繁忙,请稍后再试'
for i in range(3):
status, comment = self.check_nav_show(div_id='level:1', one_id='link000', two_id='link005')
if not status:
return constant.STATUS_INIT, comment
self.driver.switch_to.default_content() # 退出frame
self.driver.switch_to.frame('center')
self.driver.switch_to.frame('mainFrame') # 切换到frame下寻找元素
try:
time.sleep(1)
self.driver.find_element_by_xpath('//*[@id="Layer2"]/table/tbody/tr[1]/td[2]/a').click()
except Exception as e:
logger.error(str(e))
try:
self.driver.find_element_by_id('cut').click() # 点击零星减员
time.sleep(1)
except Exception as e:
logger.error(str(e))
self.driver.refresh()
continue
try:
self.driver.find_element_by_id('idCard').send_keys(id_num) # 输入身份证号
self.driver.find_element_by_id('personName').send_keys(name) # 输入名字
time.sleep(1)
self.driver.find_element_by_id('select').click() # 点击查询
try:
printinfo = self.driver.find_element_by_id('printinfo')
if printinfo.is_displayed():
cause1 = self.driver.find_element_by_xpath("//*[@id='tbody1']/tr[2]/td[2]/font").text
return False, cause1
wronginfo = self.driver.find_element_by_id('wronginfo')
if wronginfo.is_displayed():
cause2 = self.driver.find_element_by_xpath("//*[@id='tbody1']/tr[3]/td[2]/font").text
return False, cause2
retireinfo = self.driver.find_element_by_id('retireinfo')
if retireinfo.is_displayed():
cause3 = self.driver.find_element_by_xpath("//*[@id='tbody1']/tr[4]/td[2]/font").text
return False, cause3
except Exception as e:
logger.error(str(e))
# self.driver.refresh()
# continue
# 判断用户是否已停缴、中止、断缴等状态
time.sleep(1)
jfzt_text = self.driver.find_element_by_xpath('//*[@id="tbody2"]/tr[3]/td[2]').text
if len(re.findall(r'正常', jfzt_text)) != 4:
return True, jfzt_text
time.sleep(2)
# 点击提交按钮
logger.info("开始点击提交按钮... ...")
# TODO 减员改动待测试
select = Select(self.driver.find_element_by_id("reason")) # 个人停止缴费原因
select.select_by_visible_text(decrease_reason)
time.sleep(1)
# self.driver.find_element_by_xpath('/html/body/div[3]/h2/a').click() # 关闭提示信息
# self.driver.find_element_by_xpath('/html/body/div[-1]/h2/a').click() # 关闭提示信息
time.sleep(1)
# js_cl = "$('.popup').remove()"
# self.driver.execute_script(js_cl)
js = "var aa=document.getElementsByClassName('popup')[0];aa.parentNode.removeChild(aa)"
self.driver.execute_script(js)
# self.left_click(1259, 357)
time.sleep(1)
js_cl1 = 'var child=document.getElementById("cover");child.parentNode.removeChild(child);'
self.driver.execute_script(js_cl1)
time.sleep(1)
# 点击提交按钮
self.driver.find_element_by_id('submit').click() # 保存 save # 提交:submit
time.sleep(10)
for k in range(4):
time.sleep(3)
sound_code = self.driver.page_source
if '服务器繁忙' in sound_code:
logger.error('服务器繁忙,请稍后再试')
self.driver.refresh()
continue
elif '业务操作失败' in sound_code:
logger.error('减员失败,请检查是否重复减员')
cause = etree.HTML(sound_code).xpath('//*[@id="cutform"]/table/tbody/tr[2]/td/table/tbody/tr[2]/td/p/span[2]/text()')
if cause:
cause = cause[1] + cause[2]
return True, '业务操作失败: ' + cause
elif '业务操作成功' in sound_code:
gov_id = self.driver.find_element_by_xpath('//*[@id="cutform"]/table/tbody/tr[2]/td/table/tbody/tr[2]/td/p/span/span').text
if gov_id:
gov_id = gov_id.replace(' ', '')
return True, gov_id
return True, '等待查询反馈'
except Exception as e:
logger.error(str(e))
self.driver.refresh()
continue
return constant.STATUS_INIT, comment
def __payback(self):
tasks = self.__get_tasks(constant.OP_TYPE_PAYBACK, constant.STATUS_INIT)
if not tasks:
return
self.close_notice()
# 判断业务办理时间
try:
msg = self.driver.find_element_by_xpath('/html/body/table[3]/tbody/tr/td').text
if '该申报业务办理时间为每月5日-25日' in msg:
return
except Exception as e:
logger.error(str(e))
for task in tasks:
task_detail, err_code = waclient.get_si_task(self.ctx, task['id'])
if err_code != 200:
break
response = self.do_payback(task_detail)
comment = response[1]
ins = self.get_all_ins(task_detail)
if not ins:
ins = ['医疗保险', '生育保险', '养老保险', '失业保险', '工伤保险']
result = self.return_ins_result(ins=ins, status=constant.STATUS_CONFORMING)
if not self.is_once_submit_payback():
if self.is_once_submit():
return_status = constant.STATUS_SUCCESS
else:
return_status = constant.STATUS_CONFORMING
if response[0] != constant.STATUS_INIT:
if not response[0]:
return_status = constant.STATUS_FAIL
result = self.return_ins_result(ins=ins, status=constant.STATUS_FAIL)
else:
return_status = constant.STATUS_INIT
result = self.return_ins_result(ins=ins, status=constant.STATUS_INIT)
response = waclient.update_si_task(self.ctx, task['id'], return_status, comment, result=result)
if response[1] != 200:
logger.error("Task Status Update Fail: " + task['id'])
def do_payback(self, task):
"""北京社保补缴操作"""
id_num = task['insured_id_num']
name = task['insured_name']
start_month = task['start_month']
end_month = task['end_month']
id_num = id_num.upper().replace(' ', '')
if not check_id_num(id_num=id_num):
logger.error('请输入正确的身份证号: {}'.format(id_num))
return False, '请输入正确的身份证号: {}'.format(id_num)
month_lst = []
start = time.strftime('%Y-%m', time.localtime(start_month))
end = time.strftime('%Y-%m', time.localtime(end_month))
start_month = time.strptime(start, '%Y-%m')
end_month = time.strptime(end, '%Y-%m')
start_month = datetime.datetime(start_month[0], start_month[1], start_month[2], start_month[3], start_month[4], start_month[5])
end_month = datetime.datetime(end_month[0], end_month[1], end_month[2], end_month[3], end_month[4], end_month[5])
result = (end_month - start_month).days
if result < 0:
return False, '补缴起始日期不能大于结束日期'
elif result == 0:
month_lst.append(start)
elif 0 < result < 56:
month_lst.append(start)
elif 56 <= result < 84:
month_lst.append(start)
month_lst.append(end)
elif 84 <= result < 112:
month_lst.append(start)
lst = start.split('-')
mid = ''
if int(lst[1]) <= 11:
mid = lst[0] + '-' + str(int(lst[1]) + 1)
elif int(lst[1]) == 12:
mid = str(int(lst[0]) + 1) + "-01"
month_lst.append(mid)
month_lst.append(end)
else:
return False, '补缴日期不能超过规定3个月以上'
comment = '网络或服务器繁忙,请稍后再试'
for i in range(3):
status, comment = self.check_nav_show(div_id='level:1', one_id='link000', two_id='link031')
if not status:
return constant.STATUS_INIT, comment
# 判断业务办理时间
try:
msg = self.driver.find_element_by_xpath('/html/body/table[3]/tbody/tr/td').text
if '该申报业务办理时间为每月5日-25日' in msg:
return
except Exception as e:
logger.error(str(e))
try:
time.sleep(1)
self.driver.find_element_by_id('addIndaddButton').click() # 点击新增补缴
time.sleep(2)
self.driver.find_element_by_name('idCode').send_keys(id_num) # 输入身份证号
self.driver.find_element_by_name('name').send_keys(name) # 输入姓名
self.driver.find_element_by_id('addQueryBtn').click() # 点击查询
time.sleep(2)
try:
source_text = self.driver.page_source
if '没有找到符合条件的个人用户信息' in source_text:
return False, '没有找到符合条件的个人用户信息'
elif '该人不在该单位' in source_text:
return False, '该人不在该单位'
elif '未查询到满足延迟三个月补缴条件的数据' in source_text:
return True, '未查询到满足延迟三个月补缴条件的数据,如需办理其他补缴业务请通过经办窗口办理。'
# payback_btn = self.driver.find_element_by_id('buttonSubmit')
# if not payback_btn:
# msg = self.driver.find_element_by_xpath('//*[@id="show"]/table[2]/tbody/tr[1]/td/span').text
# if msg is not None:
# return False, msg
except Exception as e:
logger.error(str(e))
trs = self.driver.find_elements_by_xpath('//*[@id="indAddPayForm"]/table/tbody/tr')
if not trs:
self.driver.refresh()
continue
for k in range(1, len(trs)+1):
mark_xpath = "//*[@id='indAddPayForm']/table/tbody/tr[" + str(k) + "]/td"
tds = self.driver.find_elements_by_xpath(mark_xpath)
if len(tds) != 15:
continue
checkbox = self.driver.find_element_by_xpath(mark_xpath + "[1]/input[1]")
month_text = self.driver.find_element_by_xpath(mark_xpath + "[2]").text
month_text.strip()
if not checkbox.is_enabled():
continue
if not checkbox.is_selected() and month_text in month_lst:
checkbox.click()
try:
# 个人补缴申报导入
self.driver.find_element_by_id("buttonSubmit").click()
self.driver.switch_to_alert().accept()
except Exception as e:
logger.error(str(e))
for _ in range(3):
try:
time.sleep(2)
status = self.driver.find_element_by_xpath('/html/body/table/tbody/tr/td/table/tbody/tr[2]/td/p').text
# '/html/body/table/tbody/tr/td/table/tbody/tr[3]/td/p/span/span/text()' # 流水号
if status and '操作成功' not in status: # 个人补缴申报导入操作成功!
return False, status
# 点击返回按钮
self.driver.find_element_by_xpath('/html/body/center/input').click()
break
except Exception as e:
logger.error(str(e))
continue
# 选择保存成功的记录
for _ in range(3):
try:
time.sleep(2)
record_trs = self.driver.find_elements_by_xpath('/html/body/div[1]/table/tbody[2]/tr')
if len(record_trs) <= 1:
return True, "等待查询反馈"
for n in range(1, len(record_trs)):
# idcard_xpath = "/html/body/div[1]/table/tbody[2]/tr[" + str(n) + "]/td[4]"
check_xpath = "/html/body/div[1]/table/tbody[2]/tr[" + str(n) + "]/td[1]/input"
# if id_num != self.driver.find_element_by_xpath(idcard_xpath).text:
# continue
cb_record = self.driver.find_element_by_xpath(check_xpath)
if not cb_record.is_selected():
cb_record.click()
break
except Exception as e:
logger.error(str(e))
continue
try:
# 汇总提交
self.driver.find_element_by_id('submitButton').click()
self.driver.switch_to_alert().accept()
except Exception as e:
logger.error(str(e))
# 最终交易结果页面
for _ in range(3):
try:
time.sleep(2)
status = self.driver.find_element_by_xpath('/html/body/table/tbody/tr/td/table/tbody/tr[2]/td/p').text
if status and '操作成功' not in status: # 个人补缴申报导入操作成功!
return True, status
id_code = self.driver.find_element_by_xpath('/html/body/table/tbody/tr/td/table/tbody/tr[3]/td/p/span/span').text
return True, id_code
except Exception as e:
logger.error(str(e))
continue
return True, "等待查询反馈"
except Exception as e:
logger.error(str(e))
self.driver.refresh()
continue
return constant.STATUS_INIT, comment
def __confirm(self):
tasks = self.__get_tasks('', constant.STATUS_CONFORMING)
if not tasks:
return
self.close_notice()
for task in tasks:
task_detail, err_code = waclient.get_si_task(self.ctx, task['id'])
if err_code != 200:
break
response = self.do_confirm(task_detail)
confirm_result = response[0]
comment = response[1]
ins = self.get_all_ins(task_detail)
if not ins:
ins = ['医疗保险', '生育保险', '养老保险', '失业保险', '工伤保险']
result = self.return_ins_result(ins=ins)
if confirm_result == constant.STATUS_FAIL:
result = self.return_ins_result(ins=ins, status=constant.STATUS_FAIL)
elif confirm_result == constant.STATUS_CONFORMING:
continue
elif confirm_result == constant.STATUS_INIT:
result = self.return_ins_result(ins=ins, status=constant.STATUS_INIT)
response = waclient.update_si_task(self.ctx, task['id'], confirm_result, comment, result=result)
if response[1] != 200:
logger.error("Task Status Update Fail: ", task['id'])
def do_confirm(self, task):
"""北京社保查询"""
comment = task['comment']
if re.findall('(\d{16})', comment) and len(comment) <= 17:
return constant.STATUS_SUCCESS, '成功'
else:
id_num = task['insured_id_num']
op_type = task['op_type']
for i in range(3):
status, comments = self.check_nav_show(div_id='level:2', one_id='link012', two_id='link013')
if not status:
return constant.STATUS_CONFORMING, comment
# 设置开始日期
try:
self.driver.switch_to.default_content() # 退出frame
self.driver.switch_to.frame('center')
self.driver.switch_to.frame('mainFrame') # 切换到frame下寻找元素
time.sleep(2)
self.driver.find_element_by_id('startDate').click()
self.driver.switch_to_frame(self.driver.find_element_by_xpath("//iframe[contains(@src,'http://fuwu.rsj.beijing.gov.cn/csibiz/csirp/js/datepicker/My97DatePicker.htm')]"))
time.sleep(2)
self.driver.find_element_by_id('dpOkInput').click()
time.sleep(2)
# self.driver.switch_to.frame(0)
# start_trs = self.driver.find_elements_by_xpath('/html/body/div/div[3]/table/tbody/tr')
# if len(start_trs) == 7:
# start_tds = self.driver.find_elements_by_xpath('/html/body/div/div[3]/table/tbody/tr[2]/td')
# for item in start_tds:
# if item.text == '1':
# item.click()
# break
except Exception as e:
logger.error(str(e))
self.driver.refresh()
continue
# 设置结束日期
try:
self.driver.switch_to_default_content()
self.driver.switch_to.frame('center')
self.driver.switch_to.frame('mainFrame')
time.sleep(2)
self.driver.find_element_by_id('endDate').click()
# http://fuwu.rsj.beijing.gov.cn/csibiz/csirp/js/datepicker/My97DatePicker.htm
time.sleep(2)
self.driver.switch_to_frame(self.driver.find_element_by_xpath(
"//iframe[contains(@src,'http://fuwu.rsj.beijing.gov.cn/csibiz/csirp/js/datepicker/My97DatePicker.htm')]"))
time.sleep(2)
# self.driver.switch_to.frame(0)
self.driver.find_element_by_id('dpOkInput').click() # 点击日期窗口的确定按钮
except Exception as e:
logger.error(str(e))
self.driver.refresh()
continue
self.driver.switch_to_default_content()
self.driver.switch_to.frame('center')
self.driver.switch_to.frame('mainFrame')
self.driver.find_element_by_id('idCard').clear()
self.driver.find_element_by_id('idCard').send_keys(id_num)
dataTypeSelect = Select(self.driver.find_element_by_id('dataTypeSelect'))
if op_type == constant.OP_TYPE_INCREASE:
if task['handle_type'] == "0":
dataTypeSelect.select_by_visible_text('新参保人员登记')
elif task['handle_type'] == "1":
dataTypeSelect.select_by_visible_text('转入人员增加')
elif op_type == constant.OP_TYPE_DECREASE:
dataTypeSelect.select_by_visible_text('普通减员')
statusSelect = Select(self.driver.find_element_by_id('statusSelect'))
statusSelect.select_by_visible_text('处理结束')
self.driver.find_element_by_id('button_1').click() # 点击查询
time.sleep(2)
trs = self.driver.find_elements_by_xpath('/html/body/table[4]/tbody/tr')
if len(trs) < 2:
return constant.STATUS_FAIL, comment
k = 1
for _ in trs:
k += 1
try: # /html/body/table[5]/tbody/tr[2]/td[8]/div
result = self.driver.find_element_by_xpath("/html/body/table[4]/tbody/tr[" + str(k) + "]/td[8]/div").text
if '成功' in result:
return constant.STATUS_SUCCESS, '成功'
elif '失败' in result:
msg = self.driver.find_element_by_xpath("/html/body/table[4]/tbody/tr[" + str(k) + "]/td[9]/div").text
return constant.STATUS_FAIL, msg
else:
# msg = self.driver.find_element_by_xpath("/html/body/table[4]/tbody/tr[" + str(k) + "]/td[9]/div").text
return constant.STATUS_FAIL, comment
except Exception as e:
logger.error(str(e))
time.sleep(1)
return constant.STATUS_CONFORMING, comment
def is_once_submit(self):
return False
def close_notice(self):
"""关闭页面悬浮div弹框"""
for i in range(3):
try:
self.driver.switch_to_default_content()
self.driver.switch_to.frame('center')
self.driver.switch_to_frame('mainFrame')
xpath = '//*[@id="wBox"]/div/table/tbody/tr[2]/td[2]/div/table/tbody/tr/td[2]/div'
# xpath = '//div[@class="wBox_close_on"]'
self.driver.find_element_by_xpath(xpath).click()
except Exception as e:
logger.error(str(e))
time.sleep(1)
def check_nav_show(self, div_id='', one_id='', two_id=''):
"""检查左侧导航是否显示二级导航"""
k = 0
while True:
k += 1
if k == 6:
return False, '服务器繁忙,请稍后再试'
try:
time.sleep(1)
self.driver.switch_to.default_content()
self.driver.switch_to.frame('center')
self.driver.switch_to.frame('leftFrame') # 切换到frame下寻找元素
display = []
if div_id != '':
styles = self.driver.find_element_by_id(div_id).get_attribute('style')
styles = styles.replace(' ', '').strip().lower()
display = re.findall('display:none', styles)
if display:
if one_id != "" and two_id != "":
self.driver.find_element_by_id(one_id).click()
time.sleep(1)
self.driver.find_element_by_id(two_id).click()
else:
self.driver.find_element_by_id(two_id).click()
time.sleep(1)
sound_code = self.driver.page_source
# /html/body/table[3]/tbody/tr/td
if '此业务的使用日期' in sound_code:
msg = '此业务的使用日期为每月5日至22日(逢节假日不提前,也不错后)'
return False, msg
elif '此业务每天的使用时间' in sound_code:
logger.error('此业务每天的使用时间为6:00—22:00')
return False, '此业务每天的使用时间为6:00—22:00'
# elif '404' in sound_code:
# logger.error('页面出现404错误')
# self.driver.refresh()
# continue
elif '服务器繁忙' in sound_code:
logger.error('服务器繁忙,请稍后再试')
self.driver.refresh()
continue
return True, ''
except Exception as e:
logger.error(str(e))
self.driver.refresh()
continue
def __select_medical(self, *args):
"""判断是否有医疗机构3,4,5"""
self.driver.find_element_by_id(args[0]).click() # 配置医疗机构
self.driver.switch_to.frame(args[1]) # 切换到frame下寻找元素
self.driver.find_element_by_id('personInfoReg_search').send_keys(args[2]) # 输入医院
self.driver.find_elements_by_tag_name('input')[2].click()
time.sleep(1)
tds = self.driver.find_elements_by_tag_name('td')
if len(tds) >= 5:
inputs = self.driver.find_elements_by_tag_name('input')
for j in inputs:
if j.get_attribute('value') == '选择':
j.click()
break
self.driver.switch_to.default_content() # 退出frame
self.driver.switch_to.frame('center')
self.driver.switch_to.frame('mainFrame') # 切换到frame下寻找元素
time.sleep(2)
def system_prompt(self):
"""关闭系统提示窗口"""
time.sleep(1)
self.driver.switch_to.default_content() # 退出frame
# msg_xpath = self.driver.find_element_by_xpath('/html/body/div[3]/div/h2/a') # 系统提示
# if msg_xpath:
# msg_xpath.click()
try:
self.driver.find_element_by_xpath('/html/body/div[3]/div/h2/a').click() # 关闭系统提示
except:
pass
self.driver.switch_to.default_content() # 退出frame
self.driver.switch_to.frame('center')
self.driver.switch_to.frame('mainFrame') # 切换到frame下寻找元素
def new_system_prompt(self):
"""新关闭系统提示窗口"""
time.sleep(8)
self.driver.switch_to.default_content() # 退出frame
self.driver.switch_to.default_content() # 退出frame
# msg_xpath = self.driver.find_element_by_xpath('/html/body/div[3]/div/h2/a') # 系统提示
# if msg_xpath:
# msg_xpath.click()
# source_text = self.driver.page_source
# print(source_text)
try:
self.driver.find_element_by_xpath('//div[@class="popwrap"]/div/h2/a').click() # 关闭系统提示
except Exception as e:
logger.error(str(e))
self.driver.switch_to.default_content() # 退出frame
self.driver.switch_to.frame('center')
self.driver.switch_to.frame('mainFrame') # 切换到frame下寻找元素
def __date(self):
"""合同日期计算"""
year = datetime.datetime.now().year + 3
month = datetime.datetime.now().month
day = datetime.datetime.now().day - 1
if day == 0:
month = month - 1
if month == 0:
month = 12
if month == 2:
day = 28
elif month == 2 or month == 4 or month == 6 or month == 9 or month == 11:
day = 30
else:
day = 31
return year, month, day
def left_click(x, y):
win32api.SetCursorPos([x, y])
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)