1
0
mirror of https://github.com/MarkParker5/STARK.git synced 2025-11-28 21:39:53 +02:00

one command - one file, kinogo fullscreen mode

This commit is contained in:
MarkParker5
2020-10-31 21:11:24 +02:00
parent 0126e93e5c
commit 33b07afe5f
8 changed files with 208 additions and 200 deletions

2
.gitignore vendored
View File

@@ -1,7 +1,7 @@
__pycache__
audio
tts-gc-key.json
test.py
/test.py
sandbox.py
logs.txt
config.py

View File

@@ -1,63 +1 @@
from .Film import *
import requests
from bs4 import BeautifulSoup as BS
import os
import Command
################################################################################
def findFilm(name):
query = name + ' site:kinogo.by'
responce = requests.get(f'https://www.google.ru/search?&q={query}&lr=lang_ru&lang=ru')
page = BS(responce.content, 'html.parser')
link = page.select_one('.ZINbbc.xpd.O9g5cc.uUPGi>.kCrYT>a')
return link['href'][7:].split('&')[0] if link else None
def extractUrl(url):
responce = requests.get(url)
page = BS(responce.content, 'html.parser')
url = page.select_one('div[style="padding:22px; float:left; margin-left: 30px;"]>a[download]:last-child')
return url['href'] if url else None
def startFilm(url):
os.system(f'lxterminal --command="vlc {url}"')
def main(params):
name = params.get('text')
if name:
if url:= extractUrl(findFilm(name)):
startFilm(url)
voice = text = 'Включаю'
else:
voice = text = 'Не могу найти фильм'
type = 'simple'
else:
voice = text = 'Какой фильм включить?'
type = 'question'
callback = kinogo_cb
return {
'type': type,
'text': text,
'voice': voice,
'callback': callback or None,
}
def start(params):
name = params.get('text')
voice = text = 'Не могу найти фильм'
if name:
if url:= extractUrl(findFilm(name)):
startFilm(url)
voice = text = 'Включаю'
return {
'type': 'simple',
'text': text,
'voice': voice,
}
kinogo_cb = Command.Callback(['$text',])
kinogo_cb.setStart(start)
patterns = ['* включ* фильм $text', '* включ* фильм*']
kinogo = Film('KinogoPlayer', {}, patterns)
kinogo.setStart(main)
from .kinogo import *

67
Media/kinogo.py Normal file
View File

@@ -0,0 +1,67 @@
from .Film import *
import requests
from bs4 import BeautifulSoup as BS
import os
import Command
################################################################################
def findFilm(name):
query = name + ' site:kinogo.by'
responce = requests.get(f'https://www.google.ru/search?&q={query}&lr=lang_ru&lang=ru')
page = BS(responce.content, 'html.parser')
link = page.select_one('.ZINbbc.xpd.O9g5cc.uUPGi>.kCrYT>a')
return link['href'][7:].split('&')[0] if link else None
def extractUrl(url):
responce = requests.get(url)
page = BS(responce.content, 'html.parser')
url = page.select_one('div[style="padding:22px; float:left; margin-left: 30px;"]>a[download]:last-child')
return url['href'] if url else None
def startFilm(url):
print(url)
os.system(f'lxterminal --command="vlc {url} -f"')
def main(params):
name = params.get('text')
if name:
if url:= extractUrl(findFilm(name)):
startFilm(url)
voice = text = 'Включаю'
else:
voice = text = 'Не могу найти фильм'
type = 'simple'
else:
voice = text = 'Какой фильм включить?'
type = 'question'
callback = kinogo_cb
return {
'type': type,
'text': text,
'voice': voice,
'callback': callback,
}
return {
'type': type,
'text': text,
'voice': voice,
}
def start(params):
name = params.get('text')
voice = text = 'Не могу найти фильм'
if name:
if url:= extractUrl(findFilm(name)):
startFilm(url)
voice = text = 'Включаю'
return {
'type': 'simple',
'text': text,
'voice': voice,
}
kinogo_cb = Command.Callback(['$text',])
kinogo_cb.setStart(start)
patterns = ['* включ* фильм $text', '* включ* фильм*']
kinogo = Film('KinogoPlayer', {}, patterns)
kinogo.setStart(main)

View File

@@ -19,138 +19,6 @@
#
# @background(voice_to_speak, text_for_print) for background methods
from .SmallTalk import *
import datetime, time
import math
import requests
from bs4 import BeautifulSoup as BS
################################################################################
def method(params):
voice = text = 'Привет'
return {
'type': 'simple',
'text': text,
'voice': voice,
}
patterns = ['* привет* *',]
hello = SmallTalk('Hello', {}, patterns)
hello.setStart(method)
################################################################################
def method(params):
if city := params.get('text'):
city = city.title()
responce = requests.get(f'https://www.google.ru/search?&q=время+в+{city}&lr=lang_ru&lang=ru')
page = BS(responce.content, 'html.parser')
now = page.select('div.BNeawe>div>div.BNeawe')[0].get_text().split(':') or ''
now = datetime.time(int(now[0]), int(now[1]))
else:
now = datetime.datetime.now()
hours = now.hour%12 or 12
minutes = now.minute
get_str = ['десять', 'один', 'два', 'три', 'четыре', 'пять', 'шесть', 'семь', 'восемь', 'девять']
if hours%20 == 1:
str_hour = 'час'
elif 5 > hours%20 > 1:
str_hour = 'часа'
else:
str_hour = 'часов'
if minutes%10 == 1 and 20<minutes or minutes == 1:
str_minute = 'минута'
elif 0 < minutes%10 < 5 and math.floor(minutes/10) != 1:
str_minute = 'минуты'
else:
str_minute = 'минут'
def get_str_num(num, bool):
result = []
for i in [100, 10, 1]:
j = num//i%10
str_num = get_str[j]
if i == 1 and bool:
if j==1:
str_num = 'одна'
elif j==2:
str_num = 'две'
if str_num=='десять':
continue
elif i==10 and j == 1:
j = int(num%10)
str_num = get_str[j]
if j==0:
str_num = ''
elif j==2:
str_num = 'две'
elif j==4:
str_num = 'четыр'
elif j==5:
str_num = 'пят'
str_num += 'надцать'
if j==0:
str_num = 'десять'
result.append(str_num)
break
elif i==10:
if j==4:
str_num = 'сорок'
elif j<5:
str_num += 'дцать'
elif j==9:
str_num = 'девяноста'
else:
str_num += 'десят'
result.append(str_num)
return ' '.join(result)
if city: voice = f'В {city} сейчас {get_str_num(hours, 0)} {str_hour}'
else: voice = f'Сейчас {get_str_num(hours, 0)} {str_hour}'
if(minutes): voice += f', {get_str_num(minutes, 1)} {str_minute}'
hours = now.hour if now.hour > 9 else '0'+str(now.hour)
minutes = minutes if minutes > 9 else '0'+str(minutes) if minutes else '00'
if city: text = f'Текущее время в {city}: {hours}:{minutes}'
else: text = f'Текущее время: {hours}:{minutes}'
return {
'type': 'simple',
'text': text,
'voice': voice,
}
keywords = {
10: ['который час', 'сколько времени'],
5: ['текущее', 'сейчас', 'время'],
1: ['сколько']
}
patterns = ['* который * час в $text', '* скольк* * (врем|час)* * в $text', '* время в $text', '* который * час *', '* скольк* * (врем|час)* *']
subpatterns = ['а (сейчас|в $text)']
ctime = SmallTalk('Current Time', keywords, patterns, subpatterns)
ctime.setStart(method)
################################################################################
# Only for tests
@SmallTalk.background(answer = 'Запуск фонового процесса', voice = 'Запускаю фоновый процесс')
def method(params, finish_event):
time.sleep(10)
finish_event.set()
return {
'text': 'Фоновый процесс завершен',
'voice': 'Фоновый процесс завершен',
}
keywords = {
10: ['тестирование', 'проверка', 'потоков', 'фоновых', 'процессов'],
}
patterns = ['* [тест|провер]* * [фонов*] * (процесс|поток)* *']
test = SmallTalk('Test threads', keywords, patterns)
test.setStart(method)
################################################################################
from .hello import *
from .ctime import *
from .test import *

102
SmallTalk/ctime.py Normal file
View File

@@ -0,0 +1,102 @@
from .SmallTalk import *
import datetime, time
import requests
from bs4 import BeautifulSoup as BS
import math
################################################################################
def method(params):
if city := params.get('text'):
city = city.title()
responce = requests.get(f'https://www.google.ru/search?&q=время+в+{city}&lr=lang_ru&lang=ru')
page = BS(responce.content, 'html.parser')
now = page.select('div.BNeawe>div>div.BNeawe')[0].get_text().split(':') or ''
now = datetime.time(int(now[0]), int(now[1]))
else:
now = datetime.datetime.now()
hours = now.hour%12 or 12
minutes = now.minute
get_str = ['десять', 'один', 'два', 'три', 'четыре', 'пять', 'шесть', 'семь', 'восемь', 'девять']
if hours%20 == 1:
str_hour = 'час'
elif 5 > hours%20 > 1:
str_hour = 'часа'
else:
str_hour = 'часов'
if minutes%10 == 1 and 20<minutes or minutes == 1:
str_minute = 'минута'
elif 0 < minutes%10 < 5 and math.floor(minutes/10) != 1:
str_minute = 'минуты'
else:
str_minute = 'минут'
def get_str_num(num, bool):
result = []
for i in [100, 10, 1]:
j = num//i%10
str_num = get_str[j]
if i == 1 and bool:
if j==1:
str_num = 'одна'
elif j==2:
str_num = 'две'
if str_num=='десять':
continue
elif i==10 and j == 1:
j = int(num%10)
str_num = get_str[j]
if j==0:
str_num = ''
elif j==2:
str_num = 'две'
elif j==4:
str_num = 'четыр'
elif j==5:
str_num = 'пят'
str_num += 'надцать'
if j==0:
str_num = 'десять'
result.append(str_num)
break
elif i==10:
if j==4:
str_num = 'сорок'
elif j<5:
str_num += 'дцать'
elif j==9:
str_num = 'девяноста'
else:
str_num += 'десят'
result.append(str_num)
return ' '.join(result)
if city: voice = f'В {city} сейчас {get_str_num(hours, 0)} {str_hour}'
else: voice = f'Сейчас {get_str_num(hours, 0)} {str_hour}'
if(minutes): voice += f', {get_str_num(minutes, 1)} {str_minute}'
hours = now.hour if now.hour > 9 else '0'+str(now.hour)
minutes = minutes if minutes > 9 else '0'+str(minutes) if minutes else '00'
if city: text = f'Текущее время в {city}: {hours}:{minutes}'
else: text = f'Текущее время: {hours}:{minutes}'
return {
'type': 'simple',
'text': text,
'voice': voice,
}
keywords = {
10: ['который час', 'сколько времени'],
5: ['текущее', 'сейчас', 'время'],
1: ['сколько']
}
patterns = ['* который * час в $text', '* скольк* * (врем|час)* * в $text', '* время в $text', '* который * час *', '* скольк* * (врем|час)* *']
subpatterns = ['а (сейчас|в $text)']
ctime = SmallTalk('Current Time', keywords, patterns, subpatterns)
ctime.setStart(method)

13
SmallTalk/hello.py Normal file
View File

@@ -0,0 +1,13 @@
from .SmallTalk import *
################################################################################
def method(params):
voice = text = 'Привет'
return {
'type': 'simple',
'text': text,
'voice': voice,
}
patterns = ['* привет* *',]
hello = SmallTalk('Hello', {}, patterns)
hello.setStart(method)

20
SmallTalk/test.py Normal file
View File

@@ -0,0 +1,20 @@
from .SmallTalk import *
import time
################################################################################
# Only for tests
@SmallTalk.background(answer = 'Запуск фонового процесса', voice = 'Запускаю фоновый процесс')
def method(params, finish_event):
time.sleep(10)
finish_event.set()
return {
'text': 'Фоновый процесс завершен',
'voice': 'Фоновый процесс завершен',
}
keywords = {
10: ['тестирование', 'проверка', 'потоков', 'фоновых', 'процессов'],
}
patterns = ['* [тест|провер]* * [фонов*] * (процесс|поток)* *']
test = SmallTalk('Test threads', keywords, patterns)
test.setStart(method)

View File

@@ -35,7 +35,7 @@ def check_threads(threads):
def main(id, text):
text = text.lower()
if Command.isRepeat(text):
reply(memory[0]['responce']);
reply(id, memory[0]['responce']);
return
if memory:
responce = memory[0]['responce']