This repository has been archived by the owner on Jun 15, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathpackage.py
92 lines (79 loc) · 2.9 KB
/
package.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
import os
import re
import requests
from chat import Tuling
class Package(object):
__slots__ = ['_record','_chat']
def __init__(self):
self._record = Record()
self._chat = Tuling()
def handle_message_str(self, member, message_str,enabled_chat=False):
"""
:param message_str:
:return:
"""
try:
# judge if share url or get package
if message_str[:5] == 'ehttps':
if message_str.find("https://activity.waimai.meituan.com/") != -1 or message_str.find("https://h5.ele.me/hongbao/") != -1:
self._record.record(member,message_str)
return "请输入手机号码:"
else:
return "请确保,饿了么是以https://h5.ele.me/hongbao/开头的链接,美团是以https://activity.waimai.meituan.com/开头的链接"
else:
# check phone
if self.check_phone_number_format(message_str.strip()):
# get record
url = self._record.get_record(member)
if url == False:
return "请先分享红包链接!"
# destory
self._record.destory_record(member)
return self.get_max_package(message_str,url)
return "请分享红包链接!"
except Exception as e:
if enabled_chat:
return self._chat.response(member,message_str)
return "未启动聊天功能,请分享红包链接"
def check_phone_number_format(self,phone):
"""
check phone number format
:param phone
:return boolean
"""
pattern = re.compile('^0?(13[0-9]|14[56789]|15[012356789]|166|17[012345678]|18[0-9]|19[89])[0-9]{8}$')
if_match = pattern.match(phone)
if phone:
return True
return False
def get_max_package(self,phone,url):
data = {"url":url,"mobile":phone}
res = requests.post('https://hongbao.xxooweb.com/hongbao',data=data)
response_json = res.json()
print(response_json)
return response_json['message']
class Record(object):
"""
record the relation of member to url
"""
@staticmethod
def record(member,url):
file_name = str(member)+".txt"
with open(file_name,'w') as f:
f.write('{} {}'.format(str(member),url.strip()))
@staticmethod
def get_record(member):
file_name = str(member) + ".txt"
try:
with open(file_name,'r') as f:
member_url = f.read()
return member_url.split(" ")[1]
except expression as e:
return False
@staticmethod
def destory_record(member):
try:
path = str(member)+".txt"
os.remove(path)
except expression as e:
print(str(e))