Skip to content
This repository has been archived by the owner on May 19, 2019. It is now read-only.

Commit

Permalink
Add User-Agent (#98)
Browse files Browse the repository at this point in the history
* Added User-Agent header in loading for each site

* Moved common var in __init__
  • Loading branch information
nadyr-mg authored and korovkinand committed Feb 15, 2018
1 parent 3361279 commit 84cf301
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
5 changes: 5 additions & 0 deletions surebet/loading/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

package_dir = os.path.dirname(__file__)

browser_headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/63.0.3239.132 Safari/537.36",
}


class LoadException(Exception):
pass
Expand Down
6 changes: 4 additions & 2 deletions surebet/loading/marat.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import re
import requests

from surebet.loading import browser_headers
from surebet.loading import log_loaded_events, check_status
from surebet.loading.async import async_post, async_get

Expand All @@ -20,7 +21,7 @@


def load_events():
r = requests.get(url)
r = requests.get(url, headers=browser_headers)
check_status(r.status_code)

site_html = r.text
Expand Down Expand Up @@ -74,7 +75,8 @@ def process_sport_tree(raw_sport_tree):
async def get_event_details(event_id, session):
req_url = details_url.format(event_id)

headers = {"Content-Type": "application/x-www-form-urlencoded"}
headers = browser_headers.copy()
headers.update({"Content-Type": "application/x-www-form-urlencoded"})
resp = await async_post(session, req_url, headers=headers, allow_empty=True)

result = None
Expand Down
14 changes: 12 additions & 2 deletions surebet/loading/olimp.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
"lang_id": "2",
}

base_headers = {
"User-Agent": "okhttp/3.8.0",
}

sports_by_id = {
1: "soccer",
5: "basket",
Expand All @@ -42,7 +46,10 @@ def get_sport_tree():
"time_shift": "0",
})

r = requests.post(req_url, headers=get_xtoken(form_data), data=form_data)
headers = base_headers.copy()
headers.update(get_xtoken(form_data))

r = requests.post(req_url, headers=headers, data=form_data)
check_status(r.status_code)
response = r.json()

Expand All @@ -67,7 +74,10 @@ async def get_event_details(event_id, sport_id, session):
"id": event_id,
})

resp = await async_post(session, req_url, headers=get_xtoken(form_data), data=form_data, allow_not_found=True)
headers = base_headers.copy()
headers.update(get_xtoken(form_data))

resp = await async_post(session, req_url, headers=headers, data=form_data, allow_not_found=True)

details = resp["data"] if resp else None
return {"sport_id": sport_id, "details": details}
Expand Down
4 changes: 3 additions & 1 deletion surebet/loading/posit.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
index_url = "https://positivebet.com/en/bets/index"

xp_token = '//*[@id="login-form"]/input'

token_name = "YII_CSRF_TOKEN"

payload = {
"UserLogin[rememberMe]": ["0", "1"],
"yt0": '',
Expand All @@ -37,6 +37,8 @@ def load(session, account=default_account):
"UserLogin[password]": account["pass"],
})

session.headers.update(browser_headers)

resp = session.get(login_url)
check_status(resp.status_code)

Expand Down

0 comments on commit 84cf301

Please sign in to comment.