This repository has been archived by the owner on Aug 23, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 52
/
wxUtils.py
114 lines (88 loc) · 2.53 KB
/
wxUtils.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
#!/usr/bin/env python
# -*- coding:utf-8 -*
from time import time, strftime, localtime
from random import randint
from PIL import Image
from StringIO import StringIO
import re
import codecs
def genTimeStamp(length):
t = '%d' % (time() * 10 ** (length - 10))
return t
def genRString():
r = str(~ int(bin(int(time() * 1000))[-32:], 2))
return r
def genRandint(length):
r = str(randint(10 ** (length - 1), 10 ** length - 1))
return r
def genDeviceId():
e = 'e%s' % (genRandint(15))
return e
def displayImage(content):
Image.open(StringIO(content)).show()
return
def isPerson(contact):
if '@@' in contact['UserName']:
return False
elif contact['UserName'] in ['filehelper', 'fmessage', 'mphelper', 'weixin', 'weixingongzhong', 'wxzhifu']:
return False
elif contact['VerifyFlag'] & 8 != 0:
return False
elif contact['KeyWord'] == 'gh_':
return False
else:
return True
def removeEmoji(content):
content = re.sub(r'</?span[^>]*>|[\r\n\t]', ' ', content)
content = content.replace('&', '&').strip()
return content
def convertGender(sex):
if sex == 1:
gender = u'男'
elif sex == 2:
gender = u'女'
else:
gender = ''
return gender
def isFriend(friendsUserName, userName):
try:
if userName in friendsUserName:
val = u'是'
else:
val = u'否'
except:
val = ''
return val
def pickScreenName(NickName, RemarkName):
if RemarkName:
return removeEmoji(RemarkName)
else:
return removeEmoji(NickName)
def formatQuanPin(PYQuanPin, RemarkPYQuanPin):
PYQuanPin = re.sub(
r'spanclassemojiemoji\w{5}span|\?', '`', PYQuanPin.strip())
if re.match(r'^\d', PYQuanPin):
PYQuanPin = '`' + PYQuanPin
PYQuanPin = re.sub(r'`+', '`', PYQuanPin)
RemarkPYQuanPin = re.sub(
r'spanclassemojiemoji\w{5}span|\?', '`', RemarkPYQuanPin.strip())
if re.match(r'^\d', RemarkPYQuanPin):
RemarkPYQuanPin = '`' + RemarkPYQuanPin
RemarkPYQuanPin = re.sub(r'`+', '`', RemarkPYQuanPin)
if RemarkPYQuanPin:
return RemarkPYQuanPin.lower()
elif PYQuanPin:
return PYQuanPin.lower()
else:
return '`'
def writeLog(nickName, status):
wxLog = '[%s] - %s - %s\n' % (
strftime('%d/%b/%Y %H:%M:%S', localtime()),
nickName,
status
)
with codecs.open('wx.log', 'a+', 'utf-8') as f:
f.write(wxLog)
f.close()
if __name__ == '__main__':
pass