-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First scraper to download match summary
- Loading branch information
Showing
8 changed files
with
236 additions
and
215 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -164,3 +164,4 @@ cython_debug/ | |
|
||
# Added by Bhargav. | ||
_proc/ | ||
data/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
"""Script data about matches.""" | ||
|
||
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/01_scrape_matches.ipynb. | ||
|
||
# %% auto 0 | ||
__all__ = ['parent_dir', 'log_dir', 'data_dir', 'url', 'headers', 'response'] | ||
|
||
# %% ../nbs/01_scrape_matches.ipynb 2 | ||
import warnings | ||
warnings.filterwarnings('ignore') | ||
|
||
import json | ||
import logging | ||
import os | ||
import requests | ||
|
||
# %% ../nbs/01_scrape_matches.ipynb 4 | ||
try: | ||
# This will work when running as a script | ||
script_dir = os.path.dirname(os.path.abspath(__file__)) | ||
except NameError: | ||
# This will work when running in a Jupyter notebook | ||
script_dir = os.getcwd() | ||
|
||
parent_dir = os.path.abspath(os.path.join(script_dir, os.pardir)) | ||
log_dir = os.path.join(parent_dir, 'logs') | ||
data_dir = os.path.join(parent_dir, 'data') | ||
|
||
if not os.path.exists(log_dir): | ||
os.makedirs(log_dir) | ||
|
||
if not os.path.exists(data_dir): | ||
os.makedirs(data_dir) | ||
|
||
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s', filename=os.path.join(log_dir, 'scrape_matches.log'), filemode='a') | ||
|
||
# %% ../nbs/01_scrape_matches.ipynb 5 | ||
url = 'https://www.indiansuperleague.com/default.aspx?methodtype=3&client=3747164737&sport=2&league=india_sl_stats&timezone=0530&language=&tournament=india_sl_stats_2024' | ||
headers = { | ||
'accept': '*/*', | ||
'referer': 'https://www.indiansuperleague.com/', | ||
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36' | ||
} | ||
response = requests.get(url, headers=headers) | ||
|
||
# %% ../nbs/01_scrape_matches.ipynb 6 | ||
if response.status_code == 200: | ||
logging.info('API request successful. Content length: {}'.format(len(response.content))) | ||
with open(os.path.join(data_dir, 'scrape_matches.txt'), 'a') as f: | ||
f.write(response.text + "\n") | ||
else: | ||
logging.error('API request failed. Status code: {}'.format(response.status_code)) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"#| hide\n", | ||
"#| default_exp scrape_matches" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Scrape matches\n", | ||
"\n", | ||
"> Script data about matches." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"#| export\n", | ||
"\n", | ||
"import warnings\n", | ||
"warnings.filterwarnings('ignore')\n", | ||
"\n", | ||
"import json\n", | ||
"import logging\n", | ||
"import os\n", | ||
"import requests" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"#| hide\n", | ||
"from nbdev.showdoc import *" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"#| export\n", | ||
"try:\n", | ||
" # This will work when running as a script\n", | ||
" script_dir = os.path.dirname(os.path.abspath(__file__))\n", | ||
"except NameError:\n", | ||
" # This will work when running in a Jupyter notebook\n", | ||
" script_dir = os.getcwd()\n", | ||
"\n", | ||
"parent_dir = os.path.abspath(os.path.join(script_dir, os.pardir))\n", | ||
"log_dir = os.path.join(parent_dir, 'logs')\n", | ||
"data_dir = os.path.join(parent_dir, 'data')\n", | ||
" \n", | ||
"if not os.path.exists(log_dir):\n", | ||
" os.makedirs(log_dir)\n", | ||
"\n", | ||
"if not os.path.exists(data_dir):\n", | ||
" os.makedirs(data_dir)\n", | ||
"\n", | ||
"logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s', filename=os.path.join(log_dir, 'scrape_matches.log'), filemode='a')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"#| export\n", | ||
"url = 'https://www.indiansuperleague.com/default.aspx?methodtype=3&client=3747164737&sport=2&league=india_sl_stats&timezone=0530&language=&tournament=india_sl_stats_2024'\n", | ||
"headers = {\n", | ||
" 'accept': '*/*',\n", | ||
" 'referer': 'https://www.indiansuperleague.com/',\n", | ||
" 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36'\n", | ||
"}\n", | ||
"response = requests.get(url, headers=headers)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"#| export\n", | ||
"if response.status_code == 200:\n", | ||
" logging.info('API request successful. Content length: {}'.format(len(response.content)))\n", | ||
" with open(os.path.join(data_dir, 'scrape_matches.txt'), 'a') as f:\n", | ||
" f.write(response.text + \"\\n\")\n", | ||
"else:\n", | ||
" logging.error('API request failed. Status code: {}'.format(response.status_code))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"#| hide\n", | ||
"import nbdev; nbdev.nbdev_export()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "python3", | ||
"language": "python", | ||
"name": "python3" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |
Oops, something went wrong.