def __init__(self): self.db = SQLite() self.select_query = self.db.select_query(table_name, columns="LIKES", order_by="LIKES", distinct=True, where='USER_ID=?')
class definition: db: SQLite def __init__(self): self.db = SQLite() def blocks(self): blocks: list = [] definitions = self.select() if definitions is not None: for d in definitions: object: str = d[0] definition = d[1] blocks.append({ "type": "section", "text": { "type": "mrkdwn", "text": f"*{object}:* {definition}" } }) return (blocks) def select(self, key: str = None): logging.debug(inspect.currentframe().f_code.co_name) db_response = None if key is None: query: str = self.db.select_query(table_name, columns="OBJECT, ATTRIBUTE", order_by="OBJECT") db_response = self.db.cursor.execute(query).fetchall() else: query: str = self.db.select_query(table_name, columns="OBJECT, ATTRIBUTE", order_by="OBJECT", where="OBJECT=?") self.db.cursor.execute(query, [key]).fetchall() # if type(values) == type(tuple()): # db_response = json.loads(values[0]) return db_response def define(self, object, attribute): logging.debug(inspect.currentframe().f_code.co_name) self.db: SQLite = SQLite() self.db.cursor.execute( f"INSERT OR IGNORE INTO {table_name} (OBJECT, ATTRIBUTE) VALUES(?, ?)", (object, attribute)) self.db.connection.commit() def undefine(self, object, attribute): logging.debug(inspect.currentframe().f_code.co_name) self.db: SQLite = SQLite() self.db.cursor.execute( f"DELETE FROM {table_name} WHERE OBJECT=? AND ATTRIBUTE=?", (object, attribute)) self.db.connection.commit()
class karma: db: SQLite select_query: str def __init__(self): self.db = SQLite() self.select_query = self.db.select_query(table_name) def blocks(self): blocks: list = [] karma_karma_karma_karma_karma_queryaaaaa: str = self.select_query karma = self.db.cursor.execute( karma_karma_karma_karma_karma_queryaaaaa).fetchall() if karma is not None: for k in karma: word: str = k[0] plusses: int = k[1] minuses: int = k[2] total_score = plusses - minuses emoji: str = ":yin_yang:" if total_score > 0: emoji = ":thumbsup:" if total_score < 0: emoji = ":thumbsdown:" blocks.append({ "type": "section", "text": { "type": "mrkdwn", "text": f"{emoji} *{word}: {total_score}* `(+{plusses}/-{minuses})`" }, }) return (blocks)
class user_likes: db: SQLite select_query: str def __init__(self): self.db = SQLite() self.select_query = self.db.select_query(table_name, columns="LIKES", order_by="LIKES", distinct=True, where='USER_ID=?') def blocks(self, user_id: str): blocks: list = [] db_response = self.db.cursor.execute(self.select_query, [user_id]).fetchall() if db_response is not None: blocks.append({ "type": "header", "text": { "type": "plain_text", "text": ":+1: Likes:", "emoji": True } }) for r in db_response: like = r[0] blocks.append({ "type": "section", "text": { "type": "mrkdwn", "text": like } }) return blocks
def __init__(self, user_id: str): self.db = SQLite() if user_id: self.user_id = user_id select = self.db.select_query(table_name, where=f"user_id = '{self.user_id}'") config = self.db.cursor.execute(select).fetchone() if config is not None: self.zotero_library_type = config[1] self.zotero_library_id = config[2] self.zotero_api_key = self.db.cipher.decrypt( config[3]).decode('utf-8') self.library = PyZotero.Zotero(self.zotero_library_id, self.zotero_library_type, self.zotero_api_key)
def undefine(self, object, attribute): logging.debug(inspect.currentframe().f_code.co_name) self.db: SQLite = SQLite() self.db.cursor.execute( f"DELETE FROM {table_name} WHERE OBJECT=? AND ATTRIBUTE=?", (object, attribute)) self.db.connection.commit()
def define(self, object, attribute): logging.debug(inspect.currentframe().f_code.co_name) self.db: SQLite = SQLite() self.db.cursor.execute( f"INSERT OR IGNORE INTO {table_name} (OBJECT, ATTRIBUTE) VALUES(?, ?)", (object, attribute)) self.db.connection.commit()
class shared_links: db: SQLite select_query: str def __init__(self): self.db = SQLite() self.select_query = self.db.select_query(table_name, order_by="URL", order="ASC") def blocks(self): blocks: list = [{ "type": "header", "text": { "type": "plain_text", "text": ":link: Shared Links" } }] links = self.db.cursor.execute(self.select_query).fetchall() if links is not None: for l in links: url: str = l[1] blocks.append({ "type": "section", "text": { "type": "mrkdwn", "text": url }, }) return (blocks)
def __init__(self): self.db = SQLite() self.select_query = self.db.select_query(table_name)
from lib.database import SQLite from pathlib import Path from slack_bolt import Ack, BoltRequest, BoltResponse, Respond, Say from slack_sdk.web import WebClient import logging import re import sqlite3 plusplus: str = "\+\+" minusminus: str = "--" table_name: str = Path(__file__).stem table_params: str = "key text PRIMARY KEY, PLUS int DEFAULT 0, MINUS int DEFAULT 0" SQLite().create_table(table_name, table_params) class karma: db: SQLite select_query: str def __init__(self): self.db = SQLite() self.select_query = self.db.select_query(table_name) def blocks(self): blocks: list = [] karma_karma_karma_karma_karma_queryaaaaa: str = self.select_query karma = self.db.cursor.execute( karma_karma_karma_karma_karma_queryaaaaa).fetchall() if karma is not None: for k in karma:
class Zotero: db: SQLite keyword: str = table_name table_name: str = table_name zotero_library_id: str = None zotero_library_type: str = None zotero_api_key: bytes = None library: PyZotero.Zotero = None def __init__(self, user_id: str): self.db = SQLite() if user_id: self.user_id = user_id select = self.db.select_query(table_name, where=f"user_id = '{self.user_id}'") config = self.db.cursor.execute(select).fetchone() if config is not None: self.zotero_library_type = config[1] self.zotero_library_id = config[2] self.zotero_api_key = self.db.cipher.decrypt( config[3]).decode('utf-8') self.library = PyZotero.Zotero(self.zotero_library_id, self.zotero_library_type, self.zotero_api_key) def block(self, zotero_item): response_text = None if type(zotero_item) == type(""): response_text = zotero_item else: zotero_data = zotero_item.get('data') response_text = f"<{zotero_data.get('url')}|{zotero_data.get('title')}>" return { "type": "section", "text": { "type": "mrkdwn", "text": response_text }, } def blocks(self, zotero_items): blocks: list = [] for zotero_item in zotero_items: blocks.append(self.block(zotero_item)) return blocks def no_integration(self): logger.info( f"{self.__class__.__name__} ({inspect.currentframe().f_code.co_name})" ) return [ f":warning: <@{self.user_id}> You have not set up a zotero integration." ] def read(self, search_term: str = None): if self.library is None: return self.no_integration() if not search_term: return self.library.items() else: return self.library.items(q=search_term)
def __init__(self): self.db = SQLite()
def __init__(self): self.db = SQLite() self.select_query = self.db.select_query(table_name, order_by="URL", order="ASC")