mirror of
https://github.com/serega404/VodokanalBot.git
synced 2025-07-04 06:03:36 +03:00
Compare commits
6 Commits
2a968f3528
...
main
Author | SHA1 | Date | |
---|---|---|---|
edb51bb696
|
|||
758c090824
|
|||
132a9d81ee
|
|||
80af7ec775
|
|||
6d65395b89
|
|||
5388901294
|
41
.github/workflows/github-push-docker.yml
vendored
Normal file
41
.github/workflows/github-push-docker.yml
vendored
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
name: Create and publish a Docker image
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: ['main']
|
||||||
|
|
||||||
|
env:
|
||||||
|
REGISTRY: ghcr.io
|
||||||
|
IMAGE_NAME: ${{ github.repository }}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-and-push-image:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
packages: write
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Log in to the Container registry
|
||||||
|
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
|
||||||
|
with:
|
||||||
|
registry: ${{ env.REGISTRY }}
|
||||||
|
username: ${{ github.actor }}
|
||||||
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Extract metadata (tags, labels) for Docker
|
||||||
|
id: meta
|
||||||
|
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
|
||||||
|
with:
|
||||||
|
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
||||||
|
|
||||||
|
- name: Build and push Docker image
|
||||||
|
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
push: true
|
||||||
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
|
labels: ${{ steps.meta.outputs.labels }}
|
17
Dockerfile
Normal file
17
Dockerfile
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
FROM python:3.11.2-alpine3.17
|
||||||
|
|
||||||
|
LABEL Maintainer="serega404"
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY requirements.txt requirements.txt
|
||||||
|
RUN pip3 install -r requirements.txt
|
||||||
|
|
||||||
|
# Setting up crontab
|
||||||
|
COPY crontab /tmp/crontab
|
||||||
|
RUN cat /tmp/crontab > /etc/crontabs/root
|
||||||
|
|
||||||
|
COPY main.py main.py
|
||||||
|
|
||||||
|
# run crond as main process of container
|
||||||
|
CMD ["crond", "-f", "-l", "2"]
|
24
README.md
24
README.md
@ -1 +1,25 @@
|
|||||||
# VodokanalParser
|
# VodokanalParser
|
||||||
|
|
||||||
|
[](https://github.com/serega404/VodokanalBot)
|
||||||
|
|
||||||
|
### Запуск в Docker
|
||||||
|
|
||||||
|
``` Docker
|
||||||
|
docker volume create vodokanal_bot_data
|
||||||
|
docker run -d --name VodokanalBot \
|
||||||
|
--restart=always \
|
||||||
|
-v vodokanal_bot_data:/app/data \
|
||||||
|
-e TZ='Europe/Moscow' \
|
||||||
|
-e TELEGRAM_TOKEN='TOKEN' \
|
||||||
|
-e TELEGRAM_CHANNEL='CHAT_ID' \
|
||||||
|
ghcr.io/serega404/vodokanalbot:main
|
||||||
|
```
|
||||||
|
|
||||||
|
### Библиотеки
|
||||||
|
|
||||||
|
* [Requests](https://requests.readthedocs.io/en/latest/)
|
||||||
|
* [BeautifulSoup](https://www.crummy.com/software/BeautifulSoup/)
|
||||||
|
|
||||||
|
### Лицензия
|
||||||
|
|
||||||
|
Распространяется под MIT License. Смотри файл [`LICENSE`](./LICENSE) для того что бы узнать подробности.
|
||||||
|
2
crontab
Normal file
2
crontab
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
@reboot cd /app && python3 /app/main.py
|
||||||
|
*/10 * * * * cd /app && python3 /app/main.py
|
21
main.py
21
main.py
@ -20,8 +20,8 @@ if TELEGRAM_CHANNEL == '':
|
|||||||
# Load database
|
# Load database
|
||||||
|
|
||||||
db = None
|
db = None
|
||||||
if (os.path.isfile('db.json')):
|
if (os.path.isfile('data/db.json')):
|
||||||
with open('db.json', 'r', encoding='utf-8') as f:
|
with open('data/db.json', 'r', encoding='utf-8') as f:
|
||||||
db = json.load(f)
|
db = json.load(f)
|
||||||
else:
|
else:
|
||||||
print("Database not loaded")
|
print("Database not loaded")
|
||||||
@ -41,7 +41,7 @@ for tag in soup.find_all('font', size='2', face='VERDANA'):
|
|||||||
date = tag.select_one('font:nth-of-type(1)').b.text
|
date = tag.select_one('font:nth-of-type(1)').b.text
|
||||||
if not(date.split('.')[0] == str(datetime.today().day).zfill(2) and date.split('.')[1] == str(datetime.today().month).zfill(2)):
|
if not(date.split('.')[0] == str(datetime.today().day).zfill(2) and date.split('.')[1] == str(datetime.today().month).zfill(2)):
|
||||||
continue
|
continue
|
||||||
elements.append(tag.select_one('font:nth-of-type(2)').text.replace('\n', ''))
|
elements.append(date + "$" + tag.select_one('font:nth-of-type(2)').text.replace('\n', ''))
|
||||||
|
|
||||||
if elements == []:
|
if elements == []:
|
||||||
print("No posts")
|
print("No posts")
|
||||||
@ -62,15 +62,22 @@ def send_message(message):
|
|||||||
# Compare db and elements
|
# Compare db and elements
|
||||||
|
|
||||||
if db is not None:
|
if db is not None:
|
||||||
diff = list(set(elements).symmetric_difference(set(db)))
|
diff = set(elements) - set(db)
|
||||||
|
if diff == []:
|
||||||
|
print("No new posts")
|
||||||
|
exit()
|
||||||
|
|
||||||
for i in diff:
|
for i in diff:
|
||||||
send_message(i)
|
send_message(i.split("$",1)[1])
|
||||||
else:
|
else:
|
||||||
for element in elements:
|
for element in elements:
|
||||||
send_message(element)
|
send_message(element.split("$",1)[1])
|
||||||
|
|
||||||
# Save database
|
# Save database
|
||||||
|
|
||||||
with open('db.json', 'w', encoding='utf-8') as f:
|
if not os.path.exists("data"):
|
||||||
|
os.makedirs("data")
|
||||||
|
|
||||||
|
with open('data/db.json', 'w', encoding='utf-8') as f:
|
||||||
json.dump(elements, f, ensure_ascii=False)
|
json.dump(elements, f, ensure_ascii=False)
|
||||||
print("Database updated")
|
print("Database updated")
|
||||||
|
2
requirements.txt
Normal file
2
requirements.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
requests
|
||||||
|
beautifulsoup4
|
Reference in New Issue
Block a user