forked from Gilg4mesh/tixcraft_bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NonBrowser.py
49 lines (40 loc) · 1.55 KB
/
NonBrowser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import base64
import json
from io import BytesIO
import requests
from PIL import Image
class NonBrowser():
def __init__(self, domain_name = "tixcraft.com") -> None:
self.Session = requests.session()
self.Set_Domain(domain_name)
def Set_cookies(self, cookies:dict):
ret = False
if not cookies is None:
for cookie in cookies:
self.Session.cookies.set(cookie["name"],cookie["value"])
ret = True
return ret
def Get_cookies(self):
return self.Session.cookies.get_dict()
def set_headers(self, header:str):
self.Session.headers = header
def Set_Domain(self, domain_name, captcha_url="ticket/captcha", refresh_url="ticket/captcha?refresh=1"):
self.url = "https://%s/%s" % (domain_name, captcha_url)
self.refresh_url = "https://%s/%s" % (domain_name, refresh_url)
def Request_Captcha(self):
img = Image.open(BytesIO(self.Session.get(self.url, stream = True).content))
output_buffer = BytesIO()
img.save(output_buffer, format='JPEG')
binary_data = output_buffer.getvalue()
base64_data = base64.b64encode(binary_data)
return base64_data
def Request_Refresh_Captcha(self) -> str:
try:
result = self.Session.get(self.refresh_url, stream = True)
if result.status_code == 200:
json_data = json.loads(result.text)
return json_data.get("url","")
else:
return ""
except Exception as e:
return ""