|
import asyncio |
|
import websockets |
|
import json |
|
import requests |
|
from datetime import datetime |
|
import logging |
|
|
|
|
|
logging.basicConfig(level=logging.INFO) |
|
|
|
def send(your_data): |
|
url = "https://script.google.com/macros/s/AKfycbzT-l3-HhuiXuqUHcEqxAa91DM9WBghdKEaKA4p4wxdN3abuaOvqhX_HhFUEZRj_N92IQ/exec" |
|
|
|
try: |
|
respond = requests.get(url, data=your_data) |
|
respond.raise_for_status() |
|
print('response:', respond) |
|
logging.info("Submitted successfully to Google Form.") |
|
except requests.exceptions.RequestException as e: |
|
logging.error("Failed to submit to Google Form: " + str(e)) |
|
def send_form(form_data): |
|
url = "https://docs.google.com/forms/u/0/d/e/1FAIpQLSfGlFpSsV9KG40ZT_ttcEFdNl_l2R6FqNDOsXvv8kdTBufVow/formResponse" |
|
|
|
try: |
|
respond = requests.post(url, data=form_data) |
|
respond.raise_for_status() |
|
|
|
|
|
except requests.exceptions.RequestException as e: |
|
logging.error("Failed to submit to Google Form: " + str(e)) |
|
|
|
def card(dtCard): |
|
cardid = [] |
|
for x in dtCard: |
|
if dtCard[x] % 20 in [1, 14]: |
|
a = 1 |
|
elif dtCard[x] % 20 in [11, 12, 13]: |
|
a = 10 |
|
elif dtCard[x] % 20 in [2,3,4,5,6,7,8,9,10]: |
|
a = dtCard[x] % 20 |
|
else: |
|
a = "" |
|
cardid.append(a) |
|
return {"Cardid": cardid} |
|
def handle_case_25(data): |
|
groupID = data['groupID'] |
|
playerScore = data['playerScore'] |
|
bankerScore = data['bankerScore'] |
|
dtCard = data['dtCard'] |
|
cardno = card(dtCard) |
|
cardArr = cardno['Cardid'] |
|
|
|
if playerScore == bankerScore: |
|
result = "T" |
|
elif playerScore > bankerScore: |
|
result = "P" |
|
else: |
|
result = "B" |
|
|
|
today = datetime.now().strftime("%Y-%m-%d %H:%M:%S") |
|
record = { |
|
"Time": today, |
|
"ID": groupID, |
|
"P1": cardArr[0], |
|
"P2": cardArr[2], |
|
"P3": cardArr[4], |
|
"B1": cardArr[1], |
|
"B2": cardArr[3], |
|
"B3": cardArr[5], |
|
"playerScore": playerScore, |
|
"bankerScore": bankerScore, |
|
"Result": result, |
|
} |
|
record_form = { |
|
"entry.1910151925": groupID, |
|
"entry.345081202": cardArr[0], |
|
"entry.790265993": cardArr[2], |
|
"entry.266290562": cardArr[4], |
|
"entry.1840046760": cardArr[1], |
|
"entry.2050858893": cardArr[3], |
|
"entry.1372409472": cardArr[5], |
|
"entry.211810544": playerScore, |
|
"entry.2078666320": bankerScore, |
|
"entry.1824106848": result, |
|
} |
|
return record_form |
|
async def init_sma_ws(): |
|
uri = "wss://a45gs-t.wmetg.com/15101" |
|
try: |
|
async with websockets.connect(uri) as websocket: |
|
|
|
await send_login(websocket) |
|
print('Login message sent') |
|
|
|
|
|
while True: |
|
|
|
try: |
|
response = await websocket.recv() |
|
|
|
json_obj = json.loads(response) |
|
protocol = json_obj["protocol"] |
|
|
|
|
|
|
|
if protocol==25 : |
|
data=handle_case_25(json_obj["data"]) |
|
send_form(data) |
|
|
|
|
|
|
|
|
|
except websockets.exceptions.ConnectionClosedError as e: |
|
print(f"Connection closed: {e}") |
|
break |
|
except asyncio.CancelledError: |
|
print("WebSocket connection cancelled.") |
|
except Exception as e: |
|
print(f"Error: {e}") |
|
|
|
async def send_login(websocket): |
|
|
|
login_data = { |
|
"protocol": 1, |
|
"data": { |
|
"sid": "ANONYMOUS-1000759", |
|
"dtBetLimitSelectID": { |
|
"101": 99101, |
|
"102": 99102, |
|
"103": 99103, |
|
"104": 99104, |
|
"105": 99105, |
|
"106": 99106, |
|
"107": 99107, |
|
"108": 99108, |
|
"110": 99110, |
|
"111": 99111, |
|
"112": 99112, |
|
"113": 99113, |
|
"125": 99125, |
|
"126": 99126, |
|
"128": 99128, |
|
"129": 99129 |
|
}, |
|
"bGroupList": False, |
|
"videoName": "HttpFlv", |
|
"videoDelay": 3000, |
|
"userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36" |
|
} |
|
} |
|
login_message = json.dumps(login_data) |
|
|
|
|
|
await websocket.send(login_message) |
|
|
|
async def send_heartbeat(websocket): |
|
|
|
heartbeat_message = {"protocol": 999, "data": {}} |
|
await websocket.send(json.dumps(heartbeat_message)) |
|
|
|
|
|
await asyncio.sleep(10) |
|
|
|
|
|
asyncio.run(init_sma_ws()) |
|
|
|
|