Skip to content

Commit

Permalink
Merge pull request #62 from TimNekk/develop
Browse files Browse the repository at this point in the history
Add Docker Support
  • Loading branch information
TimNekk authored Feb 16, 2024
2 parents ac807fa + d110baf commit 313d34f
Show file tree
Hide file tree
Showing 10 changed files with 148 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .env.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
OZON_START_TIME=07:30
WILDBERRIES_START_TIME=08:00
TZ=Europe/Moscow
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM python:3.10-slim

WORKDIR /usr/src/app

COPY . .

RUN pip install --no-cache-dir -r requirements.txt
82 changes: 76 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,70 @@
# MarketplacesGoodsTracker
<h1 align=center><code>MarketplacesGoodsTracker</code></h1>
<div align=center>
Quantity and price tracker for <b>Ozon</b> and <b>Wildberries</b> (based on <strike><a href="https://github.com/SeleniumHQ/selenium">selenium</a></strike> and <a href="https://github.com/burnash/gspread">gspread</a>)
</div>

Quantity and price tracker for Ozon and Wildberries *(based on ~~[selenium](https://github.com/SeleniumHQ/selenium)~~
and [gspread](https://github.com/burnash/gspread))*
## 📄 Preview

### Ozon

![Ozon](images/ozon.png)

### Wildberries

![Wildberries](images/wildberries.png)


## Usage
## 📦 Installation

1. Clone the repository

```shell
git clone https://github.com/TimNekk/MarketplacesGoodsTracker
```

2. Rename [.env.dist](.env.dist) to `.env` and configure it

```shell
cd MarketplacesGoodsTracker
cp .env.dist .env
```

3. Add `creds.json` to the root of the project

```shell
mv /path/to/creds.json .
```

4. Install the dependencies _(Optional, if not using Docker)_

```shell
pip install -r requirements.txt
```

## 🚀 Usage

### Using Docker Compose _(with [just](https://github.com/casey/just))_

Run for both **Ozon** and **Wildberries**
```shell
just start
```

Or for **specific** marketplace
```shell
just start-oz
# or
just start-wb
```

Stop the app
```shell
just stop
```

> [!TIP]
> More commands can be found in [justfile](justfile)

### Using Pure Python

Run the app for **Ozon**

Expand All @@ -30,4 +82,22 @@ Additional options can be shown with

```shell
python run.py -h
```
```

## 👥 Contributing

**Contributions are welcome! Here's how you can help:**
1. Fork it
2. Create your feature branch
3. Commit your changes
4. Push to the branch
5. Create a new Pull Request
6. Get your code reviewed
7. Merge your code
8. Get a 🌟
## 📝 License
This project is licensed under the GPL-3.0 License - see the [LICENSE](LICENSE) file for details
32 changes: 32 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
version: '3.8'

services:
ozon:
image: marketplaces-goods-tracker-image
container_name: marketplaces-goods-tracker-ozon
build:
context: .
restart: unless-stopped
volumes:
- .:/usr/src/app
env_file:
- .env
environment:
- TZ
- START_TIME=${OZON_START_TIME}
command: python run.py -oz -u -t ${OZON_START_TIME}

wildberries:
image: marketplaces-goods-tracker-image
container_name: marketplaces-goods-tracker-wildberries
build:
context: .
restart: unless-stopped
volumes:
- .:/usr/src/app
env_file:
- .env
environment:
- TZ
- START_TIME=${WILDBERRIES_START_TIME}
command: python run.py -wb -u -t ${WILDBERRIES_START_TIME}
21 changes: 21 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
start:
docker compose up -d

start-oz:
docker compose up -d ozon

start-wb:
docker compose up -d wildberries

stop:
docker compose down

restart:
docker compose down
docker compose up -d

logs:
docker compose logs -f

build:
docker compose build
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ selenium==4.16.0
webdriver_manager==3.5.4
gspread==5.3.2
oauth2client==4.1.3
environs==9.5.0
schedule==1.1.0
coloredlogs==15.0.1
undetected-chromedriver==3.5.4
3 changes: 2 additions & 1 deletion run.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from argparse import ArgumentParser, Namespace
from time import sleep

Expand Down Expand Up @@ -29,7 +30,7 @@ def parse_args() -> Namespace:
parser.add_argument("-t", "--start-time",
help="Time to start updating",
type=str,
default="05:00")
default=os.getenv("START_TIME", "00:00"))

return parser.parse_args()

Expand Down
4 changes: 0 additions & 4 deletions src/config.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
from environs import Env
from oauth2client.service_account import ServiceAccountCredentials

env = Env()
env.read_env()

SCOPE = (
"https://spreadsheets.google.com/feeds",
"https://www.googleapis.com/auth/spreadsheets",
Expand Down
1 change: 1 addition & 0 deletions src/models/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ class Status(Enum):
PARSING_ERROR = "Ошибка"
OUT_OF_STOCK = "Нет в наличии"
WRONG_URL = ""
OUTDATED_URL = "Обновите ссылку"
7 changes: 6 additions & 1 deletion src/parsing/ozon_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,12 @@ def _get_item(url: str) -> OzonItem | None:
except OutOfStockException as e:
logger.info(e)
return OzonItem(url=url, status=Status.OUT_OF_STOCK)
quantity = OzonParser._get_quantity(response_quantity.json())

try:
quantity = OzonParser._get_quantity(response_quantity.json())
except IndexError:
logger.info("Url must be updated")
return OzonItem(url=url, status=Status.OUTDATED_URL)

item = OzonItem(
url=url,
Expand Down

0 comments on commit 313d34f

Please sign in to comment.