Skip to content

Commit

Permalink
Initial commit port over from dragon laundry bot
Browse files Browse the repository at this point in the history
  • Loading branch information
jloh02 committed May 4, 2024
1 parent 0ff6cd9 commit cd62d9c
Show file tree
Hide file tree
Showing 11 changed files with 476 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
data/

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
8 changes: 8 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM python:3.12

WORKDIR /app
COPY . .

RUN pip install -r requirements.txt

CMD ["python", "src/main.py"]
46 changes: 45 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,45 @@
# capt-laundry-bot
# CAPT Laundry Bot

Laundry bot for the management of

## Setup

### Requirements

- Python 3.12
- Docker (Only for deployment)

### Telegram Bot Setup (Local)

1. Create your own Telegram bot by following [BotFather](https://t.me/BotFather) instructions
2. Copy the `API_KEY` (keep this key secret)

### Running the Bot

1. Copy this repository

```
git clone https://github.com/jloh02/capt-laundry-bot
```

2. Create a `.env` file in root folder with the following content and update Telegram bot API key

```
```

3. Install Packages

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

4. Run Bot

```
python src/main.py
```

## Design Considerations

Instead of a DB, we opted for a local JSON file to allow for ease of deployment and logetivity of the project as this project will be managed at an individual basis outside of the management of CAPT
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: "3"
services:
laundry-bot:
build:
context: .
dockerfile: Dockerfile
volumes:
- static-volume:./data
volumes:
static-volume:
5 changes: 5 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
python-dateutil==2.9.0
python-dotenv==1.0.1
python-telegram-bot==21.1.1
python-telegram-bot[job-queue]==21.1.1
pytz==2024.1
16 changes: 16 additions & 0 deletions src/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import os
from dotenv import load_dotenv

config = {}

def read_dotenv():
global config
load_dotenv()
config.update(
{
"TELEGRAM_BOT_API_KEY": os.getenv("TELEGRAM_BOT_API_KEY"),
"WEBHOOK_URL": os.getenv("WEBHOOK_URL"),
"PRODUCTION": os.getenv("PRODUCTION") == "True",
"BASE_PATH": ("/app/static" if config.get("PRODUCTION") else "./data"),
}
)
60 changes: 60 additions & 0 deletions src/machine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
from abc import ABC
import datetime
import pytz
import utils
import storage

SGT_TIMEZONE = pytz.timezone("Asia/Singapore")


class Machine(ABC):
# constant value which stores total time required for start (IN SECONDS)
name = None
time_to_complete = None

def __init__(self, new_time_to_complete, new_name):
self.time_to_complete = new_time_to_complete
self.name = new_name

def get_name(self):
return self.name

def get_time_to_complete(self):
return self.time_to_complete

def status(self):
curr_user, end_time = storage.get_laundry_timer(self.name)
if utils.is_available(end_time):
reply = f"AVAILABLE \U00002705"
if curr_user:
reply += f', last used by @{curr_user} ({end_time.astimezone(SGT_TIMEZONE).strftime("%d/%m/%Y %I:%M%p")})'
return reply
else:
time_delta = end_time - datetime.datetime.now()
time_in_min = time_delta.seconds // 60
time_in_sec = time_delta.seconds % 60
return f"UNAVAILABLE \U0000274C for {time_in_min}mins and {time_in_sec}s by @{curr_user}"

def time_left_mins(self):
return self.time_to_complete // 60

def time_left_secs(self):
return self.time_to_complete % 60

def total_time(self):
return f"{self.time_left_mins()}mins"

def start_machine(self, new_user):
_, end_time = storage.get_laundry_timer(self.name)
if not utils.is_available(end_time):
return False
else:
new_end_time = datetime.datetime.now() + datetime.timedelta(
seconds=self.time_to_complete
)
new_curr_user = new_user
storage.set_laundry_timer(self.name, new_curr_user, new_end_time)
return True

def alarm(self):
return "Fuyohhhhhh!! Your clothes are ready for collection! Please collect them now so that others may use it"
Loading

0 comments on commit cd62d9c

Please sign in to comment.