Skip to content

Commit

Permalink
Merge pull request #22 from euanwm/feature/deprecate_js2py
Browse files Browse the repository at this point in the history
dropped js2py function
  • Loading branch information
euanwm authored Sep 1, 2024
2 parents c2e0181 + cecca34 commit e0fd77a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 25 deletions.
5 changes: 2 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@

setup(
name="sport80",
version="2.2.4",
version="2.2.5",
description="Python API interface for the Sport80 sites",
long_description='Intentionally empty',
url="https://github.com/euanwm/sport80_api",
author="Euan Meston",
author_email="[email protected]",
license="BSD",
install_requires=["requests",
"beautifulsoup4",
"js2py"],
"beautifulsoup4"],
classifiers=["Programming Language :: Python :: 3.11"],
python_requires='>=3.8'
)
4 changes: 2 additions & 2 deletions sport80/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

from .sport80 import SportEighty
from .sport80_http_client import SportEightyHTTP
from .helpers import pull_tables, convert_to_json, convert_to_py
from .helpers import pull_tables
from .pages_enum import EndPoint

__version__ = "2.2.4"
__version__ = "2.2.5"
__author__ = "Euan Meston"
8 changes: 1 addition & 7 deletions sport80/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from logging import info, debug
from bs4 import BeautifulSoup
from requests import Response
from js2py import eval_js
# from js2py import eval_js

from .pages_enum import LegacyEndPoint

Expand Down Expand Up @@ -49,12 +49,6 @@ def collate_index(page_data: dict) -> dict:
return switch_to_dict


def convert_to_py(js_vars: str) -> dict:
""" I really don't care at this stage """
py_dict = eval_js(js_vars.lstrip('[<script type="application/javascript">').rstrip('</script>]'))
return py_dict


def resolve_to_ip(url: str) -> str:
""" Returns IP address of the subdomain """
return socket.gethostbyname(url)
Expand Down
28 changes: 15 additions & 13 deletions sport80/sport80_http_client.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
""" Busy backend shit """
import logging
import requests
from typing import Union, Optional

import json
import re
from urllib.parse import urljoin
from bs4 import BeautifulSoup
from typing import Union, Optional
import requests

from .pages_enum import EndPoint, LegacyEndPoint
from .helpers import pull_tables, convert_to_json, convert_to_py, collate_index, event_dict_to_list
from .helpers import pull_tables, convert_to_json, collate_index, event_dict_to_list


class SportEightyHTTP:
Expand Down Expand Up @@ -37,14 +37,16 @@ def app_data(self):
def pull_domain_env(self) -> dict:
""" On both BWL and USAW sites, there is a JS dict needed for the API calls to work """
get_page = requests.get(urljoin(self.domain, EndPoint.INDEX_PAGE.value))
soup = BeautifulSoup(get_page.content, "html.parser")
scripts_in_page = soup.find_all('script')
js_extract = []
for js_section in scripts_in_page:
if "application/javascript" in js_section.attrs.values():
js_extract.append(js_section)
if len(js_extract) == 1:
return convert_to_py(str(js_extract))
page_data = get_page.text
reggie = re.compile(r"window.env = ({.*?});", re.DOTALL)
match = reggie.search(page_data)
if match:
try:
py_dict = json.loads(match.group(1))
return py_dict
except json.JSONDecodeError:
return {}
return {}

def test_token(self, token: str):
api_url = urljoin(self.domain_env['RANKINGS_DOMAIN_URL'], EndPoint.RANKINGS_INDEX.value)
Expand Down

0 comments on commit e0fd77a

Please sign in to comment.