-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathepn_parse.py
86 lines (79 loc) · 2.97 KB
/
epn_parse.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import requests
from selenium import webdriver
import time
import urllib.parse
session_requests = requests.session()
start_time = None
x_access_token = ''
def login_epn():
global session_requests
try:
url = 'https://oauth2.backit.me/ssid?client_id=web-client'
source_code = session_requests.get(url, headers={"x-api-version": "2"})
plain_text = source_code.json()
ssid_token = plain_text['data']['attributes']['ssid_token']
url = 'https://oauth2.backit.me/token'
payload = {
#"captcha": None,
#"check_ip": "false",
"client_id": "web-client",
"client_secret": "CLIENTSECRET",
"grant_type": "password",
"password": "YOURPASSWORD",
"ssid_token": ssid_token,
"username": "email@email.com"
}
source_code = session_requests.post(url, data=payload, headers={"x-api-version": "2"})
plain_text = source_code.json()
access_token = plain_text['data']['attributes']['access_token']
print(source_code)
return access_token
except Exception as e:
print("Exception: " + str(e))
return None
def get_cashback_cookies():
driver = webdriver.Chrome('C:\\temp\\chromedriver.exe')
driver.get('https://epn.bz/ru/cashback')
driver.switch_to.frame(0)
time.sleep(25)
cookies_list = driver.get_cookies()
return cookies_list
def get_cashback_link(cookies_list, url):
global session_requests
global start_time
global x_access_token
if not start_time:
start_time = time.time()
try:
x_access_token = login_epn()
if not x_access_token:
return None
except Exception as e:
print("Exception: " + str(e))
return None
current_time = time.time()
if current_time - start_time > 10*60:
try:
x_access_token = login_epn()
except:
return None
start_time = time.time()
#ALI_URL = 'https://www.aliexpress.com/item/Cowin-New-E7-Pro-BT-Game-Headphones-Gaming-Earphone-Stereo-Headset-Headphone-For-Travel-Work-TV/32916090288.html'
#CASHBACK_URL = 'https://epn.bz/ru/cashback/get-referral-link'
#for cookie in cookies_list:
# session_requests.cookies.set(cookie['name'], cookie['value'])
#payload = {
# "link": url,
# "ref_type": "99"
#}
#CASHBACK_URL = 'https://app.epn.bz/affiliate/cashback/link?refOfferId=99&link=' + urllib.parse.quote_plus(url)
CASHBACK_URL = 'https://app.backit.me/affiliate/cashback/link'
payload = (('refOfferId', '99'), ('link', url))
try:
#source_code = session_requests.post(CASHBACK_URL, data=payload)
source_code = session_requests.get(CASHBACK_URL, headers={"x-access-token": x_access_token}, params=payload)
plain_text = source_code.json()
#plain_text = source_code.text
return plain_text['data']['attributes']['link']
except:
return None