Download telebot/plugins/mybot/sql/users_sql.py from thenamk3/cc: direct link, hf CLI and curl.
- Browser
- Download file 1.24 kB
-
https://huggingface.co/spaces/thenamk3/cc/resolve/main/telebot/plugins/mybot/sql/users_sql.py
- Command line
-
hf download hf://spaces/thenamk3/cc/telebot/plugins/mybot/sql/users_sql.py
-
curl -L -o users_sql.py https://huggingface.co/spaces/thenamk3/cc/resolve/main/telebot/plugins/mybot/sql/users_sql.py
1.24 kB
| #!/usr/bin/env python3 | |
| # -*- coding: utf-8 -*- | |
| # (c) Shrimadhav U K | |
| """ users Table """ | |
| from sqlalchemy import ( | |
| Column, | |
| String, | |
| Integer | |
| ) | |
| from . import ( | |
| SESSION, | |
| BASE | |
| ) | |
| class Users(BASE): | |
| """ Table to store the received messages """ | |
| __tablename__ = "users" | |
| message_id = Column(Integer, primary_key=True) | |
| chat_id = Column(String(14)) | |
| um_id = Column(Integer) | |
| def __init__(self, message_id, chat_id, um_id): | |
| self.message_id = message_id | |
| self.chat_id = str(chat_id) # ensure string | |
| self.um_id = um_id | |
| def __repr__(self): | |
| return "<User %s>" % self.chat_id | |
| Users.__table__.create(checkfirst=True) | |
| def add_user_to_db(message_id: int, chat_id: int, um_id: int): | |
| """ add the message to the table """ | |
| __user = Users(message_id, str(chat_id), um_id) | |
| SESSION.add(__user) | |
| SESSION.commit() | |
| def get_user_id(message_id: int): | |
| """ get the user_id from the message_id """ | |
| try: | |
| s__ = SESSION.query(Users).get(str(message_id)) | |
| return int(s__.chat_id), s__.um_id | |
| finally: | |
| SESSION.close() | |
| def all_users(): | |
| """get all bot users""" | |
| tele = SESSION.query(Users).all() | |
| SESSION.close() | |
| return tele | |