VevoxCrusher/vevoxqa.py

82 lines
3.5 KiB
Python

#!/bin/python
#
# vevox.py
# VevoxCrusher
#
# Created by Yigit Colakoglu on 10/13/21.
# Copyright 2021. Yigit Colakoglu. All rights reserved.
#
from random import randint
from requests import get
from json import loads
from websocket import create_connection
class VevoxQA:
def __init__(self, sessid, host = "web1-httpapi.vevox.com"):
self.initialws = '{{"service":"httpapiservice-1_0","message":"SetConnectionInfo","data":{{"secret":"RIM2JSTSyk4Y/TXTwvh7nIWCrD6L5sraDV6Z7rZ1ZVk=","key":"FWfLAvjJmU9Wbnrm","thirdPartyUserId":"","deviceId":"{}","appVersion":"1.7.0","apiVersion":"1.23","tzid":"Europe/Amsterdam","tzoffset":-120,"sw":1022,"sh":241,"isAttendee":true,"gatewayMappings":{{"97":"wss://staging-httpapi.lumidev.net/api","98":"wss://qarel-httpapi.lumidev.net/api","99":"wss://qamaster-httpapi.lumidev.net/api"}}}},"timeout":60000,"requestId":3}}'
self.connectionws = '{{"service":"meetingservice-1_0","message":"DeviceConnectAction","data":{{"accessCode":"{}","appId":"b04cda41-22ea-40a5-a5e4-ce951bd12067","apiVersion":"1.23","connectProperties":{{"sortOrder":"normal"}}}},"timeout":10000,"reQquestId":4}}'
self.likews = '{{"service":"discussionservice-1_3","message":"DeviceDiscussionMessageLikeAction","data":{{"messageId":{},"topicId":{},"liked":true}},"timeout":10000,"requestId": {}}}'
self.askws = '{{"service":"discussionservice-1_3","message":"DeviceDiscussionMessagePostAction","data":{{"topicId":{},"message":"{}","anonymous":true,"nameHidden":false}},"timeout":10000,"requestId":{}}}'
self.sessid = sessid
self.connid = self._genconnid()
self.requestid = 5
self.host = host
def _genconnid(self):
connid = ""
connformat = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx"
for i in connformat:
rint = randint(0,15)
if i == "x":
connid += format(rint, 'x')
elif i == "y":
connid += format(3 & rint | 8, 'x')
else:
connid += i
return connid
# Open a connection to Vevox Q&A Session
def connect(self):
r = get("https://"+self.host)
if r.status_code != 404:
print("[ERROR]: Connection to {} returned status {}".format(self.host, r.status_code))
cookies = ""
cookiedict = dict(r.cookies)
for i in cookiedict:
cookies += i+"="+cookiedict[i]+"; "
self.ws = create_connection("wss://" + self.host + "/api?connection_id=" + self.connid, cookies=cookies)
self.ws.send(self.initialws.format(self.connid))
self.ws.recv()
self.ws.send(self.connectionws.format(self.sessid))
response = loads(self.ws.recv())
if response["status"] != "success":
print("[ERROR]: Initital connection request returned unsuccessful")
return
self.topicId = response["data"]["successMessages"][8]["topicId"]
self.messages = response["data"]["successMessages"][8]["messages"]["messages"]
def askquestion(self, question):
self.ws.send(self.askws.format(self.topicId, question, self.requestid))
data = loads(self.ws.recv())
# Like a question returns true if successful
def likequestion(self, qid):
self.ws.send(self.likews.format(qid, self.topicId, self.requestid))
data = loads(self.ws.recv())
while "message" not in data or data["message"] != "DeviceDiscussionMessageLikeCountList":
data = loads(self.ws.recv())
return data["data"]["likeCounts"][0]["likeCount"]
def close(self):
self.ws.close()