FPC 0.76__tar.gz → 0.78__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,7 +13,7 @@ def now(x=None):#x='micro' return microsecond;x='str' return now time to string;
13
13
  if not x:return int(datetime.datetime.now().timestamp())
14
14
  elif x=='micro':return datetime.datetime.now().timestamp()
15
15
  elif x=='str':return datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
16
- elif isinstance(x,(int,float)):return datetime.datetime.fromtimestamp(x).strftime('%Y-%m-%d %H:%M:%S')
16
+ elif isinstance(x,(int,float)):return datetime.datetime.fromtimestamp(x if x <1e11 else x/1000).strftime('%Y-%m-%d %H:%M:%S')
17
17
  else:
18
18
  try: import dateutil.parser;return int(dateutil.parser.parse(x).timestamp())
19
19
  except Exception: return int(datetime.datetime.strptime(x, '%Y-%m-%d %H:%M:%S').timestamp())
@@ -54,11 +54,12 @@ def print(*a,func=None,time='%m/%d %H:%M:%S',pretty=False,**s):
54
54
  for i,x in enumerate(a):
55
55
  a[i]=func(x)
56
56
  if time:
57
- a.insert(0,datetime.datetime.now().strftime(time)+' :')
57
+ builtins.print(datetime.datetime.now().strftime(time)+' : ',end='',**s)
58
58
  if pretty:
59
59
  import pprint
60
+ if s.get('file'):s['stream']=s.pop('file')
60
61
  for x in a:
61
- pprint.pprint(x)
62
+ pprint.pprint(x,**s)
62
63
  else:
63
64
  builtins.print(*a,**s)
64
65
  def split_str(strs,num=1):
@@ -71,25 +72,30 @@ def diff(a,b):
71
72
  for x in a:
72
73
  if b.get(x)!=a[x]: diff[x]=[a[x],b.get(x)]
73
74
  return diff
74
- def notice(x,c='default',silent=None,channel=None):
75
+ def notice(x,c='default',silent=None,channel=None,is_async=False,_time=''):
76
+ if is_async:
77
+ process(notice,args=(x,c,silent,channel,False,_time))
78
+ return True
75
79
  if silent:
76
80
  red=redis()
77
81
  if red.exists(x if not channel else channel):return
78
82
  else:
79
83
  red.set(x if not channel else channel,'1',silent)
80
- try:request.urlopen(r'http://call.ff2.pw/?%s=%s&passwd=frank'%(c,urllib.parse.quote_plus(x)))
81
- except:pass
84
+ try:
85
+ request.urlopen(f'http://call.ff2.pw/?{c}={urllib.parse.quote_plus(x)}&passwd=frank&time={urllib.parse.quote_plus(_time)}')
86
+ return True
87
+ except:return False
82
88
  def rand_sleep(i=0.4,a=0.8):import random;time.sleep(random.randint(int(i*1000),int(a*1000))/1000);
83
89
  def rand(i=9,a=None):import random;return random.randint(int(i),int(a)) if a else random.randint(0,int(i-1));
84
90
  def md5(x):hl = hashlib.md5();hl.update(x.encode('utf-8') if isinstance(x,str) else x);return hl.hexdigest();
85
91
  def bin2hex(x):import binascii;return binascii.hexlify(x.encode('utf-8') if isinstance(x,str) else x);
86
92
  def base64_encode(x):import base64;return base64.b64encode(x) if isinstance(x,bytes) else base64.b64encode(x.encode('utf-8'))
87
93
  def base64_decode(x):import base64;return base64.b64decode(x+(b'===' if isinstance(x,bytes) else '==='))
88
- def log(*x,path=None):#已经带有时间
94
+ def log(*x,path=None,**s):#已经带有时间
89
95
  if path is None:
90
- path='/tmp/frank.log' if os.path.exists('/tmp') else './FPC.log'
96
+ path='/tmp/FPC.log' if os.path.exists('/tmp') else './FPC.log'
91
97
  with open(path,'a',encoding='utf-8') as f:
92
- print(*x,file=f)
98
+ print(*x,file=f,**s)
93
99
  def parse(o):#print class/obj's attr beatiful
94
100
  method=[];attr=[]
95
101
  for x in dir(o):
@@ -336,21 +342,50 @@ def process_arg_construct(urls:list,args):#args must be iterable
336
342
  for i,url in enumerate(urls):
337
343
  proc_args.append((url,args[i*every_proc_count:i*every_proc_count+every_proc_count]))
338
344
  return proc_args
339
- def process(target,is_thread=True,join=False,num=1,sleep=None,daemon=False,**args):
345
+ def process(target,is_thread=True,join=False,num:int=1,sleep=None,daemon=False,**args):
346
+ '''args:{
347
+ 'sync':True,
348
+ 'args':[('',),('',)]for mult proc,('','')for single proc the same parameter to multiple processes specified by num,
349
+ 'kwargs':[{'':''}]for mult proc,{'':''}like args,
350
+ } or others that transfer to Thread or Process'''
340
351
  if isinstance(target,(str,list)):#args:target,[sync=True]
341
352
  import subprocess
342
353
  proc=subprocess.Popen(target,stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True if isinstance(target,str) else False);
343
354
  return proc.communicate() if args.get('sync',True) else proc
344
355
  pros=[]
345
- if 'args' in args:#args can be list or tuple : [('',),('',)]
346
- assert isinstance(args['args'],(tuple,list))
347
- args_list=args['args']
348
- num=len(args_list)
356
+ if 'args' in args and 'kwargs' in args and 'kwargs' in args:
357
+ _num=max(len(args['args'])if isinstance(args['args'],list)else 0,len(args['kwargs'])if isinstance(args['kwargs'],list)else 0)
358
+ if num!=1 and num!=_num:
359
+ raise ValueError(f'max args length is {_num} not equal to num:{num}')
360
+ num=_num
361
+ if 'args' in args:
362
+ if isinstance(args['args'],tuple):
363
+ args_list=[args['args']]*num
364
+ elif isinstance(args['args'],list):
365
+ if num!=1 and num!=len(args['args']):
366
+ raise ValueError('args length must be equal to num')
367
+ args_list=args['args']
368
+ num=len(args_list)
369
+ else:
370
+ raise ValueError('args must be tuple or list')
371
+ if 'kwargs' in args:
372
+ if isinstance(args['kwargs'],dict):
373
+ kwargs_list=[args['kwargs']]*num
374
+ elif isinstance(args['kwargs'],list):
375
+ if num!=1 and num!=len(args['kwargs']):
376
+ raise ValueError('kwargs length must be equal to num')
377
+ kwargs_list=args['kwargs']
378
+ num=len(kwargs_list)
379
+ else:
380
+ raise ValueError('kwargs must be tuple or list')
381
+
349
382
  if is_thread: from threading import Thread as proc
350
383
  else: from multiprocessing import Process as proc
351
384
  for x in range(num):
352
385
  if 'args' in args:
353
- args['args']=args_list[x] if isinstance(args_list[x],(tuple,list)) else [args_list[x]]
386
+ args['args']=args_list[x]
387
+ if 'kwargs' in args:
388
+ args['kwargs']=kwargs_list[x]
354
389
  pros.append(proc(target=target,**args))
355
390
  if daemon : pros[-1].daemon=True
356
391
  pros[-1].start()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: FPC
3
- Version: 0.76
3
+ Version: 0.78
4
4
  Summary: Frank's Personal Conllection
5
5
  Home-page: http://ff2.pw
6
6
  Author: Frank
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: FPC
3
- Version: 0.76
3
+ Version: 0.78
4
4
  Summary: Frank's Personal Conllection
5
5
  Home-page: http://ff2.pw
6
6
  Author: Frank
@@ -5,7 +5,7 @@ from setuptools import setup
5
5
  import setuptools
6
6
  setup(
7
7
  name='FPC',
8
- version='0.76',
8
+ version='0.78',
9
9
  description=(
10
10
  'Frank\'s Personal Conllection'
11
11
  ),
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes