diff --git a/.gitignore b/.gitignore index b2b540e..16bf87f 100644 --- a/.gitignore +++ b/.gitignore @@ -164,3 +164,4 @@ cython_debug/ # Added by Bhargav. _proc/ +data/ diff --git a/README.md b/README.md index 3235c7b..81064c6 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,20 @@ -# isl-2024 +# Indian Super League, 2024 -This file will become your README and also the index of your -documentation. +## Installation -## Developer Guide +Install latest from the GitHub +[repository](https://github.com/bkowshik/isl-2024): -If you are new to using `nbdev` here are some useful pointers to get you -started. +``` bash +$ pip install git+https://github.com/bkowshik/isl-2024.git +``` -### Install isl_2024 in Development mode +## Development -``` sh +``` bash # make sure isl_2024 package is installed in development mode $ pip install -e . @@ -24,44 +25,6 @@ $ pip install -e . $ nbdev_prepare ``` -## Usage - -### Installation - -Install latest from the GitHub -[repository](https://github.com/bkowshik/isl-2024): - -``` sh -$ pip install git+https://github.com/bkowshik/isl-2024.git -``` - -or from [conda](https://anaconda.org/bkowshik/isl-2024) - -``` sh -$ conda install -c bkowshik isl_2024 -``` - -or from [pypi](https://pypi.org/project/isl-2024/) - -``` sh -$ pip install isl_2024 -``` - -### Documentation - -Documentation can be found hosted on this GitHub -[repository](https://github.com/bkowshik/isl-2024)’s -[pages](https://bkowshik.github.io/isl-2024/). Additionally you can find -package manager specific guidelines on -[conda](https://anaconda.org/bkowshik/isl-2024) and -[pypi](https://pypi.org/project/isl-2024/) respectively. - -## How to use - -Fill me in please! Don’t forget code examples: - -``` python -1+1 -``` +## Scrapers - 2 +1. Scrape matches. diff --git a/isl_2024/_modidx.py b/isl_2024/_modidx.py index bbe443e..e563a27 100644 --- a/isl_2024/_modidx.py +++ b/isl_2024/_modidx.py @@ -5,4 +5,4 @@ 'doc_host': 'https://bkowshik.github.io', 'git_url': 'https://github.com/bkowshik/isl-2024', 'lib_path': 'isl_2024'}, - 'syms': {'isl_2024.core': {'isl_2024.core.foo': ('core.html#foo', 'isl_2024/core.py')}}} + 'syms': {'isl_2024.core': {'isl_2024.core.foo': ('core.html#foo', 'isl_2024/core.py')}, 'isl_2024.scrape_matches': {}}} diff --git a/isl_2024/scrape_matches.py b/isl_2024/scrape_matches.py new file mode 100644 index 0000000..b5000e2 --- /dev/null +++ b/isl_2024/scrape_matches.py @@ -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)) diff --git a/nbs/00_core.ipynb b/nbs/00_core.ipynb deleted file mode 100644 index 6671b71..0000000 --- a/nbs/00_core.ipynb +++ /dev/null @@ -1,61 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# core\n", - "\n", - "> Fill in a module description here" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "#| default_exp core" - ] - }, - { - "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", - "def foo(): pass" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "#| hide\n", - "import nbdev; nbdev.nbdev_export()" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "python3", - "language": "python", - "name": "python3" - } - }, - "nbformat": 4, - "nbformat_minor": 4 -} diff --git a/nbs/01_scrape_matches.ipynb b/nbs/01_scrape_matches.ipynb new file mode 100644 index 0000000..931345f --- /dev/null +++ b/nbs/01_scrape_matches.ipynb @@ -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 +} diff --git a/nbs/index.ipynb b/nbs/index.ipynb index f230db5..8af50a1 100644 --- a/nbs/index.ipynb +++ b/nbs/index.ipynb @@ -14,44 +14,57 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# isl-2024\n", + "# Indian Super League, 2024\n", "\n", - "> Indian Super League, 2024" + "> Insights from Indian Super League, 2024" ] }, { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": null, "metadata": {}, - "source": [ - "This file will become your README and also the index of your documentation." - ] + "outputs": [], + "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "## Developer Guide" + "## Installation" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "If you are new to using `nbdev` here are some useful pointers to get you started." + "Install latest from the GitHub [repository][repo]:\n", + "\n", + "```bash\n", + "$ pip install git+https://github.com/bkowshik/isl-2024.git\n", + "```\n", + "\n", + "[repo]: https://github.com/bkowshik/isl-2024" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, { "cell_type": "markdown", "metadata": {}, "source": [ - "### Install isl_2024 in Development mode" + "## Development" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "```sh\n", + "```bash\n", "# make sure isl_2024 package is installed in development mode\n", "$ pip install -e .\n", "\n", @@ -64,101 +77,27 @@ ] }, { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Usage" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Installation" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Install latest from the GitHub [repository][repo]:\n", - "\n", - "```sh\n", - "$ pip install git+https://github.com/bkowshik/isl-2024.git\n", - "```\n", - "\n", - "or from [conda][conda]\n", - "\n", - "```sh\n", - "$ conda install -c bkowshik isl_2024\n", - "```\n", - "\n", - "or from [pypi][pypi]\n", - "\n", - "\n", - "```sh\n", - "$ pip install isl_2024\n", - "```\n", - "\n", - "\n", - "[repo]: https://github.com/bkowshik/isl-2024\n", - "[docs]: https://bkowshik.github.io/isl-2024/\n", - "[pypi]: https://pypi.org/project/isl-2024/\n", - "[conda]: https://anaconda.org/bkowshik/isl-2024" - ] - }, - { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": null, "metadata": {}, - "source": [ - "### Documentation" - ] + "outputs": [], + "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Documentation can be found hosted on this GitHub [repository][repo]'s [pages][docs]. Additionally you can find package manager specific guidelines on [conda][conda] and [pypi][pypi] respectively.\n", + "## Scrapers\n", "\n", - "[repo]: https://github.com/bkowshik/isl-2024\n", - "[docs]: https://bkowshik.github.io/isl-2024/\n", - "[pypi]: https://pypi.org/project/isl-2024/\n", - "[conda]: https://anaconda.org/bkowshik/isl-2024" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## How to use" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Fill me in please! Don't forget code examples:" + "1. Scrape matches." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "2" - ] - }, - "execution_count": null, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "1+1" - ] + "outputs": [], + "source": [] }, { "cell_type": "code", @@ -170,21 +109,9 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "python3", "language": "python", "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.11.8" } }, "nbformat": 4, diff --git a/nbs/sidebar.yml b/nbs/sidebar.yml new file mode 100644 index 0000000..3b52dd2 --- /dev/null +++ b/nbs/sidebar.yml @@ -0,0 +1,5 @@ +website: + sidebar: + contents: + - index.ipynb + - 01_scrape_matches.ipynb