-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathFunction.py
1082 lines (1015 loc) · 39 KB
/
Function.py
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
# -*- coding: utf-8 -*-
from Data import *
from Error import *
import json
import hashlib
import zlib
import time
import random
import os
from urllib.request import quote
from Net import *
is_write = True
class GameFunction:
def __init__(self):
self.cookies = None
self.version = None
self.server = None
self.channel = None
def start_game_function(self, version, cookies, server, channel):
self.cookies = cookies
self.version = version
self.server = server
self.channel = channel
def get_init_data(self, res_url, end):
"""
获取init数据
:return:
"""
try:
print("请求新的res数据")
user_data = zlib.decompress(
session.get(url=res_url + end,
headers=HEADER, timeout=30).content)
user_data = json.loads(user_data)
user_data["res_url"] = res_url
user_data = json.dumps(user_data)
return user_data
except Exception as e:
log.e("获取init数据出错", e)
raise
def login_award(self):
"""
功能:获取签到奖励
:return:dict
"""
try:
log.debug("Login award:", "")
url = self.server + 'active/getLoginAward/c3ecc6250c89e88d83832e3395efb973/' + self.get_url_end()
data=self.Mdecompress(url)
data = json.loads(data)
error_find(data)
if is_write and os.path.exists('requestsData'):
with open('requestsData/login_award.json', 'w') as f:
f.write(json.dumps(data))
return data
except HmError as e:
print('Start challenge FAILED! Reason:', e.message)
raise
except Exception as e:
print('Start challenge FAILED! Reason:', e)
raise
def challenge_start(self, maps, team, head="pve"):
"""
功能:开始出征
返回值:dict
"""
try:
url = self.server + '{head}/cha11enge/{map}/{team}/0/'.format(map=maps, team=team, head=head) + self.get_url_end()
log.debug("Start challenge:", "{head}/cha11enge/{map}/{team}".format(map=maps, team=team, head=head))
data=self.Mdecompress(url)
data = json.loads(data)
error_find(data)
if is_write and os.path.exists('requestsData'):
with open('requestsData/challenge_start.json', 'w') as f:
f.write(json.dumps(data))
return data
except HmError as e:
print('Start challenge FAILED! Reason:', e.message)
raise
except Exception as e:
print('Start challenge FAILED! Reason:', e)
raise
def challenge_new_next(self, head="pve"):
"""
功能:下一点
返回值:bytes
"""
try:
url = self.server + '{head}/newNext/'.format(head=head) + self.get_url_end()
data=self.Mdecompress(url)
data = json.loads(data)
error_find(data)
if is_write and os.path.exists('requestsData'):
with open('requestsData/challenge_new_next.json', 'w') as f:
f.write(json.dumps(data))
return data
except HmError as e:
print('New next FAILED! Reason:', e.message)
raise
except Exception as Error_information:
print('New next FAILED! Reason:', Error_information)
raise
def challenge_fight(self, maps, team, formats, head="pve",dealto='dealto'):
"""
功能:开始战斗
返回值:dict
"""
try:
arg = self.str_arg(maps=maps, team=team, formats=formats, head=head,dealto=dealto)
#玩具图
if int(maps)>941900:
arg["team"]='0'
log.debug("Challenge fight", arg)
url = self.server + '{head}/{dealto}/{maps}/{team}/{formats}/'.format(**arg) + self.get_url_end()
data = zlib.decompress(
session.post(url=url, headers=HEADER,
cookies=self.cookies, timeout=10, data={'pve_level': 1, 'pid': random.randint(1000000, 2000000)}).content)
data = json.loads(data)
error_find(data)
if is_write and os.path.exists('requestsData'):
with open('requestsData/challenge_fight.json', 'w') as f:
f.write(json.dumps(data))
return data
except HmError as e:
print('Challenge fight FAILED! Reason:', e.message)
raise
except Exception as e:
print('Challenge fight FAILED! Reason:', e)
raise
def challenge_get_result(self, is_night_fight, head="pve"):
"""
功能:取战斗结果
返回值:dict
"""
# isNightFight:是否夜战,是:1,不是:0
try:
url = self.server + '{head}/getWarResult/'.format(head=head) + str(is_night_fight) + '/' + self.get_url_end()
log.debug("Get Result", url)
data=self.Mdecompress(url)
data = json.loads(data)
error_find(data)
if is_write and os.path.exists('requestsData'):
with open('requestsData/challenge_get_result.json', 'w') as f:
f.write(json.dumps(data))
return data
except HmError as e:
print('Get Result FAILED! Reason:', e.message)
raise
except Exception as e:
print('Get Result FAILED! Reason:', e)
raise
def challenge_skip_war(self, head="pve"):
"""
功能:迂回
返回值:dict
"""
try:
url = self.server + '{head}/SkipWar/'.format(head=head) + self.get_url_end()
data=self.Mdecompress(url)
data = json.loads(data)
error_find(data)
if is_write and os.path.exists('requestsData'):
with open('requestsData/challenge_skip_war.json', 'w') as f:
f.write(json.dumps(data))
return data
except Exception as e:
print('Skip war FAILED! Reason:', e)
raise
def challenge_spy(self, head="pve"):
"""
功能:索敌
返回值:dict
"""
try:
url = self.server + '{head}/spy/'.format(head=head) + self.get_url_end()
data=self.Mdecompress(url)
data = json.loads(data)
error_find(data)
if is_write and os.path.exists('requestsData'):
with open('requestsData/challenge_spy.json', 'w') as f:
f.write(json.dumps(data))
return data
except HmError as e:
print('Spy FAILED! Reason:', e.message)
raise
except Exception as e:
print('Spy FAILED! Reason:', e)
raise
def repair(self, ship):
"""
功能:修理
返回值:dict
"""
try:
wait = [str(x) for x in ship]
url = self.server + 'boat/instantRepairShips/[' + ','.join(wait) + ']/' + self.get_url_end()
log.debug("Repair:", ','.join(wait))
data=self.Mdecompress(url)
data = json.loads(data)
error_find(data)
if 'packageVo' in data:
gameData.fastRepair = data['packageVo'][0]['num']
if "userVo" in data:
gameData.oil = data['userVo']['oil']
gameData.steel = data['userVo']['steel']
gameData.ammo = data['userVo']['ammo']
gameData.aluminium = data['userVo']['aluminium']
if is_write and os.path.exists('requestsData'):
with open('requestsData/repair.json', 'w') as f:
f.write(json.dumps(data))
return data
except HmError as e:
print('Repair FAILED! Reason:', e.message)
raise
except Exception as e:
print('Repair FAILED! Reason:', e)
raise
def strengthen(self, ids, ship):
"""
功能:强化
返回值:dict
"""
try:
wait = [str(x) for x in ship]
arg = self.str_arg(ids=str(ids), ship=','.join(wait))
url = self.server + 'boat/strengthen/{ids}/[{ship}]/'.format(**arg) + self.get_url_end()
data=self.Mdecompress(url)
data = json.loads(data)
if 'eid' in data:
if data["eid"]!=-412:
error_find(data)
if is_write and os.path.exists('requestsData'):
with open('requestsData/strengthen.json', 'w') as f:
f.write(json.dumps(data))
return data
except HmError as e:
print('Repair FAILED! Reason:', e.message)
raise
except Exception as e:
print('Repair FAILED! Reason:', e)
raise
def skillLevelUp(self, ship):
"""
功能:升级
返回值:dict
"""
try:
url = self.server + 'boat/skillLevelUp/{ship}/'.format(ship=ship) + self.get_url_end()
data=self.Mdecompress(url)
data = json.loads(data)
if 'eid' in data:
if data["eid"]!=-317 and data["eid"]!=-315 and data["eid"]!=-316:
error_find(data)
if is_write and os.path.exists('requestsData'):
with open('requestsData/skillLevelUp.json', 'w') as f:
f.write(json.dumps(data))
return data
except HmError as e:
print('skillLevelUp FAILED! Reason:', e.message)
raise
except Exception as e:
print('skillLevelUp FAILED! Reason:', e)
raise
def shower(self, ship):
"""
功能:修理
返回值:dict
"""
try:
arg = self.str_arg(ship=ship)
url = self.server + 'boat/repair/{ship}/0/'.format(**arg) + self.get_url_end()
data=self.Mdecompress(url)
data = json.loads(data)
error_find(data)
if is_write and os.path.exists('requestsData'):
with open('requestsData/shower.json', 'w') as f:
f.write(json.dumps(data))
return data
except HmError as e:
print('Shower FAILED! Reason:', e.message)
raise
except Exception as e:
print('Shower FAILED! Reason:', e)
raise
def rubdown(self, ship):
"""
功能:修理
返回值:dict
"""
try:
arg = self.str_arg(ship=ship)
url = self.server + 'boat/rubdown/{ship}'.format(**arg) + self.get_url_end()
data=self.Mdecompress(url)
data = json.loads(data)
error_find(data)
if is_write and os.path.exists('requestsData'):
with open('requestsData/rubdown.json', 'w') as f:
f.write(json.dumps(data))
return data
except HmError as e:
print('Rubdown FAILED! Reason:', e.message)
raise
except Exception as e:
print('Rubdown FAILED! Reason:', e)
raise
def repair_complete(self, ids, ship):
"""
功能:出浴
返回值:dict
"""
try:
arg = self.str_arg(ship=ship, ids=ids)
url = self.server + 'boat/repairComplete/{ids}/{ship}/'.format(**arg) + self.get_url_end()
data=self.Mdecompress(url)
data = json.loads(data)
error_find(data)
if is_write and os.path.exists('requestsData'):
with open('requestsData/repair_complete.json', 'w') as f:
f.write(json.dumps(data))
return data
except HmError as e:
print('RepairComplete FAILED! Reason:', e.message)
raise
except Exception as e:
print('RepairComplete FAILED! Reason:', e)
raise
def supply(self, ship):
"""
功能:快速补给
返回值:dict
"""
try:
wait = []
for each in ship:
wait.append(str(each))
url = self.server + 'boat/supplyBoats/[' + ','.join(wait) + ']/0/0/' + self.get_url_end()
content=session.get(url=url, headers=HEADER, cookies=self.cookies, timeout=10).content
try:#战役报错部分
data = zlib.decompress(content)
except Exception as e:
data=content
data = json.loads(data)
error_find(data)
if is_write and os.path.exists('requestsData'):
with open('requestsData/supply.json', 'w') as f:
f.write(json.dumps(data))
return data
except HmError as e:
print('Fast supply FAILED! Reason:', e.message)
raise
except Exception as Error_information:
print('Fast supply FAILED! Reason:', Error_information)
raise
def dismantle(self, ship, is_save):
"""
功能:分解
返回值:dict
"""
try:
url = self.server + 'dock/dismantleBoat/[' + ','.join(ship) \
+ ']/' + str(is_save) + '/' + self.get_url_end()
data=self.Mdecompress(url)
data = json.loads(data)
error_find(data)
if is_write and os.path.exists('requestsData'):
with open('requestsData/dismantle.json', 'w') as f:
f.write(json.dumps(data))
return data
except HmError as e:
print('Decompose FAILED! Reason:', e.message)
raise
except Exception as e:
print('Decompose FAILED! Reason:', e)
raise
def get_explore(self, maps):
"""
功能:收远征
返回值:bytes
"""
try:
arg = self.str_arg(maps=maps)
url = self.server + 'explore/getResult/{maps}/'.format(**arg) + self.get_url_end()
data=self.Mdecompress(url)
data = json.loads(data)
error_find(data)
if is_write and os.path.exists('requestsData'):
with open('requestsData/get_explore.json', 'w') as f:
f.write(json.dumps(data))
return data
except HmError as e:
print('Get explore FAILED! Reason:', e.message)
raise
except Exception as e:
print('Get explore FAILED! Reason:', e)
raise
def get_task(self, cid):
"""
功能:收任务
返回值:bytes
"""
try:
arg = self.str_arg(cid=cid)
url = self.server + 'task/getAward/{cid}/'.format(**arg) + self.get_url_end()
data=self.Mdecompress(url)
data = json.loads(data)
error_find(data)
if is_write and os.path.exists('requestsData'):
with open('requestsData/get_task.json', 'w') as f:
f.write(json.dumps(data))
return data
except HmError as e:
print('Get explore FAILED! Reason:', e.message)
raise
except Exception as e:
print('Get explore FAILED! Reason:', e)
raise
def start_explore(self, maps, team):
"""
功能:开始远征
返回值:bytes
"""
try:
arg = self.str_arg(maps=maps, team=team)
url = self.server + 'explore/start/{team}/{maps}/'.format(**arg) + self.get_url_end()
data=self.Mdecompress(url)
data = json.loads(data)
error_find(data)
if is_write and os.path.exists('requestsData'):
with open('requestsData/start_explore.json', 'w') as f:
f.write(json.dumps(data))
return data
except HmError as e:
print('Start explore FAILED! Reason:', e.message)
raise
except Exception as Error_information:
print('Start explore FAILED! Reason:', Error_information)
raise
def lock_ship(self, ship):
"""
功能:开始远征
返回值:bytes
"""
try:
url = self.server + 'boat/lock/{ship}/'.format(ship=str(ship)) + self.get_url_end()
data=self.Mdecompress(url)
data = json.loads(data)
error_find(data)
if is_write and os.path.exists('requestsData'):
with open('requestsData/lock_ship.json', 'w') as f:
f.write(json.dumps(data))
return data
except HmError as e:
print('Lock ship FAILED! Reason:', e.message)
raise
except Exception as Error_information:
print('Lock ship FAILED! Reason:', Error_information)
raise
def campaign_get_fleet(self, maps):
"""
获取用户战役船只信息
:return:
"""
try:
url = self.server + 'campaign/getFleet/{maps}/'.format(maps=str(maps)) + self.get_url_end()
data=self.Mdecompress(url)
data = json.loads(data)
error_find(data)
if is_write and os.path.exists('requestsData'):
with open('requestsData/campaign_get_fleet.json', 'w') as f:
f.write(json.dumps(data))
return data
except HmError as e:
print('Skip war FAILED! Reason:', e.message)
raise
except Exception as e:
print('Skip war FAILED! Reason:', e)
raise
def campaign_get_spy(self, maps):
"""
获取用户战役船只信息
:return:
"""
try:
url = self.server + 'campaign/spy/{maps}/'.format(maps=str(maps)) + self.get_url_end()
data=self.Mdecompress(url)
data = json.loads(data)
if is_write and os.path.exists('requestsData'):
with open('requestsData/campaign_get_spy.json', 'w') as f:
f.write(json.dumps(data))
return data
except HmError as e:
print('Campaign spy FAILED! Reason:', e.message)
raise
except Exception as e:
print('Campaign spy FAILED! Reason:', e)
raise
def campaign_fight(self, maps, formats):
"""
获取用户战役船只信息
:return:
"""
try:
arg = self.str_arg(maps=maps, formats=formats)
url = self.server + 'campaign/challenge/{maps}/{formats}/'.format(**arg) + self.get_url_end()
data=self.Mdecompress(url)
data = json.loads(data)
error_find(data)
if is_write and os.path.exists('requestsData'):
with open('requestsData/campaign_fight.json', 'w') as f:
f.write(json.dumps(data))
return data
except HmError as e:
print('Campaign fight FAILED! Reason:', e.message)
raise
except Exception as Error_information:
print('Campaign fight FAILED! Reason:', Error_information)
raise
def campaign_get_result(self, is_night_fight):
"""
功能:取战斗结果
返回值:dict
"""
# isNightFight:是否夜战,是:1,不是:0
try:
url = self.server + 'campaign/getWarResult/{0}/'.format(str(is_night_fight)) + self.get_url_end()
data=self.Mdecompress(url)
data = json.loads(data)
error_find(data)
if is_write and os.path.exists('requestsData'):
with open('requestsData/campaign_get_result.json', 'w') as f:
f.write(json.dumps(data))
return data
except HmError as e:
print('Campaign get result FAILED! Reason:', e.message)
raise
except Exception as e:
print('Campaign get result FAILED! Reason:', e)
raise
@property
def pvp_get_list(self):
"""
功能:取演习列表
返回值:dict
"""
try:
url = self.server + 'pvp/getChallengeList/' + self.get_url_end()
data=self.Mdecompress(url)
data = json.loads(data)
if is_write and os.path.exists('requestsData'):
with open('requestsData/pvp_list.json', 'w') as f:
f.write(json.dumps(data))
return data
except HmError as e:
print('PVP get list FAILED! Reason:', e.message)
raise
except Exception as e:
print('PVP get list FAILED! Reason:', e)
raise
@property
def friend_get_list(self):
"""
功能:取好友演习列表
返回值:dict
"""
try:
url = self.server + 'friend/getlist' + self.get_url_end()
data=self.Mdecompress(url)
data = json.loads(data)
if is_write and os.path.exists('requestsData'):
with open('requestsData/friend_list.json', 'w') as f:
f.write(json.dumps(data))
return data
except HmError as e:
print('friend get list FAILED! Reason:', e.message)
raise
except Exception as e:
print('friend get list FAILED! Reason:', e)
raise
def friend_visitorFriend(self, uid):
"""
功能:查询好友状态
返回值:dict
"""
try:
arg = self.str_arg(uid=uid)
url = self.server + 'friend/visitorFriend/{uid}/'.format(**arg) + self.get_url_end()
data=self.Mdecompress(url)
data = json.loads(data)
error_find(data)
if is_write and os.path.exists('requestsData'):
with open('requestsData/visitor_Friend.json', 'w') as f:
f.write(json.dumps(data))
return data
except HmError as e:
print('visitor_Friend FAILED! Reason:', e.message)
raise
except Exception as e:
print('visitor_Friend FAILED! Reason:', e)
raise
def pvp_spy(self, uid, fleet,pvp="pvp"):
"""
功能:索敌
返回值:dict
"""
try:
arg = self.str_arg(uid=uid, fleet=fleet,pvp=pvp)
url = self.server + '{pvp}/spy/{uid}/{fleet}/'.format(**arg) + self.get_url_end()
data=self.Mdecompress(url)
data = json.loads(data)
error_find(data)
if is_write and os.path.exists('requestsData'):
with open('requestsData/pvp_spy.json', 'w') as f:
f.write(json.dumps(data))
return data
except HmError as e:
print('PVP spy FAILED! Reason:', e.message)
raise
except Exception as e:
print('PVP spy FAILED! Reason:', e)
raise
def pvp_fight(self, uid, fleet, formats,pvp="pvp"):
"""
功能:战斗
返回值:dict
"""
try:
arg = self.str_arg(uid=uid, fleet=fleet, formats=formats,pvp=pvp)
url = self.server + '{pvp}/challenge/{uid}/{fleet}/{formats}/'.format(**arg) + self.get_url_end()
data=self.Mdecompress(url)
data = json.loads(data)
error_find(data)
if is_write and os.path.exists('requestsData'):
with open('requestsData/pvp_fight.json', 'w') as f:
f.write(json.dumps(data))
return data
except HmError as e:
print('PVP fight FAILED! Reason:', e.message)
raise
except Exception as Error_information:
print('PVP fight FAILED! Reason:', Error_information)
raise
def pvp_get_result(self, is_night_fight,pvp="pvp"):
"""
功能:取战斗结果
返回值:dict
"""
# isNightFight:是否夜战,是:1,不是:0
try:
arg = self.str_arg(is_night_fight=str(is_night_fight), pvp=pvp)
url = self.server + '{pvp}/getWarResult/{is_night_fight}/'.format(**arg) + self.get_url_end()
data=self.Mdecompress(url)
data = json.loads(data)
error_find(data)
if is_write and os.path.exists('requestsData'):
with open('requestsData/PVP_get_result.json', 'w') as f:
f.write(json.dumps(data))
return data
except HmError as e:
print('PVP get Result FAILED! Reason:', e.message)
raise
except Exception as Error_information:
print('PVP get Result FAILED! Reason:', Error_information)
raise
def build_ship(self, dock, oil, ammo, steel, aluminium):
"""
功能:建造船只
返回值:dict
"""
#
try:
arg = self.str_arg(dock=dock, oil=oil, ammo=ammo, steel=steel, aluminium=aluminium)
url = self.server + 'dock/buildBoat/{dock}/{oil}/{steel}/{ammo}/{aluminium}'.format(
**arg) + self.get_url_end()
data=self.Mdecompress(url)
data = json.loads(data)
error_find(data)
if is_write and os.path.exists('requestsData'):
with open('requestsData/Build_ship.json', 'w') as f:
f.write(json.dumps(data))
return data
except HmError as e:
print('Build ship FAILED! Reason:', e.message)
raise
except Exception as Error_information:
print('Build ship FAILED! Reason:', Error_information)
raise
def build_equipment(self, dock, oil, ammo, steel, aluminium):
"""
功能:开发装备
返回值:dict
"""
#
try:
arg = self.str_arg(dock=dock, oil=oil, ammo=ammo, steel=steel, aluminium=aluminium)
url = self.server + 'dock/buildEquipment/{dock}/{oil}/{steel}/{ammo}/{aluminium}'.format(
**arg) + self.get_url_end()
data=self.Mdecompress(url)
data = json.loads(data)
error_find(data)
if is_write and os.path.exists('requestsData'):
with open('requestsData/Build_equipment.json', 'w') as f:
f.write(json.dumps(data))
return data
except HmError as e:
print('Build equipment FAILED! Reason:', e.message)
raise
except Exception as Error_information:
print('Build equipment FAILED! Reason:', Error_information)
raise
def build_get_ship(self, dock):
"""
功能:收船
返回值:dict
"""
try:
arg = self.str_arg(dock=dock)
url = self.server + 'dock/getBoat/{dock}/'.format(**arg) + self.get_url_end()
data=self.Mdecompress(url)
data = json.loads(data)
error_find(data)
if is_write and os.path.exists('requestsData'):
with open('requestsData/build_get_ship.json', 'w') as f:
f.write(json.dumps(data))
return data
except HmError as e:
print('Build get ship FAILED! Reason:', e.message)
raise
except Exception as Error_information:
print('Build get ship FAILED! Reason:', Error_information)
raise
def build_get_equipment(self, dock):
"""
功能:收装备
返回值:dict
"""
try:
arg = self.str_arg(dock=dock)
url = self.server + 'dock/getEquipment/{dock}/'.format(**arg) + self.get_url_end()
data=self.Mdecompress(url)
data = json.loads(data)
error_find(data)
if is_write and os.path.exists('requestsData'):
with open('requestsData/build_get_equipment.json', 'w') as f:
f.write(json.dumps(data))
return data
except HmError as e:
print('Build get equipment FAILED! Reason:', e.message)
raise
except Exception as Error_information:
print('Build get equipment FAILED! Reason:', Error_information)
raise
def build_instant_ship(self, dock):
"""
功能:快速建造
返回值:dict
"""
try:
arg = self.str_arg(dock=dock)
url = self.server + 'dock/instantBuild/{dock}/'.format(**arg) + self.get_url_end()
data=self.Mdecompress(url)
data = json.loads(data)
error_find(data)
if is_write and os.path.exists('requestsData'):
with open('requestsData/build_instant_ship.json', 'w') as f:
f.write(json.dumps(data))
return data
except HmError as e:
print('Build instant ship FAILED! Reason:', e.message)
raise
except Exception as Error_information:
print('Build instant ship FAILED! Reason:', Error_information)
raise
def build_instant_equipment(self, dock):
"""
功能:快速开发
返回值:dict
"""
try:
arg = self.str_arg(dock=dock)
url = self.server + 'dock/instantEquipmentBuild/{dock}/'.format(**arg) + self.get_url_end()
data=self.Mdecompress(url)
data = json.loads(data)
error_find(data)
if is_write and os.path.exists('requestsData'):
with open('requestsData/build_instant_equipment.json', 'w') as f:
f.write(json.dumps(data))
return data
except HmError as e:
print('Build instant equipment FAILED! Reason:', e.message)
raise
except Exception as Error_information:
print('Build instant equipment FAILED! Reason:', Error_information)
raise
def change_ship(self, fleet, ids, path):
"""
功能:换船
返回值:dict
"""
try:
arg = self.str_arg(fleet=fleet, ids=ids, path=path)
url = self.server + 'boat/changeBoat/{fleet}/{ids}/{path}/'.format(**arg) + self.get_url_end()
data=self.Mdecompress(url)
data = json.loads(data)
error_find(data)
if is_write and os.path.exists('requestsData'):
with open('requestsData/change_ship.json', 'w') as f:
f.write(json.dumps(data))
return data
except HmError as e:
print('Change ship FAILED! Reason:', e.message)
raise
except Exception as Error_information:
print('Change ship FAILED! Reason:', Error_information)
raise
def remove_ship(self, fleet, path):
"""
功能:换船
返回值:dict
"""
try:
arg = self.str_arg(fleet=fleet, path=path)
url = self.server + 'boat/removeBoat/{fleet}/{path}/'.format(**arg) + self.get_url_end()
data=self.Mdecompress(url)
data = json.loads(data)
error_find(data)
if is_write and os.path.exists('requestsData'):
with open('requestsData/remove_ship.json', 'w') as f:
f.write(json.dumps(data))
return data
except HmError as e:
print('Remove ship FAILED! Reason:', e.message)
raise
except Exception as Error_information:
print('Change ship FAILED! Reason:', Error_information)
raise
def remove_equipment(self, ids, path):
"""
功能:移除装备
返回值:dict
"""
try:
arg = self.str_arg(ids=ids, path=path)
url = self.server + 'boat/removeEquipment/{ids}/{path}'.format(**arg) + self.get_url_end()
data=self.Mdecompress(url)
data = json.loads(data)
error_find(data)
if is_write and os.path.exists('requestsData'):
with open('requestsData/remove_equipment.json', 'w') as f:
f.write(json.dumps(data))
return data
except HmError as e:
print('Remove equipment FAILED! Reason:', e.message)
raise
except Exception as Error_information:
print('Remove equipment FAILED! Reason:', Error_information)
raise
def change_equipment(self, ids, cid, path):
"""
功能:更换装备
返回值:dict
"""
try:
arg = self.str_arg(ids=ids, path=path, cid=cid)
url = self.server + 'boat/changeEquipment/{ids}/{cid}/{path}'.format(**arg) + self.get_url_end()
data=self.Mdecompress(url)
data = json.loads(data)
error_find(data)
if is_write and os.path.exists('requestsData'):
with open('requestsData/change_equipment.json', 'w') as f:
f.write(json.dumps(data))
return data
except HmError as e:
print('Change equipment FAILED! Reason:', e.message)
raise
except Exception as e:
print('Change equipment FAILED! Reason:', e)
raise
def rename(self, ids, new_name):
"""
功能:改名
返回值:dict
"""
try:
arg = self.str_arg(ids=ids, new_name=new_name)
url = self.server + 'boat/renameShip/{ids}/{new_name}/'.format(**arg) + self.get_url_end()
url = quote(url, safe=";/?:@&=+$,", encoding="utf-8")
data=self.Mdecompress(url)
data = json.loads(data)
error_find(data)
if is_write and os.path.exists('requestsData'):
with open('requestsData/rename.json', 'w') as f:
f.write(json.dumps(data))
return data
except HmError as e:
print('Rename FAILED! Reason:', e.message)
raise
except Exception as Error_information:
print('Rename FAILED! Reason:', Error_information)
raise
def dismantle_equipment(self, cid, num):
"""
功能:分解装备
返回值:dict
"""
try:
url = self.server + 'dock/dismantleEquipment/' + self.get_url_end()
vdata = 'content={' + '"{}":{}'.format(str(cid), str(num)) + '}'
data=self.Mdecompress(url,vdata)
data = json.loads(data)
error_find(data)
if is_write and os.path.exists('requestsData'):
with open('requestsData/dismantle_equipment.json', 'w') as f:
f.write(json.dumps(data))
return data
except HmError as e:
print('Dismantle equipment FAILED! Reason:', e.message)
raise
except Exception as Error_information:
print('Dismantle equipment FAILED! Reason:', Error_information)
raise
def get_active_data(self):
"""
功能:收装备
返回值:dict
"""
try:
url = self.server + 'ocean/getCIAList/' + self.get_url_end()
data=self.Mdecompress(url)
data = json.loads(data)
error_find(data)
if is_write and os.path.exists('requestsData'):
with open('requestsData/get_active_data.json', 'w') as f:
f.write(json.dumps(data))
return data
except HmError as e:
print('Get active data FAILED! Reason:', e.message)
raise
except Exception as Error_information:
print('Get active data FAILED! Reason:', Error_information)
raise
def instant_fleet(self, fleet, ship):
try:
ships = "[" + ",".join([str(x) for x in ship]) + "]"