File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 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 }}
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change @@ -127,3 +127,6 @@ dmypy.json
127127
128128# Pyre type checker
129129.pyre /
130+
131+ # Secret file
132+ .secrets.toml
Original file line number Diff line number Diff line change 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" ))
Original file line number Diff line number Diff line change 1+ from dynaconf import Dynaconf
2+
3+ config = Dynaconf (
4+ settings_files = [".secrets.toml" ],
5+ )
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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 )
You can’t perform that action at this time.
0 commit comments