diff --git a/.gitignore b/.gitignore index 028ec81..95b83f1 100644 --- a/.gitignore +++ b/.gitignore @@ -226,8 +226,6 @@ crashlytics-build.properties fabric.properties # Editor-based Rest Client -.idea/httpRequests +.idea/ -# Android studio 3.1+ serialized cache file -.idea/caches/build_file_checksums.ser diff --git a/datetime.json b/datetime.json new file mode 100644 index 0000000..2bf75c2 --- /dev/null +++ b/datetime.json @@ -0,0 +1 @@ +"2022-06-01 12:48:39.950777" diff --git a/main.py b/main.py new file mode 100644 index 0000000..5b380d5 --- /dev/null +++ b/main.py @@ -0,0 +1,41 @@ +import json +from datetime import datetime + +import pyodbc +import requests +from bs4 import BeautifulSoup + +server = '10.3.1.13\SQLEXPRESS' +database = 'DepartmentDatabaseContext' +username = 'sa' +password = 'isadmin' +cnxn = pyodbc.connect( + 'DRIVER={ODBC Driver 17 for SQL Server};SERVER=' + server + ';' + + 'DATABASE=' + database + ';UID=' + username + ';PWD=' + password) + + +def main(): + with open('datetime.json') as json_file: + date = json.load(json_file) + + cursor = cnxn.cursor() + cursor.execute("SELECT Id, Title, Body FROM Newses " + "WHERE Newses.IsDeleted = 0 AND Newses.DateCreate >= ? " + "ORDER BY Newses.DateCreate", date) # например - 2022-04-02 11:19:29.778400 + row = cursor.fetchone() + + while row: + soup = BeautifulSoup(row[2], features="html.parser") + textNews = soup.get_text('\n').replace("\n\n\n\n", "\n").replace("\n\n\n", "\n").replace("\n\n", "\n") + params = {'chat_id': '-1001637207513', + 'text': f'{row[1]}\n{textNews}\nhttp://is.ulstu.ru/News/ShowNews/{row[0]}'} + requests.get('https://api.telegram.org/bot5567223643:AAG6DYNUNq7BNqm7-pI2p-SdvEmAKielViE/sendMessage', + params=params) + row = cursor.fetchone() + + with open('datetime.json', 'w') as outfile: + json.dump(str(datetime.now()), outfile) + + +if __name__ == '__main__': + main() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..f4f0c45 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +bs4 +pyodbc +requests