Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,166 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import asyncio
|
2 |
+
import websockets
|
3 |
+
import json
|
4 |
+
import requests
|
5 |
+
from datetime import datetime
|
6 |
+
import logging
|
7 |
+
|
8 |
+
# Set up logging configuration
|
9 |
+
logging.basicConfig(level=logging.INFO)
|
10 |
+
|
11 |
+
def send(your_data):
|
12 |
+
url = "https://script.google.com/macros/s/AKfycbzT-l3-HhuiXuqUHcEqxAa91DM9WBghdKEaKA4p4wxdN3abuaOvqhX_HhFUEZRj_N92IQ/exec"
|
13 |
+
|
14 |
+
try:
|
15 |
+
respond = requests.get(url, data=your_data)
|
16 |
+
respond.raise_for_status()
|
17 |
+
print('response:', respond)
|
18 |
+
logging.info("Submitted successfully to Google Form.")
|
19 |
+
except requests.exceptions.RequestException as e:
|
20 |
+
logging.error("Failed to submit to Google Form: " + str(e))
|
21 |
+
def send_form(form_data):
|
22 |
+
url = "https://docs.google.com/forms/u/0/d/e/1FAIpQLSfGlFpSsV9KG40ZT_ttcEFdNl_l2R6FqNDOsXvv8kdTBufVow/formResponse"
|
23 |
+
|
24 |
+
try:
|
25 |
+
respond = requests.post(url, data=form_data)
|
26 |
+
respond.raise_for_status()
|
27 |
+
#print('response:', respond)
|
28 |
+
logging.info("Submitted successfully to Google Form.")
|
29 |
+
except requests.exceptions.RequestException as e:
|
30 |
+
logging.error("Failed to submit to Google Form: " + str(e))
|
31 |
+
|
32 |
+
def card(dtCard):
|
33 |
+
cardid = []
|
34 |
+
for x in dtCard:
|
35 |
+
if dtCard[x] % 20 in [1, 14]:
|
36 |
+
a = 1
|
37 |
+
elif dtCard[x] % 20 in [11, 12, 13]:
|
38 |
+
a = 10
|
39 |
+
elif dtCard[x] % 20 in [2,3,4,5,6,7,8,9,10]:
|
40 |
+
a = dtCard[x] % 20
|
41 |
+
else:
|
42 |
+
a = ""
|
43 |
+
cardid.append(a)
|
44 |
+
return {"Cardid": cardid}
|
45 |
+
def handle_case_25(data):
|
46 |
+
groupID = data['groupID']
|
47 |
+
playerScore = data['playerScore']
|
48 |
+
bankerScore = data['bankerScore']
|
49 |
+
dtCard = data['dtCard']
|
50 |
+
cardno = card(dtCard)
|
51 |
+
cardArr = cardno['Cardid']
|
52 |
+
|
53 |
+
if playerScore == bankerScore:
|
54 |
+
result = "T"
|
55 |
+
elif playerScore > bankerScore:
|
56 |
+
result = "P"
|
57 |
+
else:
|
58 |
+
result = "B"
|
59 |
+
|
60 |
+
today = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
61 |
+
record = {
|
62 |
+
"Time": today,
|
63 |
+
"ID": groupID,
|
64 |
+
"P1": cardArr[0],
|
65 |
+
"P2": cardArr[2],
|
66 |
+
"P3": cardArr[4],
|
67 |
+
"B1": cardArr[1],
|
68 |
+
"B2": cardArr[3],
|
69 |
+
"B3": cardArr[5],
|
70 |
+
"playerScore": playerScore,
|
71 |
+
"bankerScore": bankerScore,
|
72 |
+
"Result": result,
|
73 |
+
}
|
74 |
+
record_form = {
|
75 |
+
"entry.1910151925": groupID,
|
76 |
+
"entry.345081202": cardArr[0],
|
77 |
+
"entry.790265993": cardArr[2],
|
78 |
+
"entry.266290562": cardArr[4],
|
79 |
+
"entry.1840046760": cardArr[1],
|
80 |
+
"entry.2050858893": cardArr[3],
|
81 |
+
"entry.1372409472": cardArr[5],
|
82 |
+
"entry.211810544": playerScore,
|
83 |
+
"entry.2078666320": bankerScore,
|
84 |
+
"entry.1824106848": result,
|
85 |
+
}
|
86 |
+
return record_form
|
87 |
+
async def init_sma_ws():
|
88 |
+
uri = "wss://a45gs-t.wmetg.com/15101"
|
89 |
+
try:
|
90 |
+
async with websockets.connect(uri) as websocket:
|
91 |
+
# Send login message to the WebSocket server
|
92 |
+
await send_login(websocket)
|
93 |
+
print('Login message sent')
|
94 |
+
|
95 |
+
# Receive and process responses from the server
|
96 |
+
while True:
|
97 |
+
#await send_heartbeat(websocket)
|
98 |
+
try:
|
99 |
+
response = await websocket.recv()
|
100 |
+
#print('Response:', response)
|
101 |
+
json_obj = json.loads(response)
|
102 |
+
protocol = json_obj["protocol"]
|
103 |
+
#print('protocol:', protocol)
|
104 |
+
#c = json_obj["data"]
|
105 |
+
#print('data:', json.dumps(c))
|
106 |
+
if protocol==25 :
|
107 |
+
data=handle_case_25(json_obj["data"])
|
108 |
+
send_form(data)
|
109 |
+
# Perform other processing based on the server response
|
110 |
+
|
111 |
+
# Send periodic heartbeat messages to maintain the connection
|
112 |
+
#await send_heartbeat(websocket)
|
113 |
+
except websockets.exceptions.ConnectionClosedError as e:
|
114 |
+
print(f"Connection closed: {e}")
|
115 |
+
break
|
116 |
+
except asyncio.CancelledError:
|
117 |
+
print("WebSocket connection cancelled.")
|
118 |
+
except Exception as e:
|
119 |
+
print(f"Error: {e}")
|
120 |
+
|
121 |
+
async def send_login(websocket):
|
122 |
+
# Create a JSON message containing login information
|
123 |
+
login_data = {
|
124 |
+
"protocol": 1,
|
125 |
+
"data": {
|
126 |
+
"sid": "ANONYMOUS-1000759",
|
127 |
+
"dtBetLimitSelectID": {
|
128 |
+
"101": 99101,
|
129 |
+
"102": 99102,
|
130 |
+
"103": 99103,
|
131 |
+
"104": 99104,
|
132 |
+
"105": 99105,
|
133 |
+
"106": 99106,
|
134 |
+
"107": 99107,
|
135 |
+
"108": 99108,
|
136 |
+
"110": 99110,
|
137 |
+
"111": 99111,
|
138 |
+
"112": 99112,
|
139 |
+
"113": 99113,
|
140 |
+
"125": 99125,
|
141 |
+
"126": 99126,
|
142 |
+
"128": 99128,
|
143 |
+
"129": 99129
|
144 |
+
},
|
145 |
+
"bGroupList": False,
|
146 |
+
"videoName": "HttpFlv",
|
147 |
+
"videoDelay": 3000,
|
148 |
+
"userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"
|
149 |
+
}
|
150 |
+
}
|
151 |
+
login_message = json.dumps(login_data)
|
152 |
+
|
153 |
+
# Send the login message to the WebSocket server
|
154 |
+
await websocket.send(login_message)
|
155 |
+
|
156 |
+
async def send_heartbeat(websocket):
|
157 |
+
# Send a heartbeat message to the WebSocket server
|
158 |
+
heartbeat_message = {"protocol": 999, "data": {}}
|
159 |
+
await websocket.send(json.dumps(heartbeat_message))
|
160 |
+
|
161 |
+
# Wait for a period of time before sending the next heartbeat
|
162 |
+
await asyncio.sleep(10) # Send heartbeat every 10 seconds
|
163 |
+
|
164 |
+
# Create an event loop and run the coroutine until completion
|
165 |
+
#asyncio.run(init_sma_ws())
|
166 |
+
await init_sma_ws()
|