Skip to content

Instantly share code, notes, and snippets.

@drpshtiwan
Created May 21, 2023 22:52
Show Gist options
  • Save drpshtiwan/4d92a3b40371d1e47a418f817cdf0822 to your computer and use it in GitHub Desktop.
Save drpshtiwan/4d92a3b40371d1e47a418f817cdf0822 to your computer and use it in GitHub Desktop.
import json
import requests
import time
import paho.mqtt.client as mqtt
# Football Topic
football_topic = "thesports/football/match/v1"
# username
username = "USERNAME"
# password
password = "SECRET KEY"
# Connection callback
def on_connect(c, userdata, flags, rc):
if rc == 0:
# Subscribe to related topics
print("connected")
c.subscribe(football_topic)
elif rc in [4, 5]:
print(
"If the verification fails, please confirm whether the user name, key, and authorized ip are correct, otherwise the authentication will fail"
)
# Message callback
def on_message(c, userdata, msg):
# Message processing logic, please refer to the document for specific format
print(msg.payload)
# json => team, player, compotition
# database
# after anaylize data, type, uci
# send websocket request
# send push notification
# response = requests.post('http://yariga.test/api/fcm',data={'fcm':msg.payload,})
if __name__ == "__main__":
# websocket protocol
client = mqtt.Client(transport="websockets")
client.tls_set()
client.username_pw_set(username=username, password=password)
client.on_connect = on_connect
client.on_message = on_message
client.connect("mq.thesports.com", 443)
client.loop_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment