Главная страница

авыа ыва ыва. Diplomnaya.Rabota._цуеуцеыы1_ — копия. ЫНаучный руководитель ученая степень, должность


Скачать 1.57 Mb.
НазваниеЫНаучный руководитель ученая степень, должность
Анкоравыа ыва ыва
Дата18.05.2022
Размер1.57 Mb.
Формат файлаdocx
Имя файлаDiplomnaya.Rabota._цуеуцеыы1_ — копия.docx
ТипРеферат
#537003
страница4 из 7
1   2   3   4   5   6   7

Класс config.py

# -*- coding: utf-8 -*-
token = "392082983:AAGzN9IBtPca0AC7WCs5hyNweJPQsfYoa1Q"


Класс bot.py

# -*- coding: utf-8 -*-

import telebot

import time

from fysom import Fysom

import config

import response_storage

import utils

chat_id = ''

section_number = 0

# Массив финальных состояний

finals = ['first1_no', 'first2_yes', 'first2_no', 'first3_yes', 'first4_yes', 'first5_yes', 'first6_yes', 'first6_no',

'second10_no', 'partnership9_no', 'tradename1_no', 'tradename2_no', 'tradename3_no', 'tradename3_yes',

'third1_no', 'third2_no', 'third3_no', 'third17', 'third_4_16_no', 'fourth1_no', 'fourth3_no', 'fourth21',

'fourth_4_20_no', 'fifth1_no', 'fifth2_no', 'fifth4_no', 'fifth17', 'fifth_5_16_no', 'sixth2_yes',

'sixth2_no', 'sixth3_no']

# Массив состояний из которых можно сразу перейти в состояние partnership

src_to_partnership = ['second1', 'second2', 'second3', 'second4', 'second5', 'second6', 'second7', 'second8',

'second9', 'second10']

# Массив состояний из которых можно сразу перейти в состояние tradename

src_to_tradename = ['partnership', 'partnership1', 'partnership2', 'partnership3', 'partnership4', 'partnership5',

'partnership6', 'partnership7', 'partnership8', 'partnership9']

# Массив состояний c 4 по 16 из которых можно сразу перейти в финальное состояние

src_third_4_16_no = ['third4', 'third5', 'third6', 'third7', 'third8', 'third9', 'third10', 'third11', 'third12',

'third13', 'third14', 'third15', 'third16']

# Массив состояний с 4 по 20 из которых можно сразу перейти в финальное состояние

src_fourth_4_20_no = ['fourth4', 'fourth5', 'fourth6', 'fourth7', 'fourth8', 'fourth9', 'fourth10', 'fourth11',

'fourth12', 'fourth13', 'fourth14', 'fourth15', 'fourth16', 'fourth17', 'fourth18', 'fourth19',

'fourth20']

# Массив состояний с 5 по 16 из которых можно сразу перейти в финальное состояние

src_fifth_5_16_no = ['fifth5', 'fifth6', 'fifth7', 'fifth8', 'fifth9', 'fifth10', 'fifth11', 'fifth12',

'fifth13', 'fifth14', 'fifth15', 'fifth16']

def create_fsm():

# Создаем объект ДКА

fsm = Fysom({'initial': 'waiting_start', #начальное состояние

'events': [ #переходы

{'name': 'go_to_start', 'src': finals, 'dst': 'show_sections'},

{'name': 'gotstart', 'src': 'waiting_start', 'dst': 'show_sections'},

{'name': 'selected_first', 'src': 'show_sections', 'dst': 'first1'},

{'name': 'first1_to_no', 'src': 'first1', 'dst': 'first1_no'},

{'name': 'first1_to_first2', 'src': 'first1', 'dst': 'first2'},

{'name': 'first2_to_yes', 'src': 'first2', 'dst': 'first2_yes'},

{'name': 'first2_to_no', 'src': 'first2', 'dst': 'first2_no'},

{'name': 'first2_to_first3', 'src': 'first2', 'dst': 'first3'},

{'name': 'first3_to_yes', 'src': 'first3', 'dst': 'first3_yes'},

{'name': 'first3_to_first4', 'src': 'first3', 'dst': 'first4'},

{'name': 'first4_to_yes', 'src': 'first4', 'dst': 'first4_yes'},

{'name': 'first4_to_first5', 'src': 'first4', 'dst': 'first5'},

{'name': 'first5_to_yes', 'src': 'first5', 'dst': 'first5_yes'},

{'name': 'first5_to_first6', 'src': 'first5', 'dst': 'first6'},

{'name': 'first6_to_yes', 'src': 'first6', 'dst': 'first6_yes'},

{'name': 'first6_to_no', 'src': 'first6', 'dst': 'first6_no'},

{'name': 'selected_second', 'src': 'show_sections', 'dst': 'second1'},

{'name': 'second_to_partnership', 'src': src_to_partnership, 'dst': 'partnership'},

{'name': 'second1_to_second2', 'src': 'second1', 'dst': 'second2'},

{'name': 'second2_to_second3', 'src': 'second2', 'dst': 'second3'},

{'name': 'second3_to_second4', 'src': 'second3', 'dst': 'second4'},

{'name': 'second4_to_second5', 'src': 'second4', 'dst': 'second5'},

{'name': 'second5_to_second6', 'src': 'second5', 'dst': 'second6'},

{'name': 'second6_to_second7', 'src': 'second6', 'dst': 'second7'},

{'name': 'second7_to_second8', 'src': 'second7', 'dst': 'second8'},

{'name': 'second8_to_second9', 'src': 'second8', 'dst': 'second9'},

{'name': 'second9_to_second10', 'src': 'second9', 'dst': 'second10'},

{'name': 'second10_to_no', 'src': 'second10', 'dst': 'second10_no'},

{'name': 'partnership_to_tradename', 'src': src_to_tradename, 'dst': 'tradename'},

{'name': 'partnership_to_partnership1', 'src': 'partnership', 'dst': 'partnership1'},

{'name': 'partnership1_to_partnership2', 'src': 'partnership1', 'dst': 'partnership2'},

{'name': 'partnership2_to_partnership3', 'src': 'partnership2', 'dst': 'partnership3'},

{'name': 'partnership3_to_partnership4', 'src': 'partnership3', 'dst': 'partnership4'},

{'name': 'partnership4_to_partnership5', 'src': 'partnership4', 'dst': 'partnership5'},

{'name': 'partnership5_to_partnership6', 'src': 'partnership5', 'dst': 'partnership6'},

{'name': 'partnership6_to_partnership7', 'src': 'partnership6', 'dst': 'partnership7'},

{'name': 'partnership7_to_partnership8', 'src': 'partnership7', 'dst': 'partnership8'},

{'name': 'partnership8_to_partnership9', 'src': 'partnership8', 'dst': 'partnership9'},

{'name': 'partnership9_to_no', 'src': 'partnership9', 'dst': 'partnership9_no'},

{'name': 'tradename_to_tradename1', 'src': 'tradename', 'dst': 'tradename1'},

{'name': 'tradename_to_tradename2', 'src': 'tradename', 'dst': 'tradename2'},

{'name': 'tradename1_to_tradename1_no', 'src': 'tradename1', 'dst': 'tradename1_no'},

{'name': 'tradename1_to_tradename2', 'src': 'tradename1', 'dst': 'tradename2'},

{'name': 'tradename2_to_tradename2_no', 'src': 'tradename2', 'dst': 'tradename2_no'},

{'name': 'tradename2_to_tradename3', 'src': 'tradename2', 'dst': 'tradename3'},

{'name': 'tradename3_to_tradename3_no', 'src': 'tradename3', 'dst': 'tradename3_no'},

{'name': 'tradename3_to_tradename3_yes', 'src': 'tradename3', 'dst': 'tradename3_yes'},

{'name': 'selected_third', 'src': 'show_sections', 'dst': 'third1'},

{'name': 'third1_to_no', 'src': 'third1', 'dst': 'third1_no'},

{'name': 'third1_to_third2', 'src': 'third1', 'dst': 'third2'},

{'name': 'third2_to_no', 'src': 'third2', 'dst': 'third2_no'},

{'name': 'third2_to_third3', 'src': 'third2', 'dst': 'third3'},

{'name': 'third3_to_no', 'src': 'third3', 'dst': 'third3_no'},

{'name': 'third3_to_third4', 'src': 'third3', 'dst': 'third4'},

{'name': 'third4_to_third5', 'src': 'third4', 'dst': 'third5'},

{'name': 'third5_to_third6', 'src': 'third5', 'dst': 'third6'},

{'name': 'third6_to_third7', 'src': 'third6', 'dst': 'third7'},

{'name': 'third7_to_third8', 'src': 'third7', 'dst': 'third8'},

{'name': 'third8_to_third9', 'src': 'third8', 'dst': 'third9'},

{'name': 'third9_to_third10', 'src': 'third9', 'dst': 'third10'},

{'name': 'third10_to_third11', 'src': 'third10', 'dst': 'third11'},

{'name': 'third11_to_third12', 'src': 'third11', 'dst': 'third12'},

{'name': 'third12_to_third13', 'src': 'third12', 'dst': 'third13'},

{'name': 'third13_to_third14', 'src': 'third13', 'dst': 'third14'},

{'name': 'third14_to_third15', 'src': 'third14', 'dst': 'third15'},

{'name': 'third15_to_third16', 'src': 'third15', 'dst': 'third16'},

{'name': 'third16_to_third17', 'src': 'third16', 'dst': 'third17'},

{'name': 'third_4_16_to_no', 'src': src_third_4_16_no, 'dst': 'third_4_16_no'},

{'name': 'selected_fourth', 'src': 'show_sections', 'dst': 'fourth1'},

{'name': 'fourth1_to_no', 'src': 'fourth1', 'dst': 'fourth1_no'},

{'name': 'fourth1_to_fourth2', 'src': 'fourth1', 'dst': 'fourth2'},

{'name': 'fourth2_to_no', 'src': 'fourth2', 'dst': 'fourth1_no'},

{'name': 'fourth2_to_fourth3', 'src': 'fourth2', 'dst': 'fourth3'},

{'name': 'fourth3_to_no', 'src': 'fourth3', 'dst': 'fourth3_no'},

{'name': 'fourth3_to_fourth4', 'src': 'fourth3', 'dst': 'fourth4'},

{'name': 'fourth4_to_fourth5', 'src': 'fourth4', 'dst': 'fourth5'},

{'name': 'fourth5_to_fourth6', 'src': 'fourth5', 'dst': 'fourth6'},

{'name': 'fourth6_to_fourth7', 'src': 'fourth6', 'dst': 'fourth7'},

{'name': 'fourth7_to_fourth8', 'src': 'fourth7', 'dst': 'fourth8'},

{'name': 'fourth8_to_fourth9', 'src': 'fourth8', 'dst': 'fourth9'},

{'name': 'fourth9_to_fourth10', 'src': 'fourth9', 'dst': 'fourth10'},

{'name': 'fourth10_to_fourth11', 'src': 'fourth10', 'dst': 'fourth11'},

{'name': 'fourth11_to_fourth12', 'src': 'fourth11', 'dst': 'fourth12'},

{'name': 'fourth12_to_fourth13', 'src': 'fourth12', 'dst': 'fourth13'},

{'name': 'fourth13_to_fourth14', 'src': 'fourth13', 'dst': 'fourth14'},

{'name': 'fourth14_to_fourth15', 'src': 'fourth14', 'dst': 'fourth15'},

{'name': 'fourth15_to_fourth16', 'src': 'fourth15', 'dst': 'fourth16'},

{'name': 'fourth16_to_fourth17', 'src': 'fourth16', 'dst': 'fourth17'},

{'name': 'fourth17_to_fourth18', 'src': 'fourth17', 'dst': 'fourth18'},

{'name': 'fourth18_to_fourth19', 'src': 'fourth18', 'dst': 'fourth19'},

{'name': 'fourth19_to_fourth20', 'src': 'fourth19', 'dst': 'fourth20'},

{'name': 'fourth20_to_fourth21', 'src': 'fourth20', 'dst': 'fourth21'},

{'name': 'fourth_4_20_to_no', 'src': src_fourth_4_20_no, 'dst': 'fourth_4_20_no'},

{'name': 'selected_fifth', 'src': 'show_sections', 'dst': 'fifth1'},

{'name': 'fifth1_to_no', 'src': 'fifth1', 'dst': 'fifth1_no'},

{'name': 'fifth1_to_fifth2', 'src': 'fifth1', 'dst': 'fifth2'},

{'name': 'fifth2_to_no', 'src': 'fifth2', 'dst': 'fifth2_no'},

{'name': 'fifth2_to_fifth3', 'src': 'fifth2', 'dst': 'fifth3'},

{'name': 'fifth3_to_no', 'src': 'fifth3', 'dst': 'fifth2_no'},

{'name': 'fifth3_to_fifth4', 'src': 'fifth3', 'dst': 'fifth4'},

{'name': 'fifth4_to_no', 'src': 'fifth4', 'dst': 'fifth4_no'},

{'name': 'fifth4_to_fifth5', 'src': 'fifth4', 'dst': 'fifth5'},

{'name': 'fifth5_to_fifth6', 'src': 'fifth5', 'dst': 'fifth6'},

{'name': 'fifth6_to_fifth7', 'src': 'fifth6', 'dst': 'fifth7'},

{'name': 'fifth7_to_fifth8', 'src': 'fifth7', 'dst': 'fifth8'},

{'name': 'fifth8_to_fifth9', 'src': 'fifth8', 'dst': 'fifth9'},

{'name': 'fifth9_to_fifth10', 'src': 'fifth9', 'dst': 'fifth10'},

{'name': 'fifth10_to_fifth11', 'src': 'fifth10', 'dst': 'fifth11'},

{'name': 'fifth11_to_fifth12', 'src': 'fifth11', 'dst': 'fifth12'},

{'name': 'fifth12_to_fifth13', 'src': 'fifth12', 'dst': 'fifth13'},

{'name': 'fifth13_to_fifth14', 'src': 'fifth13', 'dst': 'fifth14'},

{'name': 'fifth14_to_fifth15', 'src': 'fifth14', 'dst': 'fifth15'},

{'name': 'fifth15_to_fifth16', 'src': 'fifth15', 'dst': 'fifth16'},

{'name': 'fifth16_to_fifth17', 'src': 'fifth16', 'dst': 'fifth17'},

{'name': 'fifth_5_16_to_no', 'src': src_fifth_5_16_no, 'dst': 'fifth_5_16_no'},

{'name': 'selected_sixth', 'src': 'show_sections', 'dst': 'sixth1'},

{'name': 'sixth1_to_sixth2', 'src': 'sixth1', 'dst': 'sixth2'},

{'name': 'sixth1_to_sixth3', 'src': 'sixth1', 'dst': 'sixth3'},

{'name': 'sixth2_to_yes', 'src': 'sixth2', 'dst': 'sixth2_yes'},

{'name': 'sixth2_to_no', 'src': 'sixth2', 'dst': 'sixth2_no'},

{'name': 'sixth3_to_yes', 'src': 'sixth3', 'dst': 'sixth2'},

{'name': 'sixth3_to_no', 'src': 'sixth3', 'dst': 'sixth3_no'},

],

'callbacks': { #Коллбеки.Указываем какой метод будет отвечать за обработку какого события

'onwaiting_start': onwaiting_start,

'onshow_sections': onshow_sections,

'onfirst1': onfirst1, 'onfirst1_no': onfirst1_no,

'onfirst2': onfirst2, 'onfirst2_yes': onfirst2_yes, 'onfirst2_no': onfirst2_no,

'onfirst3': onfirst3, 'onfirst3_yes': onfirst3_yes,

'onfirst4': onfirst4, 'onfirst4_yes': onfirst4_yes,

'onfirst5': onfirst5, 'onfirst5_yes': onfirst5_yes,

'onfirst6': onfirst6, 'onfirst6_yes': onfirst6_yes, 'onfirst6_no': onfirst6_no,

'onsecond1': onsecond1, 'onsecond2': onsecond2, 'onsecond3': onsecond3, 'onsecond4': onsecond4,

'onsecond5': onsecond5, 'onsecond6': onsecond6, 'onsecond7': onsecond7, 'onsecond8': onsecond8,

'onsecond9': onsecond9, 'onsecond10': onsecond10, 'onsecond10_no': onsecond10_no,

'onpartnership': onpartnership,

'onpartnership1': onpartnership1,

'onpartnership2': onpartnership2,

'onpartnership3': onpartnership3,

'onpartnership4': onpartnership4,

'onpartnership5': onpartnership5,

'onpartnership6': onpartnership6,

'onpartnership7': onpartnership7,

'onpartnership8': onpartnership8,

'onpartnership9': onpartnership9,

'onpartnership9_no': onpartnership9_no,

'ontradename': ontradename,

'ontradename1': ontradename1,

'ontradename1_no': ontradename1_no,

'ontradename2': ontradename2,

'ontradename2_no': ontradename2_no,

'ontradename3': ontradename3,

'ontradename3_no': ontradename3_no,

'ontradename3_yes': ontradename3_yes,

'onthird1': onthird1, 'onthird1_no': onthird1_no,

'onthird2': onthird2, 'onthird2_no': onthird2_no,

'onthird3': onthird3, 'onthird3_no': onthird3_no,

'onthird4': onthird4, 'onthird_4_16_no': onthird_4_16_no,

'onthird5': onthird5,

'onthird6': onthird6,

'onthird7': onthird7,

'onthird8': onthird8,

'onthird9': onthird9,

'onthird10': onthird10,

'onthird11': onthird11,

'onthird12': onthird12,

'onthird13': onthird13,

'onthird14': onthird14,

'onthird15': onthird15,

'onthird16': onthird16,

'onthird17': onthird17,

'onfourth1': onfourth1, 'onfourth1_no': onfourth1_no,

'onfourth2': onfourth2, 'onfourth3_no': onfourth3_no,

'onfourth3': onfourth3, 'onfourth_4_20_no': onfourth_4_20_no,

'onfourth4': onfourth4,

'onfourth5': onfourth5,

'onfourth6': onfourth6,

'onfourth7': onfourth7,

'onfourth8': onfourth8,

'onfourth9': onfourth9,

'onfourth10': onfourth10,

'onfourth11': onfourth11,

'onfourth12': onfourth12,

'onfourth13': onfourth13,

'onfourth14': onfourth14,

'onfourth15': onfourth15,

'onfourth16': onfourth16,

'onfourth17': onfourth17,

'onfourth18': onfourth18,

'onfourth19': onfourth19,

'onfourth20': onfourth20,

'onfourth21': onfourth21,

'onfifth1': onfifth1, 'onfifth1_no': onfifth1_no,

'onfifth2': onfifth2, 'onfifth2_no': onfifth2_no,

'onfifth3': onfifth3, 'onfifth4_no': onfifth4_no,

'onfifth4': onfifth4, 'onfifth_5_16_no': onfifth_5_16_no,

'onfifth5': onfifth5,

'onfifth6': onfifth6,

'onfifth7': onfifth7,

'onfifth8': onfifth8,

'onfifth9': onfifth9,

'onfifth10': onfifth10,

'onfifth11': onfifth11,

'onfifth12': onfifth12,

'onfifth13': onfifth13,

'onfifth14': onfifth14,

'onfifth15': onfifth15,

'onfifth16': onfifth16,

'onfifth17': onfifth17,

'onsixth1': onsixth1,

'onsixth2': onsixth2, 'onsixth2_yes': onsixth2_yes, 'onsixth2_no': onsixth2_no,

'onsixth3': onsixth3, 'onsixth3_no': onsixth3_no,

}})

return fsm

#Метод для перехода на следующее состояние после набора команды "/start"

def change_state(state):

if state == 'waiting_start':

fsm.gotstart()

#Описываем работу обработчика события "onwaiting_start"

def onwaiting_start(e):

@bot.message_handler(commands=["start"]) #атрибут отвечающие за реагирование на набор команды "/start"

def start(message):

bot.send_message(chat_id=message.chat.id,

text=response_storage.welcome_message) #берем текст сообщения из

# банка всех текстов(response_storage.py)

global chat_id

chat_id = message.chat.id

fsm.current = 'waiting_start' #указываем, что текущее состояние - "waiting_start"

change_state(fsm.current)

#Описываем работу обработчика события "onshow_sections"

def onshow_sections(e):

keyboard = utils.select_keyboard("section-number")

bot.send_message(chat_id=chat_id,

text=response_storage.first_response,

reply_markup=keyboard)

#Дальше пошло описание действий при попадании на каждое конкретное состояние.

def onfirst1(e):

keyboard = utils.select_keyboard("yes-no")

bot.send_message(chat_id=chat_id,

text=response_storage.select_message(section_number, 1, 'question'),

reply_markup=keyboard)

def onfirst1_no(e):

bot.send_message(chat_id=chat_id,

text=response_storage.select_message(section_number, 1, 'answer'))

if fsm.current in finals: #если текущее состояние является финальным, то

fsm.go_to_start() #переходим снова в начало к выбору ветки
1   2   3   4   5   6   7


написать администратору сайта