Skip to content

Commit 45879f4

Browse files
Merge 9d8ff54 into e39c92e
2 parents e39c92e + 9d8ff54 commit 45879f4

15 files changed

+74
-362
lines changed

.dockerignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ README.md
1717
LICENSE
1818

1919
# Configuration
20-
requirements.txt
2120
changelog.json
2221
settings.toml
2322
*.db

.github/workflows/publish.yaml

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,9 @@ jobs:
5454
See changes: https://github.com/${{ github.repository }}/commit/${{ github.sha }}
5555
5656
build:
57-
name: Build packages
58-
runs-on: ${{ matrix.os }}
57+
name: Build docker image
58+
runs-on: ubuntu-latest
5959
needs: prepare
60-
strategy:
61-
matrix:
62-
include:
63-
- os: ubuntu-latest
64-
SERVICENAME: news_db
65-
CONTAINERFILE: Containerfile-db
66-
- os: ubuntu-latest
67-
SERVICENAME: truth_seeker
68-
CONTAINERFILE: Containerfile-ts
69-
- os: ubuntu-latest
70-
SERVICENAME: datapath
71-
CONTAINERFILE: Containerfile-dp
7260

7361
steps:
7462

@@ -87,8 +75,8 @@ jobs:
8775
with:
8876
context: .
8977
push: true
90-
file: ${{ matrix.CONTAINERFILE }}
91-
tags: h0d0user/${{ matrix.SERVICENAME }}:${{ needs.prepare.outputs.get_current_tag }}
78+
file: Containerfile
79+
tags: h0d0user/datapath:${{ needs.prepare.outputs.get_current_tag }}
9280

9381
- name: Notify if failure
9482
if: ${{ failure() }}
@@ -126,8 +114,6 @@ jobs:
126114
127115
Branch: ${{ github.ref }}
128116
129-
<b>Pushed image:</b> <code>docker pull h0d0user/news_db:${{ needs.prepare.outputs.get_current_tag }}</code>,
130-
<code>docker pull h0d0user/truth_seeker:${{ needs.prepare.outputs.get_current_tag }}</code>,
131-
<code>docker pull h0d0user/datapath:${{ needs.prepare.outputs.get_current_tag }}</code>
117+
<b>Pushed image:</b> <code>docker pull h0d0user/datapath:${{ needs.prepare.outputs.get_current_tag }}</code>
132118
133119
See changes: https://github.com/${{ github.repository }}/commit/${{ github.sha }}

.github/workflows/release.yaml

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,7 @@ jobs:
9999
build:
100100
name: Build packages
101101
needs: [ prepare, release ]
102-
runs-on: ${{ matrix.os }}
103-
strategy:
104-
matrix:
105-
include:
106-
- os: ubuntu-latest
107-
SERVICENAME: news_db
108-
CONTAINERFILE: Containerfile-db
109-
- os: ubuntu-latest
110-
SERVICENAME: truth_seeker
111-
CONTAINERFILE: Containerfile-ts
112-
- os: ubuntu-latest
113-
SERVICENAME: datapath
114-
CONTAINERFILE: Containerfile-dp
102+
runs-on: ubuntu-latest
115103

116104
steps:
117105

@@ -130,8 +118,8 @@ jobs:
130118
with:
131119
context: .
132120
push: true
133-
file: ${{ matrix.CONTAINERFILE }}
134-
tags: h0d0user/${{ matrix.SERVICENAME }}:latest
121+
file: Containerfile
122+
tags: h0d0user/datapath:latest
135123

136124
- name: Notify if failure
137125
if: ${{ failure() }}
@@ -169,9 +157,7 @@ jobs:
169157
170158
Branch: ${{ github.ref }}
171159
172-
<b>Pushed image:</b> <code>docker pull h0d0user/news_db:latest</code>,
173-
<code>docker pull h0d0user/truth_seeker:latest</code>,
174-
<code>docker pull h0d0user/datapath:latest</code>
160+
<b>Pushed image:</b> <code>docker pull h0d0user/datapath:latest</code>
175161
See changes: https://github.com/${{ github.repository }}/commit/${{ github.sha }}
176162
177163
<b>Release URL:</b> https://github.com/${{ github.repository }}/releases/tag/${{ needs.prepare.outputs.get_current_tag }}

Containerfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# FROM python:3.9-alpine as builder
2+
FROM h0d0user/emperor_pandas:latest as builder
3+
4+
WORKDIR /opt/
5+
6+
COPY ["datapath.py", "/opt/"]
7+
COPY ["dynaconfig.py", "/opt/"]
8+
9+
COPY requirements.txt requirements.txt
10+
11+
RUN pip3 install -U pip
12+
RUN pip3 install --no-cache-dir -r requirements.txt
13+
RUN apt update -y && \
14+
apt install curl jq -y
15+
16+
FROM builder
17+
18+
CMD ["python3.9", "datapath.py"]

Containerfile-db

Lines changed: 0 additions & 13 deletions
This file was deleted.

Containerfile-dp

Lines changed: 0 additions & 13 deletions
This file was deleted.

Containerfile-ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

datapath.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import requests
66

77
import dynaconfig
8-
import news_db
98

109
# Time range for sending messages loaded from settings.toml
1110
TIME_TO_SEND_START = dynaconfig.settings["TIMINIGS"]["TIME_TO_SEND_START"]
@@ -28,6 +27,17 @@
2827
API_URL = f"https://api.telegram.org/bot{API_TOKEN}/sendMessage"
2928
CHAT_ID = dynaconfig.settings["TELEGRAM"]["CHAT_ID"]
3029

30+
NEWS_DB_API_URL = dynaconfig.settings["DB"]["DB_API_URL"]
31+
32+
33+
def check_api_available() -> bool:
34+
try:
35+
logging.info(f"Try to connect to API, URL: {NEWS_DB_API_URL}/healthcheck")
36+
time.sleep(1)
37+
return requests.get(f"{NEWS_DB_API_URL}/healthcheck").ok
38+
except (ConnectionError, ConnectionRefusedError) as con_err:
39+
logging.error(con_err)
40+
3141

3242
def send_news_to_telegram(message):
3343
"""
@@ -40,15 +50,15 @@ def send_news_to_telegram(message):
4050
API_URL,
4151
json={
4252
"chat_id": CHAT_ID,
43-
"text": f"Author: {message[0]}\n"
53+
"text": f"Author: {message['author']}\n"
4454
f"\n"
45-
f"Title: {message[1]}\n"
55+
f"Title: {message['title']}\n"
4656
f"\n"
47-
f"{message[2]}\n"
57+
f"{message['description']}\n"
4858
f"\n"
49-
f"URL: {message[3]}\n"
59+
f"URL: {message['url']}\n"
5060
f"\n"
51-
f"Date published: {message[4]}\n",
61+
f"Date published: {message['pub_date']}\n",
5262
},
5363
)
5464
if response.status_code == 200:
@@ -64,14 +74,13 @@ def send_news_to_telegram(message):
6474

6575

6676
if __name__ == "__main__":
67-
db_connection = news_db.create_connection(news_db.DB_FILE)
6877
while True:
69-
if db_connection:
78+
if check_api_available():
7079
time.sleep(1)
7180
current_time = datetime.now().strftime("%H:%M")
7281
if TIME_TO_SEND_START < current_time < TIME_TO_SEND_END:
7382
logging.info("Time to send news has come !")
74-
data_from_db = news_db.send_all_news(db_connection)
83+
data_from_db = requests.get(NEWS_DB_API_URL).json()
7584
if len(data_from_db) == 0:
7685
logging.warning("Database is empty !")
7786
else:
@@ -83,4 +92,4 @@ def send_news_to_telegram(message):
8392
else:
8493
logging.info("Still waiting to send.")
8594
else:
86-
logging.error("Connection to db is not exist !")
95+
logging.error("API is not available !")

docker-compose.yaml

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,46 @@
11
version: '3'
22

33
services:
4-
news_db:
5-
container_name: news_db
6-
image: h0d0user/news_db:latest
4+
attainments_sanctuary:
5+
container_name: attainments_sanctuary
6+
image: h0d0user/attainments_sanctuary:latest
77
pull_policy: always
88
restart: always
9-
network_mode: host
10-
volumes:
11-
- "shared-volume:/mnt/"
12-
- "./settings.toml:/opt/settings.toml"
9+
networks:
10+
- etl
11+
ports:
12+
- "8888:8888"
13+
# healthcheck:
14+
# test: "curl http://attainments_sanctuary:8888/healthcheck | jq -r '.healthcheck'"
15+
# interval: 5s
16+
# timeout: 5s
17+
# retries: 20
18+
# start_period: 5s
1319

14-
truth_seeker:
15-
container_name: truth_seeker
16-
image: h0d0user/truth_seeker:latest
20+
epistolary:
21+
container_name: epistolary
22+
image: h0d0user/epistolary:latest
1723
pull_policy: always
1824
restart: always
19-
network_mode: host
25+
networks:
26+
- etl
27+
hostname: epistolary
2028
depends_on:
21-
- "news_db"
29+
- "attainments_sanctuary"
2230
volumes:
23-
- "shared-volume:/mnt/"
2431
- "./settings.toml:/opt/settings.toml"
2532

2633
datapath:
2734
container_name: datapath
2835
image: h0d0user/datapath:latest
2936
pull_policy: always
3037
restart: always
31-
network_mode: host
38+
networks:
39+
- etl
3240
depends_on:
33-
- "news_db"
41+
- "attainments_sanctuary"
3442
volumes:
35-
- "shared-volume:/mnt/"
3643
- "./settings.toml:/opt/settings.toml"
3744

38-
volumes:
39-
shared-volume:
45+
networks:
46+
etl:

0 commit comments

Comments
 (0)