diff --git a/1.jsob b/1.jsob deleted file mode 100644 index f2c7c1d..0000000 --- a/1.jsob +++ /dev/null @@ -1 +0,0 @@ -{"title": "\u0417\u0430\u043c\u0456\u043d\u0438 \u0434\u043e \u0440\u043e\u0437\u043a\u043b\u0430\u0434\u0443", "body": {"content": [{"endIndex": 1, "sectionBreak": {"sectionStyle": {"columnSeparatorStyle": "NONE", "contentDirection": "LEFT_TO_RIGHT", "sectionType": "CONTINUOUS"}}}, {"startIndex": 1, "endIndex": 20, "paragraph": {"elements": [{"startIndex": 1, "endIndex": 20, "textRun": {"content": "\u0417\u0430\u043c\u0456\u043d\u0438 \u0434\u043e \u0440\u043e\u0437\u043a\u043b\u0430\u0434\u0443\n", "textStyle": {"bold": true, "backgroundColor": {"color": {"rgbColor": {"red": 1, "green": 1, "blue": 1}}}, "fontSize": {"magnitude": 20, "unit": "PT"}, "weightedFontFamily": {"fontFamily": "Times New Roman", "weight": 400}}}}], "paragraphStyle": {"namedStyleType": "NORMAL_TEXT", "alignment": "CENTER", "lineSpacing": 100, "direction": "LEFT_TO_RIGHT", "spaceAbove": {"magnitude": 12, "unit": "PT"}, "indentFirstLine": {"unit": "PT"}, "indentStart": {"unit": "PT"}}}}, {"startIndex": 20, "endIndex": 22, "paragraph": {"elements": [{"startIndex": 20, "endIndex": 21, "inlineObjectElement": {"inlineObjectId": "kix.x5vm3f73wn5o", "textStyle": {"bold": true, "backgroundColor": {"color": {"rgbColor": {"red": 1, "green": 1, "blue": 1}}}, "fontSize": {"magnitude": 20, "unit": "PT"}, "weightedFontFamily": {"fontFamily": "Times New Roman", "weight": 400}}}}, {"startIndex": 21, "endIndex": 22, "textRun": {"content": "\n", "textStyle": {"bold": true, "backgroundColor": {"color": {"rgbColor": {"red": 1, "green": 1, "blue": 1}}}, "fontSize": {"magnitude": 20, "unit": "PT"}, "weightedFontFamily": {"fontFamily": "Times New Roman", "weight": 400}}}}], "paragraphStyle": {"namedStyleType": "NORMAL_TEXT", "alignment": "CENTER", "lineSpacing": 100, "direction": "LEFT_TO_RIGHT", "spaceAbove": {"magnitude": 12, "unit": "PT"}, "indentFirstLine": {"unit": "PT"}, "indentStart": {"unit": "PT"}}}}]}, "headers": {"kix.6vee0g5srhfm": {"headerId": "kix.6vee0g5srhfm", "content": [{"endIndex": 1, "paragraph": {"elements": [{"endIndex": 1, "textRun": {"content": "\n", "textStyle": {"fontSize": {"magnitude": 12, "unit": "PT"}}}}], "paragraphStyle": {"headingId": "h.u6ln6uwnxj1m", "namedStyleType": "TITLE", "alignment": "CENTER", "lineSpacing": 100, "direction": "LEFT_TO_RIGHT", "spaceAbove": {"magnitude": 12, "unit": "PT"}, "indentFirstLine": {"magnitude": 14.173228346456689, "unit": "PT"}, "indentStart": {"magnitude": 85.03937007874016, "unit": "PT"}}}}]}, "kix.i6h67293cr5": {"headerId": "kix.i6h67293cr5", "content": [{"endIndex": 1, "paragraph": {"elements": [{"endIndex": 1, "textRun": {"content": "\n", "textStyle": {}}}], "paragraphStyle": {"namedStyleType": "NORMAL_TEXT", "direction": "LEFT_TO_RIGHT", "pageBreakBefore": false}}}]}}, "footers": {"kix.vzzvlgoavtbc": {"footerId": "kix.vzzvlgoavtbc", "content": [{"endIndex": 1, "paragraph": {"elements": [{"endIndex": 1, "textRun": {"content": "\n", "textStyle": {}}}], "paragraphStyle": {"namedStyleType": "NORMAL_TEXT", "direction": "LEFT_TO_RIGHT", "pageBreakBefore": false}}}]}}, "documentStyle": {"background": {"color": {}}, "defaultHeaderId": "kix.6vee0g5srhfm", "firstPageHeaderId": "kix.i6h67293cr5", "firstPageFooterId": "kix.vzzvlgoavtbc", "pageNumberStart": 1, "marginTop": {"magnitude": 72, "unit": "PT"}, "marginBottom": {"magnitude": 72, "unit": "PT"}, "marginRight": {"magnitude": 36, "unit": "PT"}, "marginLeft": {"magnitude": 63.75, "unit": "PT"}, "pageSize": {"height": {"magnitude": 841.8897637795277, "unit": "PT"}, "width": {"magnitude": 595.2755905511812, "unit": "PT"}}, "marginHeader": {"magnitude": 36, "unit": "PT"}, "marginFooter": {"magnitude": 36, "unit": "PT"}}, "namedStyles": {"styles": [{"namedStyleType": "NORMAL_TEXT", "textStyle": {"bold": false, "italic": false, "underline": false, "strikethrough": false, "smallCaps": false, "backgroundColor": {}, "foregroundColor": {"color": {"rgbColor": {}}}, "fontSize": {"magnitude": 11, "unit": "PT"}, "weightedFontFamily": {"fontFamily": "Arial", "weight": 400}, "baselineOffset": "NONE"}, "paragraphStyle": {"namedStyleType": "NORMAL_TEXT", "alignment": "START", "lineSpacing": 115, "direction": "LEFT_TO_RIGHT", "spacingMode": "NEVER_COLLAPSE", "spaceAbove": {"unit": "PT"}, "spaceBelow": {"unit": "PT"}, "borderBetween": {"color": {}, "width": {"unit": "PT"}, "padding": {"unit": "PT"}, "dashStyle": "SOLID"}, "borderTop": {"color": {}, "width": {"unit": "PT"}, "padding": {"unit": "PT"}, "dashStyle": "SOLID"}, "borderBottom": {"color": {}, "width": {"unit": "PT"}, "padding": {"unit": "PT"}, "dashStyle": "SOLID"}, "borderLeft": {"color": {}, "width": {"unit": "PT"}, "padding": {"unit": "PT"}, "dashStyle": "SOLID"}, "borderRight": {"color": {}, "width": {"unit": "PT"}, "padding": {"unit": "PT"}, "dashStyle": "SOLID"}, "indentFirstLine": {"unit": "PT"}, "indentStart": {"unit": "PT"}, "indentEnd": {"unit": "PT"}, "keepLinesTogether": false, "keepWithNext": false, "avoidWidowAndOrphan": true, "shading": {"backgroundColor": {}}, "pageBreakBefore": false}}, {"namedStyleType": "HEADING_1", "textStyle": {"fontSize": {"magnitude": 20, "unit": "PT"}}, "paragraphStyle": {"namedStyleType": "NORMAL_TEXT", "direction": "LEFT_TO_RIGHT", "spaceAbove": {"magnitude": 20, "unit": "PT"}, "spaceBelow": {"magnitude": 6, "unit": "PT"}, "keepLinesTogether": true, "keepWithNext": true, "pageBreakBefore": false}}, {"namedStyleType": "HEADING_2", "textStyle": {"bold": false, "fontSize": {"magnitude": 16, "unit": "PT"}}, "paragraphStyle": {"namedStyleType": "NORMAL_TEXT", "direction": "LEFT_TO_RIGHT", "spaceAbove": {"magnitude": 18, "unit": "PT"}, "spaceBelow": {"magnitude": 6, "unit": "PT"}, "keepLinesTogether": true, "keepWithNext": true, "pageBreakBefore": false}}, {"namedStyleType": "HEADING_3", "textStyle": {"bold": false, "foregroundColor": {"color": {"rgbColor": {"red": 0.2627451, "green": 0.2627451, "blue": 0.2627451}}}, "fontSize": {"magnitude": 14, "unit": "PT"}}, "paragraphStyle": {"namedStyleType": "NORMAL_TEXT", "direction": "LEFT_TO_RIGHT", "spaceAbove": {"magnitude": 16, "unit": "PT"}, "spaceBelow": {"magnitude": 4, "unit": "PT"}, "keepLinesTogether": true, "keepWithNext": true, "pageBreakBefore": false}}, {"namedStyleType": "HEADING_4", "textStyle": {"foregroundColor": {"color": {"rgbColor": {"red": 0.4, "green": 0.4, "blue": 0.4}}}, "fontSize": {"magnitude": 12, "unit": "PT"}}, "paragraphStyle": {"namedStyleType": "NORMAL_TEXT", "direction": "LEFT_TO_RIGHT", "spaceAbove": {"magnitude": 14, "unit": "PT"}, "spaceBelow": {"magnitude": 4, "unit": "PT"}, "keepLinesTogether": true, "keepWithNext": true, "pageBreakBefore": false}}, {"namedStyleType": "HEADING_5", "textStyle": {"foregroundColor": {"color": {"rgbColor": {"red": 0.4, "green": 0.4, "blue": 0.4}}}, "fontSize": {"magnitude": 11, "unit": "PT"}}, "paragraphStyle": {"namedStyleType": "NORMAL_TEXT", "direction": "LEFT_TO_RIGHT", "spaceAbove": {"magnitude": 12, "unit": "PT"}, "spaceBelow": {"magnitude": 4, "unit": "PT"}, "keepLinesTogether": true, "keepWithNext": true, "pageBreakBefore": false}}, {"namedStyleType": "HEADING_6", "textStyle": {"italic": true, "foregroundColor": {"color": {"rgbColor": {"red": 0.4, "green": 0.4, "blue": 0.4}}}, "fontSize": {"magnitude": 11, "unit": "PT"}}, "paragraphStyle": {"namedStyleType": "NORMAL_TEXT", "direction": "LEFT_TO_RIGHT", "spaceAbove": {"magnitude": 12, "unit": "PT"}, "spaceBelow": {"magnitude": 4, "unit": "PT"}, "keepLinesTogether": true, "keepWithNext": true, "pageBreakBefore": false}}, {"namedStyleType": "TITLE", "textStyle": {"fontSize": {"magnitude": 26, "unit": "PT"}}, "paragraphStyle": {"namedStyleType": "NORMAL_TEXT", "direction": "LEFT_TO_RIGHT", "spaceAbove": {"unit": "PT"}, "spaceBelow": {"magnitude": 3, "unit": "PT"}, "keepLinesTogether": true, "keepWithNext": true, "pageBreakBefore": false}}, {"namedStyleType": "SUBTITLE", "textStyle": {"italic": false, "foregroundColor": {"color": {"rgbColor": {"red": 0.4, "green": 0.4, "blue": 0.4}}}, "fontSize": {"magnitude": 15, "unit": "PT"}, "weightedFontFamily": {"fontFamily": "Arial", "weight": 400}}, "paragraphStyle": {"namedStyleType": "NORMAL_TEXT", "direction": "LEFT_TO_RIGHT", "spaceAbove": {"unit": "PT"}, "spaceBelow": {"magnitude": 16, "unit": "PT"}, "keepLinesTogether": true, "keepWithNext": true, "pageBreakBefore": false}}]}, "lists": {"kix.d3btfm56ji6u": {"listProperties": {"nestingLevels": [{"bulletAlignment": "START", "glyphSymbol": "\u25cf", "glyphFormat": "%0", "indentFirstLine": {"magnitude": 18, "unit": "PT"}, "indentStart": {"magnitude": 36, "unit": "PT"}, "textStyle": {"underline": false}, "startNumber": 1}, {"bulletAlignment": "START", "glyphSymbol": "\u25cb", "glyphFormat": "%1", "indentFirstLine": {"magnitude": 54, "unit": "PT"}, "indentStart": {"magnitude": 72, "unit": "PT"}, "textStyle": {"underline": false}, "startNumber": 1}, {"bulletAlignment": "START", "glyphSymbol": "\u25a0", "glyphFormat": "%2", "indentFirstLine": {"magnitude": 90, "unit": "PT"}, "indentStart": {"magnitude": 108, "unit": "PT"}, "textStyle": {"underline": false}, "startNumber": 1}, {"bulletAlignment": "START", "glyphSymbol": "\u25cf", "glyphFormat": "%3", "indentFirstLine": {"magnitude": 126, "unit": "PT"}, "indentStart": {"magnitude": 144, "unit": "PT"}, "textStyle": {"underline": false}, "startNumber": 1}, {"bulletAlignment": "START", "glyphSymbol": "\u25cb", "glyphFormat": "%4", "indentFirstLine": {"magnitude": 162, "unit": "PT"}, "indentStart": {"magnitude": 180, "unit": "PT"}, "textStyle": {"underline": false}, "startNumber": 1}, {"bulletAlignment": "START", "glyphSymbol": "\u25a0", "glyphFormat": "%5", "indentFirstLine": {"magnitude": 198, "unit": "PT"}, "indentStart": {"magnitude": 216, "unit": "PT"}, "textStyle": {"underline": false}, "startNumber": 1}, {"bulletAlignment": "START", "glyphSymbol": "\u25cf", "glyphFormat": "%6", "indentFirstLine": {"magnitude": 234, "unit": "PT"}, "indentStart": {"magnitude": 252, "unit": "PT"}, "textStyle": {"underline": false}, "startNumber": 1}, {"bulletAlignment": "START", "glyphSymbol": "\u25cb", "glyphFormat": "%7", "indentFirstLine": {"magnitude": 270, "unit": "PT"}, "indentStart": {"magnitude": 288, "unit": "PT"}, "textStyle": {"underline": false}, "startNumber": 1}, {"bulletAlignment": "START", "glyphSymbol": "\u25a0", "glyphFormat": "%8", "indentFirstLine": {"magnitude": 306, "unit": "PT"}, "indentStart": {"magnitude": 324, "unit": "PT"}, "textStyle": {"underline": false}, "startNumber": 1}]}}}, "suggestionsViewMode": "PREVIEW_WITHOUT_SUGGESTIONS", "inlineObjects": {"kix.x5vm3f73wn5o": {"objectId": "kix.x5vm3f73wn5o", "inlineObjectProperties": {"embeddedObject": {"imageProperties": {"contentUri": "https://lh4.googleusercontent.com/V6dX_A92qmmRYdkfOLKTNymjMuY6icJ6vDTmRL8n6HDf5cAgQ7TrDsrYsiBgffyE7Tx8n-tvvkJOq8rFr_Su7tmhhscsFiuL0GWykpAMJjIunDDowK_wc6K8oUBcXfagfEmsnNJtk80dM3xTc_kL2RL2xb2w2txW", "cropProperties": {}}, "embeddedObjectBorder": {"color": {"color": {"rgbColor": {}}}, "width": {"unit": "PT"}, "dashStyle": "SOLID", "propertyState": "NOT_RENDERED"}, "size": {"height": {"magnitude": 452, "unit": "PT"}, "width": {"magnitude": 495.52559055118115, "unit": "PT"}}, "marginTop": {"magnitude": 9, "unit": "PT"}, "marginBottom": {"magnitude": 9, "unit": "PT"}, "marginRight": {"magnitude": 9, "unit": "PT"}, "marginLeft": {"magnitude": 9, "unit": "PT"}}}}}, "documentId": "18FYetZmms7sNCVvjZfLKgJT-RG5xo9NviKXfwdYHIFM"} diff --git a/1.p b/1.p deleted file mode 100644 index 1bc77f4..0000000 --- a/1.p +++ /dev/null @@ -1,117 +0,0 @@ -diff --git a/engineering_works.py b/engineering_works.py -index a122c3c..ebd6cea 100644 ---- a/engineering_works.py -+++ b/engineering_works.py -@@ -13,11 +13,11 @@ logging.basicConfig( - - - --WEBAPP_HOST = config.bot("ip") --WEBAPP_PORT = config.bot("port") -+WEBAPP_HOST = config.ip -+WEBAPP_PORT = config.port - - WEBHOOK_HOST = f'http://{WEBAPP_HOST}:{WEBAPP_PORT}' --WEBHOOK_PATH = f'/bot{config.bot("token")}/' -+WEBHOOK_PATH = f'/bot{config.token}/' - WEBHOOK_URL = f"{WEBHOOK_HOST}{WEBHOOK_PATH}" - - engeneerings_works = ( -@@ -29,7 +29,7 @@ parse_error = ( - "Бот приостановлен на неопределенный срок!\n" - "Что случилось?\n" - "Администрация коледжа изменила формат файла с google docs на docx(Microsoft Office)\n" -- "Замены вы можете посмотреть тут: https://docs.google.com/document/d/{}".format(config.documentid) -+ "Замены вы можете посмотреть тут: https://docs.google.com/document/d/{}".format("") - ) - - new_year = ( -@@ -48,7 +48,11 @@ september_1 = ("Всіх з 1 вересням, всього найкращог - "Бот буде запущений чуть пізніше, " - "коли заміни будуть публіковаться текстом") - --send_msg = the_end -+upd_1 = ("Невеликі зміни в боті.\n" -+ "1. Добавлени донати, тепер ви можете підтримати автора бота\n" -+ "2. Добалено звязок з адміністратором") -+ -+send_msg = upd_1 - - async def on_startup(dp): - await bot.set_webhook(url=WEBHOOK_URL) -@@ -81,7 +85,7 @@ async def start(message: types.Message): - ) - - if __name__ == "__main__": -- if config.bot("use_webhook").lower() in ['t', 'true', '1', 'yes', 'y']: -+ if config.use_webhook.lower() in ['t', 'true', '1', 'yes', 'y']: - executor.start_webhook( - dispatcher=dp, - webhook_path=WEBHOOK_PATH, -diff --git a/filters/main.py b/filters/main.py -index 849e6de..7539de0 100644 ---- a/filters/main.py -+++ b/filters/main.py -@@ -28,7 +28,7 @@ class BotAdmin(BoundFilter): - self.admin = admin - - async def check(self, message: types.Message): -- if message.from_user.id in config.admin_user: -+ if message.from_user.id in [int(i) for i in config.admin_users.split(",")]: - return True - else: - await message.answer("Хорошая попытка, но ты не администратор!") -diff --git a/handlers/private/main.py b/handlers/private/main.py -index de03596..370218a 100644 ---- a/handlers/private/main.py -+++ b/handlers/private/main.py -@@ -45,7 +45,7 @@ async def get_replace(message: types.Message, state: FSMContext): - - link = ( - 'Проверьте замены тут' -- .format(config.bot("link")) -+ .format(config.link) - ) - logging.info("User: {user_id} - {username}".format( - user_id=str(message.from_user.id), -@@ -94,7 +94,7 @@ async def get_replace(message: types.Message, state: FSMContext): - async def get_link(message: types.Message): - msg = ( - 'Проверьте замены тут' -- .format(config.bot("link")) -+ .format(config.link) - ) - await bot.send_message( - message.chat.id, -diff --git a/utils/announcements.py b/utils/announcements.py -index f70541e..4e264de 100644 ---- a/utils/announcements.py -+++ b/utils/announcements.py -@@ -1,3 +1,4 @@ -+ - import datetime - import asyncio - import aioschedule as schedule -@@ -15,8 +16,8 @@ async def announce(): - except Exception: - message = "Ошибка обновления данных!" - if config.admin_users.split(',') is not None: -- for user_id in config.admin_users.split(','): -- if user_id in config.exclude: -+ for user_id in [int(i) for i in config.admin_users.split(',')]: -+ if user_id in [int(i) for i in config.exclude.split(",")]: - continue - await dp.bot.send_message(user_id, message) - -diff --git a/utils/bot_commands.py b/utils/bot_commands.py -index b65bc62..3de6ed1 100644 ---- a/utils/bot_commands.py -+++ b/utils/bot_commands.py -@@ -7,6 +7,6 @@ async def set_commands(dp): - types.BotCommand("help", "информация"), - types.BotCommand("link", "получить ссылку на файл"), - types.BotCommand('timetable', "Розклад"), -- types.BotCommand('feedback', "Звязок з адміністратором") -+ types.BotCommand('feedback', "Звязок з адміністратором"), - types.BotCommand("reload", "только для администрации"), - ]) diff --git a/parser/parser.py b/parser/parser.py index 6db8588..e10656e 100644 --- a/parser/parser.py +++ b/parser/parser.py @@ -68,7 +68,6 @@ def get_about_replacements() -> dict: count = document['body']["content"][element]["table"]["rows"] except (IndexError, KeyError): image, image_bytes = helper.find_image(document) - print(image) if not image: element = helper.find_with_table(document) if element: diff --git a/parser/utils.py b/parser/utils.py index ede3578..ccb387c 100644 --- a/parser/utils.py +++ b/parser/utils.py @@ -32,14 +32,6 @@ self.months = { } ''' -headers = { - 'user-agent':( - "Mozilla/5.0 (Windows NT 10.0; WOW64) " - "AppleWebKit/537.36 (KHTML, like Gecko) " - "Chrome/62.0.3202.9 Safari/537.36" - ) -} - class Helper(): def __init__(self): @@ -199,13 +191,23 @@ class Helper(): element += 1 - + @classmethod + def get_link_and_download(cls, id_doc, document): + if "inlineObjects" in document: + if id_doc in document['inlineObjects']: + link = (document + ['inlineObjects'][id_doc]['inlineObjectProperties'] + ['embeddedObject']['imageProperties']['contentUri']) + r = requests.get(link, stream=True) + return base64.b64encode(r.content).decode('utf-8') + @classmethod def find_image(cls, document): for i in document['body']["content"]: if ("paragraph" in i) and ("elements" in i["paragraph"]): - if "inlineObjectElement" in i["paragraph"]["elements"][0]: - import base64 - return True, base64.b64encode(open("photo.png", 'rb').read()).decode('utf-8') + if "inlineObjectElement" in i["paragraph"]["elements"]: + return True, cls.get_link_and_download( + i["paragraph"]["elements"] + ['inlineObjectElement']['inlineObjectId'], document) return False, None diff --git a/photo.png b/photo.png deleted file mode 100644 index 030dbb3..0000000 Binary files a/photo.png and /dev/null differ