7
7
import json
8
8
import random
9
9
import re
10
+ import sys
10
11
import time
11
12
12
13
import requests
@@ -187,16 +188,16 @@ def push_server(_sckey, desp=""):
187
188
print (f"[{ now } ] 推送失败:{ json_data ['code' ]} ({ json_data ['message' ]} )" )
188
189
189
190
190
- def push_pushplus (_token , content = "" ):
191
+ def push_pushplus (token , content = "" ):
191
192
"""
192
193
推送消息到pushplus
193
194
"""
194
- if _token == '' :
195
+ if token == '' :
195
196
print ("[注意] 未提供token,不进行pushplus推送!" )
196
197
else :
197
198
server_url = "http://www.pushplus.plus/send"
198
199
params = {
199
- "token" : _token ,
200
+ "token" : token ,
200
201
"title" : '小米运动 步数修改' ,
201
202
"content" : content
202
203
}
@@ -210,16 +211,16 @@ def push_pushplus(_token, content=""):
210
211
print (f"[{ now } ] 推送失败:{ json_data ['code' ]} ({ json_data ['message' ]} )" )
211
212
212
213
213
- def push_tg (_token , chat_id , desp = "" ):
214
+ def push_tg (token , chat_id , desp = "" ):
214
215
"""
215
216
推送消息到TG
216
217
"""
217
- if _token == '' :
218
+ if token == '' :
218
219
print ("[注意] 未提供token,不进行tg推送!" )
219
220
elif chat_id == '' :
220
221
print ("[注意] 未提供chat_id,不进行tg推送!" )
221
222
else :
222
- server_url = f"https://api.telegram.org/bot{ _token } /sendmessage"
223
+ server_url = f"https://api.telegram.org/bot{ token } /sendmessage"
223
224
params = {
224
225
"text" : '小米运动 步数修改\n \n ' + desp ,
225
226
"chat_id" : chat_id
@@ -300,69 +301,112 @@ def get_message(_msg, _usr):
300
301
send_message (msg , usr )
301
302
302
303
303
- if __name__ == "__main__" :
304
- # Push Mode
305
- Pm = input ()
306
- if Pm == 'wx' or Pm == 'nwx' :
307
- # ServerChan
308
- sckey = input ()
309
- if str (sckey ) == '0' :
310
- sckey = ''
311
- elif Pm == 'tg' :
312
- token = input ()
313
- sl = token .split ('@' )
314
- if len (sl ) != 2 :
304
+ class ToPush :
305
+ """
306
+ 推送接口类
307
+ 处理pkey并转发推送消息到推送函数
308
+ """
309
+ push_msg : str
310
+
311
+ def __init__ (self , _pkey ):
312
+ self .pkey = _pkey
313
+
314
+ def to_push_wx (self ):
315
+ """
316
+ 推送server酱接口
317
+ """
318
+ if str (self .pkey ) == '0' :
319
+ self .pkey = ''
320
+ push_wx (self .pkey , self .push_msg )
321
+
322
+ def to_push_server (self ):
323
+ """
324
+ 推送消息到微信接口
325
+ """
326
+ if str (self .pkey ) == '0' :
327
+ self .pkey = ''
328
+ push_server (self .pkey , self .push_msg )
329
+
330
+ def to_push_tg (self ):
331
+ """
332
+ 推送消息到TG接口
333
+ """
334
+ try :
335
+ token , chat_id = self .pkey .split ('@' )
336
+ push_tg (token , chat_id , self .push_msg )
337
+ except ValueError :
315
338
print ('tg推送参数有误!' )
316
- elif Pm == 'qwx' :
317
- token = input ()
318
- sl = token .split ('-' )
319
- if len (sl ) < 3 :
339
+
340
+ def to_wxpush (self ):
341
+ """
342
+ 企业微信推送接口
343
+ """
344
+ try :
345
+ usr , corpid , corpsecret , * agentid = self .pkey .split ('-' )
346
+ if agentid :
347
+ wxpush (self .push_msg , usr , corpid , corpsecret , int (agentid [0 ]))
348
+ else :
349
+ wxpush (self .push_msg , usr , corpid , corpsecret )
350
+ except ValueError :
320
351
print ('企业微信推送参数有误!' )
321
- elif Pm == 'pp' :
322
- token = input ()
323
- if token == '' :
352
+
353
+ def to_push_pushplus (self ):
354
+ """
355
+ 接口
356
+ """
357
+ if self .pkey == '' :
324
358
print ('pushplus token错误' )
325
- elif Pm == 'off' :
326
- input ()
359
+ else :
360
+ push_pushplus (self .pkey , self .push_msg )
361
+
362
+ @staticmethod
363
+ def no_push ():
364
+ """
365
+ 不推送
366
+ """
327
367
print ('不推送' )
328
- else :
329
- print ('推送选项有误!' )
330
- exit (0 )
368
+
369
+
370
+ if __name__ == "__main__" :
371
+ # Push Mode
372
+ Pm = sys .argv [0 ]
373
+ pkey = sys .argv [1 ]
374
+
375
+ to_push = ToPush (pkey )
331
376
332
377
# 用户名(格式为 13800138000)
333
- user = input ()
378
+ user = sys . argv [ 2 ]
334
379
# 登录密码
335
- passwd = input ()
380
+ passwd = sys . argv [ 3 ]
336
381
# 要修改的步数,直接输入想要修改的步数值,留空为随机步数
337
- step = input () .replace ('[' , '' ).replace (']' , '' )
382
+ step = sys . argv [ 4 ] .replace ('[' , '' ).replace (']' , '' )
338
383
339
384
user_list = user .split ('#' )
340
385
passwd_list = passwd .split ('#' )
341
386
setp_array = step .split ('-' )
342
387
343
388
if len (user_list ) == len (passwd_list ):
344
- push = ''
389
+ push_msg = ''
345
390
for user , passwd in zip (user_list , passwd_list ):
346
391
if len (setp_array ) == 2 :
347
392
step = str (random .randint (int (setp_array [0 ]), int (setp_array [1 ])))
348
393
print (f"已设置为随机步数({ setp_array [0 ]} -{ setp_array [1 ]} )" )
349
394
elif str (step ) == '0' :
350
395
step = ''
351
- push += main (user , passwd , step ) + '\n '
352
- if Pm == 'wx' :
353
- push_wx (sckey , push )
354
- elif Pm == 'nwx' :
355
- push_server (sckey , push )
356
- elif Pm == 'tg' :
357
- push_tg (sl [0 ], sl [1 ], push )
358
- elif Pm == 'qwx' :
359
- if len (sl ) == 4 :
360
- wxpush (push , sl [0 ], sl [1 ], sl [2 ], int (sl [3 ]))
361
- else :
362
- wxpush (push , sl [0 ], sl [1 ], sl [2 ])
363
- elif Pm == 'pp' :
364
- push_pushplus (token , push )
365
- elif Pm == 'off' :
366
- pass
396
+ push_msg += main (user , passwd , step ) + '\n '
397
+
398
+ push = {
399
+ 'wx' : to_push .to_push_wx ,
400
+ 'nwx' : to_push .to_push_server ,
401
+ 'tg' : to_push .to_push_tg ,
402
+ 'qwx' : to_push .to_wxpush ,
403
+ 'pp' : to_push .to_push_pushplus ,
404
+ 'off' : to_push .no_push
405
+ }
406
+ try :
407
+ push [Pm ]()
408
+ except KeyError :
409
+ print ('推送选项有误!' )
410
+ exit (0 )
367
411
else :
368
412
print ('用户名和密码数量不对' )
0 commit comments