spotted.scripts namespace

Submodules

spotted.scripts.f_crypto module

class spotted.scripts.f_crypto.Fernet(key, backend=None)[source]

Bases: object

decrypt(token, ttl=None)[source]
Return type:

bytes

decrypt_at_time(token, ttl, current_time)[source]
Return type:

bytes

encrypt(data)[source]
Return type:

bytes

encrypt_at_time(data, current_time)[source]
Return type:

bytes

extract_timestamp(token)[source]
Return type:

int

classmethod generate_key()[source]
Return type:

bytes

spotted.scripts.f_crypto.cast(typ, val)[source]

Cast a value to a type.

This returns the value unchanged. To the type checker this signals that the return value has the designated type, but at runtime we intentionally don’t check anything (we want this to be as fast as possible).

spotted.scripts.f_crypto.main()[source]

Main function

spotted.scripts.f_crypto.parse_args()[source]

Parse the command line arguments

Returns:

DecryptArgs – data structure containing the command line arguments

spotted.scripts.run_sql module

class spotted.scripts.run_sql.Config[source]

Bases: object

Configurations

AUTOREPLIES_PATH = 'autoreplies.yaml'
DEFAULT_AUTOREPLIES_PATH = '/opt/hostedtoolcache/Python/3.14.3/x64/lib/python3.14/site-packages/spotted/config/yaml/autoreplies.yaml'
DEFAULT_SETTINGS_PATH = '/opt/hostedtoolcache/Python/3.14.3/x64/lib/python3.14/site-packages/spotted/config/yaml/settings.yaml'
SETTINGS_PATH = 'settings.yaml'
classmethod autoreplies_get(*keys, default=None)[source]

Get the value of the specified key in the autoreplies configuration dictionary. If the key is a tuple, it will return the value of the nested key. If the key is not present, it will return the default value.

Parameters:
  • key – key to get

  • default (Any, default: None) – default value to return if the key is not present

Returns:

dict – value of the key or default value

classmethod debug_get(key, default=None)[source]

Get the value of the specified key in the configuration under the ‘debug’ section. If the key is not present, it will return the default value.

Parameters:
  • key (Literal['local_log', 'reset_on_load', 'log_file', 'log_error_file', 'db_file', 'backup_chat_id', 'backup_keep_pending', 'crypto_key', 'zip_backup']) – key to get

  • default (Any, default: None) – default value to return if the key is not present

Returns:

Any – value of the key or default value

classmethod override_settings(config)[source]

Overrides the settings with the configuration provided in the config dict.

Parameters:

config (dict) – configuration dict used to override the current settings

classmethod post_get(key, default=None)[source]

Get the value of the specified key in the configuration under the ‘post’ section. If the key is not present, it will return the default value.

Parameters:
  • key (Literal['community_group_id', 'channel_id', 'channel_tag', 'comments', 'admin_group_id', 'n_votes', 'remove_after_h', 'report', 'report_wait_mins', 'replace_anonymous_comments', 'delete_anonymous_comments', 'blacklist_messages', 'max_n_warns', 'warn_expiration_days', 'mute_default_duration_days', 'autoreplies_per_page', 'reject_after_autoreply']) – key to get

  • default (Any, default: None) – default value to return if the key is not present

Returns:

Any – value of the key or default value

classmethod reload(force_reload=False)[source]

Reset the configuration. The next time a setting parameter is required, the whole configuration will be reloaded. If force_reload is True, the configuration will be reloaded immediately.

Parameters:

force_reload (bool, default: False) – if True, the configuration will be reloaded immediately

classmethod settings_get(*keys, default=None)[source]

Get the value of the specified key in the configuration. If the key is a tuple, it will return the value of the nested key. If the key is not present, it will return the default value.

Parameters:
  • key – key to get

  • default (Any, default: None) – default value to return if the key is not present

Returns:

Any – value of the key or default value

class spotted.scripts.run_sql.DbManager[source]

Bases: object

Class that handles the management of databases

classmethod count_from(table_name, select='*', where='', where_args=None)[source]

Returns the number of rows found with the query. Executes “SELECT COUNT(select) FROM table_name [WHERE where (with where_args)]”

Parameters:
  • table_name (str) – name of the table used in the FROM

  • select (str, default: '*') – columns considered for the query

  • where (str, default: '') – where clause, with %s placeholders for the where_args

  • where_args (tuple | None, default: None) – args used in the where clause

Returns:

int – number of rows

classmethod delete_from(table_name, where='', where_args=None)[source]

Deletes the rows from the specified table, where the condition, when set, is satisfied. Executes “DELETE FROM table_name [WHERE where (with where_args)]”

Parameters:
  • table_name (str) – name of the table used in the DELETE FROM

  • where (str, default: '') – where clause, with %s placeholders for the where args

  • where_args (tuple | None, default: None) – args used in the where clause

classmethod get_db()[source]

Creates the connection to the database. It can be sqlite or postgres

Returns:

tuple[Connection, Cursor] – sqlite database connection and cursor

classmethod insert_into(table_name, values, columns='', multiple_rows=False)[source]

Inserts the specified values in the database. Executes “INSERT INTO table_name ([columns]) VALUES (placeholders)”

Parameters:
  • table_name (str) – name of the table used in the INSERT INTO

  • values (tuple) – values to be inserted. If multiple_rows is true, tuple of tuples of values to be inserted

  • columns (tuple | str, default: '') – columns that will be inserted, as a tuple of strings

  • multiple_rows (bool, default: False) – whether or not multiple rows will be inserted at the same time

classmethod query_from_file(*file_path)[source]

Commits all the queries in the specified file. The queries must be separated by a —– string Should not be used to select something

Parameters:

file_path (str) – path of the text file containing the queries

classmethod query_from_string(*queries)[source]

Commits all the queries in the string Should not be used to select something

Parameters:

queries (str) – tuple of queries

static register_adapters_and_converters()[source]

Registers the adapter and converters for the datetime type. Needed from python 3.12 onwards, as the default option has been deprecated

static row_factory(cursor, row)[source]

Converts the rows from the database into a dictionary

Parameters:
  • cursor (Cursor) – database cursor

  • row (dict) – row from the database

Returns:

dict – dictionary containing the row. The keys are the column names

classmethod select_from(table_name, select='*', where='', where_args=None, group_by='', order_by='')[source]

Returns the results of a query. Executes “SELECT select FROM table_name [WHERE where (with where_args)] [GROUP_BY group_by] [ORDER BY order_by]”

Parameters:
  • table_name (str) – name of the table used in the FROM

  • select (str, default: '*') – columns considered for the query

  • where (str, default: '') – where clause, with %s placeholders for the where_args

  • where_args (tuple | None, default: None) – args used in the where clause

  • group_by (str, default: '') – group by clause

  • order_by (str, default: '') – order by clause

Returns:

list – rows from the select

classmethod update_from(table_name, set_clause, where='', args=None)[source]

Updates the rows from the specified table, where the condition, when set, is satisfied. Executes “UPDATE table_name SET set_clause (with args) [WHERE where (with args)]”

Parameters:
  • table_name (str) – name of the table used in the DELETE FROM

  • set_clause (str) – set clause, with %s placeholders

  • where (str, default: '') – where clause, with %s placeholders for the where args

  • args (tuple | None, default: None) – args used both in the set clause and in the where clause, in this order

spotted.scripts.run_sql.cast(typ, val)[source]

Cast a value to a type.

This returns the value unchanged. To the type checker this signals that the return value has the designated type, but at runtime we intentionally don’t check anything (we want this to be as fast as possible).

spotted.scripts.run_sql.main()[source]

Main function

spotted.scripts.run_sql.parse_args()[source]

Parse the command line arguments

Returns:

RunSQLArgs – data structure containing the command line arguments