diff --git a/davtelepot/__init__.py b/davtelepot/__init__.py index ae13201..82cea4f 100644 --- a/davtelepot/__init__.py +++ b/davtelepot/__init__.py @@ -7,7 +7,7 @@ __author__ = "Davide Testa" __email__ = "davte@libero.it" __credits__ = "Marco Origlia" __license__ = "GNU General Public License v3.0" -__version__ = "1.5.0" +__version__ = "1.5.1" __maintainer__ = "Davide Testa" __contact__ = "t.me/davte" diff --git a/davtelepot/custombot.py b/davtelepot/custombot.py index 9b47b66..bfdb290 100644 --- a/davtelepot/custombot.py +++ b/davtelepot/custombot.py @@ -2305,3 +2305,28 @@ class Bot(telepot.aio.Bot, Gettable): else: logging.info("Invalid name, please try again.") return 65 # Keep running, making user select another bot + + def create_views(self, views, overwrite=False): + """Take a list of `views` and add them to bot database. + + Each element of this list should have + - a `name` field + - a `query field` + """ + with self.db as db: + for view in views: + try: + if overwrite: + db.query( + f""" + DROP VIEW IF EXISTS {view['name']} + """ + ) + db.query( + f""" + CREATE VIEW IF NOT EXISTS {view['name']} + AS {view['query']} + """ + ) + except Exception as e: + logging.error(f"{e}")