Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Python-bot/data/base.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"205589546": {"2020-01-29|13:39:28.778879": "a", "2020-01-29|13:39:35.527274": "aa", "2020-01-29|13:39:40.711174": "aaa"}}
{"205589546": {"2020-01-29|13:39:28.778879": "a", "2020-01-29|13:39:35.527274": "aa", "2020-01-29|13:39:40.711174": "aaa"}, "109297779": {"2020-02-07|21:46:53.837151": "\u041d\u0435 \u043c\u043e\u0433\u0443 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u0443", "2020-02-07|21:47:25.329122": "\u041d\u0435 \u043c\u043e\u0433\u0443 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u0443", "null": "\u0441\u0445\u043e\u0434\u0438\u0442\u044c \u0432 \u043a\u0438\u043d\u043e 08.02.2020", "null": "\u0441\u0445\u043e\u0434\u0438\u0442\u044c \u0432 \u043a\u0438\u043d\u043e 08.02.2020"}}
51 changes: 51 additions & 0 deletions Python-bot/parsing/PrettyOutput.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<html xmlns:fo="http://www.w3.org/1999/XSL/Format"><HEAD><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></HEAD></html><body xmlns:fo="http://www.w3.org/1999/XSL/Format">
<p><a name="0"><span title="напомнить V, sg, imper, 2p, pf, tran (&lt;b&gt;TAuxDicArticle [Напоминания]&lt;/b&gt;)
напомнить V, sg, imper, 2p, pf, tran (&lt;b&gt;TAuxDicArticle [Базовая грамматика]&lt;/b&gt;) ">Напомни</span>

<span title="завтра ADV
завтра S, nom, gen, dat, acc, ins, abl, sg, pl, n, inan">завтра</span>

<span title="сходить V, inf, ipf, intr
сходить V, inf, pf">сходить</span>

<span title="в PR">в</span>

<span title="качалочку ">качалочку</span>

<span title="напомнить V, sg, imper, 2p, pf, tran (&lt;b&gt;TAuxDicArticle [Напоминания]&lt;/b&gt;)
напомнить V, sg, imper, 2p, pf, tran (&lt;b&gt;TAuxDicArticle [Базовая грамматика]&lt;/b&gt;) ">напомни</span>

<span title="погулять V, inf, pf, intr">погулять</span>

<span title="напомнить V, sg, imper, 2p, pf, tran (&lt;b&gt;TAuxDicArticle [Напоминания]&lt;/b&gt;)
напомнить V, sg, imper, 2p, pf, tran (&lt;b&gt;TAuxDicArticle [Базовая грамматика]&lt;/b&gt;) ">напомни</span>

<span title="напомнить V, sg, imper, 2p, pf, tran (&lt;b&gt;TAuxDicArticle [Напоминания]&lt;/b&gt;)
напомнить V, sg, imper, 2p, pf, tran (&lt;b&gt;TAuxDicArticle [Базовая грамматика]&lt;/b&gt;) ">напомни</span>

<span title="иии ">иии</span>

<b> EOS</b> </a><p></p></p>
<table border="1"><tbody>
<tr align="center">
<th>Text</th>
<th>Type</th>
</tr>
<tr align="center">
<td><a href="#0">напомни</a></td>
<td>TAuxDicArticle [Базовая грамматика]</td>
</tr>
<tr align="center">
<td><a href="#0">напомни</a></td>
<td>TAuxDicArticle [Базовая грамматика]</td>
</tr>
<tr align="center">
<td><a href="#0">напомни</a></td>
<td>TAuxDicArticle [Базовая грамматика]</td>
</tr>
<tr align="center">
<td><a href="#0">напомни</a></td>
<td>TAuxDicArticle [Базовая грамматика]</td>
</tr>
</tbody></table>
</body>
16 changes: 16 additions & 0 deletions Python-bot/parsing/config.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
encoding "utf8"; // указываем кодировку, в которой написан конфигурационный файл

TTextMinerConfig {
Dictionary = "mydic.gzt"; // путь к корневому словарю

PrettyOutput = "PrettyOutput.html"; // путь к файлу с отладочным выводом в удобном для чтения виде

Input = {
File = "test.txt"; // путь к входному файлу
}

Articles = [
{ Name = "Базовая грамматика" } // название статьи в корневом словаре,
// которая содержит запускаемую грамматику
]
}
Binary file added Python-bot/parsing/first.bin
Binary file not shown.
4 changes: 4 additions & 0 deletions Python-bot/parsing/first.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#encoding "utf-8" // сообщаем парсеру о том, в какой кодировке написана грамматика
#GRAMMAR_ROOT Remind // указываем корневой нетерминал грамматики

Remind -> Word<kwtype="Напоминания">;
16 changes: 16 additions & 0 deletions Python-bot/parsing/mydic.gzt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
encoding "utf8"; // указываем кодировку, в которой написан этот файл

import "base.proto"; // подключаем описания protobuf-типов (TAuxDicArticle и прочих)
import "articles_base.proto"; // Файлы base.proto и articles_base.proto встроены в компилятор.
// Их необходимо включать в начало любого gzt-словаря.

TAuxDicArticle "Напоминания"
{
key = { "Напомни" | "напомни"}
}

TAuxDicArticle "Базовая грамматика"
{
key = { "tomita:first.cxx" type=CUSTOM }
}

Binary file added Python-bot/parsing/mydic.gzt.bin
Binary file not shown.
4 changes: 4 additions & 0 deletions Python-bot/parsing/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Напомни завтра сходить в качалочку
напомни погулять
напомни
напомни иии
36 changes: 25 additions & 11 deletions Python-bot/server.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import requests
import json
import random
import datetime
import os
import re
from user import UserList


class Server:
group_id = 191177272
access_token = 'access_token=f068c796542cba0f4dbdd0f6e39ba656a489731d36cfdcbdf7cee30de822ae000aa9e1aa8293bc61d77c7'
Expand All @@ -12,16 +14,18 @@ class Server:
data = UserList()

def __init__(self):
Server.getLongPollServer(self)
self.server = str()
self.key = str()
self.ts = str()
self.get_long_poll_server()

def getLongPollServer(self):
def get_long_poll_server(self):
method = 'groups.getLongPollServer?group_id=191177272'
reply = requests.get("&".join([Server.body + method, Server.v, Server.access_token]))
data = json.loads(reply.text)
self.server = data['response']['server']
self.key = data['response']['key']
self.ts = data['response']['ts']
# print(self.server, self.key, self.ts)

def simple_request(self):
method = self.server + '?act=a_check&key=' + self.key + '&ts=' + self.ts + "&wait=25"
Expand All @@ -30,16 +34,26 @@ def simple_request(self):
def simple_loop(self):
reply = json.loads(self.simple_request().text)
self.ts = reply['ts']
# print(json.dumps(reply, indent='\t'))
if reply['updates']:
message = reply['updates'][0]['object']['message']['text']
if 'Напомни' in message:
date = re.search('$d{2}-$d{2}-$d{4}', message)
if str(date) != '':
message = str(message).replace('Напомни ', '').replace(str(date), '')
else:
message = 'Не могу разобрать команду'
date = datetime.datetime.now().isoformat('|')
else:
message = 'Не могу разобрать команду'
date = datetime.datetime.now().isoformat('|')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут не совсем так должно быть. Посмотри в моих коммитах как дата сохраняется

user_id = reply['updates'][0]['object']['message']['from_id']
self.data.add_rec(str(user_id), {datetime.datetime.now().isoformat('|'): message})
random_id = random.randint(0, 100)
method = 'messages.send?' + 'user_id=' + str(user_id) + '&random_id=' + str(random_id) \
+ '&message=' + message
r = requests.get("&".join([Server.body + method, Server.v, Server.access_token]))
print("&".join([Server.body + method, Server.v, Server.access_token]))
if message != 'Не могу разобрать команду':
catalog = os.system('pwd')
if str(catalog).endswith('/parsing'):
os.system('tomita-parser config.proto')
else:
os.system('cd parsing/ && tomita-parser config.proto')
self.data.add_rec(str(user_id), {date: message})
self.simple_loop()


Expand Down
16 changes: 16 additions & 0 deletions parsing/config.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
encoding "utf8"; // указываем кодировку, в которой написан конфигурационный файл

TTextMinerConfig {
Dictionary = "mydic.gzt"; // путь к корневому словарю

PrettyOutput = "PrettyOutput.html"; // путь к файлу с отладочным выводом в удобном для чтения виде

Input = {
File = "test.txt"; // путь к входному файлу
}

Articles = [
{ Name = "наша_первая_грамматика" } // название статьи в корневом словаре,
// которая содержит запускаемую грамматику
]
}
4 changes: 4 additions & 0 deletions parsing/first.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#encoding "utf-8" // сообщаем парсеру о том, в какой кодировке написана грамматика
#GRAMMAR_ROOT S // указываем корневой нетерминал грамматики

Remind -> Noun<kwtype="Напомни">
15 changes: 15 additions & 0 deletions parsing/mydic.gzt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
encoding "utf8"; // указываем кодировку, в которой написан этот файл

import "base.proto"; // подключаем описания protobuf-типов (TAuxDicArticle и прочих)
import "articles_base.proto"; // Файлы base.proto и articles_base.proto встроены в компилятор.
// Их необходимо включать в начало любого gzt-словаря.

TAuxDicArticle "Базовая грамматика"
{
key = { "tomita:first.cxx" type=CUSTOM }
}

TAuxDicArticle "Напоминания"
{
key = { "Напомни" | "напомни"}
}
1 change: 1 addition & 0 deletions parsing/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Тяжёлый труд облагораживает хорошего человека.
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

requirements = [
# TODO: put package requirements here
'requests'
'requests',
'datetime'
]

test_requirements = [
Expand Down