-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit port over from dragon laundry bot
- Loading branch information
Showing
11 changed files
with
476 additions
and
1 deletion.
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
data/ | ||
|
||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
|
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,8 @@ | ||
FROM python:3.12 | ||
|
||
WORKDIR /app | ||
COPY . . | ||
|
||
RUN pip install -r requirements.txt | ||
|
||
CMD ["python", "src/main.py"] |
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 |
---|---|---|
@@ -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 |
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,10 @@ | ||
version: "3" | ||
services: | ||
laundry-bot: | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
volumes: | ||
- static-volume:./data | ||
volumes: | ||
static-volume: |
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,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 |
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,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"), | ||
} | ||
) |
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,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" |
Oops, something went wrong.