Skip to content

Commit

Permalink
fix linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Perceval ARENOU committed Nov 9, 2023
1 parent 03337f9 commit eb59bcc
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 30 deletions.
19 changes: 14 additions & 5 deletions src/flantier/christmas_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@
import logging

import keyboards
from commands_admin import *
from commands_flantier import *
from commands_gift import *
from commands_user import *
from commands_admin import (
add_spouse,
close_registrations,
open_registrations,
process,
update_wishes_list,
)
from commands_flantier import hello, quote_oss1, quote_oss2
from commands_gift import comments, dont_offer, offer, wishes
from commands_user import get_result, list_users, register, unregister
from roulette import Roulette
from settings import Settings
from telegram import (
Expand Down Expand Up @@ -105,7 +111,10 @@ def help_message(update: Update, context: CallbackContext):
else:
help_text = simple_help + admin_help

context.bot.send_message(chat_id=update.effective_chat.id, text=help_text) # type: ignore
context.bot.send_message(
chat_id=update.effective_chat.id, # type: ignore
text=help_text,
)


def unknown_command(update: Update, context: CallbackContext):
Expand Down
12 changes: 1 addition & 11 deletions src/flantier/commands_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,21 @@
"""COMMANDES ADMINISTRATEUR"""

import logging
import os
from pathlib import Path
from random import choice

import configs
import keyboards
import noel_flantier
import santa
from roulette import Roulette
from telegram import (
ChatAction,
ReplyKeyboardRemove,
Update,
)
from telegram.ext import (
CallbackContext,
CallbackQueryHandler,
CommandHandler,
Filters,
MessageHandler,
Updater,
)

logger = logging.getLogger("flantier")


def is_admin(update: Update, context: CallbackContext) -> bool:
"""check if the given telegram id is admin of the bot
Expand Down
2 changes: 1 addition & 1 deletion src/flantier/commands_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,4 @@ def get_result(update: Update, context: CallbackContext):
context.bot.send_message(
chat_id=update.message.from_user.id,
text=f"🎅 Youpi tu offres à : {receiver['name']} 🎁\n",
)
)
3 changes: 1 addition & 2 deletions src/flantier/santa.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#!/usr/bin/python3
"""
Manage wishes and gifts from google sheets.
Manage wishes and gifts from google sheets.
Stores every wishes and who is offering what.
"""

import logging
import pickle

from settings import Settings
from apiclient.discovery import build

logger = logging.getLogger("flantier")
Expand Down
30 changes: 19 additions & 11 deletions src/flantier/settings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
"""Manage settings stored in settings.toml file.
Implement a singleton to access settings everywhere in the code.
"""

from pathlib import Path

import toml

# config_template = {
Expand All @@ -8,7 +13,7 @@
# GOOGLE_API_KEY = ''
# # file to store users data and roulette results
# USERS_FILE = 'users.json'
# # enable google sheets feature
# # enable google sheets feature
# extended_mode = False
# # Google Sheets Document
# spreadsheet_id = ''
Expand All @@ -21,25 +26,25 @@

class Settings:
"""Singleton class to store settings."""

DEFAULT_SETTINGS = Path("~/.config/flantier/settings.toml")
DEFAULT_USERS_DB = Path("~/.cache/flantier/users.json")
settings: dict

settings: dict
telegram_bot_token: str
google_api_key: str

# file to store users data and roulette results
users_file: Path
# cache file to store google sheets data locally
gifts_file: Path
# enable google sheets feature

# enable google sheets feature
extended_mode: bool = False
# Google Sheets Document, select the area where to search for whishes in sheet
spreadsheet_id: str
sheet_id: str
data_range: str = 'A1:AB30'
data_range: str = "A1:AB30"

# singleton
__instance = None
Expand All @@ -49,22 +54,25 @@ def __new__(cls, *args, **kwargs):
Settings.__instance = super(Settings, cls).__new__(cls, *args, **kwargs)
return Settings.__instance


def get_settings(self):
"""load settings from file in module folder"""
full_file_path = Path(__file__).parent.joinpath('settings.toml')
with open(full_file_path) as settings:
full_file_path = Path(__file__).parent.joinpath("settings.toml")
with open(full_file_path, "r", encoding="utf-8") as settings:
settings_data = toml.load(settings.read())
return settings_data


def load_settings(self, settings_file: Path = DEFAULT_SETTINGS):
"""load settings from settings file in default location"""
with open(settings_file, "r", encoding="utf-8") as f:
self.settings = toml.load(f.read())

return self.settings

def save_settings(self, settings_file: Path = DEFAULT_SETTINGS):
"""save settings to settings file in default location"""
with open(settings_file, "w", encoding="utf-8") as f:
toml.dump(self.settings, f)

def setup_templates(self):
"""install templates files in home directory if they does not exist"""

Expand Down

0 comments on commit eb59bcc

Please sign in to comment.