Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
2d1b50a
Add easy func for searching info via API
CoolCoderCarl Oct 17, 2022
1629a6e
Add security & requirements.txt; update .gitignore & truth_seeker.py
CoolCoderCarl Oct 17, 2022
f2222d9
Blacked & isorted
CoolCoderCarl Oct 17, 2022
ee34c23
Update requirements.txt
CoolCoderCarl Oct 17, 2022
82ff37c
Update requirements.txt & truth_seeker.py
CoolCoderCarl Oct 17, 2022
692866c
Update requirements.txt & truth_seeker.py
CoolCoderCarl Oct 17, 2022
f829484
Merge pull request #1 from CoolCoderCarl/feature/FUNC_1
CoolCoderCarl Oct 17, 2022
80b7302
Change output method in build.yaml
CoolCoderCarl Oct 17, 2022
fb6b0a5
Change output method in build.yaml & release.yaml
CoolCoderCarl Oct 17, 2022
bd874ec
Merge pull request #2 from CoolCoderCarl/feature/CI_1
CoolCoderCarl Oct 17, 2022
62dfc55
Add funcs & logging
CoolCoderCarl Oct 17, 2022
5e4b803
Update truth_seeker.py
CoolCoderCarl Oct 18, 2022
838e7bc
Merge pull request #3 from CoolCoderCarl/feature/FUNC_2
CoolCoderCarl Oct 18, 2022
3133b1f
Add testing with pytest
CoolCoderCarl Oct 18, 2022
8cafa81
Blacked & isorted
CoolCoderCarl Oct 18, 2022
347fdf5
Update code_quality.yaml
CoolCoderCarl Oct 18, 2022
52e83b3
Renamed to test_truth_seeker.py
CoolCoderCarl Oct 18, 2022
c9f4f6a
Update project structure
CoolCoderCarl Oct 18, 2022
a74a175
Update code_quality.yaml
CoolCoderCarl Oct 18, 2022
06e883d
Update CI; package tests
CoolCoderCarl Oct 18, 2022
950d408
Update requirements.txt
CoolCoderCarl Oct 18, 2022
7e6e919
Merge pull request #5 from CoolCoderCarl/feature/TEST_1
CoolCoderCarl Oct 18, 2022
3301639
Update CI
CoolCoderCarl Oct 18, 2022
38cca8d
Merge pull request #6 from CoolCoderCarl/feature/TEST_1
CoolCoderCarl Oct 18, 2022
a9d7ab0
Update CI
CoolCoderCarl Oct 18, 2022
51e680a
Update CI
CoolCoderCarl Oct 18, 2022
184bd9e
Update CI
CoolCoderCarl Oct 18, 2022
6a5809f
Update CI
CoolCoderCarl Oct 18, 2022
886956f
Update CI
CoolCoderCarl Oct 18, 2022
c0f095e
Update CI
CoolCoderCarl Oct 18, 2022
49fd1f6
Update CI
CoolCoderCarl Oct 18, 2022
b2c0fa9
Update CI
CoolCoderCarl Oct 18, 2022
0a1cf75
Update CI
CoolCoderCarl Oct 18, 2022
f6817aa
Merge pull request #7 from CoolCoderCarl/feature/CI_2
CoolCoderCarl Oct 18, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ jobs:
include:
- os: windows-latest
TARGET: windows
CMD_BUILD: python -m PyInstaller --clean --workpath /tmp/build --specpath /tmp -F truth_seeker.py
CMD_BUILD: python -m PyInstaller --clean --workpath /tmp/build --specpath /tmp -F ./app/truth_seeker.py
OUT_FILE_NAME: truth_seeker.exe
ASSET_MIME: application/vnd.microsoft.portable-executable
- os: ubuntu-latest
TARGET: ubuntu
CMD_BUILD: python -m PyInstaller --clean --workpath /tmp/build --specpath /tmp -F truth_seeker.py
CMD_BUILD: python -m PyInstaller --clean --workpath /tmp/build --specpath /tmp -F ./app/truth_seeker.py
OUT_FILE_NAME: truth_seeker
ASSET_MIME: application/x-binary

Expand Down
29 changes: 29 additions & 0 deletions .github/workflows/code_quality.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,32 @@ jobs:
<b>!!! FAILED !!!</b>
<b>Failed job:</b> https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
See changes: https://github.com/${{ github.repository }}/commit/${{ github.sha }}

pytesting:
runs-on: ubuntu-latest
name: Testing with pytest
container: python:3.9
needs: [ code_quality ]

steps:

- name: Checkout code
uses: actions/checkout@v2

- name: Run script
run: pip install -r requirements.txt

- name: Testing
run: pytest -v ./tests/

- name: Notify if failure
if: ${{ failure() }}
uses: appleboy/telegram-action@master
with:
to: ${{ secrets.TELEGRAM_CHAT }}
token: ${{ secrets.TELEGRAM_TOKEN }}
format: html
message: |
<b>!!! FAILED !!!</b>
<b>Failed job:</b> https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
See changes: https://github.com/${{ github.repository }}/commit/${{ github.sha }}
4 changes: 2 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ jobs:
include:
- os: windows-latest
TARGET: windows
CMD_BUILD: python -m PyInstaller --clean --workpath /tmp/build --specpath /tmp -F truth_seeker.py
CMD_BUILD: python -m PyInstaller --clean --workpath /tmp/build --specpath /tmp -F ./app/truth_seeker.py
OUT_FILE_NAME: truth_seeker.exe
ASSET_MIME: application/vnd.microsoft.portable-executable
- os: ubuntu-latest
TARGET: ubuntu
CMD_BUILD: python -m PyInstaller --clean --workpath /tmp/build --specpath /tmp -F truth_seeker.py
CMD_BUILD: python -m PyInstaller --clean --workpath /tmp/build --specpath /tmp -F ./app/truth_seeker.py
OUT_FILE_NAME: truth_seeker
ASSET_MIME: application/x-binary

Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,6 @@ dmypy.json

# Pyre type checker
.pyre/

# Secret file
.secrets.toml
54 changes: 54 additions & 0 deletions app/truth_seeker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import logging

from newsapi import NewsApiClient

import dynaconfig

# https://newsapi.org/

API_KEY = dynaconfig.config["API_KEY"]

newsapi = NewsApiClient(api_key=API_KEY)

# Logging
logging.basicConfig(
format="%(asctime)s - %(levelname)s - %(message)s", level=logging.INFO
)
logging.basicConfig(
format="%(asctime)s - %(levelname)s - %(message)s", level=logging.WARNING
)
logging.basicConfig(
format="%(asctime)s - %(levelname)s - %(message)s", level=logging.ERROR
)


def fetch_info(query: str) -> dict:
try:
result = newsapi.get_everything(q=query, sort_by="popularity")
logging.info(f"Searching for {query}")
return result
except ConnectionError as con_err:
logging.error(con_err)
return {}
except BaseException as base_err:
logging.error(base_err)
return {}


def list_info(fetch_info: dict):
if fetch_info:
for article in fetch_info.get("articles"):
for article_point, article_data in article.items():
if article_point == "urlToImage":
continue
elif article_point == "source":
print(article_point.capitalize(), article_data.get("name"))
else:
print(article_point.capitalize(), article_data)
else:
logging.warning("Empty response from API")
raise IndexError


if __name__ == "__main__":
list_info(fetch_info("test"))
5 changes: 5 additions & 0 deletions dynaconfig.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from dynaconf import Dynaconf

config = Dynaconf(
settings_files=[".secrets.toml"],
)
7 changes: 7 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
black
isort
pyinstaller
pytest~=7.1.3
dynaconfig~=0.4
dynaconf~=3.1.11
newsapi-python~=0.2.6
Empty file added tests/__init__.py
Empty file.
17 changes: 17 additions & 0 deletions tests/test_truth_seeker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from app import truth_seeker


def test_fetch_info():
"""
Simple test for fetching func
:return:
"""
return isinstance(truth_seeker.fetch_info("test"), dict)


def test_fetch_info_empty():
"""
Empty query
:return:
"""
return isinstance(truth_seeker.fetch_info(""), dict)