Compare commits
No commits in common. "python" and "golang-database-try" have entirely different histories.
python
...
golang-dat
@ -1,39 +0,0 @@
|
|||||||
name: Actions Build Docker Image
|
|
||||||
run-name: ${{ gitea.actor }} is building new image 🚀
|
|
||||||
on: [push]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
Explore-Gitea-Actions:
|
|
||||||
runs-on: soaska
|
|
||||||
steps:
|
|
||||||
- run: echo "🎉 The job was automatically triggered by a ${{ gitea.event_name }} event."
|
|
||||||
- name: Install Node.js
|
|
||||||
run: |
|
|
||||||
apk add --no-cache nodejs
|
|
||||||
- name: Check out repository code
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
- name: List files in the repository
|
|
||||||
run: |
|
|
||||||
ls ${{ gitea.workspace }}
|
|
||||||
- run: echo "🍏 This job's status is ${{ job.status }}."
|
|
||||||
- name: Install Docker
|
|
||||||
run: |
|
|
||||||
apk add --no-cache docker
|
|
||||||
- name: Start Docker service
|
|
||||||
run: |
|
|
||||||
dockerd &
|
|
||||||
sleep 5
|
|
||||||
docker info
|
|
||||||
- name: Build Dockerfile
|
|
||||||
run: |
|
|
||||||
docker build -t $(basename ${{ github.repository }}) .
|
|
||||||
- name: Upload Docker image to soaska.ru
|
|
||||||
run: |
|
|
||||||
package_name=$(basename ${{ github.repository }})
|
|
||||||
branch_name=$(git rev-parse --abbrev-ref HEAD)
|
|
||||||
|
|
||||||
docker login -u ${{ secrets.username }} -p ${{ secrets.password }} soaska.ru
|
|
||||||
docker tag $package_name soaska.ru/soaska/$package_name:$branch_name
|
|
||||||
docker tag $package_name soaska.ru/soaska/$package_name:latest
|
|
||||||
docker push soaska.ru/soaska/$package_name:$branch_name
|
|
||||||
docker push soaska.ru/soaska/$package_name:latest
|
|
11
.gitignore
vendored
11
.gitignore
vendored
@ -1,10 +1,5 @@
|
|||||||
/.env
|
|
||||||
/venv
|
/venv
|
||||||
/Eljur/__pycache__
|
/Python
|
||||||
/.idea
|
/.env
|
||||||
/__pycache__
|
|
||||||
/logfile.log
|
|
||||||
/data
|
/data
|
||||||
|
/dockerfile
|
||||||
# Временно
|
|
||||||
/docker
|
|
27
.vscode/settings.json
vendored
27
.vscode/settings.json
vendored
@ -1,15 +1,20 @@
|
|||||||
{
|
{
|
||||||
"python.analysis.typeCheckingMode": "basic",
|
|
||||||
"cSpell.words": [
|
"cSpell.words": [
|
||||||
"authorisation",
|
"телеграме",
|
||||||
"domcontentloaded",
|
"Экспуатация",
|
||||||
"fromdesc",
|
"Элжур",
|
||||||
"fromlines",
|
"documize",
|
||||||
|
"Eljur",
|
||||||
|
"Fjournal",
|
||||||
|
"godotenv",
|
||||||
|
"htmldiff",
|
||||||
|
"joho",
|
||||||
"lgray",
|
"lgray",
|
||||||
"lxml",
|
"lightgreen",
|
||||||
"todesc",
|
"lightpink",
|
||||||
"tolines",
|
"lightskyblue",
|
||||||
"wrapcolumn"
|
"loginviewport",
|
||||||
],
|
"Sosiaka",
|
||||||
"cSpell.language": "en,ru"
|
"Vasya"
|
||||||
|
]
|
||||||
}
|
}
|
42
Dockerfile
42
Dockerfile
@ -1,11 +1,31 @@
|
|||||||
FROM python:3.11-slim-bullseye
|
# Stage 1: Build the Rod application
|
||||||
|
FROM golang:1.21.2 AS builder
|
||||||
WORKDIR /app/
|
|
||||||
COPY requirements.txt .
|
# Set the working directory inside the Docker image
|
||||||
RUN pip install -r requirements.txt --no-cache-dir
|
WORKDIR /app
|
||||||
RUN playwright install chromium
|
|
||||||
RUN playwright install-deps
|
# Copy the go mod and sum files, and download dependencies
|
||||||
|
COPY go.mod go.sum /app/
|
||||||
COPY . .
|
RUN go mod download
|
||||||
ENTRYPOINT ["python", "main.py"]
|
|
||||||
CMD [ "start" ]
|
# Copy the source code into the Docker image
|
||||||
|
COPY *.go /app/
|
||||||
|
|
||||||
|
# Build the Rod application
|
||||||
|
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main .
|
||||||
|
|
||||||
|
# Stage 2: Use a slim image for the runnable container
|
||||||
|
FROM alpine:3.14 as runtime
|
||||||
|
|
||||||
|
# Set the working directory
|
||||||
|
WORKDIR /root/
|
||||||
|
|
||||||
|
# Install browser
|
||||||
|
RUN apk add chromium
|
||||||
|
|
||||||
|
# Copy the binary from the builder stage
|
||||||
|
COPY --from=builder /app/main .
|
||||||
|
COPY Golang/ .
|
||||||
|
|
||||||
|
# Set the binary as the default command to run when starting the container
|
||||||
|
CMD ["./main"]
|
@ -1,93 +0,0 @@
|
|||||||
from bs4 import BeautifulSoup
|
|
||||||
from requests import Session, post
|
|
||||||
import json
|
|
||||||
from Eljur.errors import _checkStatus, _checkSubdomain, _findData
|
|
||||||
|
|
||||||
|
|
||||||
class Authorization:
|
|
||||||
def login(self, subdomain, data):
|
|
||||||
"""
|
|
||||||
Подключение к пользователю eljur.ru.
|
|
||||||
|
|
||||||
# :param subdomain: Поддомен eljur.ru // str
|
|
||||||
:param data: Дата, состоящая из {"username": "ваш логин",
|
|
||||||
"password": "ваш пароль"} // dict
|
|
||||||
|
|
||||||
:return: Словарь с ошибкой или с положительным ответом: // dict
|
|
||||||
answer // dict
|
|
||||||
session // Session
|
|
||||||
subdomain // str
|
|
||||||
result // bool
|
|
||||||
"""
|
|
||||||
|
|
||||||
subdomain = _checkSubdomain(subdomain)
|
|
||||||
if "error" in subdomain:
|
|
||||||
return subdomain
|
|
||||||
|
|
||||||
session = Session()
|
|
||||||
url = f"https://{subdomain}.eljur.ru/ajaxauthorize"
|
|
||||||
err = session.post(url=url, data=data)
|
|
||||||
|
|
||||||
checkStatus = _checkStatus(err, url)
|
|
||||||
if "error" in checkStatus:
|
|
||||||
return checkStatus
|
|
||||||
del checkStatus
|
|
||||||
|
|
||||||
if not err.json()["result"]:
|
|
||||||
return {"error": {"error_code": -103,
|
|
||||||
"error_msg": err.json()['error'],
|
|
||||||
"full_error": err.json()}}
|
|
||||||
del err
|
|
||||||
|
|
||||||
url = f"https://{subdomain}.eljur.ru/?show=home"
|
|
||||||
account = session.get(url=url)
|
|
||||||
checkStatus = _checkStatus(account, url)
|
|
||||||
if "error" in checkStatus:
|
|
||||||
return checkStatus
|
|
||||||
|
|
||||||
soup = BeautifulSoup(account.text, 'lxml')
|
|
||||||
|
|
||||||
sentryData = _findData(soup)
|
|
||||||
del soup
|
|
||||||
if not sentryData:
|
|
||||||
return {"error": {"error_code": -104,
|
|
||||||
"error_msg": "Данные о пользователю не найдены."}}
|
|
||||||
|
|
||||||
return {"answer": json.loads(sentryData[17:-1]),
|
|
||||||
"session": session,
|
|
||||||
"subdomain": subdomain,
|
|
||||||
"result": True}
|
|
||||||
|
|
||||||
def recover(self, subdomain, email):
|
|
||||||
"""
|
|
||||||
Восстановление пароль пользователю eljur.ru. через почту.
|
|
||||||
|
|
||||||
Внимание! Для использования данные функции требуется привязать почту.
|
|
||||||
В ином случае восстановление происходит через Администратора или другого лица вашей школы.
|
|
||||||
|
|
||||||
:param subdomain: Домен вашей школы. // str
|
|
||||||
:param email: Ваша почта, привязанная к аккаунту eljur // str
|
|
||||||
|
|
||||||
:return: Словарь с ошибкой или с положительным ответом: // dict
|
|
||||||
answer // dict
|
|
||||||
result // bool
|
|
||||||
"""
|
|
||||||
|
|
||||||
subdomain = _checkSubdomain(subdomain)
|
|
||||||
if "error" in subdomain:
|
|
||||||
return subdomain
|
|
||||||
|
|
||||||
url = f"https://{subdomain}.eljur.ru/ajaxrecover"
|
|
||||||
answer = post(url=url,
|
|
||||||
data={"email": email})
|
|
||||||
|
|
||||||
checkStatus = _checkStatus(answer, url)
|
|
||||||
if "error" in checkStatus:
|
|
||||||
return checkStatus
|
|
||||||
|
|
||||||
if not answer.json()["result"]:
|
|
||||||
return {"error": {"error_code": -105,
|
|
||||||
"error_msg": answer.json()['error'],
|
|
||||||
"full_error": answer.json()}}
|
|
||||||
return {"answer": "Сообщение успешно отправлено на почту.",
|
|
||||||
"result": True}
|
|
@ -1,86 +0,0 @@
|
|||||||
import re
|
|
||||||
from bs4 import BeautifulSoup
|
|
||||||
from requests import Session
|
|
||||||
|
|
||||||
|
|
||||||
def _findData(soup):
|
|
||||||
for tag in soup.find_all("script"):
|
|
||||||
contents = tag.contents
|
|
||||||
for content in contents:
|
|
||||||
if "sentryData" in content:
|
|
||||||
return content
|
|
||||||
|
|
||||||
|
|
||||||
def _checkStatus(err, url):
|
|
||||||
if not err.status_code:
|
|
||||||
return {"error": {"error_code": -102,
|
|
||||||
"error_msg": f"Возникла ошибка при отправке запроса по ссылке {url}"}}
|
|
||||||
if err.status_code >= 400:
|
|
||||||
return {"error": {"error_code": -102,
|
|
||||||
"error_msg": f"Возникла ошибка {err.status_code} при отправке запроса по ссылке {url}"}}
|
|
||||||
else:
|
|
||||||
return {"answer": "Ok",
|
|
||||||
"result": True}
|
|
||||||
|
|
||||||
|
|
||||||
def _checkSubdomain(subdomain):
|
|
||||||
subdomain = re.search(r"[a-zA-Z0-9]+", subdomain)
|
|
||||||
if not subdomain:
|
|
||||||
return {"error": {"error_code": -101,
|
|
||||||
"error_msg": "Поддомен не найден"}}
|
|
||||||
else:
|
|
||||||
return subdomain[0]
|
|
||||||
|
|
||||||
|
|
||||||
def _checkInstance(obj, cls):
|
|
||||||
if not isinstance(obj, cls):
|
|
||||||
return {"error": {"error_code": -201,
|
|
||||||
"error_msg": f"Экземпляр не пренадлежит к классу. {type(obj)} - {type(cls)}"}}
|
|
||||||
else:
|
|
||||||
return {"answer": "Ok",
|
|
||||||
"result": True}
|
|
||||||
|
|
||||||
|
|
||||||
def _fullCheck(subdomain, session, url, data=None):
|
|
||||||
subdomain = _checkSubdomain(subdomain)
|
|
||||||
if "error" in subdomain:
|
|
||||||
return subdomain
|
|
||||||
|
|
||||||
checkSession = _checkInstance(session, Session)
|
|
||||||
if "error" in checkSession:
|
|
||||||
return checkSession
|
|
||||||
del checkSession
|
|
||||||
|
|
||||||
getInfo = session.post(url=url, data=data)
|
|
||||||
|
|
||||||
checkStatus = _checkStatus(getInfo, url)
|
|
||||||
if "error" in checkStatus:
|
|
||||||
return checkStatus
|
|
||||||
del checkStatus
|
|
||||||
|
|
||||||
soup = BeautifulSoup(getInfo.text, 'lxml')
|
|
||||||
del getInfo, url
|
|
||||||
|
|
||||||
sentryData = _findData(soup)
|
|
||||||
if not sentryData:
|
|
||||||
return {"error": {"error_code": -104,
|
|
||||||
"error_msg": "Данные о пользователе не найдены."}}
|
|
||||||
del sentryData
|
|
||||||
|
|
||||||
return soup
|
|
||||||
|
|
||||||
|
|
||||||
def _smallCheck(subdomain, session, args):
|
|
||||||
subdomain = _checkSubdomain(subdomain)
|
|
||||||
if "error" in subdomain:
|
|
||||||
return subdomain
|
|
||||||
|
|
||||||
checkSession = _checkInstance(session, Session)
|
|
||||||
if "error" in checkSession:
|
|
||||||
return checkSession
|
|
||||||
del checkSession
|
|
||||||
|
|
||||||
checkDict = _checkInstance(args, dict)
|
|
||||||
if "error" in checkDict:
|
|
||||||
return checkDict
|
|
||||||
del checkDict
|
|
@ -1,68 +0,0 @@
|
|||||||
from Eljur.errors import _fullCheck, _checkInstance
|
|
||||||
|
|
||||||
|
|
||||||
class Journal:
|
|
||||||
|
|
||||||
def journal(self, subdomain, session, week=0):
|
|
||||||
"""
|
|
||||||
Получение страницы дневника с расписанием, оценками и другой информации.
|
|
||||||
|
|
||||||
:param subdomain: Поддомен eljur.ru // str
|
|
||||||
:param session: Активная сессия пользователя // Session
|
|
||||||
:param week: Нужная вам неделя (0 - нынешняя, -1 - предыдущая, 1 - следующая). По умолчанию 0 (нынешняя) // str
|
|
||||||
|
|
||||||
:return: Словарь с ошибкой или с расписанием пользователя: // dict
|
|
||||||
answer // dict
|
|
||||||
result // bool
|
|
||||||
"""
|
|
||||||
checkWeek = _checkInstance(week, int)
|
|
||||||
if "error" in checkWeek:
|
|
||||||
return checkWeek
|
|
||||||
del checkWeek
|
|
||||||
|
|
||||||
url = f"https://{subdomain}.eljur.ru/journal-app/week.{week * -1}"
|
|
||||||
|
|
||||||
soup = _fullCheck(subdomain, session, url)
|
|
||||||
if "error" in soup:
|
|
||||||
return soup
|
|
||||||
|
|
||||||
info = {}
|
|
||||||
for day in soup.find_all("div", class_="dnevnik-day"):
|
|
||||||
title = day.find("div", class_="dnevnik-day__title")
|
|
||||||
week, date = title.contents[0].strip().replace("\n", "").split(", ")
|
|
||||||
|
|
||||||
if day.find("div", class_="page-empty"):
|
|
||||||
info.update([(week, {"date": date, "isEmpty": True, "comment": "Нет уроков", "lessons": {}})])
|
|
||||||
continue
|
|
||||||
|
|
||||||
if day.find("div", class_="dnevnik-day__holiday"):
|
|
||||||
info.update([(week, {"date": date, "isEmpty": True, "comment": "Выходной", "lessons": {}})])
|
|
||||||
continue
|
|
||||||
|
|
||||||
lessons = day.find_all("div", class_="dnevnik-lesson")
|
|
||||||
lessonsDict = {}
|
|
||||||
if lessons:
|
|
||||||
for lesson in lessons:
|
|
||||||
lessonNumber = lesson.find("div", class_="dnevnik-lesson__number dnevnik-lesson__number--time")
|
|
||||||
if lessonNumber:
|
|
||||||
lessonNumber = lessonNumber.contents[0].replace("\n", "").strip()[:-1]
|
|
||||||
|
|
||||||
lessonTime = lesson.find("div", class_="dnevnik-lesson__time").contents[0].strip().replace("\n", "")
|
|
||||||
lessonName = lesson.find("span", class_="js-rt_licey-dnevnik-subject").contents[0]
|
|
||||||
|
|
||||||
lessonHomeTask = lesson.find("div", class_="dnevnik-lesson__task")
|
|
||||||
if lessonHomeTask:
|
|
||||||
lessonHomeTask = lessonHomeTask.contents[2].replace("\n", "").strip()
|
|
||||||
|
|
||||||
lessonMark = lesson.find("div", class_="dnevnik-mark")
|
|
||||||
if lessonMark:
|
|
||||||
lessonMark = lessonMark.contents[1].attrs["value"]
|
|
||||||
|
|
||||||
lessonsDict.update([(lessonNumber, {"time": lessonTime,
|
|
||||||
"name": lessonName,
|
|
||||||
"hometask": lessonHomeTask,
|
|
||||||
"mark": lessonMark})])
|
|
||||||
|
|
||||||
info.update([(week, {"date": date, "isEmpty": False, "comment": "Выходной", "lessons": lessonsDict})])
|
|
||||||
|
|
||||||
return info
|
|
196
Eljur/message.py
196
Eljur/message.py
@ -1,196 +0,0 @@
|
|||||||
from Eljur.errors import _checkStatus, _checkSubdomain, _smallCheck
|
|
||||||
|
|
||||||
|
|
||||||
class Message:
|
|
||||||
|
|
||||||
def schoolList(self, subdomain, session):
|
|
||||||
"""
|
|
||||||
Получение тех, кому можем отправить сообщение.
|
|
||||||
|
|
||||||
:param subdomain: Поддомен eljur.ru // str
|
|
||||||
:param session: Активная сессия пользователя // Session
|
|
||||||
|
|
||||||
:return: Возвращает ошибку или массив из словарей возможных получателей сообщения. // list
|
|
||||||
"""
|
|
||||||
|
|
||||||
pattern = {"0": "school",
|
|
||||||
"1": "null",
|
|
||||||
"2": "null",
|
|
||||||
"3": "null"}
|
|
||||||
typePattern = ["classruks", "administration", "specialists", "ext_5_teachers", "teachers", "parents",
|
|
||||||
"students"]
|
|
||||||
listAnswer = {}
|
|
||||||
|
|
||||||
subdomain = _checkSubdomain(subdomain)
|
|
||||||
if "error" in subdomain:
|
|
||||||
return subdomain
|
|
||||||
|
|
||||||
for typeOf in enumerate(typePattern):
|
|
||||||
if typeOf[0] == 4:
|
|
||||||
pattern["2"] = "1"
|
|
||||||
|
|
||||||
pattern["1"] = typePattern[typeOf[0]]
|
|
||||||
|
|
||||||
url = f"https://{subdomain}.eljur.ru/journal-messages-ajax-action?method=getRecipientList"
|
|
||||||
getPattern = session.post(url=url, data=pattern)
|
|
||||||
|
|
||||||
checkStatus = _checkStatus(getPattern, url)
|
|
||||||
if "error" in checkStatus:
|
|
||||||
return checkStatus
|
|
||||||
del checkStatus
|
|
||||||
|
|
||||||
listAnswer.update([(typeOf[1], getPattern.json())])
|
|
||||||
|
|
||||||
return [listAnswer, typePattern]
|
|
||||||
|
|
||||||
def sendMessage(self, subdomain, session, args):
|
|
||||||
"""
|
|
||||||
Отправка сообщения по ID пользователя.
|
|
||||||
|
|
||||||
:param subdomain: Поддомен eljur.ru // str
|
|
||||||
:param session: Активная сессия пользователя // Session
|
|
||||||
|
|
||||||
:param args: Словарь, состоящий из:
|
|
||||||
receivers: ID пользователя. Если несколько, то через ; // str
|
|
||||||
subject: Тема сообщение (заглавие) // str
|
|
||||||
message: Сообщение // str
|
|
||||||
|
|
||||||
|
|
||||||
:return: Словарь с ошибкой или bool ответ, в котором True - успешная отправка соообщения // dict или bool
|
|
||||||
"""
|
|
||||||
|
|
||||||
check = _smallCheck(subdomain, session, args)
|
|
||||||
if not check:
|
|
||||||
return check
|
|
||||||
del check
|
|
||||||
|
|
||||||
url = f"https://{subdomain}.eljur.ru/journal-messages-compose-action"
|
|
||||||
get_cookies = session.get(url, data={"_msg": "sent"})
|
|
||||||
|
|
||||||
checkStatus = _checkStatus(get_cookies, url)
|
|
||||||
if "error" in checkStatus:
|
|
||||||
return checkStatus
|
|
||||||
del checkStatus
|
|
||||||
|
|
||||||
pattern = {"csrf": get_cookies.cookies.values()[0],
|
|
||||||
"submit": "Отправить",
|
|
||||||
"cancel": "Отмена"}
|
|
||||||
pattern.update(args)
|
|
||||||
|
|
||||||
url = f"https://{subdomain}.eljur.ru/journal-messages-send-action/"
|
|
||||||
send = session.post(url, data=pattern)
|
|
||||||
|
|
||||||
checkStatus = _checkStatus(send, url)
|
|
||||||
if "error" in checkStatus:
|
|
||||||
return checkStatus
|
|
||||||
del checkStatus
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
def getMessages(self, subdomain, session, args):
|
|
||||||
"""
|
|
||||||
Получение сообщений пользователя.
|
|
||||||
|
|
||||||
:param subdomain: Поддомен eljur.ru // str
|
|
||||||
:param session: Активная сессия пользователя // Session
|
|
||||||
:param args: Словарь, состоящий из:
|
|
||||||
"0": inbox/sent (полученные/отправленные) // str
|
|
||||||
"1": Текст заглавия // str
|
|
||||||
"2": Сколько сообщений показать (default: 20 / limit: 44) // str
|
|
||||||
"3": С какого сообщение начало // str
|
|
||||||
"4": 0 или id пользователя. // str
|
|
||||||
"5": read/unread/trash (Прочитанные/Непрочитанные/Корзина) // str
|
|
||||||
"6": ID пользователя, чьи сообщения мы хотим получить. // str
|
|
||||||
"7": Дата (false, today, week, month, two_month, year) // str
|
|
||||||
|
|
||||||
:return: Словарь с ошибкой или с сообщениями // dict
|
|
||||||
"""
|
|
||||||
|
|
||||||
pattern = {"method": "getList",
|
|
||||||
"2": "20"}
|
|
||||||
|
|
||||||
check = _smallCheck(subdomain, session, args)
|
|
||||||
if check:
|
|
||||||
return check
|
|
||||||
del check
|
|
||||||
|
|
||||||
pattern.update(args)
|
|
||||||
|
|
||||||
url = f"https://{subdomain}.eljur.ru/journal-messages-ajax-action/getmessages"
|
|
||||||
send = session.post(url, data=pattern)
|
|
||||||
|
|
||||||
checkStatus = _checkStatus(send, url)
|
|
||||||
if "error" in checkStatus:
|
|
||||||
return checkStatus
|
|
||||||
del checkStatus
|
|
||||||
|
|
||||||
return send.json()
|
|
||||||
|
|
||||||
def deleteMessages(self, subdomain, session, args):
|
|
||||||
"""
|
|
||||||
Удаление сообщения у пользователя.
|
|
||||||
Внимание! Eljur удаляет сообщение ТОЛЬКО у пользователя (как если вы не выбрали "Также удалить у")
|
|
||||||
Получатель сможет прочитать сообщение даже после удаления у вас.
|
|
||||||
|
|
||||||
:param subdomain: Поддомен eljur.ru // str
|
|
||||||
:param session: Активная сессия пользователя // Session
|
|
||||||
:param args: Словарь, состоящий из:
|
|
||||||
0: ID сообщения. Если несколько, то через ; без пробелов // str
|
|
||||||
1: Полученные/Отправленные (inbox/sent) Корзина (trash) не удаляется // str
|
|
||||||
|
|
||||||
|
|
||||||
:return: Словарь с ошибкой или с ответом: // dict
|
|
||||||
result // bool
|
|
||||||
error // str
|
|
||||||
"""
|
|
||||||
|
|
||||||
check = _smallCheck(subdomain, session, args)
|
|
||||||
if not check:
|
|
||||||
return check
|
|
||||||
del check
|
|
||||||
|
|
||||||
pattern = {"method": "delete"}
|
|
||||||
pattern.update(args)
|
|
||||||
|
|
||||||
url = f"https://{subdomain}.eljur.ru/journal-messages-ajax-action/"
|
|
||||||
delete = session.post(url, data=pattern)
|
|
||||||
|
|
||||||
checkStatus = _checkStatus(delete, url)
|
|
||||||
if "error" in checkStatus:
|
|
||||||
return checkStatus
|
|
||||||
del checkStatus
|
|
||||||
|
|
||||||
return delete.json()
|
|
||||||
|
|
||||||
def recoverMessages(self, subdomain, session, args):
|
|
||||||
"""
|
|
||||||
Возвращает сообщение из Корзины.
|
|
||||||
|
|
||||||
:param subdomain: Поддомен eljur.ru // str
|
|
||||||
:param session: Активная сессия пользователя // Session
|
|
||||||
:param args: Словарь, состоящий из:
|
|
||||||
0: ID сообщения. Если несколько, то через ; без пробелов // str
|
|
||||||
|
|
||||||
:return: Словарь с ошибкой или с ответом: // dict
|
|
||||||
result // bool
|
|
||||||
error // str
|
|
||||||
"""
|
|
||||||
|
|
||||||
check = _smallCheck(subdomain, session, args)
|
|
||||||
if not check:
|
|
||||||
return check
|
|
||||||
del check
|
|
||||||
|
|
||||||
pattern = {"method": "restore",
|
|
||||||
"1": "inbox"}
|
|
||||||
pattern.update(args)
|
|
||||||
|
|
||||||
url = f"https://{subdomain}.eljur.ru/journal-messages-ajax-action/"
|
|
||||||
recover = session.post(url, data=pattern)
|
|
||||||
|
|
||||||
checkStatus = _checkStatus(recover, url)
|
|
||||||
if "error" in checkStatus:
|
|
||||||
return checkStatus
|
|
||||||
del checkStatus
|
|
||||||
|
|
||||||
return recover.json()
|
|
@ -1,132 +0,0 @@
|
|||||||
from Eljur.errors import _fullCheck
|
|
||||||
|
|
||||||
|
|
||||||
def _checkForID(lesson_id):
|
|
||||||
return lesson_id.has_attr("data-lesson_id")
|
|
||||||
|
|
||||||
|
|
||||||
def _pattern(att):
|
|
||||||
dictionary = {"Всего": att.contents[3].contents[0],
|
|
||||||
"По болезни": att.contents[5].contents[0],
|
|
||||||
"По ув. причине": att.contents[7].contents[0],
|
|
||||||
"По неув. причине": att.contents[9].contents[0]}
|
|
||||||
return dictionary
|
|
||||||
|
|
||||||
|
|
||||||
class Portfolio:
|
|
||||||
|
|
||||||
def reportCard(self, subdomain, session, user_id, quarter="I"):
|
|
||||||
"""
|
|
||||||
Получение списка оценок.
|
|
||||||
|
|
||||||
:param subdomain: Поддомен eljur.ru // str
|
|
||||||
:param session: Активная сессия пользователя // Session
|
|
||||||
:param user_id: ID пользователя // str
|
|
||||||
:param quarter: Четверть (I, II, III, IV) // str
|
|
||||||
|
|
||||||
:return: Словарь с ошибкой или ответом (отсутствие оценок или словарь с оценками) // dict
|
|
||||||
"""
|
|
||||||
|
|
||||||
url = f"https://{subdomain}.eljur.ru/journal-student-grades-action/u.{user_id}/sp.{quarter}+четверть"
|
|
||||||
|
|
||||||
soup = _fullCheck(subdomain, session, url)
|
|
||||||
if "error" in soup:
|
|
||||||
return soup
|
|
||||||
|
|
||||||
answer = soup.find("div", class_="page-empty")
|
|
||||||
|
|
||||||
if answer:
|
|
||||||
return {"answer": answer.contents[0],
|
|
||||||
"result": False}
|
|
||||||
|
|
||||||
card = {}
|
|
||||||
subjects = soup.find_all("div", class_="text-overflow lhCell offset16")
|
|
||||||
|
|
||||||
for subject in subjects:
|
|
||||||
scores = []
|
|
||||||
for score in soup.find_all("div", class_=["cell blue", "cell"], attrs={"name": subject.contents[0]}):
|
|
||||||
if "mark_date" in score.attrs:
|
|
||||||
if score.attrs["id"] != "N":
|
|
||||||
scores.append({score.attrs["mark_date"], score.contents[1].contents[0]})
|
|
||||||
card.update([(subject.contents[0], scores)])
|
|
||||||
card.update(result=True)
|
|
||||||
|
|
||||||
return card
|
|
||||||
|
|
||||||
def attendance(self, subdomain, session, user_id, quarter="I"):
|
|
||||||
"""
|
|
||||||
Изменение подписи в новых сообщениях пользователя.
|
|
||||||
|
|
||||||
:param subdomain: Поддомен eljur.ru // str
|
|
||||||
:param session: Активная сессия пользователя // Session
|
|
||||||
:param user_id: ID пользователя // str
|
|
||||||
:param quarter: Четверть (I, II, III, IV) // str
|
|
||||||
|
|
||||||
:return: Словарь с ошибкой или ответом в виде словаря с предметами и пропущенными уроками // dict
|
|
||||||
"""
|
|
||||||
url = f"https://{subdomain}.eljur.ru/journal-app/view.miss_report/u.{user_id}/sp.{quarter}+четверть"
|
|
||||||
|
|
||||||
soup = _fullCheck(subdomain, session, url)
|
|
||||||
if "error" in soup:
|
|
||||||
return soup
|
|
||||||
|
|
||||||
answer = soup.find("div", class_="page-empty")
|
|
||||||
|
|
||||||
if answer:
|
|
||||||
return {"answer": answer.contents[0],
|
|
||||||
"result": False}
|
|
||||||
|
|
||||||
card = {}
|
|
||||||
subjects = soup.find_all(_checkForID)
|
|
||||||
|
|
||||||
for subject in subjects:
|
|
||||||
lessonInfo = _pattern(subject)
|
|
||||||
if not subject.contents[1].contents:
|
|
||||||
subject.contents[1].contents = ["Всего"]
|
|
||||||
card.update([(subject.contents[1].contents[0], lessonInfo)])
|
|
||||||
|
|
||||||
days = soup.find_all("tr", attrs={"xls": "hrow"})
|
|
||||||
daysInfo = _pattern(days[1])
|
|
||||||
|
|
||||||
card.update([(days[1].contents[1].contents[0], daysInfo)])
|
|
||||||
|
|
||||||
return card
|
|
||||||
|
|
||||||
def finalGrades(self, subdomain, session, user_id, data=None):
|
|
||||||
"""
|
|
||||||
Изменение подписи в новых сообщениях пользователя.
|
|
||||||
|
|
||||||
:param subdomain: Поддомен eljur.ru // str
|
|
||||||
:param session: Активная сессия пользователя // Session
|
|
||||||
:param user_id: ID пользователя // str
|
|
||||||
:param data: Учебный год (Например: 2020/2021) // str
|
|
||||||
|
|
||||||
:return: Словарь с ошибкой или ответом (отсутствие оценок или словарь с оценками) // dict
|
|
||||||
"""
|
|
||||||
url = f"https://{subdomain}.eljur.ru/journal-student-resultmarks-action/u.{user_id}"
|
|
||||||
|
|
||||||
soup = _fullCheck(subdomain, session, url, data)
|
|
||||||
if "error" in soup:
|
|
||||||
return soup
|
|
||||||
|
|
||||||
answer = soup.find("div", class_="page-empty")
|
|
||||||
|
|
||||||
if answer:
|
|
||||||
return {"answer": answer.contents[0],
|
|
||||||
"result": False}
|
|
||||||
|
|
||||||
card = {}
|
|
||||||
subjects = soup.find_all("div", class_="text-overflow lhCell offset16")
|
|
||||||
|
|
||||||
for subject in subjects:
|
|
||||||
scores = []
|
|
||||||
for score in soup.find_all("div", class_="cell", attrs={"name": subject.contents[0]}):
|
|
||||||
if score.contents[0].attrs["class"][0] != "cell-data":
|
|
||||||
continue
|
|
||||||
if not score.contents[0].contents:
|
|
||||||
continue
|
|
||||||
scores.append(score.contents[0].contents[0])
|
|
||||||
card.update([(subject.contents[0], scores)])
|
|
||||||
card.update(result=True)
|
|
||||||
|
|
||||||
return card
|
|
202
Eljur/profile.py
202
Eljur/profile.py
@ -1,202 +0,0 @@
|
|||||||
from requests import Session
|
|
||||||
from Eljur.errors import _checkInstance, _checkStatus, _checkSubdomain, _fullCheck
|
|
||||||
|
|
||||||
|
|
||||||
class Profile:
|
|
||||||
|
|
||||||
def getProfile(self, subdomain, session):
|
|
||||||
"""
|
|
||||||
Получение информации о пользователе.
|
|
||||||
Внимание. В данной функции специально не выводится СНИЛС, почта и мобильный телефон пользователя.
|
|
||||||
|
|
||||||
:param subdomain: Поддомен eljur.ru // str
|
|
||||||
:param session: Активная сессия пользователя // Session
|
|
||||||
|
|
||||||
:return: Словарь с ошибкой или с информацией о пользователе: // dict
|
|
||||||
"""
|
|
||||||
|
|
||||||
url = f"https://{subdomain}.eljur.ru/journal-user-preferences-action"
|
|
||||||
|
|
||||||
soup = _fullCheck(subdomain, session, url)
|
|
||||||
if "error" in soup:
|
|
||||||
return soup
|
|
||||||
|
|
||||||
label = None
|
|
||||||
info = {}
|
|
||||||
for tag in soup.find_all(["label", "span"], class_=["ej-form-label", "control-label"]):
|
|
||||||
if tag.contents[0] == "СНИЛС":
|
|
||||||
break
|
|
||||||
|
|
||||||
if tag.name == "label":
|
|
||||||
label = tag.contents[0]
|
|
||||||
info.update([(label, None)])
|
|
||||||
|
|
||||||
if tag.name == "span":
|
|
||||||
info[label] = tag.contents[0]
|
|
||||||
|
|
||||||
return info
|
|
||||||
|
|
||||||
|
|
||||||
class Security:
|
|
||||||
|
|
||||||
def changePassword(self, subdomain, session, old_password, new_password):
|
|
||||||
"""
|
|
||||||
Изменение пароля в личном кабинете пользователя.
|
|
||||||
|
|
||||||
:param subdomain: Поддомен eljur.ru // str
|
|
||||||
:param session: Активная сессия пользователя // Session
|
|
||||||
:param old_password: Старый пароль. // str
|
|
||||||
:param new_password: Новый пароль, который пользователь желает использовать. // str
|
|
||||||
|
|
||||||
:return: Словарь с ошибкой или bool ответ, в котором True - успешная смена пароля // dict или bool
|
|
||||||
"""
|
|
||||||
|
|
||||||
subdomain = _checkSubdomain(subdomain)
|
|
||||||
if "error" in subdomain:
|
|
||||||
return subdomain
|
|
||||||
|
|
||||||
checkSession = _checkInstance(session, Session)
|
|
||||||
if "error" in checkSession:
|
|
||||||
return checkSession
|
|
||||||
del checkSession
|
|
||||||
|
|
||||||
url = f"https://{subdomain}.eljur.ru/journal-messages-compose-action"
|
|
||||||
getCookies = session.get(url=url, data={"_msg": "sent"})
|
|
||||||
|
|
||||||
checkStatus = _checkStatus(getCookies, url)
|
|
||||||
if "error" in checkStatus:
|
|
||||||
return checkStatus
|
|
||||||
del checkStatus
|
|
||||||
|
|
||||||
data = {"csrf": getCookies.cookies.values()[0],
|
|
||||||
"old_password": old_password,
|
|
||||||
"new_password": new_password,
|
|
||||||
"verify": new_password,
|
|
||||||
"submit_button": "Сохранить"}
|
|
||||||
|
|
||||||
url = f"https://{subdomain}.eljur.ru/journal-user-security-action/"
|
|
||||||
answer = session.post(url=url, data=data)
|
|
||||||
|
|
||||||
checkStatus = _checkStatus(answer, url)
|
|
||||||
if "error" in checkStatus:
|
|
||||||
return checkStatus
|
|
||||||
del checkStatus
|
|
||||||
|
|
||||||
if "Ваш пароль успешно изменен!" in answer.text:
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
class Settings:
|
|
||||||
|
|
||||||
def changeSing(self, subdomain, session, text):
|
|
||||||
"""
|
|
||||||
Изменение подписи в новых сообщениях пользователя.
|
|
||||||
|
|
||||||
:param subdomain: Поддомен eljur.ru // str
|
|
||||||
:param session: Активная сессия пользователя // Session
|
|
||||||
:param text: Текст подписи // str
|
|
||||||
|
|
||||||
:return: Словарь с ошибкой или bool ответ, в котором True - успешное изменение подписи. // dict или bool
|
|
||||||
"""
|
|
||||||
|
|
||||||
subdomain = _checkSubdomain(subdomain)
|
|
||||||
if "error" in subdomain:
|
|
||||||
return subdomain
|
|
||||||
|
|
||||||
checkSession = _checkInstance(session, Session)
|
|
||||||
if "error" in checkSession:
|
|
||||||
return checkSession
|
|
||||||
del checkSession
|
|
||||||
|
|
||||||
url = f"https://{subdomain}.eljur.ru/journal-index-rpc-action"
|
|
||||||
data = {"method": "setPref",
|
|
||||||
"0": "msgsignature",
|
|
||||||
"1": text}
|
|
||||||
|
|
||||||
changeSing = session.post(url=url, data=data)
|
|
||||||
|
|
||||||
checkStatus = _checkStatus(changeSing, url)
|
|
||||||
if "error" in checkStatus:
|
|
||||||
return checkStatus
|
|
||||||
|
|
||||||
if "result" not in checkStatus:
|
|
||||||
return False
|
|
||||||
else:
|
|
||||||
return checkStatus["result"]
|
|
||||||
|
|
||||||
def switcher(self, subdomain, session, choose, switch):
|
|
||||||
"""
|
|
||||||
Переключение настраиваиваемых функций в настройках.
|
|
||||||
Доступно переключение следующих функций:
|
|
||||||
`Отмечать сообщение прочитанным при его открытии на электронной почте` // 0 или checkforwardedemail
|
|
||||||
`Отображать расписание обучающегося по умолчанию (вместо расписания класса)` // 1 или schedule_default_student
|
|
||||||
|
|
||||||
:param subdomain: Поддомен eljur.ru // str
|
|
||||||
:param session: Активная сессия пользователя // Session
|
|
||||||
:param choose: Выбор переключаемой функции // int или str
|
|
||||||
:param switch: True/False // bool
|
|
||||||
|
|
||||||
:return: Словарь с ошибкой или bool ответ, в котором True - успешное переключение. // dict или bool
|
|
||||||
"""
|
|
||||||
|
|
||||||
numSwitch = [0, 1]
|
|
||||||
numStrSwitch = ["0", "1"]
|
|
||||||
strSwitch = ["checkforwardedemail", "schedule_default_student"]
|
|
||||||
switchers = {"checkforwardedemail": {"on": "on",
|
|
||||||
"off": "off"},
|
|
||||||
"schedule_default_student": {"on": "yes",
|
|
||||||
"off": "no"}}
|
|
||||||
data = {"method": "setPref",
|
|
||||||
"0": None,
|
|
||||||
"1": None}
|
|
||||||
|
|
||||||
subdomain = _checkSubdomain(subdomain)
|
|
||||||
if "error" in subdomain:
|
|
||||||
return subdomain
|
|
||||||
|
|
||||||
checkSession = _checkInstance(session, Session)
|
|
||||||
if "error" in checkSession:
|
|
||||||
return checkSession
|
|
||||||
del checkSession
|
|
||||||
|
|
||||||
checkInt = _checkInstance(choose, int)
|
|
||||||
if "error" in checkInt:
|
|
||||||
checkStr = _checkInstance(choose, str)
|
|
||||||
if "error" in checkStr:
|
|
||||||
return checkStr
|
|
||||||
else:
|
|
||||||
if choose not in strSwitch:
|
|
||||||
if choose not in numStrSwitch:
|
|
||||||
return {"error": {"error_code": -302,
|
|
||||||
"error_msg": f"Вашего выбора нет в предложенных. {choose}"}}
|
|
||||||
else:
|
|
||||||
data["0"] = strSwitch[int(choose)]
|
|
||||||
data["0"] = choose
|
|
||||||
else:
|
|
||||||
if choose not in numSwitch:
|
|
||||||
return {"error": {"error_code": -302,
|
|
||||||
"error_msg": f"Вашего выбора нет в предложенных. {choose}"}}
|
|
||||||
data["0"] = strSwitch[choose]
|
|
||||||
|
|
||||||
checkBool = _checkInstance(switch, bool)
|
|
||||||
if "error" not in checkBool:
|
|
||||||
return checkBool
|
|
||||||
del checkBool, checkStr, checkInt
|
|
||||||
|
|
||||||
if switch:
|
|
||||||
data["1"] = switchers[data["0"]]["on"]
|
|
||||||
else:
|
|
||||||
data["1"] = switchers[data["0"]]["off"]
|
|
||||||
|
|
||||||
url = f"https://{subdomain}.eljur.ru/journal-index-rpc-action"
|
|
||||||
changeSing = session.post(url=url, data=data)
|
|
||||||
|
|
||||||
checkStatus = _checkStatus(changeSing, url)
|
|
||||||
if "error" in checkStatus:
|
|
||||||
return checkStatus
|
|
||||||
|
|
||||||
if "result" not in checkStatus:
|
|
||||||
return False
|
|
||||||
else:
|
|
||||||
return checkStatus["result"]
|
|
@ -1,29 +0,0 @@
|
|||||||
class Timetable:
|
|
||||||
|
|
||||||
def timetable(self, subdomain, session, week):
|
|
||||||
"""
|
|
||||||
Получение страницы расписания.
|
|
||||||
|
|
||||||
:param week: Нужная вам неделя (even, odd, both) // str
|
|
||||||
:param subdomain: Поддомен eljur.ru // str
|
|
||||||
:param session: Активная сессия пользователя // Session
|
|
||||||
|
|
||||||
:return: Словарь с ошибкой или с расписанием пользователя: // dict
|
|
||||||
answer // dict
|
|
||||||
result // bool
|
|
||||||
"""
|
|
||||||
return
|
|
||||||
|
|
||||||
def journal(self, subdomain, session, week=0):
|
|
||||||
"""
|
|
||||||
Получение страницы дневника с расписанием и оценками.
|
|
||||||
|
|
||||||
:param subdomain: Поддомен eljur.ru // str
|
|
||||||
:param session: Активная сессия пользователя // Session
|
|
||||||
:param week: Нужная вам неделя (0, -1, 3 и.т.д). По умолчанию 0 (нынешняя) // str
|
|
||||||
|
|
||||||
:return: Словарь с ошибкой или с расписанием пользователя: // dict
|
|
||||||
answer // dict
|
|
||||||
result // bool
|
|
||||||
"""
|
|
||||||
return
|
|
0
Golang/data/difference.html
Normal file
0
Golang/data/difference.html
Normal file
Before Width: | Height: | Size: 62 KiB After Width: | Height: | Size: 62 KiB |
0
Golang/data/table.html
Normal file
0
Golang/data/table.html
Normal file
90
README.md
90
README.md
@ -1,19 +1,70 @@
|
|||||||
# Элжур бот
|
## Идея для нового метода обработки объявлений
|
||||||
|
- [ ] Обрабатывать не как текст, а в виде объекта структуры объявления
|
||||||
|
- [ ] Сохранять объявления в виде байт кода массива объявлений
|
||||||
|
- [ ] Снова переделать функцию поиска различий для новых структур данных
|
||||||
|
|
||||||
|
### Структура объявления `board-item`
|
||||||
|
- `active` -- *bool* -- из названия класса
|
||||||
|
- `dates` -- *string pair* -- дата-дата в формате *ДД.ММ.ГГГГ* (в будущем отправлять только с флажком "удалено раньше времени")
|
||||||
|
- `title` -- *string* -- заголовок из класса `board-item__title`
|
||||||
|
- `content` -- *string* -- текст из объявления. Ознакомьтесь с [поддерживаемыми тегами](https://core.telegram.org/bots/api#html-style) и на тег `br`. Класс `typography typography--links`
|
||||||
|
- `attachments` -- *array* из структур `outline` -- если есть вложения, класс `button`
|
||||||
|
- `creator` -- *string* -- из класса `b-href`
|
||||||
|
- `receivers` -- *string* -- строку собираем из всех получателей с разделителем ` · `
|
||||||
|
- `edit_pattern` -- *[]int* -- 6 значений `0` или `1` по изменениям
|
||||||
|
- `unique` -- *bool* -- уникально ли объявление относительно нового / старого списка
|
||||||
|
> `edit pattern` и `unique` заполняются после получения новых объявлений отдельной функцией, вызываемой во время генерации сообщения
|
||||||
|
|
||||||
|
### Структура вложения `outline`
|
||||||
|
> Берем класс `button` на разбор
|
||||||
|
- `title` -- *string* -- заголовок
|
||||||
|
- `link` -- *string* -- ссылка на контент
|
||||||
|
- `type` -- *string* -- название вложенного класса по тегу `i`
|
||||||
|
|
||||||
|
### Изменения в экспорте содержимого страницы `get_content`
|
||||||
|
- [x] С помощью указателей `rod` найти все объявления как указатели на объекты JS
|
||||||
|
- [ ] отправить текст каждого объекта в функцию `parse_post`, принимающую текст и возвращающую объект структуры объявления с заполненными полями.
|
||||||
|
- [x] Собрать все структуры объявлений в массив и вернуть его
|
||||||
|
|
||||||
|
### Изменения в обработке содержимого `scape`
|
||||||
|
- [x] Адаптация под новый `get_content`
|
||||||
|
- [x] Теперь возвращает массив
|
||||||
|
|
||||||
|
### Изменения в `get_difference`
|
||||||
|
- Теперь мы сравниваем два массива, формируем сообщение в формате *string* с html форматированием
|
||||||
|
- Появился новый заголовок == новое объявление ->> целиком под заголовком `появились объявления`
|
||||||
|
- Изменилось что-то в объявлении ->> заголовок + "изменилось <слой>" + новый слой, под заголовком `изменились объявления`
|
||||||
|
- Пропал заголовок объявления раньше времени ->> целиком под заголовком `удалено вручную`
|
||||||
|
|
||||||
|
### Изменения в работе с файлами `get_file` и `update_file`
|
||||||
|
- Добавить вызов функции для работы с байткодом
|
||||||
|
- Сохранить полученный байткод в файл
|
||||||
|
|
||||||
|
## Бонус
|
||||||
|
- Переименовать функции под стандарты *golang*
|
||||||
|
- Пример: `get_difference` ->> `GetDifference`
|
||||||
|
|
||||||
|
- Написать комментарии к коду
|
||||||
|
|
||||||
|
# Комментарии [ТУТ](http://git.soaska.ru/sosiska/eljur/-/snippets/6#note_40)!
|
||||||
|
|
||||||
|
|
||||||
|
## Элжур бот
|
||||||
|
|
||||||
Предназначен для получения объявлений в телеграме в виде скриншота и html файла,
|
Предназначен для получения объявлений в телеграме в виде скриншота и html файла,
|
||||||
а также присутствует возможность узнать какие объявления были удалены.
|
а также присутствует возможность узнать какие объявления были удалены.
|
||||||
|
|
||||||
- [Быстрая установка и запуск с помощью Docker](https://git.soaska.ru/sosiska/eljur/-/wikis/home)
|
- [Быстрая установка и запуск с помощью Docker](https://git.soaska.ru/sosiska/eljur/-/wikis/home)
|
||||||
|
|
||||||
## Экспуатация проекта
|
### Экспуатация проекта
|
||||||
|
|
||||||
#### Скачивание проекта
|
##### Скачивание проекта
|
||||||
```bash
|
```bash
|
||||||
git clone https://git.soaska.ru/sosiska/eljur
|
git clone https://git.soaska.ru/sosiska/eljur
|
||||||
cd eljur
|
cd eljur
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Создание .env файла
|
##### Создание .env файла
|
||||||
Используйте [sample.env](https://git.soaska.ru/sosiska/eljur/-/blob/main/sample.env?ref_type=heads), чтобы создать свой .env файл.
|
Используйте [sample.env](https://git.soaska.ru/sosiska/eljur/-/blob/main/sample.env?ref_type=heads), чтобы создать свой .env файл.
|
||||||
[env.example](https://git.soaska.ru/sosiska/eljur/-/blob/main/env.example?ref_type=heads) - пример, как может выглядеть файл .env
|
[env.example](https://git.soaska.ru/sosiska/eljur/-/blob/main/env.example?ref_type=heads) - пример, как может выглядеть файл .env
|
||||||
|
|
||||||
@ -29,32 +80,29 @@ TG_API_URL=https://api.telegram.org/
|
|||||||
|
|
||||||
- [Как получить данные телеграм](https://git.soaska.ru/sosiska/eljur/-/wikis/How-to-get-telegram-data)
|
- [Как получить данные телеграм](https://git.soaska.ru/sosiska/eljur/-/wikis/How-to-get-telegram-data)
|
||||||
|
|
||||||
### Подготовка к запуску проекта
|
#### Подготовка к запуску проекта
|
||||||
|
|
||||||
1) Создайте виртуальное окружение в папке с проектом и активируйте его:
|
1) Установите библиотеки:
|
||||||
|
|
||||||
`(Debian)`
|
|
||||||
```bash
|
|
||||||
python3 -m venv venv
|
|
||||||
source venv/bin/activate
|
|
||||||
```
|
|
||||||
|
|
||||||
2) Установите библиотеки:
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pip install -r requirements.txt
|
go mod download
|
||||||
```
|
```
|
||||||
|
|
||||||
3) Установите движок chromium:
|
2) Перенесите папку data:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
playwright install chromium
|
cp -r Golang/data .
|
||||||
playwright install-deps
|
|
||||||
```
|
```
|
||||||
|
|
||||||
4) Запустите проект:
|
3) Запустите проект:
|
||||||
|
|
||||||
`(Debian)`
|
|
||||||
```bash
|
```bash
|
||||||
python3 main.py
|
go run .
|
||||||
|
```
|
||||||
|
|
||||||
|
> **Примечание:** \
|
||||||
|
Скомпилированный бинарник можно взять [здесь](https://git.soaska.ru/sosiska/eljur/-/packages/2). Используйте Эту команду как п.3 в случае использования скомпилированного бинарника:
|
||||||
|
```bash
|
||||||
|
curl https://git.soaska.ru/api/v4/projects/13/packages/generic/bin/2.0B/eljur-bot -o eljur-bot
|
||||||
|
./eljur-bot
|
||||||
```
|
```
|
||||||
|
58
env_init.py
58
env_init.py
@ -1,58 +0,0 @@
|
|||||||
import os
|
|
||||||
from dotenv import load_dotenv
|
|
||||||
import logging
|
|
||||||
from typing import Any, Dict, Tuple
|
|
||||||
from requests import Session
|
|
||||||
import requests
|
|
||||||
|
|
||||||
|
|
||||||
load_dotenv()
|
|
||||||
|
|
||||||
LOGIN = os.getenv("ELJUR_LOGIN")
|
|
||||||
PASSWORD = os.getenv("ELJUR_PASSWORD")
|
|
||||||
DOMAIN = os.getenv("ELJUR_DOMAIN")
|
|
||||||
|
|
||||||
TG_TOKEN = os.getenv("TG_TOKEN")
|
|
||||||
TG_ID = os.getenv("TG_ID")
|
|
||||||
TG_API_URL = os.getenv("TG_API_URL")
|
|
||||||
|
|
||||||
|
|
||||||
logging.basicConfig(level=logging.DEBUG, filename="logfile.log",filemode="w")
|
|
||||||
|
|
||||||
if LOGIN == None or PASSWORD == None or DOMAIN == None or TG_TOKEN == None or TG_ID == None or TG_API_URL == None:
|
|
||||||
logging.critical("Env load error!")
|
|
||||||
exit(1)
|
|
||||||
|
|
||||||
TG_ID = int(TG_ID)
|
|
||||||
|
|
||||||
|
|
||||||
def send_photo(path):
|
|
||||||
url = f'{TG_API_URL}bot{TG_TOKEN}/sendPhoto'
|
|
||||||
|
|
||||||
params = {
|
|
||||||
'chat_id': TG_ID,
|
|
||||||
}
|
|
||||||
|
|
||||||
with open(path, 'rb') as img_file:
|
|
||||||
response = requests.post(url, params=params, files={'photo': img_file})
|
|
||||||
|
|
||||||
if response.status_code == 200:
|
|
||||||
logging.debug('photo sent')
|
|
||||||
else:
|
|
||||||
logging.error(f'can`t send photo: {response.status_code}')
|
|
||||||
|
|
||||||
|
|
||||||
def send_document(path):
|
|
||||||
url = f'{TG_API_URL}bot{TG_TOKEN}/sendDocument'
|
|
||||||
|
|
||||||
params = {
|
|
||||||
'chat_id': TG_ID,
|
|
||||||
}
|
|
||||||
|
|
||||||
with open(path, 'rb') as doc_file:
|
|
||||||
response = requests.post(url, params=params, files={'document': doc_file})
|
|
||||||
|
|
||||||
if response.status_code == 200:
|
|
||||||
logging.debug('doc sent')
|
|
||||||
else:
|
|
||||||
logging.error(f'can`t send document: {response.status_code}')
|
|
28
go.mod
Normal file
28
go.mod
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
module git.soaska.ru/sosiska/eljur-bot
|
||||||
|
|
||||||
|
go 1.21.2
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/Sosiaka/htmldiff v0.0.0-20231014152201-9444409b44c3 // indirect
|
||||||
|
github.com/anaskhan96/soup v1.2.5 // indirect
|
||||||
|
github.com/aryann/difflib v0.0.0-20210328193216-ff5ff6dc229b // indirect
|
||||||
|
github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964 // indirect
|
||||||
|
github.com/documize/html-diff v0.0.0-20160503140253-f61c192c7796 // indirect
|
||||||
|
github.com/go-jose/go-jose/v3 v3.0.0 // indirect
|
||||||
|
github.com/go-rod/rod v0.114.4 // indirect
|
||||||
|
github.com/go-stack/stack v1.8.1 // indirect
|
||||||
|
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1 // indirect
|
||||||
|
github.com/joho/godotenv v1.5.1 // indirect
|
||||||
|
github.com/mb0/diff v0.0.0-20131118162322-d8d9a906c24d // indirect
|
||||||
|
github.com/myENA/html-diff v0.0.0-20200616131349-b5478371670f // indirect
|
||||||
|
github.com/playwright-community/playwright-go v0.3800.0 // indirect
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
|
github.com/ysmood/fetchup v0.2.3 // indirect
|
||||||
|
github.com/ysmood/goob v0.4.0 // indirect
|
||||||
|
github.com/ysmood/got v0.34.1 // indirect
|
||||||
|
github.com/ysmood/gson v0.7.3 // indirect
|
||||||
|
github.com/ysmood/leakless v0.8.0 // indirect
|
||||||
|
go.uber.org/multierr v1.11.0 // indirect
|
||||||
|
golang.org/x/net v0.17.0 // indirect
|
||||||
|
golang.org/x/text v0.13.0 // indirect
|
||||||
|
)
|
64
go.sum
Normal file
64
go.sum
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
github.com/Sosiaka/html-diff v0.0.0-20231014151826-7a46f9715518 h1:2sFP+caHJJO1XUWoF4yUzm/w6V/2zY16NKc9HM/qVF4=
|
||||||
|
github.com/Sosiaka/html-diff v0.0.0-20231014151826-7a46f9715518/go.mod h1:FdPp57hpkPZTPd76i5TmQ40Kz7XQFRoZmP2c6srgQfY=
|
||||||
|
github.com/Sosiaka/htmldiff v0.0.0-20231014152201-9444409b44c3 h1:Jdj/LV+0ddFb2U6n1Ohg5uCCn/bLR1qZobqGRNArz/U=
|
||||||
|
github.com/Sosiaka/htmldiff v0.0.0-20231014152201-9444409b44c3/go.mod h1:xxmvkoUBGtrPNIiQaHV3+PvAVZIUcuWqSOibvPZwf90=
|
||||||
|
github.com/anaskhan96/soup v1.2.5 h1:V/FHiusdTrPrdF4iA1YkVxsOpdNcgvqT1hG+YtcZ5hM=
|
||||||
|
github.com/anaskhan96/soup v1.2.5/go.mod h1:6YnEp9A2yywlYdM4EgDz9NEHclocMepEtku7wg6Cq3s=
|
||||||
|
github.com/aryann/difflib v0.0.0-20210328193216-ff5ff6dc229b h1:uUXgbcPDK3KpW29o4iy7GtuappbWT0l5NaMo9H9pJDw=
|
||||||
|
github.com/aryann/difflib v0.0.0-20210328193216-ff5ff6dc229b/go.mod h1:DAHtR1m6lCRdSC2Tm3DSWRPvIPr6xNKyeHdqDQSQT+A=
|
||||||
|
github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964 h1:y5HC9v93H5EPKqaS1UYVg1uYah5Xf51mBfIoWehClUQ=
|
||||||
|
github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964/go.mod h1:Xd9hchkHSWYkEqJwUGisez3G1QY8Ryz0sdWrLPMGjLk=
|
||||||
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/documize/html-diff v0.0.0-20160503140253-f61c192c7796 h1:CuipXymSP8DiNHYVGWak4cF2IbYFQeL5CZ37Y6aDVq4=
|
||||||
|
github.com/documize/html-diff v0.0.0-20160503140253-f61c192c7796/go.mod h1:GTEVMy1JkyV+k/j8hLGRGHVs/IHJS4s7AtJJ9LSYjRQ=
|
||||||
|
github.com/go-jose/go-jose/v3 v3.0.0 h1:s6rrhirfEP/CGIoc6p+PZAeogN2SxKav6Wp7+dyMWVo=
|
||||||
|
github.com/go-jose/go-jose/v3 v3.0.0/go.mod h1:RNkWWRld676jZEYoV3+XK8L2ZnNSvIsxFMht0mSX+u8=
|
||||||
|
github.com/go-rod/rod v0.114.4 h1:FpkNFukjCuZLwnoLs+S9aCL95o/EMec6M+41UmvQay8=
|
||||||
|
github.com/go-rod/rod v0.114.4/go.mod h1:aiedSEFg5DwG/fnNbUOTPMTTWX3MRj6vIs/a684Mthw=
|
||||||
|
github.com/go-stack/stack v1.8.1 h1:ntEHSVwIt7PNXNpgPmVfMrNhLtgjlmnZha2kOpuRiDw=
|
||||||
|
github.com/go-stack/stack v1.8.1/go.mod h1:dcoOX6HbPZSZptuspn9bctJ+N/CnF5gGygcUP3XYfe4=
|
||||||
|
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1 h1:wG8n/XJQ07TmjbITcGiUaOtXxdrINDz1b0J1w0SzqDc=
|
||||||
|
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1/go.mod h1:A2S0CWkNylc2phvKXWBBdD3K0iGnDBGbzRpISP2zBl8=
|
||||||
|
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
|
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||||
|
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||||
|
github.com/mb0/diff v0.0.0-20131118162322-d8d9a906c24d h1:eAS2t2Vy+6psf9LZ4T5WXWsbkBt3Tu5PWekJy5AGyEU=
|
||||||
|
github.com/mb0/diff v0.0.0-20131118162322-d8d9a906c24d/go.mod h1:3YMHqrw2Qu3Liy82v4QdAG17e9k91HZ7w3hqlpWqhDo=
|
||||||
|
github.com/myENA/html-diff v0.0.0-20200616131349-b5478371670f h1:8AfNa+QS4jUxg/oaAQn0rb7JCF39bfP8jyxHzZnWpgo=
|
||||||
|
github.com/myENA/html-diff v0.0.0-20200616131349-b5478371670f/go.mod h1:B4c7Jsz+iqBoliHTdFpFsH/CJOl0kCF4fGyFuemjfgU=
|
||||||
|
github.com/playwright-community/playwright-go v0.3800.0 h1:9ATUzVh8Hio6W1LvfjPX76PSR9jPc5YwyOzNzMzQV6w=
|
||||||
|
github.com/playwright-community/playwright-go v0.3800.0/go.mod h1:mbNzMqt04IVRdhVfXWqmCxd81gCdL3BA5hj6/pVAIqM=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
|
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
|
github.com/ysmood/fetchup v0.2.3 h1:ulX+SonA0Vma5zUFXtv52Kzip/xe7aj4vqT5AJwQ+ZQ=
|
||||||
|
github.com/ysmood/fetchup v0.2.3/go.mod h1:xhibcRKziSvol0H1/pj33dnKrYyI2ebIvz5cOOkYGns=
|
||||||
|
github.com/ysmood/goob v0.4.0 h1:HsxXhyLBeGzWXnqVKtmT9qM7EuVs/XOgkX7T6r1o1AQ=
|
||||||
|
github.com/ysmood/goob v0.4.0/go.mod h1:u6yx7ZhS4Exf2MwciFr6nIM8knHQIE22lFpWHnfql18=
|
||||||
|
github.com/ysmood/gop v0.0.2/go.mod h1:rr5z2z27oGEbyB787hpEcx4ab8cCiPnKxn0SUHt6xzk=
|
||||||
|
github.com/ysmood/got v0.34.1 h1:IrV2uWLs45VXNvZqhJ6g2nIhY+pgIG1CUoOcqfXFl1s=
|
||||||
|
github.com/ysmood/got v0.34.1/go.mod h1:yddyjq/PmAf08RMLSwDjPyCvHvYed+WjHnQxpH851LM=
|
||||||
|
github.com/ysmood/gotrace v0.6.0/go.mod h1:TzhIG7nHDry5//eYZDYcTzuJLYQIkykJzCRIo4/dzQM=
|
||||||
|
github.com/ysmood/gson v0.7.3 h1:QFkWbTH8MxyUTKPkVWAENJhxqdBa4lYTQWqZCiLG6kE=
|
||||||
|
github.com/ysmood/gson v0.7.3/go.mod h1:3Kzs5zDl21g5F/BlLTNcuAGAYLKt2lV5G8D1zF3RNmg=
|
||||||
|
github.com/ysmood/leakless v0.8.0 h1:BzLrVoiwxikpgEQR0Lk8NyBN5Cit2b1z+u0mgL4ZJak=
|
||||||
|
github.com/ysmood/leakless v0.8.0/go.mod h1:R8iAXPRaG97QJwqxs74RdwzcRHT1SWCGTNqY8q0JvMQ=
|
||||||
|
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
|
||||||
|
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
|
||||||
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
|
golang.org/x/crypto v0.0.0-20190911031432-227b76d455e7/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
|
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
|
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa h1:F+8P+gmewFQYRk6JoLQLwjBCTu3mcIURZfNkVweuRKA=
|
||||||
|
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
|
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
|
||||||
|
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
|
||||||
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
|
||||||
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
|
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
|
||||||
|
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||||
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
123
main.go
Normal file
123
main.go
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/go-rod/rod"
|
||||||
|
"github.com/go-rod/rod/lib/launcher"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Старый вариант взятия разницы
|
||||||
|
//func get_difference(old_string, new_string string) {
|
||||||
|
// difference := " "
|
||||||
|
//
|
||||||
|
// var cfg = &htmldiff.Config{
|
||||||
|
// Granularity: 5,
|
||||||
|
// InsertedSpan: []htmldiff.Attribute{{Key: "style", Val: "background-color: lightgreen;"}},
|
||||||
|
// DeletedSpan: []htmldiff.Attribute{{Key: "style", Val: "background-color: lightpink;"}},
|
||||||
|
// ReplacedSpan: []htmldiff.Attribute{{Key: "style", Val: "background-color: lightskyblue;"}},
|
||||||
|
// CleanTags: []string{""},
|
||||||
|
// }
|
||||||
|
// res, err := cfg.HTMLdiff([]string{old_string, new_string})
|
||||||
|
// if err != nil {
|
||||||
|
// log.Fatal("cant make difference html body:", err)
|
||||||
|
// } else {
|
||||||
|
// difference = res[0]
|
||||||
|
// }
|
||||||
|
// update_file(difference, "data/difference.html")
|
||||||
|
//}
|
||||||
|
|
||||||
|
func item_status(item board_item, table []board_item) (bool, []int) {
|
||||||
|
is_new := true
|
||||||
|
edit_pattern := []int{0, 0, 0, 0, 0, 0}
|
||||||
|
|
||||||
|
i := 0
|
||||||
|
for i < len(table) {
|
||||||
|
if table[i].title == item.title {
|
||||||
|
is_new = false
|
||||||
|
|
||||||
|
if table[i].active != item.active {
|
||||||
|
edit_pattern[0] = i
|
||||||
|
}
|
||||||
|
if table[i].dates != item.dates {
|
||||||
|
edit_pattern[1] = i
|
||||||
|
}
|
||||||
|
if table[i].content != item.content {
|
||||||
|
edit_pattern[2] = i
|
||||||
|
}
|
||||||
|
if len(table[i].attachments) != len(item.attachments) {
|
||||||
|
edit_pattern[3] = i
|
||||||
|
} else {
|
||||||
|
j := 0
|
||||||
|
for j < len(item.attachments) {
|
||||||
|
if item.attachments[j] != table[i].attachments[j] {
|
||||||
|
edit_pattern[3] = i
|
||||||
|
}
|
||||||
|
j++
|
||||||
|
}
|
||||||
|
if table[i].creator != item.creator {
|
||||||
|
edit_pattern[4] = i
|
||||||
|
}
|
||||||
|
if table[i].receivers != item.receivers {
|
||||||
|
edit_pattern[5] = i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return is_new, edit_pattern
|
||||||
|
}
|
||||||
|
|
||||||
|
func update_patterns(old_table, new_table []board_item) ([]board_item, []board_item) {
|
||||||
|
i := 0
|
||||||
|
for i < len(new_table) {
|
||||||
|
new_table[i].unique, new_table[i].edit_pattern = item_status(new_table[i], old_table)
|
||||||
|
}
|
||||||
|
i = 0
|
||||||
|
for i < len(old_table) {
|
||||||
|
old_table[i].unique, old_table[i].edit_pattern = item_status(old_table[i], new_table)
|
||||||
|
}
|
||||||
|
return old_table, new_table
|
||||||
|
}
|
||||||
|
|
||||||
|
func generate_message(old_table, new_table []board_item) {
|
||||||
|
// message := "Новые объявления \n"
|
||||||
|
|
||||||
|
old_table, new_table = update_patterns(old_table, new_table)
|
||||||
|
// for table := range new_table {
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
func run(browser *rod.Browser, LOGIN, PASSWORD, ELJUR_URL, TELEGRAM_CHAT_ID, TELEGRAM_API_URL string) {
|
||||||
|
new_table := scape(browser, LOGIN, PASSWORD, ELJUR_URL)
|
||||||
|
// Старые методы
|
||||||
|
// old_table := get_file("data/table.html")
|
||||||
|
// old_last_post := ""
|
||||||
|
// if strings.Contains(old_table, `<div class="board-item__footer">`) {
|
||||||
|
// old_last_post = old_table[strings.Index(old_table, `<h1 class="page-title">Объявления</h1>`):strings.Index(old_table, `<div class="board-item__footer">`)]
|
||||||
|
// }
|
||||||
|
// if new_table != " " && new_table != old_table {
|
||||||
|
// update_file(new_table, "data/table.html")
|
||||||
|
// if new_last_post != old_last_post {
|
||||||
|
// send_photo("data/last_post.png", TELEGRAM_API_URL, TELEGRAM_CHAT_ID)
|
||||||
|
// } else {
|
||||||
|
// send_photo("data/sad.png", TELEGRAM_API_URL, TELEGRAM_CHAT_ID)
|
||||||
|
// }
|
||||||
|
// get_difference(old_table, new_table)
|
||||||
|
// send_document("data/difference.html", TELEGRAM_API_URL, TELEGRAM_CHAT_ID)
|
||||||
|
// }
|
||||||
|
println(new_table)
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
LOGIN, PASSWORD, ELJUR_URL, TELEGRAM_CHAT_ID, TELEGRAM_API_URL := load_env_vars()
|
||||||
|
|
||||||
|
path, _ := launcher.LookPath()
|
||||||
|
launcher := launcher.New().Bin(path).MustLaunch()
|
||||||
|
browser := rod.New().ControlURL(launcher).MustConnect()
|
||||||
|
for {
|
||||||
|
run(browser, LOGIN, PASSWORD, ELJUR_URL, TELEGRAM_CHAT_ID, TELEGRAM_API_URL)
|
||||||
|
time.Sleep(400 * time.Second)
|
||||||
|
}
|
||||||
|
}
|
125
main.py
125
main.py
@ -1,125 +0,0 @@
|
|||||||
from Eljur.auth import Authorization
|
|
||||||
from scraper import scrape
|
|
||||||
from env_init import LOGIN, PASSWORD, DOMAIN, TG_ID, send_photo, send_document
|
|
||||||
import logging
|
|
||||||
from time import sleep
|
|
||||||
from random import randint
|
|
||||||
from os import mkdir
|
|
||||||
from difflib import HtmlDiff
|
|
||||||
from bs4 import BeautifulSoup
|
|
||||||
|
|
||||||
|
|
||||||
def get_difference(old, new):
|
|
||||||
old = old.split("\n")
|
|
||||||
new = new.split("\n")
|
|
||||||
difference = HtmlDiff(wrapcolumn=81)
|
|
||||||
|
|
||||||
try:
|
|
||||||
html_file = open("data/difference.html", "w")
|
|
||||||
html_file.truncate(0)
|
|
||||||
ans = difference.make_file(fromlines=old, tolines=new, fromdesc="Было", todesc="Стало")
|
|
||||||
html_file.write(ans)
|
|
||||||
html_file.close
|
|
||||||
logging.debug("data/difference.html updated")
|
|
||||||
except:
|
|
||||||
logging.critical(f"cant update data/difference.html: {Exception}")
|
|
||||||
|
|
||||||
|
|
||||||
def update_html(val=""):
|
|
||||||
try:
|
|
||||||
html_file = open("data/table.html", "w")
|
|
||||||
html_file.truncate(0)
|
|
||||||
html_file.write(val)
|
|
||||||
html_file.close
|
|
||||||
logging.debug("data/table.html updated")
|
|
||||||
except FileNotFoundError:
|
|
||||||
mkdir("data")
|
|
||||||
logging.info(f"cant update data/table.html: {Exception}")
|
|
||||||
logging.info("retry")
|
|
||||||
update_html(val=val)
|
|
||||||
except:
|
|
||||||
logging.critical(f"cant update data/table.html: {Exception}")
|
|
||||||
exit(1)
|
|
||||||
|
|
||||||
|
|
||||||
def get_html():
|
|
||||||
val = ""
|
|
||||||
try:
|
|
||||||
with open('data/table.html') as html_file:
|
|
||||||
val = html_file.read()
|
|
||||||
logging.debug("data/table.html got")
|
|
||||||
except Exception as error:
|
|
||||||
logging.error(f"cant read data/table.html: {str(error)}")
|
|
||||||
return val
|
|
||||||
|
|
||||||
|
|
||||||
def verify_data():
|
|
||||||
authorisation = Authorization()
|
|
||||||
|
|
||||||
data = {
|
|
||||||
"username": LOGIN,
|
|
||||||
"password": PASSWORD,
|
|
||||||
}
|
|
||||||
subdomain = DOMAIN
|
|
||||||
|
|
||||||
answer = authorisation.login(subdomain, data)
|
|
||||||
if "session" not in answer:
|
|
||||||
print(answer)
|
|
||||||
logging.critical("can`t log in")
|
|
||||||
logging.error(answer)
|
|
||||||
exit(1)
|
|
||||||
elif answer['answer']['user']['username'] != LOGIN: # type: ignore
|
|
||||||
print(answer)
|
|
||||||
logging.critical("data verified. Wrong LOGIN!")
|
|
||||||
logging.error(f"Your login is {answer['answer']['user']['username']}! Update env") # type: ignore
|
|
||||||
exit(255)
|
|
||||||
logging.info(f'logged in as {LOGIN}')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def run():
|
|
||||||
global new_table, old_table
|
|
||||||
new_table = scrape()
|
|
||||||
old_table = get_html()
|
|
||||||
old_last_block = ""
|
|
||||||
|
|
||||||
if old_table != "":
|
|
||||||
old_last_block = old_table[old_table.find("""<h1 class="page-title">Объявления</h1>"""):old_table.find("""<div class="board-item__footer">""")]
|
|
||||||
|
|
||||||
if new_table != " ":
|
|
||||||
# new_table = new_table[new_table.find("""<h1 class="page-title">Объявления</h1>"""):new_table.find("""<div class="board-item__footer">""")]
|
|
||||||
new_table = new_table[new_table.find("""<h1 class="page-title">Объявления</h1>"""):new_table.find("""<span class="control-label lgray">""")]
|
|
||||||
|
|
||||||
|
|
||||||
if old_table != new_table and new_table != " ":
|
|
||||||
new_last_block = new_table[new_table.find("""<h1 class="page-title">Объявления</h1>"""):new_table.find("""<div class="board-item__footer">""")]
|
|
||||||
|
|
||||||
update_html(new_table)
|
|
||||||
new_table_soup = BeautifulSoup(new_table, "lxml")
|
|
||||||
new_table_pretty = new_table_soup.prettify()
|
|
||||||
old_table_soup = BeautifulSoup(old_table, "lxml")
|
|
||||||
old_table_pretty = old_table_soup.prettify()
|
|
||||||
get_difference(old_table_pretty, new_table_pretty)
|
|
||||||
|
|
||||||
|
|
||||||
if old_last_block != new_last_block:
|
|
||||||
send_photo("data/screenshot.png")
|
|
||||||
else:
|
|
||||||
send_photo("sad.png")
|
|
||||||
|
|
||||||
send_document("data/difference.html")
|
|
||||||
send_document("data/table.html")
|
|
||||||
|
|
||||||
return
|
|
||||||
logging.debug("same result. nothing to do")
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
verify_data()
|
|
||||||
logging.info("log in success")
|
|
||||||
|
|
||||||
while True:
|
|
||||||
run()
|
|
||||||
interval = randint(300, 500)
|
|
||||||
logging.debug(f"sleep: {interval}")
|
|
||||||
sleep(interval)
|
|
@ -1,5 +0,0 @@
|
|||||||
bs4
|
|
||||||
requests
|
|
||||||
lxml
|
|
||||||
playwright
|
|
||||||
python-dotenv
|
|
99
scaper.go
Normal file
99
scaper.go
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/go-rod/rod"
|
||||||
|
)
|
||||||
|
|
||||||
|
func scape(browser *rod.Browser, LOGIN, PASSWORD, ELJUR_URL string) []board_item {
|
||||||
|
response, err := http.Get(ELJUR_URL + "journal-board-action")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("Error while request:", err)
|
||||||
|
} else if response.StatusCode != 200 {
|
||||||
|
log.Fatalln("Eljur status:", response.Status)
|
||||||
|
} else {
|
||||||
|
content := get_content(browser, LOGIN, PASSWORD, ELJUR_URL)
|
||||||
|
log.Println("Content got")
|
||||||
|
return content
|
||||||
|
// Старый метод
|
||||||
|
//// Проверка на возможность среза
|
||||||
|
//if strings.Contains(content, `<span class="control-label lgray">`) {
|
||||||
|
// all_posts := content[strings.Index(content, `<h1 class="page-title">Объявления</h1>`):strings.Index(content, `<span class="control-label lgray">`)]
|
||||||
|
// // Почему-то в начале страницы около 108 открывающихся тегов <br>
|
||||||
|
// all_posts = strings.ReplaceAll(all_posts, `<br>`, ``)
|
||||||
|
// last_post := content[strings.Index(content, `<h1 class="page-title">Объявления</h1>`):strings.Index(content, `<div class="board-item__footer">`)]
|
||||||
|
//
|
||||||
|
// return all_posts, last_post
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
return []board_item{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func parse(page_HTML string) board_item {
|
||||||
|
// println(page_HTML) // тест
|
||||||
|
// Тут будет обрабатываться объявление
|
||||||
|
var page_item board_item
|
||||||
|
|
||||||
|
return page_item
|
||||||
|
}
|
||||||
|
|
||||||
|
// wait всегда ли работает?
|
||||||
|
func get_content(browser *rod.Browser, LOGIN, PASSWORD, ELJUR_URL string) []board_item {
|
||||||
|
t := 500 * time.Millisecond // максимальное время выполнения каждой функции chromium
|
||||||
|
item_table := []board_item{}
|
||||||
|
|
||||||
|
// Создание новой вкладки
|
||||||
|
page := browser.MustPage(ELJUR_URL + "journal-board-action")
|
||||||
|
page.WaitLoad()
|
||||||
|
time.Sleep(t)
|
||||||
|
log.Println(page.MustInfo().URL)
|
||||||
|
|
||||||
|
// Авторизация
|
||||||
|
if page.MustInfo().URL == ELJUR_URL+`authorize?return_uri=%2Fjournal-board-action` {
|
||||||
|
page.MustElementX("/html/body/div[1]/div/main/div/div/div/div/form/div[1]/div[1]/div/input").MustInput(LOGIN)
|
||||||
|
page.MustElementX("/html/body/div[1]/div/main/div/div/div/div/form/div[1]/div[2]/div/input").MustInput(PASSWORD)
|
||||||
|
page.MustElement("#loginviewport > div > div > form > div.ej-form__footer > button").MustClick()
|
||||||
|
|
||||||
|
// Загрузка сайта после входа
|
||||||
|
page.WaitLoad()
|
||||||
|
time.Sleep(t)
|
||||||
|
log.Println(page.MustInfo().URL)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Проверка входа
|
||||||
|
if page.MustInfo().URL == ELJUR_URL+`authorize?return_uri=%2Fjournal-board-action` {
|
||||||
|
log.Fatal("Wrong eljur credentials")
|
||||||
|
// os.Exit(127) -- вдруг wait неверный
|
||||||
|
return []board_item{}
|
||||||
|
} else if page.MustInfo().URL != ELJUR_URL+"journal-board-action" {
|
||||||
|
page.Navigate(ELJUR_URL + "journal-board-action")
|
||||||
|
page.WaitLoad()
|
||||||
|
time.Sleep(t)
|
||||||
|
log.Println(page.MustInfo().URL)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Сбор информации о объявлениях
|
||||||
|
item_number := 1
|
||||||
|
for {
|
||||||
|
item_selector, err := page.Timeout(t).Element(fmt.Sprintf("#board-items > div:nth-child(%d)", item_number))
|
||||||
|
if err != nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
item_table = append(item_table, parse(item_selector.MustHTML()))
|
||||||
|
// Точно плохая идея!
|
||||||
|
// item_selector.MustScreenshot(fmt.Sprintf("data/screenshot%d.png", item_number))
|
||||||
|
item_number++
|
||||||
|
}
|
||||||
|
|
||||||
|
println("Hmm")
|
||||||
|
// Старые методы
|
||||||
|
// content := page.MustHTML()
|
||||||
|
// page.MustElement("#board-items > div:nth-child(1)").MustScreenshot("data/last_post.png")
|
||||||
|
page.Close()
|
||||||
|
|
||||||
|
return item_table
|
||||||
|
}
|
70
scraper.py
70
scraper.py
@ -1,70 +0,0 @@
|
|||||||
from bs4 import BeautifulSoup
|
|
||||||
from playwright.sync_api import sync_playwright
|
|
||||||
from env_init import LOGIN, PASSWORD, DOMAIN
|
|
||||||
import logging
|
|
||||||
from playwright._impl import _api_types
|
|
||||||
from os import mkdir
|
|
||||||
|
|
||||||
|
|
||||||
# Use sync version of Playwright
|
|
||||||
p = sync_playwright().start()
|
|
||||||
# Launch the browser
|
|
||||||
browser = p.chromium.launch()
|
|
||||||
logging.debug("browser opened")
|
|
||||||
|
|
||||||
# Open a new browser page
|
|
||||||
page = browser.new_page()
|
|
||||||
|
|
||||||
|
|
||||||
def scrape():
|
|
||||||
global page
|
|
||||||
try:
|
|
||||||
# Open our test file in the opened page
|
|
||||||
page.goto(f"https://{DOMAIN}.eljur.ru/authorize?return_uri=%2Fjournal-board-action")
|
|
||||||
try:
|
|
||||||
# Log In
|
|
||||||
login_field = page.locator('[type="text"]')
|
|
||||||
password_field = page.locator('[type="password"]')
|
|
||||||
|
|
||||||
login_field.fill(value=LOGIN) # type: ignore
|
|
||||||
password_field.fill(value=PASSWORD) # type: ignore
|
|
||||||
|
|
||||||
submit_button = page.locator('[type="submit"]')
|
|
||||||
submit_button.click()
|
|
||||||
except Exception as error:
|
|
||||||
logging.debug(f"Error while request: {str(error)}")
|
|
||||||
page.goto(f"https://{DOMAIN}.eljur.ru/journal-board-action?user={LOGIN}&domain={DOMAIN}")
|
|
||||||
pass
|
|
||||||
|
|
||||||
page.wait_for_url(f"https://{DOMAIN}.eljur.ru/journal-board-action?user={LOGIN}&domain={DOMAIN}")
|
|
||||||
page.wait_for_load_state("domcontentloaded")
|
|
||||||
if page.url != f"https://{DOMAIN}.eljur.ru/journal-board-action?user={LOGIN}&domain={DOMAIN}" and page.url != f"https://{DOMAIN}.eljur.ru/journal-board-action":
|
|
||||||
page.goto(f"https://{DOMAIN}.eljur.ru/journal-board-action")
|
|
||||||
page.wait_for_load_state("domcontentloaded")
|
|
||||||
|
|
||||||
page_content = page.content()
|
|
||||||
|
|
||||||
new_content = page.locator('[class="board-item active"]').first
|
|
||||||
try:
|
|
||||||
new_content.screenshot(path = "data/screenshot.png")
|
|
||||||
except FileNotFoundError:
|
|
||||||
mkdir("data")
|
|
||||||
logging.info("can`t take screenshot")
|
|
||||||
logging.info("retry")
|
|
||||||
new_content.screenshot(path = "data/screenshot.png")
|
|
||||||
except:
|
|
||||||
logging.error("can`t take screenshot")
|
|
||||||
|
|
||||||
# Process extracted content with BeautifulSoup
|
|
||||||
soup = BeautifulSoup(page_content, features="lxml")
|
|
||||||
|
|
||||||
logging.debug("content extracted")
|
|
||||||
# return '\n'.join(el.strip() for el in str(soup.get_text).split('\n') if el.strip())
|
|
||||||
return str(soup.get_text)
|
|
||||||
|
|
||||||
except _api_types.TimeoutError:
|
|
||||||
logging.error("connection timed out")
|
|
||||||
return " "
|
|
||||||
except Exception as error:
|
|
||||||
logging.error(f"Error while request: {str(error)}")
|
|
||||||
return " "
|
|
204
worker.go
Normal file
204
worker.go
Normal file
@ -0,0 +1,204 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"log"
|
||||||
|
"mime/multipart"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
type board_item struct {
|
||||||
|
active bool
|
||||||
|
dates date_pair
|
||||||
|
title string
|
||||||
|
content string
|
||||||
|
attachments []outline
|
||||||
|
creator string
|
||||||
|
receivers string
|
||||||
|
edit_pattern []int
|
||||||
|
unique bool
|
||||||
|
}
|
||||||
|
|
||||||
|
type date_pair struct {
|
||||||
|
begin string
|
||||||
|
end string
|
||||||
|
}
|
||||||
|
|
||||||
|
type outline struct {
|
||||||
|
title string
|
||||||
|
link string
|
||||||
|
doctype string
|
||||||
|
}
|
||||||
|
|
||||||
|
func load_env_vars() (string, string, string, string, string) {
|
||||||
|
LOGIN := os.Getenv("ELJUR_LOGIN")
|
||||||
|
PASSWORD := os.Getenv("ELJUR_PASSWORD")
|
||||||
|
DOMAIN := os.Getenv("ELJUR_DOMAIN")
|
||||||
|
TG_TOKEN := os.Getenv("TG_TOKEN")
|
||||||
|
TG_ID := os.Getenv("TG_ID")
|
||||||
|
TG_API_URL := os.Getenv("TG_API_URL")
|
||||||
|
|
||||||
|
return LOGIN, PASSWORD, fmt.Sprintf("https://%s.eljur.ru/", DOMAIN), TG_ID, TG_API_URL + "bot" + TG_TOKEN + `/`
|
||||||
|
}
|
||||||
|
|
||||||
|
func update_file(val, path string) {
|
||||||
|
var file, err = os.OpenFile(path, os.O_RDWR, 0644)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("cant update ", path, " : ", err)
|
||||||
|
os.Exit(1)
|
||||||
|
} else {
|
||||||
|
file.Truncate(0)
|
||||||
|
file.Write([]byte(val))
|
||||||
|
file.Close()
|
||||||
|
log.Println(path, "updated")
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
func get_file(path string) string {
|
||||||
|
var val, err = os.ReadFile(path)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("cant get", path, ":", err)
|
||||||
|
return " "
|
||||||
|
} else {
|
||||||
|
log.Println("data/table.html got")
|
||||||
|
return string(val)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send photo & docs
|
||||||
|
|
||||||
|
func send_document(path, TELEGRAM_API_URL, TELEGRAM_CHAT_ID string) {
|
||||||
|
url := TELEGRAM_API_URL + "sendDocument"
|
||||||
|
|
||||||
|
var b bytes.Buffer
|
||||||
|
w := multipart.NewWriter(&b)
|
||||||
|
|
||||||
|
// Open the file
|
||||||
|
f, err := os.Open(path)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("cannot open file: %v", err)
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
// Add file as stream of bytes
|
||||||
|
fw, err := w.CreateFormFile("document", f.Name())
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("cannot create form file: %v", err)
|
||||||
|
}
|
||||||
|
_, err = io.Copy(fw, f)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("cannot write file to form file: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add other fields
|
||||||
|
err = w.WriteField("chat_id", TELEGRAM_CHAT_ID)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("cannot write chat_id to form: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close the writer
|
||||||
|
err = w.Close()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("cannot close writer: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a client
|
||||||
|
client := &http.Client{}
|
||||||
|
|
||||||
|
// Create a new request
|
||||||
|
req, err := http.NewRequest("POST", url, &b)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("cannot create request: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the content type, this is important
|
||||||
|
req.Header.Set("Content-Type", w.FormDataContentType())
|
||||||
|
|
||||||
|
// Submit the request
|
||||||
|
res, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("HTTP error occurred: %v", err)
|
||||||
|
}
|
||||||
|
defer res.Body.Close()
|
||||||
|
|
||||||
|
// Check the response
|
||||||
|
if res.StatusCode == http.StatusOK {
|
||||||
|
log.Println("photo sent")
|
||||||
|
} else {
|
||||||
|
body, err := io.ReadAll(res.Body)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("cannot read response body: %v", err)
|
||||||
|
}
|
||||||
|
log.Printf("can't send photo: %d - %s", res.StatusCode, string(body))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func send_photo(path, TELEGRAM_API_URL, TELEGRAM_CHAT_ID string) {
|
||||||
|
url := TELEGRAM_API_URL + "sendPhoto"
|
||||||
|
|
||||||
|
var b bytes.Buffer
|
||||||
|
w := multipart.NewWriter(&b)
|
||||||
|
|
||||||
|
// Open the file
|
||||||
|
f, err := os.Open(path)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("cannot open file: %v", err)
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
// Add file as stream of bytes
|
||||||
|
fw, err := w.CreateFormFile("photo", f.Name())
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("cannot create form file: %v", err)
|
||||||
|
}
|
||||||
|
_, err = io.Copy(fw, f)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("cannot write file to form file: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add other fields
|
||||||
|
err = w.WriteField("chat_id", TELEGRAM_CHAT_ID)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("cannot write chat_id to form: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close the writer
|
||||||
|
err = w.Close()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("cannot close writer: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a client
|
||||||
|
client := &http.Client{}
|
||||||
|
|
||||||
|
// Create a new request
|
||||||
|
req, err := http.NewRequest("POST", url, &b)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("cannot create request: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the content type, this is important
|
||||||
|
req.Header.Set("Content-Type", w.FormDataContentType())
|
||||||
|
|
||||||
|
// Submit the request
|
||||||
|
res, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("HTTP error occurred: %v", err)
|
||||||
|
}
|
||||||
|
defer res.Body.Close()
|
||||||
|
|
||||||
|
// Check the response
|
||||||
|
if res.StatusCode == http.StatusOK {
|
||||||
|
log.Println("photo sent")
|
||||||
|
} else {
|
||||||
|
body, err := io.ReadAll(res.Body)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("cannot read response body: %v", err)
|
||||||
|
}
|
||||||
|
log.Printf("can't send photo: %d - %s", res.StatusCode, string(body))
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user