@ankit_anmol, It isn’t working!
import requests
import ast
import socketio
sio = socketio.Client(logger=True)
token = 'my token'
@sio.on('updateMessageCount')
def onMessage():
messagecountreq = requests.get('https://api.wasteof.money/messages/count')
if messagecountreq.text.get('count') == "0":
exit()
req = requests.get('https://api.wasteof.money/messages/unread', headers = {'Authorization': token})
message = req.json()["unread"][0]
messageID = message.get('_id')
post = requests.post(f"https://api.wasteof.money/users/wombucks/wall", headers = {"Authorization": token}, json={"content": "Okay", "parent":messageID})
sio.connect("https://api.wasteof.money/", auth= {"token" : token})
Traceback (most recent call last):
File "C:\Users\drewm\AppData\Local\Programs\Python\Python39\lib\threading.py", line 973, in bootstrapinner
self.run()
File "C:\Users\drewm\AppData\Local\Programs\Python\Python39\lib\threading.py", line 910, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\drewm\AppData\Local\Programs\Python\Python39\lib\site-packages\socketio\client.py", line 705, in handleeio_message
self._handle_event(pkt.namespace, pkt.id, pkt.data)
File "C:\Users\drewm\AppData\Local\Programs\Python\Python39\lib\site-packages\socketio\client.py", line 581, in handleevent
r = self._trigger_event(data[0], namespace, *data[1:])
File "C:\Users\drewm\AppData\Local\Programs\Python\Python39\lib\site-packages\socketio\client.py", line 629, in triggerevent
return self.handlers[namespace][event](*args)
TypeError: onMessage() takes 0 positional arguments but 1 was given
Make this change:
@sio.on("updateMessageCount")
def onMessage(data): #added data as the decorator automatically passes it.
It will work :)
Also data
variable in the function has the message count. So no need to get that from the api
I might just do what I said in another comment, though it isn’t that efficient
Nvm, @ankit_anmol, I’m just going to use while True:
and time.sleep(1)
so yeah.
I hate SocketIO.
You shouldn't. I really like it as it is EASY!!
Just ask me anything like you asked now
I don’t have anything at the moment besides on how to read a comment by _id?