-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
86 lines (69 loc) · 3.36 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
from googleapiclient.discovery import build
from aiogram import Bot, Dispatcher, Router
from aiogram.fsm.state import StatesGroup, State
from aiogram.fsm.storage.memory import MemoryStorage
from aiogram.types import ReplyKeyboardMarkup, KeyboardButton
from config.settings import TELEGRAM_BOT_TOKEN
from handlers import start, auth, salary
import asyncio
import os
TELEGRAM_BOT_TOKEN = os.getenv('TELEGRAM_BOT_TOKEN')
GOOGLE_SHEET_ID = os.getenv('GOOGLE_SHEET_ID')
CREDENTIALS_FILE = os.getenv('CREDENTIALS_FILE')
FOLDER_ID = os.getenv('FOLDER_ID')
# Инициализация бота и диспетчера
bot = Bot(token=TELEGRAM_BOT_TOKEN)
storage = MemoryStorage()
dp = Dispatcher(storage=storage)
router = Router()
#p.include_router(router)
# === Создаем группу состояний для FSM ===
class AuthStates(StatesGroup):
waiting_for_employee_id = State()
waiting_for_passport_digits = State()
waiting_for_salary_type = State()
waiting_for_period_start = State()
waiting_for_period_end = State()
waiting_for_month = State() # Для выбора зарплаты за месяц
# === Получаем список файлов в папке (за исключением файла с авторизационными данными) ===
def list_files_in_folder(service, folder_id):
# Используем запрос, чтобы получить список файлов в указанной папке Google Drive
query = f"'{folder_id}' in parents and trashed=false"
results = service.files().list(q=query, fields="files(id, name)").execute()
return results.get('files', [])
# === Получаем список листов в файле Google Sheets ===
def get_sheets_from_file(file_id):
# Подключаем Google Sheets API для работы с таблицами
_, sheets_service = get_drive_service()
# Получаем метаданные о таблице
spreadsheet = sheets_service.spreadsheets().get(spreadsheetId=file_id).execute()
sheets = spreadsheet.get('sheets', [])
# Собираем названия листов
sheet_names = [sheet['properties']['title'] for sheet in sheets]
return sheet_names
# === Логика получения списка файлов после авторизации ===
def list_files_exclude_auth(service, folder_id, auth_file_id):
files = list_files_in_folder(service, folder_id)
# Исключаем файл с авторизацией из списка
return [file for file in files if file['id'] != auth_file_id]
# === Логика получения списка файлов после авторизации ===
def list_files_exclude_auth(service, folder_id, auth_file_id):
files = list_files_in_folder(service, folder_id)
# Исключаем файл с авторизацией из списка
return [file for file in files if file['id'] != auth_file_id]
# === Клавиатура ===
main_menu = ReplyKeyboardMarkup(
keyboard=[
[KeyboardButton(text="FAQ"), KeyboardButton(text="Авторизоваться")]
],
resize_keyboard=True
)
# Регистрация роутеров
dp.include_router(start.router)
dp.include_router(auth.router)
dp.include_router(salary.router)
# Запуск бота
async def main():
await dp.start_polling(bot)
if __name__ == '__main__':
asyncio.run(main())