Skip to content

Commit 775b9f2

Browse files
Merge pull request #4 from CoolCoderCarl/develop
Develop
2 parents f441d4e + f6817aa commit 775b9f2

9 files changed

Lines changed: 119 additions & 4 deletions

File tree

.github/workflows/build.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ jobs:
6262
include:
6363
- os: windows-latest
6464
TARGET: windows
65-
CMD_BUILD: python -m PyInstaller --clean --workpath /tmp/build --specpath /tmp -F truth_seeker.py
65+
CMD_BUILD: python -m PyInstaller --clean --workpath /tmp/build --specpath /tmp -F ./app/truth_seeker.py
6666
OUT_FILE_NAME: truth_seeker.exe
6767
ASSET_MIME: application/vnd.microsoft.portable-executable
6868
- os: ubuntu-latest
6969
TARGET: ubuntu
70-
CMD_BUILD: python -m PyInstaller --clean --workpath /tmp/build --specpath /tmp -F truth_seeker.py
70+
CMD_BUILD: python -m PyInstaller --clean --workpath /tmp/build --specpath /tmp -F ./app/truth_seeker.py
7171
OUT_FILE_NAME: truth_seeker
7272
ASSET_MIME: application/x-binary
7373

.github/workflows/code_quality.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,32 @@ jobs:
3535
<b>!!! FAILED !!!</b>
3636
<b>Failed job:</b> https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
3737
See changes: https://github.com/${{ github.repository }}/commit/${{ github.sha }}
38+
39+
pytesting:
40+
runs-on: ubuntu-latest
41+
name: Testing with pytest
42+
container: python:3.9
43+
needs: [ code_quality ]
44+
45+
steps:
46+
47+
- name: Checkout code
48+
uses: actions/checkout@v2
49+
50+
- name: Run script
51+
run: pip install -r requirements.txt
52+
53+
- name: Testing
54+
run: pytest -v ./tests/
55+
56+
- name: Notify if failure
57+
if: ${{ failure() }}
58+
uses: appleboy/telegram-action@master
59+
with:
60+
to: ${{ secrets.TELEGRAM_CHAT }}
61+
token: ${{ secrets.TELEGRAM_TOKEN }}
62+
format: html
63+
message: |
64+
<b>!!! FAILED !!!</b>
65+
<b>Failed job:</b> https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
66+
See changes: https://github.com/${{ github.repository }}/commit/${{ github.sha }}

.github/workflows/release.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,12 @@ jobs:
105105
include:
106106
- os: windows-latest
107107
TARGET: windows
108-
CMD_BUILD: python -m PyInstaller --clean --workpath /tmp/build --specpath /tmp -F truth_seeker.py
108+
CMD_BUILD: python -m PyInstaller --clean --workpath /tmp/build --specpath /tmp -F ./app/truth_seeker.py
109109
OUT_FILE_NAME: truth_seeker.exe
110110
ASSET_MIME: application/vnd.microsoft.portable-executable
111111
- os: ubuntu-latest
112112
TARGET: ubuntu
113-
CMD_BUILD: python -m PyInstaller --clean --workpath /tmp/build --specpath /tmp -F truth_seeker.py
113+
CMD_BUILD: python -m PyInstaller --clean --workpath /tmp/build --specpath /tmp -F ./app/truth_seeker.py
114114
OUT_FILE_NAME: truth_seeker
115115
ASSET_MIME: application/x-binary
116116

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,6 @@ dmypy.json
127127

128128
# Pyre type checker
129129
.pyre/
130+
131+
# Secret file
132+
.secrets.toml

app/truth_seeker.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import logging
2+
3+
from newsapi import NewsApiClient
4+
5+
import dynaconfig
6+
7+
# https://newsapi.org/
8+
9+
API_KEY = dynaconfig.config["API_KEY"]
10+
11+
newsapi = NewsApiClient(api_key=API_KEY)
12+
13+
# Logging
14+
logging.basicConfig(
15+
format="%(asctime)s - %(levelname)s - %(message)s", level=logging.INFO
16+
)
17+
logging.basicConfig(
18+
format="%(asctime)s - %(levelname)s - %(message)s", level=logging.WARNING
19+
)
20+
logging.basicConfig(
21+
format="%(asctime)s - %(levelname)s - %(message)s", level=logging.ERROR
22+
)
23+
24+
25+
def fetch_info(query: str) -> dict:
26+
try:
27+
result = newsapi.get_everything(q=query, sort_by="popularity")
28+
logging.info(f"Searching for {query}")
29+
return result
30+
except ConnectionError as con_err:
31+
logging.error(con_err)
32+
return {}
33+
except BaseException as base_err:
34+
logging.error(base_err)
35+
return {}
36+
37+
38+
def list_info(fetch_info: dict):
39+
if fetch_info:
40+
for article in fetch_info.get("articles"):
41+
for article_point, article_data in article.items():
42+
if article_point == "urlToImage":
43+
continue
44+
elif article_point == "source":
45+
print(article_point.capitalize(), article_data.get("name"))
46+
else:
47+
print(article_point.capitalize(), article_data)
48+
else:
49+
logging.warning("Empty response from API")
50+
raise IndexError
51+
52+
53+
if __name__ == "__main__":
54+
list_info(fetch_info("test"))

dynaconfig.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from dynaconf import Dynaconf
2+
3+
config = Dynaconf(
4+
settings_files=[".secrets.toml"],
5+
)

requirements.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
black
2+
isort
3+
pyinstaller
4+
pytest~=7.1.3
5+
dynaconfig~=0.4
6+
dynaconf~=3.1.11
7+
newsapi-python~=0.2.6

tests/__init__.py

Whitespace-only changes.

tests/test_truth_seeker.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from app import truth_seeker
2+
3+
4+
def test_fetch_info():
5+
"""
6+
Simple test for fetching func
7+
:return:
8+
"""
9+
return isinstance(truth_seeker.fetch_info("test"), dict)
10+
11+
12+
def test_fetch_info_empty():
13+
"""
14+
Empty query
15+
:return:
16+
"""
17+
return isinstance(truth_seeker.fetch_info(""), dict)

0 commit comments

Comments
 (0)