init
This commit is contained in:
parent
f3c78bcae6
commit
13eb8184dc
4
.gitignore
vendored
4
.gitignore
vendored
@ -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
|
||||
|
||||
|
1
datetime.json
Normal file
1
datetime.json
Normal file
@ -0,0 +1 @@
|
||||
"2022-06-01 12:48:39.950777"
|
41
main.py
Normal file
41
main.py
Normal file
@ -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()
|
3
requirements.txt
Normal file
3
requirements.txt
Normal file
@ -0,0 +1,3 @@
|
||||
bs4
|
||||
pyodbc
|
||||
requests
|
Loading…
x
Reference in New Issue
Block a user