Skip to content

Commit

Permalink
Camply: CodeQuality (#49)
Browse files Browse the repository at this point in the history
* chore/linting_compliance

* chore/linting_compliance

* Linting

* Selective Tests

* lint
  • Loading branch information
juftin authored Jan 19, 2022
1 parent 7334561 commit 3542344
Show file tree
Hide file tree
Showing 33 changed files with 272 additions and 137 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ blank_issues_enabled: false
contact_links:
- name: Have a question about how to use camply?
url: https://github.com/juftin/camply/discussions
about: Check out camply discussions. There's lots of useful stuff there.
about: Check out camply discussions. There's lots of useful stuff there.
2 changes: 0 additions & 2 deletions .github/config/yamllint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,3 @@ rules:
max: 120
truthy:
check-keys: false
ignore: |
tests/models/cassettes/
62 changes: 31 additions & 31 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,27 @@ jobs:
- name: Setup Node Dependency
uses: actions/setup-node@v2
- name: Install Python Dependencies
run: |
python -m pip install --upgrade pip wheel
python -m pip install tox
run: |
python -m pip install --upgrade pip wheel
python -m pip install tox
- name: Install Node Dependencies
run: |
npm i -g eslint eslint-plugin-markdown
npm install eslint-plugin-markdown@latest --save-dev
- name: Lint with Flake8
id: flake8
run: |
npm i -g eslint eslint-plugin-markdown
npm install eslint-plugin-markdown@latest --save-dev
- name: Lint with ESLint
id: eslint
continue-on-error: true
run: |
echo "::add-matcher::.github/matchers/flake8.json"
tox -e flake8
echo "::remove-matcher owner=flake8::"
run: |
echo "::add-matcher::.github/matchers/eslint.json"
eslint . --config "${{ github.workspace }}/.github/config/.eslintrc.js"
echo "::remove-matcher owner=eslint::"
- name: Lint with Flake8
id: flake8
continue-on-error: true
run: |
echo "::add-matcher::.github/matchers/flake8.json"
tox -e flake8
echo "::remove-matcher owner=flake8::"
- name: Lint with YAML-Lint
id: yamllint
continue-on-error: true
Expand All @@ -47,22 +54,15 @@ jobs:
echo "::add-matcher::.github/matchers/mypy.json"
tox -e mypy
echo "::remove-matcher owner=mypy::"
- name: Lint with ESLint
id: eslint
continue-on-error: true
run: |
echo "::add-matcher::.github/matchers/eslint.json"
eslint . --config "${{ github.workspace }}/.github/config/.eslintrc.js"
echo "::remove-matcher owner=eslint::"
- name: (Don't actualy) Raise Errors For Linting Failures
if: |
steps.flake8.outcome != 'success' ||
steps.yamllint.outcome != 'success' ||
steps.mypy.outcome != 'success' ||
steps.eslint.outcome != 'success'
run: |
echo "Flake8: ${{ steps.flake8.outcome }}"
echo "YAML-Lint: ${{ steps.yamllint.outcome }}"
echo "MyPy: ${{ steps.mypy.outcome }}"
echo "ESLint: ${{ steps.eslint.outcome }}"
echo "I Should be Raising an Error"
- name: Raise Errors For Linting Failures
if: |
steps.flake8.outcome != 'success' ||
steps.yamllint.outcome != 'success' ||
steps.eslint.outcome != 'success'
run: |
echo "Flake8: ${{ steps.flake8.outcome }}"
echo "MyPy: ${{ steps.mypy.outcome }}"
echo "YamlLint: ${{ steps.yamllint.outcome }}"
echo "EsLint: ${{ steps.eslint.outcome }}"
echo "I Should Really Be Enforcing MyPy Errors
exit 1
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,5 @@ jobs:
id: docker_build
uses: docker/build-push-action@v2
with:
push: True
push: true
tags: juftin/camply:latest,juftin/camply:${{ env.CAMPLY_VERSION }}
3 changes: 3 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
- main
pull_request:
branches: [ "**" ]
paths:
- "camply/**"
- "!camply/README.md"
schedule:
- cron: "0 12 1 * *"
jobs:
Expand Down
2 changes: 1 addition & 1 deletion camply/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
camply __version__ file
"""

__version__ = "0.1.14"
__version__ = "0.1.15"
16 changes: 16 additions & 0 deletions camply/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,19 @@
from .notification_config import EmailConfig, PushbulletConfig, PushoverConfig
from .search_config import SearchConfig
from .yellowstone_config import YellowstoneConfig

__all__ = [
"RecreationBookingConfig",
"RIDBConfig",
"STANDARD_HEADERS",
"USER_AGENTS",
"CommandLineConfig",
"CampsiteContainerFields",
"DataColumns",
"FileConfig",
"EmailConfig",
"PushbulletConfig",
"PushoverConfig",
"SearchConfig",
"YellowstoneConfig",
]
6 changes: 4 additions & 2 deletions camply/config/api_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"""

from os import getenv
from typing import Dict, List
from typing import Dict, List, Union

from dotenv import load_dotenv

Expand Down Expand Up @@ -187,9 +187,10 @@ class RIDBConfig:
https://ridb.recreation.gov/docs
"""

_camply_ridb_service_account_api_token: bytes = \
b'YTc0MTY0NzEtMWI1ZC00YTY0LWFkM2QtYTIzM2U3Y2I1YzQ0'
_api_key: str = getenv("RIDB_API_KEY", _camply_ridb_service_account_api_token)
_api_key: Union[str, bytes] = getenv("RIDB_API_KEY", _camply_ridb_service_account_api_token)
API_KEY = _camply_ridb_service_account_api_token if _api_key == "" else _api_key

RIDB_SCHEME: str = "https"
Expand Down Expand Up @@ -229,6 +230,7 @@ class RecreationBookingConfig:
"""
Variable Storage Class for Recreation.gov Booking API
"""

API_SCHEME: str = "https"
API_NET_LOC = "www.recreation.gov"
API_BASE_PATH: str = "api/camps/availability/campground/"
Expand Down
5 changes: 4 additions & 1 deletion camply/config/cli_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class CommandLineActions:
"""
ArgParse Actions
"""

VERSION: str = "version"
STORE: str = "store"
STORE_TRUE: str = "store_true"
Expand All @@ -32,6 +33,7 @@ class CommandLineArguments:
"""
Argument Config
"""

VERSION_ARGUMENT: str = "--version"

STATE_ARGUMENT: str = "--state"
Expand Down Expand Up @@ -81,7 +83,7 @@ class CommandLineArguments:

POLLING_INTERVAL_ARGUMENT: str = "--polling-interval"
POLLING_INTERVAL_DESTINATION: str = "polling_interval"
POLLING_INTERVAL_DEFAULT: str = SearchConfig.RECOMMENDED_POLLING_INTERVAL
POLLING_INTERVAL_DEFAULT: int = SearchConfig.RECOMMENDED_POLLING_INTERVAL
POLLING_INTERVAL_HELP: str = ("If --continuous is activated, how often to wait in between "
"checks (in minutes). Defaults to 10, cannot be less than 5.")

Expand Down Expand Up @@ -118,6 +120,7 @@ class CommandLineValidation:
"""
Camply CLI Validation Config
"""

ERROR_NO_ARGUMENT_FOUND: str = "You must provide an argument to the Camply CLI"
ERROR_MESSAGE_RECREATION_AREA: str = ("You must add a --search or --state parameter to search "
"for Recreation Areas.")
Expand Down
2 changes: 2 additions & 0 deletions camply/config/data_columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class DataColumns:
"""
Variable Storage Class
"""

CAMPSITE_ID_COLUMN: str = "campsite_code"
BOOKING_DATE_COLUMN: str = "booking_date"
BOOKING_END_DATE_COLUMN: str = "booking_end_date"
Expand All @@ -30,6 +31,7 @@ class CampsiteContainerFields:
"""
String Variable Storage Class
"""

CAMPSITE_ID: str = "campsite_id"
CAMPGROUND_ID: str = "facility_id"
BOOKING_DATE: str = "booking_date"
Expand Down
4 changes: 2 additions & 2 deletions camply/config/file_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
from collections import OrderedDict
from os.path import abspath, join
from pathlib import Path
from typing import List


class FileConfig:
"""
File Path Storage Class
"""

HOME_PATH = abspath(Path.home())
DOT_CAMPLY_FILE = join(HOME_PATH, ".camply")
_file_config_file = Path(abspath(__file__))
Expand All @@ -24,7 +24,7 @@ class FileConfig:
CAMPLY_DIRECTORY = _config_dir.parent
ROOT_DIRECTORY = CAMPLY_DIRECTORY.parent

DOT_CAMPLY_FIELDS: List[str] = OrderedDict(
DOT_CAMPLY_FIELDS = OrderedDict(
PUSHOVER_PUSH_USER=dict(default="", notes="Enables Pushover Notifications"),
PUSHBULLET_API_TOKEN=dict(default="", notes="Enables Pushbullet Notifications"),
EMAIL_TO_ADDRESS=dict(default="", notes="Email Notifications will be sent here"),
Expand Down
9 changes: 5 additions & 4 deletions camply/config/notification_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import logging
from os import environ, getenv
from typing import List
from typing import List, Optional

from dotenv import load_dotenv

Expand Down Expand Up @@ -39,15 +39,16 @@ class EmailConfig:
"""
Email Notification Config Class
"""
EMAIL_TO_ADDRESS: str = getenv("EMAIL_TO_ADDRESS", None)

EMAIL_TO_ADDRESS: Optional[str] = getenv("EMAIL_TO_ADDRESS", None)
DEFAULT_FROM_ADDRESS: str = "[email protected]"
EMAIL_FROM_ADDRESS: str = getenv("EMAIL_FROM_ADDRESS", DEFAULT_FROM_ADDRESS)
DEFAULT_SUBJECT_LINE: str = "Camply Notification"
EMAIL_SUBJECT_LINE: str = getenv("EMAIL_SUBJECT_LINE", DEFAULT_SUBJECT_LINE)
DEFAULT_SMTP_SERVER: str = "smtp.gmail.com"
EMAIL_SMTP_SERVER: str = getenv("EMAIL_SMTP_SERVER", DEFAULT_SMTP_SERVER)
EMAIL_USERNAME: str = getenv("EMAIL_USERNAME", None)
EMAIL_PASSWORD: str = getenv("EMAIL_PASSWORD", None)
EMAIL_USERNAME: Optional[str] = getenv("EMAIL_USERNAME", None)
EMAIL_PASSWORD: Optional[str] = getenv("EMAIL_PASSWORD", None)
DEFAULT_SMTP_PORT: int = 465
EMAIL_SMTP_PORT: int = int(getenv("EMAIL_SMTP_PORT", DEFAULT_SMTP_PORT))

Expand Down
1 change: 1 addition & 0 deletions camply/config/search_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class SearchConfig:
"""
File Path Storage Class
"""

POLLING_INTERVAL_MINIMUM: int = 5 # 5 MINUTES
RECOMMENDED_POLLING_INTERVAL: int = 10 # 10 MINUTES
ERROR_MESSAGE: str = "No search days configured. Exiting"
Expand Down
9 changes: 7 additions & 2 deletions camply/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,18 @@ class SearchWindow(NamedTuple):
"""
Search Window for Campsite Search
"""

start_date: datetime
end_date: datetime


class AvailableCampsite(NamedTuple):
"""
Campsite Storage, this container should be universal regardless of
API Provider
Campsite Storage
This container should be universal regardless of API Provider
"""

campsite_id: int
booking_date: datetime
booking_end_date: datetime
Expand All @@ -47,6 +50,7 @@ class CampgroundFacility(NamedTuple):
"""
Campground Facility Data Storage
"""

facility_name: str
recreation_area: str
facility_id: int
Expand All @@ -57,6 +61,7 @@ class RecreationArea(NamedTuple):
"""
Recreation Area Data Storage
"""

recreation_area: str
recreation_area_id: int
recreation_area_location: str
3 changes: 3 additions & 0 deletions camply/notifications/email_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ def __init__(self):
_email_server.quit()

def __repr__(self):
"""
String Representation
"""
return "<EmailNotifications>"

@staticmethod
Expand Down
18 changes: 12 additions & 6 deletions camply/notifications/pushbullet.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,24 @@ class PushbulletNotifications(BaseNotifications, ABC):
def __init__(self):
if any([PushbulletConfig.API_TOKEN is None,
PushbulletConfig.API_TOKEN == ""]):
warning_message = ("Pushbullet is not configured properly. To send Pushbullet messages "
"make sure to run `camply configure` or set the "
"proper environment variable: `PUSHBULLET_API_TOKEN`.")
warning_message = (
"Pushbullet is not configured properly. To send Pushbullet messages "
"make sure to run `camply configure` or set the "
"proper environment variable: `PUSHBULLET_API_TOKEN`.")
logger.error(warning_message)
raise EnvironmentError(warning_message)

def __repr__(self):
"""
String Representation
"""
return "<PushbulletNotifications>"

@staticmethod
def send_message(message: str, **kwargs) -> Optional[requests.Response]:
"""
Send a message via PushBullet - if environment variables are configured
`
Parameters
----------
message: str
Expand All @@ -54,7 +58,8 @@ def send_message(message: str, **kwargs) -> Optional[requests.Response]:
pushbullet_headers.update({"Access-Token": PushbulletConfig.API_TOKEN})
message_type = kwargs.pop("type", "note")
message_title = kwargs.pop("title", "Camply Notification")
message_json = dict(type=message_type, title=message_title, body=message, **kwargs)
message_json = dict(type=message_type, title=message_title, body=message,
**kwargs)
logger.debug(message_json)
response = requests.post(url=PushbulletConfig.PUSHBULLET_API_ENDPOINT,
headers=pushbullet_headers,
Expand Down Expand Up @@ -87,5 +92,6 @@ def send_campsites(campsites: List[AvailableCampsite], **kwargs):
composed_message = "\n".join(fields)
message_title = (f"{campsite.recreation_area} | {campsite.facility_name} | "
f"{campsite.booking_date.strftime('%Y-%m-%d')}")
PushbulletNotifications.send_message(message=composed_message, title=message_title,
PushbulletNotifications.send_message(message=composed_message,
title=message_title,
type="note")
3 changes: 3 additions & 0 deletions camply/notifications/pushover.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ def __init__(self, level: Optional[int] = logging.INFO):
raise EnvironmentError(warning_message)

def __repr__(self):
"""
String Representation
"""
return "<PushoverNotifications>"

@staticmethod
Expand Down
Loading

0 comments on commit 3542344

Please sign in to comment.