t.me/xtekky commited on
Commit ·
c38e367
1
Parent(s): 90f6f65
quora (poe) [gpt-4/3.5] api unpatch
Browse files- quora/__init__.py +50 -31
- quora/api.py +38 -14
- quora/cookies.txt +1 -0
- quora/mail.py +30 -53
quora/__init__.py
CHANGED
|
@@ -8,9 +8,25 @@ from pathlib import Path
|
|
| 8 |
from random import choice, choices, randint
|
| 9 |
from string import ascii_letters, digits
|
| 10 |
from urllib import parse
|
| 11 |
-
from os
|
| 12 |
-
from hashlib
|
| 13 |
-
from json
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
class PoeResponse:
|
| 16 |
|
|
@@ -79,7 +95,8 @@ class Model:
|
|
| 79 |
|
| 80 |
client = Session()
|
| 81 |
client.cookies['p-b'] = token
|
| 82 |
-
|
|
|
|
| 83 |
settings = client.get('https://poe.com/api/settings').json()
|
| 84 |
|
| 85 |
client.headers = {
|
|
@@ -87,7 +104,7 @@ class Model:
|
|
| 87 |
"origin" : "https://poe.com",
|
| 88 |
"referer" : "https://poe.com/",
|
| 89 |
"content-type" : "application/json",
|
| 90 |
-
"poe-formkey" :
|
| 91 |
"poe-tchannel" : settings['tchannelData']['channel'],
|
| 92 |
"user-agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36",
|
| 93 |
"connection" : "keep-alive",
|
|
@@ -102,8 +119,8 @@ class Model:
|
|
| 102 |
"accept-encoding" : "gzip, deflate, br",
|
| 103 |
"accept-language" : "en-GB,en-US;q=0.9,en;q=0.8",
|
| 104 |
}
|
| 105 |
-
|
| 106 |
-
|
| 107 |
'queryName': 'CreateBotMain_poeBotCreate_Mutation',
|
| 108 |
'variables': {
|
| 109 |
'model' : models[model],
|
|
@@ -124,6 +141,11 @@ class Model:
|
|
| 124 |
'query': 'mutation CreateBotMain_poeBotCreate_Mutation(\n $model: String!\n $handle: String!\n $prompt: String!\n $isPromptPublic: Boolean!\n $introduction: String!\n $description: String!\n $profilePictureUrl: String\n $apiUrl: String\n $apiKey: String\n $isApiBot: Boolean\n $hasLinkification: Boolean\n $hasMarkdownRendering: Boolean\n $hasSuggestedReplies: Boolean\n $isPrivateBot: Boolean\n) {\n poeBotCreate(model: $model, handle: $handle, promptPlaintext: $prompt, isPromptPublic: $isPromptPublic, introduction: $introduction, description: $description, profilePicture: $profilePictureUrl, apiUrl: $apiUrl, apiKey: $apiKey, isApiBot: $isApiBot, hasLinkification: $hasLinkification, hasMarkdownRendering: $hasMarkdownRendering, hasSuggestedReplies: $hasSuggestedReplies, isPrivateBot: $isPrivateBot) {\n status\n bot {\n id\n ...BotHeader_bot\n }\n }\n}\n\nfragment BotHeader_bot on Bot {\n displayName\n messageLimit {\n dailyLimit\n }\n ...BotImage_bot\n ...BotLink_bot\n ...IdAnnotation_node\n ...botHelpers_useViewerCanAccessPrivateBot\n ...botHelpers_useDeletion_bot\n}\n\nfragment BotImage_bot on Bot {\n displayName\n ...botHelpers_useDeletion_bot\n ...BotImage_useProfileImage_bot\n}\n\nfragment BotImage_useProfileImage_bot on Bot {\n image {\n __typename\n ... on LocalBotImage {\n localName\n }\n ... on UrlBotImage {\n url\n }\n }\n ...botHelpers_useDeletion_bot\n}\n\nfragment BotLink_bot on Bot {\n displayName\n}\n\nfragment IdAnnotation_node on Node {\n __isNode: __typename\n id\n}\n\nfragment botHelpers_useDeletion_bot on Bot {\n deletionState\n}\n\nfragment botHelpers_useViewerCanAccessPrivateBot on Bot {\n isPrivateBot\n viewerIsCreator\n}\n',
|
| 125 |
})
|
| 126 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
if not 'success' in response.text:
|
| 128 |
raise Exception('''
|
| 129 |
Bot creation Failed
|
|
@@ -136,15 +158,14 @@ class Model:
|
|
| 136 |
|
| 137 |
class Account:
|
| 138 |
def create(proxy: None or str = None, logging: bool = False, enable_bot_creation: bool = False):
|
| 139 |
-
|
| 140 |
client = Session()
|
| 141 |
client.proxies = {
|
| 142 |
'http': f'http://{proxy}',
|
| 143 |
'https': f'http://{proxy}'} if proxy else None
|
| 144 |
-
|
| 145 |
mail = Mail(client.proxies)
|
| 146 |
mail_token = None
|
| 147 |
-
mail_address = mail.get_mail()
|
| 148 |
|
| 149 |
if logging: print('email', mail_address)
|
| 150 |
|
|
@@ -167,12 +188,9 @@ class Account:
|
|
| 167 |
"upgrade-insecure-requests": "1",
|
| 168 |
}
|
| 169 |
|
| 170 |
-
|
| 171 |
-
|
| 172 |
|
| 173 |
-
client.headers["poe-formkey"] = next_data['props']['formkey']
|
| 174 |
-
client.headers["poe-tchannel"] = client.get('https://poe.com/api/settings').json()['tchannelData']['channel']
|
| 175 |
-
|
| 176 |
payload = dumps(separators = (',', ':'), obj = {
|
| 177 |
'queryName': 'MainSignupLoginSection_sendVerificationCodeMutation_Mutation',
|
| 178 |
'variables': {
|
|
@@ -189,18 +207,18 @@ class Account:
|
|
| 189 |
response = client.post('https://poe.com/api/gql_POST', data=payload)
|
| 190 |
if 'Bad Request' in response.text:
|
| 191 |
if logging: print('bad request, retrying...' , response.json())
|
| 192 |
-
|
| 193 |
|
| 194 |
if logging: print('send_code' ,response.json())
|
| 195 |
|
| 196 |
while True:
|
| 197 |
sleep(1)
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
mail_token = findall(r';">(\d{6,7})</div>',
|
| 203 |
-
|
| 204 |
if mail_token:
|
| 205 |
break
|
| 206 |
|
|
@@ -215,7 +233,7 @@ class Account:
|
|
| 215 |
},
|
| 216 |
"query": "mutation SignupOrLoginWithCodeSection_signupWithVerificationCodeMutation_Mutation(\n $verificationCode: String!\n $emailAddress: String\n $phoneNumber: String\n) {\n signupWithVerificationCode(verificationCode: $verificationCode, emailAddress: $emailAddress, phoneNumber: $phoneNumber) {\n status\n errorMessage\n }\n}\n"
|
| 217 |
})
|
| 218 |
-
|
| 219 |
base_string = payload + client.headers["poe-formkey"] + 'WpuLMiXEKKE98j56k'
|
| 220 |
client.headers["poe-tag-id"] = md5(base_string.encode()).hexdigest()
|
| 221 |
|
|
@@ -223,23 +241,24 @@ class Account:
|
|
| 223 |
if logging: print('verify_code', response.json())
|
| 224 |
|
| 225 |
token = parse.unquote(client.cookies.get_dict()['p-b'])
|
| 226 |
-
|
| 227 |
with open(Path(__file__).resolve().parent / 'cookies.txt', 'a') as f:
|
| 228 |
f.write(f'{token}\n')
|
| 229 |
|
| 230 |
if enable_bot_creation:
|
| 231 |
-
|
| 232 |
-
payload = {
|
| 233 |
"queryName": "UserProfileConfigurePreviewModal_markMultiplayerNuxCompleted_Mutation",
|
| 234 |
"variables": {},
|
| 235 |
"query": "mutation UserProfileConfigurePreviewModal_markMultiplayerNuxCompleted_Mutation {\n markMultiplayerNuxCompleted {\n viewer {\n hasCompletedMultiplayerNux\n id\n }\n }\n}\n"
|
| 236 |
-
}
|
| 237 |
|
| 238 |
-
base_string =
|
| 239 |
client.headers["poe-tag-id"] = md5(base_string.encode()).hexdigest()
|
| 240 |
-
|
| 241 |
-
client.post("https://poe.com/api/gql_POST",
|
| 242 |
-
|
|
|
|
| 243 |
return token
|
| 244 |
|
| 245 |
def get():
|
|
|
|
| 8 |
from random import choice, choices, randint
|
| 9 |
from string import ascii_letters, digits
|
| 10 |
from urllib import parse
|
| 11 |
+
from os import urandom
|
| 12 |
+
from hashlib import md5
|
| 13 |
+
from json import dumps
|
| 14 |
+
|
| 15 |
+
def extract_formkey(html):
|
| 16 |
+
script_regex = r'<script>if\(.+\)throw new Error;(.+)</script>'
|
| 17 |
+
script_text = search(script_regex, html).group(1)
|
| 18 |
+
key_regex = r'var .="([0-9a-f]+)",'
|
| 19 |
+
key_text = search(key_regex, script_text).group(1)
|
| 20 |
+
cipher_regex = r'.\[(\d+)\]=.\[(\d+)\]'
|
| 21 |
+
cipher_pairs = findall(cipher_regex, script_text)
|
| 22 |
+
|
| 23 |
+
formkey_list = [""] * len(cipher_pairs)
|
| 24 |
+
for pair in cipher_pairs:
|
| 25 |
+
formkey_index, key_index = map(int, pair)
|
| 26 |
+
formkey_list[formkey_index] = key_text[key_index]
|
| 27 |
+
formkey = "".join(formkey_list)
|
| 28 |
+
|
| 29 |
+
return formkey
|
| 30 |
|
| 31 |
class PoeResponse:
|
| 32 |
|
|
|
|
| 95 |
|
| 96 |
client = Session()
|
| 97 |
client.cookies['p-b'] = token
|
| 98 |
+
|
| 99 |
+
formkey = extract_formkey(client.get('https://poe.com').text)
|
| 100 |
settings = client.get('https://poe.com/api/settings').json()
|
| 101 |
|
| 102 |
client.headers = {
|
|
|
|
| 104 |
"origin" : "https://poe.com",
|
| 105 |
"referer" : "https://poe.com/",
|
| 106 |
"content-type" : "application/json",
|
| 107 |
+
"poe-formkey" : formkey,
|
| 108 |
"poe-tchannel" : settings['tchannelData']['channel'],
|
| 109 |
"user-agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36",
|
| 110 |
"connection" : "keep-alive",
|
|
|
|
| 119 |
"accept-encoding" : "gzip, deflate, br",
|
| 120 |
"accept-language" : "en-GB,en-US;q=0.9,en;q=0.8",
|
| 121 |
}
|
| 122 |
+
|
| 123 |
+
payload = dumps(separators=(',', ':'), obj = {
|
| 124 |
'queryName': 'CreateBotMain_poeBotCreate_Mutation',
|
| 125 |
'variables': {
|
| 126 |
'model' : models[model],
|
|
|
|
| 141 |
'query': 'mutation CreateBotMain_poeBotCreate_Mutation(\n $model: String!\n $handle: String!\n $prompt: String!\n $isPromptPublic: Boolean!\n $introduction: String!\n $description: String!\n $profilePictureUrl: String\n $apiUrl: String\n $apiKey: String\n $isApiBot: Boolean\n $hasLinkification: Boolean\n $hasMarkdownRendering: Boolean\n $hasSuggestedReplies: Boolean\n $isPrivateBot: Boolean\n) {\n poeBotCreate(model: $model, handle: $handle, promptPlaintext: $prompt, isPromptPublic: $isPromptPublic, introduction: $introduction, description: $description, profilePicture: $profilePictureUrl, apiUrl: $apiUrl, apiKey: $apiKey, isApiBot: $isApiBot, hasLinkification: $hasLinkification, hasMarkdownRendering: $hasMarkdownRendering, hasSuggestedReplies: $hasSuggestedReplies, isPrivateBot: $isPrivateBot) {\n status\n bot {\n id\n ...BotHeader_bot\n }\n }\n}\n\nfragment BotHeader_bot on Bot {\n displayName\n messageLimit {\n dailyLimit\n }\n ...BotImage_bot\n ...BotLink_bot\n ...IdAnnotation_node\n ...botHelpers_useViewerCanAccessPrivateBot\n ...botHelpers_useDeletion_bot\n}\n\nfragment BotImage_bot on Bot {\n displayName\n ...botHelpers_useDeletion_bot\n ...BotImage_useProfileImage_bot\n}\n\nfragment BotImage_useProfileImage_bot on Bot {\n image {\n __typename\n ... on LocalBotImage {\n localName\n }\n ... on UrlBotImage {\n url\n }\n }\n ...botHelpers_useDeletion_bot\n}\n\nfragment BotLink_bot on Bot {\n displayName\n}\n\nfragment IdAnnotation_node on Node {\n __isNode: __typename\n id\n}\n\nfragment botHelpers_useDeletion_bot on Bot {\n deletionState\n}\n\nfragment botHelpers_useViewerCanAccessPrivateBot on Bot {\n isPrivateBot\n viewerIsCreator\n}\n',
|
| 142 |
})
|
| 143 |
|
| 144 |
+
base_string = payload + client.headers["poe-formkey"] + 'WpuLMiXEKKE98j56k'
|
| 145 |
+
client.headers["poe-tag-id"] = md5(base_string.encode()).hexdigest()
|
| 146 |
+
|
| 147 |
+
response = client.post("https://poe.com/api/gql_POST", data = payload)
|
| 148 |
+
|
| 149 |
if not 'success' in response.text:
|
| 150 |
raise Exception('''
|
| 151 |
Bot creation Failed
|
|
|
|
| 158 |
|
| 159 |
class Account:
|
| 160 |
def create(proxy: None or str = None, logging: bool = False, enable_bot_creation: bool = False):
|
|
|
|
| 161 |
client = Session()
|
| 162 |
client.proxies = {
|
| 163 |
'http': f'http://{proxy}',
|
| 164 |
'https': f'http://{proxy}'} if proxy else None
|
| 165 |
+
|
| 166 |
mail = Mail(client.proxies)
|
| 167 |
mail_token = None
|
| 168 |
+
_, mail_address = mail.get_mail()
|
| 169 |
|
| 170 |
if logging: print('email', mail_address)
|
| 171 |
|
|
|
|
| 188 |
"upgrade-insecure-requests": "1",
|
| 189 |
}
|
| 190 |
|
| 191 |
+
client.headers["poe-formkey"] = extract_formkey(client.get('https://poe.com/login').text)
|
| 192 |
+
client.headers["poe-tchannel"] = client.get('https://poe.com/api/settings').json()['tchannelData']['channel']
|
| 193 |
|
|
|
|
|
|
|
|
|
|
| 194 |
payload = dumps(separators = (',', ':'), obj = {
|
| 195 |
'queryName': 'MainSignupLoginSection_sendVerificationCodeMutation_Mutation',
|
| 196 |
'variables': {
|
|
|
|
| 207 |
response = client.post('https://poe.com/api/gql_POST', data=payload)
|
| 208 |
if 'Bad Request' in response.text:
|
| 209 |
if logging: print('bad request, retrying...' , response.json())
|
| 210 |
+
quit()
|
| 211 |
|
| 212 |
if logging: print('send_code' ,response.json())
|
| 213 |
|
| 214 |
while True:
|
| 215 |
sleep(1)
|
| 216 |
+
messages = mail.fetch_inbox()
|
| 217 |
+
|
| 218 |
+
if len(messages["messages"]) > 0:
|
| 219 |
+
email_content = mail.get_message_content(messages["messages"][0]["_id"])
|
| 220 |
+
mail_token = findall(r';">(\d{6,7})</div>', email_content)[0]
|
| 221 |
+
|
| 222 |
if mail_token:
|
| 223 |
break
|
| 224 |
|
|
|
|
| 233 |
},
|
| 234 |
"query": "mutation SignupOrLoginWithCodeSection_signupWithVerificationCodeMutation_Mutation(\n $verificationCode: String!\n $emailAddress: String\n $phoneNumber: String\n) {\n signupWithVerificationCode(verificationCode: $verificationCode, emailAddress: $emailAddress, phoneNumber: $phoneNumber) {\n status\n errorMessage\n }\n}\n"
|
| 235 |
})
|
| 236 |
+
|
| 237 |
base_string = payload + client.headers["poe-formkey"] + 'WpuLMiXEKKE98j56k'
|
| 238 |
client.headers["poe-tag-id"] = md5(base_string.encode()).hexdigest()
|
| 239 |
|
|
|
|
| 241 |
if logging: print('verify_code', response.json())
|
| 242 |
|
| 243 |
token = parse.unquote(client.cookies.get_dict()['p-b'])
|
| 244 |
+
|
| 245 |
with open(Path(__file__).resolve().parent / 'cookies.txt', 'a') as f:
|
| 246 |
f.write(f'{token}\n')
|
| 247 |
|
| 248 |
if enable_bot_creation:
|
| 249 |
+
|
| 250 |
+
payload = dumps(separators = (',', ':'), obj={
|
| 251 |
"queryName": "UserProfileConfigurePreviewModal_markMultiplayerNuxCompleted_Mutation",
|
| 252 |
"variables": {},
|
| 253 |
"query": "mutation UserProfileConfigurePreviewModal_markMultiplayerNuxCompleted_Mutation {\n markMultiplayerNuxCompleted {\n viewer {\n hasCompletedMultiplayerNux\n id\n }\n }\n}\n"
|
| 254 |
+
})
|
| 255 |
|
| 256 |
+
base_string = payload + client.headers["poe-formkey"] + 'WpuLMiXEKKE98j56k'
|
| 257 |
client.headers["poe-tag-id"] = md5(base_string.encode()).hexdigest()
|
| 258 |
+
|
| 259 |
+
resp = client.post("https://poe.com/api/gql_POST", data = payload)
|
| 260 |
+
if logging: print(resp.json())
|
| 261 |
+
|
| 262 |
return token
|
| 263 |
|
| 264 |
def get():
|
quora/api.py
CHANGED
|
@@ -7,10 +7,12 @@ import time
|
|
| 7 |
import queue
|
| 8 |
import threading
|
| 9 |
import traceback
|
|
|
|
| 10 |
import websocket
|
| 11 |
from pathlib import Path
|
| 12 |
from urllib.parse import urlparse
|
| 13 |
|
|
|
|
| 14 |
parent_path = Path(__file__).resolve().parent
|
| 15 |
queries_path = parent_path / "graphql"
|
| 16 |
queries = {}
|
|
@@ -75,12 +77,15 @@ class Client:
|
|
| 75 |
"Referrer": "https://poe.com/",
|
| 76 |
"Origin": "https://poe.com",
|
| 77 |
}
|
| 78 |
-
self.ws_domain = f"tch{random.randint(1, 1e6)}"
|
| 79 |
-
|
| 80 |
self.session.headers.update(self.headers)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
self.next_data = self.get_next_data(overwrite_vars=True)
|
| 82 |
self.channel = self.get_channel_data()
|
| 83 |
-
self.connect_ws()
|
| 84 |
self.bots = self.get_bots(download_next_data=False)
|
| 85 |
self.bot_names = self.get_bot_names()
|
| 86 |
|
|
@@ -91,6 +96,22 @@ class Client:
|
|
| 91 |
self.gql_headers = {**self.gql_headers, **self.headers}
|
| 92 |
self.subscribe()
|
| 93 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
def get_next_data(self, overwrite_vars=False):
|
| 95 |
logger.info("Downloading next_data...")
|
| 96 |
|
|
@@ -100,7 +121,7 @@ class Client:
|
|
| 100 |
next_data = json.loads(json_text)
|
| 101 |
|
| 102 |
if overwrite_vars:
|
| 103 |
-
self.formkey =
|
| 104 |
self.viewer = next_data["props"]["pageProps"]["payload"]["viewer"]
|
| 105 |
|
| 106 |
return next_data
|
|
@@ -145,7 +166,6 @@ class Client:
|
|
| 145 |
r = request_with_retries(self.session.get, self.settings_url)
|
| 146 |
data = r.json()
|
| 147 |
|
| 148 |
-
self.formkey = data["formkey"]
|
| 149 |
return data["tchannelData"]
|
| 150 |
|
| 151 |
def get_websocket_url(self, channel=None):
|
|
@@ -157,19 +177,20 @@ class Client:
|
|
| 157 |
def send_query(self, query_name, variables):
|
| 158 |
for i in range(20):
|
| 159 |
json_data = generate_payload(query_name, variables)
|
| 160 |
-
payload = json.dumps(json_data, separators=(
|
| 161 |
-
|
| 162 |
-
base_string = payload +
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
headers =
|
| 166 |
"content-type": "application/json",
|
| 167 |
-
"poe-tag-id": md5(base_string.encode()).hexdigest()
|
| 168 |
}
|
| 169 |
-
|
|
|
|
| 170 |
r = request_with_retries(
|
| 171 |
self.session.post, self.gql_url, data=payload, headers=headers)
|
| 172 |
-
|
| 173 |
data = r.json()
|
| 174 |
if data["data"] == None:
|
| 175 |
logger.warn(
|
|
@@ -280,10 +301,13 @@ class Client:
|
|
| 280 |
self.active_messages["pending"] = None
|
| 281 |
|
| 282 |
logger.info(f"Sending message to {chatbot}: {message}")
|
|
|
|
| 283 |
# reconnect websocket
|
| 284 |
if not self.ws_connected:
|
| 285 |
self.disconnect_ws()
|
|
|
|
| 286 |
self.connect_ws()
|
|
|
|
| 287 |
message_data = self.send_query("SendMessageMutation", {
|
| 288 |
"bot": chatbot,
|
| 289 |
"query": message,
|
|
|
|
| 7 |
import queue
|
| 8 |
import threading
|
| 9 |
import traceback
|
| 10 |
+
import hashlib
|
| 11 |
import websocket
|
| 12 |
from pathlib import Path
|
| 13 |
from urllib.parse import urlparse
|
| 14 |
|
| 15 |
+
|
| 16 |
parent_path = Path(__file__).resolve().parent
|
| 17 |
queries_path = parent_path / "graphql"
|
| 18 |
queries = {}
|
|
|
|
| 77 |
"Referrer": "https://poe.com/",
|
| 78 |
"Origin": "https://poe.com",
|
| 79 |
}
|
|
|
|
|
|
|
| 80 |
self.session.headers.update(self.headers)
|
| 81 |
+
|
| 82 |
+
self.setup_connection()
|
| 83 |
+
self.connect_ws()
|
| 84 |
+
|
| 85 |
+
def setup_connection(self):
|
| 86 |
+
self.ws_domain = f"tch{random.randint(1, 1e6)}"
|
| 87 |
self.next_data = self.get_next_data(overwrite_vars=True)
|
| 88 |
self.channel = self.get_channel_data()
|
|
|
|
| 89 |
self.bots = self.get_bots(download_next_data=False)
|
| 90 |
self.bot_names = self.get_bot_names()
|
| 91 |
|
|
|
|
| 96 |
self.gql_headers = {**self.gql_headers, **self.headers}
|
| 97 |
self.subscribe()
|
| 98 |
|
| 99 |
+
def extract_formkey(self, html):
|
| 100 |
+
script_regex = r'<script>if\(.+\)throw new Error;(.+)</script>'
|
| 101 |
+
script_text = re.search(script_regex, html).group(1)
|
| 102 |
+
key_regex = r'var .="([0-9a-f]+)",'
|
| 103 |
+
key_text = re.search(key_regex, script_text).group(1)
|
| 104 |
+
cipher_regex = r'.\[(\d+)\]=.\[(\d+)\]'
|
| 105 |
+
cipher_pairs = re.findall(cipher_regex, script_text)
|
| 106 |
+
|
| 107 |
+
formkey_list = [""] * len(cipher_pairs)
|
| 108 |
+
for pair in cipher_pairs:
|
| 109 |
+
formkey_index, key_index = map(int, pair)
|
| 110 |
+
formkey_list[formkey_index] = key_text[key_index]
|
| 111 |
+
formkey = "".join(formkey_list)
|
| 112 |
+
|
| 113 |
+
return formkey
|
| 114 |
+
|
| 115 |
def get_next_data(self, overwrite_vars=False):
|
| 116 |
logger.info("Downloading next_data...")
|
| 117 |
|
|
|
|
| 121 |
next_data = json.loads(json_text)
|
| 122 |
|
| 123 |
if overwrite_vars:
|
| 124 |
+
self.formkey = self.extract_formkey(r.text)
|
| 125 |
self.viewer = next_data["props"]["pageProps"]["payload"]["viewer"]
|
| 126 |
|
| 127 |
return next_data
|
|
|
|
| 166 |
r = request_with_retries(self.session.get, self.settings_url)
|
| 167 |
data = r.json()
|
| 168 |
|
|
|
|
| 169 |
return data["tchannelData"]
|
| 170 |
|
| 171 |
def get_websocket_url(self, channel=None):
|
|
|
|
| 177 |
def send_query(self, query_name, variables):
|
| 178 |
for i in range(20):
|
| 179 |
json_data = generate_payload(query_name, variables)
|
| 180 |
+
payload = json.dumps(json_data, separators=(",", ":"))
|
| 181 |
+
|
| 182 |
+
base_string = payload + \
|
| 183 |
+
self.gql_headers["poe-formkey"] + "WpuLMiXEKKE98j56k"
|
| 184 |
+
|
| 185 |
+
headers = {
|
| 186 |
"content-type": "application/json",
|
| 187 |
+
"poe-tag-id": hashlib.md5(base_string.encode()).hexdigest()
|
| 188 |
}
|
| 189 |
+
headers = {**self.gql_headers, **headers}
|
| 190 |
+
|
| 191 |
r = request_with_retries(
|
| 192 |
self.session.post, self.gql_url, data=payload, headers=headers)
|
| 193 |
+
|
| 194 |
data = r.json()
|
| 195 |
if data["data"] == None:
|
| 196 |
logger.warn(
|
|
|
|
| 301 |
self.active_messages["pending"] = None
|
| 302 |
|
| 303 |
logger.info(f"Sending message to {chatbot}: {message}")
|
| 304 |
+
|
| 305 |
# reconnect websocket
|
| 306 |
if not self.ws_connected:
|
| 307 |
self.disconnect_ws()
|
| 308 |
+
self.setup_connection()
|
| 309 |
self.connect_ws()
|
| 310 |
+
|
| 311 |
message_data = self.send_query("SendMessageMutation", {
|
| 312 |
"bot": chatbot,
|
| 313 |
"query": message,
|
quora/cookies.txt
CHANGED
|
@@ -15,3 +15,4 @@ juCAh6kB0sUpXHvKik2woA==
|
|
| 15 |
nBvuNYRLaE4xE4HuzBPiIQ==
|
| 16 |
oyae3iClomSrk6RJywZ4iw==
|
| 17 |
1Z27Ul8BTdNOhncT5H6wdg==
|
|
|
|
|
|
| 15 |
nBvuNYRLaE4xE4HuzBPiIQ==
|
| 16 |
oyae3iClomSrk6RJywZ4iw==
|
| 17 |
1Z27Ul8BTdNOhncT5H6wdg==
|
| 18 |
+
wfUfJIlwQwUss8l-3kDt3w==
|
quora/mail.py
CHANGED
|
@@ -1,62 +1,39 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
from
|
| 4 |
|
| 5 |
class Mail:
|
| 6 |
-
def __init__(self, proxies:
|
| 7 |
-
self.
|
| 8 |
-
self.
|
| 9 |
-
self.
|
| 10 |
-
|
| 11 |
-
"connection": "keep-alive",
|
| 12 |
-
"sec-ch-ua": "\"Google Chrome\";v=\"111\", \"Not(A:Brand\";v=\"8\", \"Chromium\";v=\"111\"",
|
| 13 |
-
"accept": "application/json, text/plain, */*",
|
| 14 |
-
"content-type": "application/json",
|
| 15 |
-
"sec-ch-ua-mobile": "?0",
|
| 16 |
-
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36",
|
| 17 |
-
"sec-ch-ua-platform": "\"macOS\"",
|
| 18 |
-
"origin": "https://mail.tm",
|
| 19 |
-
"sec-fetch-site": "same-site",
|
| 20 |
-
"sec-fetch-mode": "cors",
|
| 21 |
-
"sec-fetch-dest": "empty",
|
| 22 |
-
"referer": "https://mail.tm/",
|
| 23 |
-
"accept-encoding": "gzip, deflate, br",
|
| 24 |
-
"accept-language": "en-GB,en-US;q=0.9,en;q=0.8"
|
| 25 |
-
}
|
| 26 |
|
|
|
|
|
|
|
| 27 |
def get_mail(self) -> str:
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
init = self.client.post("https://api.mail.tm/accounts", json={
|
| 31 |
-
"address" : f"{token}@bugfoo.com",
|
| 32 |
-
"password": token
|
| 33 |
-
})
|
| 34 |
-
|
| 35 |
-
if init.status_code == 201:
|
| 36 |
-
resp = self.client.post("https://api.mail.tm/token", json = {
|
| 37 |
-
**init.json(),
|
| 38 |
-
"password": token
|
| 39 |
-
})
|
| 40 |
-
|
| 41 |
-
self.client.headers['authorization'] = 'Bearer ' + resp.json()['token']
|
| 42 |
-
|
| 43 |
-
return f"{token}@bugfoo.com"
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
def fetch_inbox(self):
|
| 49 |
-
return self.client.get(f"https://api.mail.tm/messages").json()["hydra:member"]
|
| 50 |
-
|
| 51 |
-
def get_message(self, message_id: str):
|
| 52 |
-
return self.client.get(f"https://api.mail.tm/messages/{message_id}").json()
|
| 53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
def get_message_content(self, message_id: str):
|
| 55 |
-
return self.
|
| 56 |
|
|
|
|
| 57 |
|
| 58 |
-
#
|
| 59 |
-
#
|
| 60 |
-
#
|
| 61 |
-
|
| 62 |
-
|
|
|
|
| 1 |
+
import html
|
| 2 |
+
import json
|
| 3 |
+
from tls_client import Session
|
| 4 |
|
| 5 |
class Mail:
|
| 6 |
+
def __init__(self, proxies: str = None, timeout: int = 15, bearer_token: str or None = None) -> None:
|
| 7 |
+
self.session = Session(client_identifier='chrome110')
|
| 8 |
+
self.base_url = 'https://web2.temp-mail.org'
|
| 9 |
+
self.proxies = proxies
|
| 10 |
+
self.timeout = timeout
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
+
self.session.headers['authorization'] = f'Bearer {bearer_token}' if bearer_token else None
|
| 13 |
+
|
| 14 |
def get_mail(self) -> str:
|
| 15 |
+
status: html = self.session.get(self.base_url).status_code
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
+
try:
|
| 18 |
+
if status == 200:
|
| 19 |
+
data = self.session.post(f'{self.base_url}/mailbox').json()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
+
self.session.headers['authorization'] = f'Bearer {data["token"]}'
|
| 22 |
+
return data["token"], data["mailbox"]
|
| 23 |
+
|
| 24 |
+
except Exception as e:
|
| 25 |
+
print(e)
|
| 26 |
+
return f'Email creation error. {e} | use proxies', False
|
| 27 |
+
|
| 28 |
+
def fetch_inbox(self) -> json:
|
| 29 |
+
return self.session.get(f'{self.base_url}/messages').json()
|
| 30 |
+
|
| 31 |
def get_message_content(self, message_id: str):
|
| 32 |
+
return self.session.get(f'{self.base_url}/messages/{message_id}').json()["bodyHtml"]
|
| 33 |
|
| 34 |
+
# if __name__ == '__main__':
|
| 35 |
|
| 36 |
+
# email_client = TempMail()
|
| 37 |
+
# token, email = email_client.get_mail()
|
| 38 |
+
# print(email)
|
| 39 |
+
# print(token)
|
|
|