diff --git a/.gitignore b/.gitignore index 59d6915..d940ab0 100644 --- a/.gitignore +++ b/.gitignore @@ -8,10 +8,7 @@ __pycache__ *.save *.xls -/audio -/tts-gc-key.json -/test.py -/sandbox.py -/logs.txt + /config.py -/status.json +/tts-gc-key.json +/logs.txt diff --git a/Controls/Django/Django.py b/Controls/Django/Django.py index 0f56655..70e13ec 100644 --- a/Controls/Django/Django.py +++ b/Controls/Django/Django.py @@ -1,4 +1,6 @@ -class DJango(Control): +from ..Control import Control + +class Django(Control): def start(self): # run manage.py pass diff --git a/Controls/TelegramBot/TelegramBot.py b/Controls/TelegramBot/TelegramBot.py index e65d975..be6bb7c 100644 --- a/Controls/TelegramBot/TelegramBot.py +++ b/Controls/TelegramBot/TelegramBot.py @@ -1,11 +1,12 @@ #!/usr/local/bin/python3.8 -from Command import Command -import Text2Speech -import telebot -import config -import modules + import time import os +import telebot +import config +from Features import Command +from General import Text2Speech +from Controls.Control import Control class TelegramBot(Control): threads = [] @@ -16,9 +17,9 @@ class TelegramBot(Control): bot = telebot.TeleBot(config.telebot) # Singleton - def __new__(self, cls): + def __new__(cls): if not hasattr(cls, 'instance'): - cls.instance = super(VoiceAssistant, cls).__new__(cls) + cls.instance = super(TelegramBot, cls).__new__(cls) return cls.instance def reply(self, id, response): @@ -89,8 +90,8 @@ class TelegramBot(Control): print("Start polling...") bot.polling(callback = check_threads, args = (threads,) ) except: - time.sleep(10) print("Polling failed") + time.sleep(10) if __name__ == '__main__': diff --git a/Controls/VoiceAssistant/VoiceAssistant.py b/Controls/VoiceAssistant/VoiceAssistant.py index cf87cd4..f83a306 100644 --- a/Controls/VoiceAssistant/VoiceAssistant.py +++ b/Controls/VoiceAssistant/VoiceAssistant.py @@ -1,10 +1,9 @@ #!/usr/local/bin/python3.8 -import SpeechRecognition -import Text2Speech -from Command import Command -import config -import modules import os +from Controls.Control import Control +from General import SpeechRecognition, Text2Speech +from Features.Command import Command +import config if config.double_clap_activation: import RPi.GPIO as GPIO diff --git a/Controls/__init__.py b/Controls/__init__.py new file mode 100644 index 0000000..803b66e --- /dev/null +++ b/Controls/__init__.py @@ -0,0 +1,4 @@ +from .Django.Django import Django +from .TelegramBot.TelegramBot import TelegramBot +from .VoiceAssistant.VoiceAssistant import VoiceAssistant +from .Control import Control diff --git a/Features/Command/Command.py b/Features/Command/Command.py index bb4c3dc..ced38b3 100644 --- a/Features/Command/Command.py +++ b/Features/Command/Command.py @@ -31,7 +31,7 @@ from abc import ABC, abstractmethod from threading import Thread, Event import re -from synonyms import synonyms +from .synonyms import synonyms class RThread(Thread): def __init__(self, *args, **kwargs): diff --git a/Controls/VoiceAssistant/synonyms.py b/Features/Command/synonyms.py similarity index 100% rename from Controls/VoiceAssistant/synonyms.py rename to Features/Command/synonyms.py diff --git a/Features/Media/Media.py b/Features/Media/Media.py index 097c5b6..4d27d3c 100644 --- a/Features/Media/Media.py +++ b/Features/Media/Media.py @@ -1,4 +1,4 @@ -from Command import Command +from ..Command import Command class Media(Command): def start(this, string): # main method diff --git a/Features/Media/kinogo.py b/Features/Media/kinogo.py index 6092110..4d09fbe 100644 --- a/Features/Media/kinogo.py +++ b/Features/Media/kinogo.py @@ -2,7 +2,7 @@ from .Media import * import requests from bs4 import BeautifulSoup as BS import os -from Command import Callback, Response +from ..Command import Callback, Response ################################################################################ def findPage(name): query = name + ' site:kinogo.by' diff --git a/Features/QA/QA.py b/Features/QA/QA.py index 0765176..4362979 100644 --- a/Features/QA/QA.py +++ b/Features/QA/QA.py @@ -1,9 +1,8 @@ from bs4 import BeautifulSoup as BS -from Command import Command +from ..Command import Command import wikipedia as wiki import requests import random -import apiai import json import re diff --git a/Features/Raspi/Raspi.py b/Features/Raspi/Raspi.py index 2d7010f..a1c440c 100644 --- a/Features/Raspi/Raspi.py +++ b/Features/Raspi/Raspi.py @@ -1,4 +1,4 @@ -from Command import Command # import parent class +from ..Command import Command # import parent class import os class Raspi(Command): diff --git a/Features/Raspi/__init__.py b/Features/Raspi/__init__.py deleted file mode 100644 index dc66b56..0000000 --- a/Features/Raspi/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -from .gitpull import * -from .tv import * diff --git a/Features/Raspi/gitpull.py b/Features/Raspi/gitpull.py index 081f962..171968e 100644 --- a/Features/Raspi/gitpull.py +++ b/Features/Raspi/gitpull.py @@ -1,6 +1,6 @@ from .Raspi import * import os -from Command import Callback, Response +from ..Command import Callback, Response import config ################################################################################ def reboot(params): diff --git a/Features/Raspi/tv.py b/Features/Raspi/tv.py index d68bbac..19ffc69 100644 --- a/Features/Raspi/tv.py +++ b/Features/Raspi/tv.py @@ -1,5 +1,5 @@ from .Raspi import * -from Command import Response +from ..Command import Response ################################################################################ def method(params): Raspi.hdmi_cec('on 0') @@ -29,7 +29,7 @@ def method(params): return Response(text = text, voice = voice) keywords = {} -patterns = ['* (выведи|вывести|покажи|открой|показать|открыть) * с (|провода|hdmi|кабеля|порта) * $num *'] +patterns = ['* (выведи|вывести|покажи|открой|показать|открыть) * с (провода|hdmi|кабеля|порта) * $num *'] tv_hdmi = Raspi('tv hdmi source', keywords, patterns) tv_hdmi.setStart(method) ################################################################################ @@ -39,7 +39,7 @@ def method(params): return Response(text = text, voice = voice) keywords = {} -patterns = ['* (выведи|вывести|покажи|открой|показать|открыть) * с (ноута|ноутбука|провода|hdmi)'] +patterns = ['* (выведи|вывести|покажи|открой|показать|открыть) * с (ноута|ноутбука|планшета|провода|hdmi)'] tv_hdmi = Raspi('tv hdmi source', keywords, patterns) tv_hdmi.setStart(method) ################################################################################ @@ -49,6 +49,6 @@ def method(params): return Response(text = text, voice = voice) keywords = {} -patterns = ['* (верни|вернуть|включи*|покажи|показать) [нормальн|стандартн|привычн]* (телевизор|экран|картинк|изображение) *'] +patterns = ['* (верни|вернуть|включи*|покажи|показать) [основн|нормальн|стандартн|привычн]* (телевизор|экран|картинк|изображение) *'] tv_rpi = Raspi('tv rpi source', keywords, patterns) tv_rpi.setStart(method) diff --git a/Features/SmallTalk/SmallTalk.py b/Features/SmallTalk/SmallTalk.py index 147ed35..8b2636a 100644 --- a/Features/SmallTalk/SmallTalk.py +++ b/Features/SmallTalk/SmallTalk.py @@ -3,9 +3,7 @@ # Module for speaking with voice assistent # See class Command - - -from Command import Command # import parent class +from ..Command import Command # import parent class class SmallTalk(Command): def start(this, string): # main method diff --git a/Features/SmallTalk/__init__.py b/Features/SmallTalk/__init__.py deleted file mode 100644 index 76c00f2..0000000 --- a/Features/SmallTalk/__init__.py +++ /dev/null @@ -1,24 +0,0 @@ -# Initialisation SmallTalk -# Creating objects (add commands) -# setStart(method) is required -# setConfirm(method) is optional -# -# How to add new command: -# 1. def method() # return string -# 1.2 def confirm_method() # optional, not required -# 2. kw = { -# (int)weight : ['word1', 'word2', 'word3'], -# (int)weight1 : ['word3', 'word4'], -# (int)weight2 : ['word5', 'word6', 'word7', 'word8', 'word9'], -# } -# patterns = ['* который * час *', '* скольк* * (врем|час)* *'] -# subpatterns = [...] #like patterns -# 3. new_command = SmallTalk(Name, kw, patterns, subpatterns) -# 4. new_command.setStart(method) -# 5. new_command.setConfirm(confirm_method) # optional, not required -# -# @background(voice_to_speak, text_for_print) for background methods - -from .hello import * -from .ctime import * -from .test import * diff --git a/Features/SmallTalk/ctime.py b/Features/SmallTalk/ctime.py index 4f9e468..b36b9cf 100644 --- a/Features/SmallTalk/ctime.py +++ b/Features/SmallTalk/ctime.py @@ -1,9 +1,9 @@ -from .SmallTalk import * import datetime, time import requests from bs4 import BeautifulSoup as BS import math -from Command import Response +from .SmallTalk import SmallTalk +from ..Command import Response ################################################################################ def method(params): if city := params.get('text'): diff --git a/Features/SmallTalk/hello.py b/Features/SmallTalk/hello.py index 4d1db03..4eec1c1 100644 --- a/Features/SmallTalk/hello.py +++ b/Features/SmallTalk/hello.py @@ -1,5 +1,5 @@ from .SmallTalk import * -from Command import Response +from ..Command import Response ################################################################################ def method(params): voice = text = 'Привет' diff --git a/Features/SmartHome/SmartHome.py b/Features/SmartHome/SmartHome.py index 333caec..3fb7fdd 100644 --- a/Features/SmartHome/SmartHome.py +++ b/Features/SmartHome/SmartHome.py @@ -1,12 +1,13 @@ import RPi.GPIO as GPIO -GPIO.setmode(GPIO.BCM) from .lib_nrf24 import NRF24 import spidev import time import json as JSON -from Command import Command from threading import Thread +from ..Command import Command + +GPIO.setmode(GPIO.BCM) pipe = [0xf0, 0xf0, 0xf0, 0xf0, 0xe1] diff --git a/Features/SmartHome/__init__.py b/Features/SmartHome/__init__.py deleted file mode 100644 index 35e19ec..0000000 --- a/Features/SmartHome/__init__.py +++ /dev/null @@ -1,4 +0,0 @@ -from .main_light import * -from .window import * -from .alarmclock import * -from .light import * diff --git a/Features/SmartHome/alarmclock.py b/Features/SmartHome/alarmclock.py index 9755530..bd4fbd1 100644 --- a/Features/SmartHome/alarmclock.py +++ b/Features/SmartHome/alarmclock.py @@ -1,6 +1,5 @@ from .SmartHome import * -from Command import Response -from Command import Command +from ..Command import Response, Command import Text2Speech import os ################################################################################ diff --git a/Features/SmartHome/light.py b/Features/SmartHome/light.py index 1c5fc9a..7eaa2bf 100644 --- a/Features/SmartHome/light.py +++ b/Features/SmartHome/light.py @@ -1,5 +1,5 @@ from .SmartHome import * -from Command import Response +from ..Command import Response ################################################################################ def method(params): diff --git a/Features/SmartHome/main_light.py b/Features/SmartHome/main_light.py index a7fb38f..f3825e0 100644 --- a/Features/SmartHome/main_light.py +++ b/Features/SmartHome/main_light.py @@ -1,5 +1,5 @@ from .SmartHome import * -from Command import Response +from ..Command import Response ################################################################################ def method(params): diff --git a/Features/Zieit/Zieit.py b/Features/Zieit/Zieit.py index e50e84c..e46b53b 100644 --- a/Features/Zieit/Zieit.py +++ b/Features/Zieit/Zieit.py @@ -1,4 +1,4 @@ -from Command import Command, Response # import parent class +from ..Command import Command, Response # import parent class import urllib.request import xlrd import xlwt diff --git a/Features/Zieit/__init__.py b/Features/Zieit/__init__.py deleted file mode 100644 index 5faa130..0000000 --- a/Features/Zieit/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from .myshedule import * diff --git a/Features/__init__.py b/Features/__init__.py new file mode 100644 index 0000000..cad00d6 --- /dev/null +++ b/Features/__init__.py @@ -0,0 +1,12 @@ +from .Command import Command +from .Command import Command +from .Command import Response + +from .Media import Media +from .QA.QA import QA +from .SmallTalk import SmallTalk +from .Raspi import Raspi +from .Zieit import Zieit + +try: from .SmartHome import SmartHome +except: print('cannot import module named "SmartHome" from Features/Smarthome\n') diff --git a/start.py b/start.py index 55e2942..45b199e 100644 --- a/start.py +++ b/start.py @@ -1,7 +1,12 @@ #!/usr/local/bin/python3.8 # entry point +import Controls +import Features + # TODO: # import subprocess # start oll controls in own thread or subprocess: # voice assistant, telegram bot, django(api and ui) + +Controls.TelegramBot().start()