Skip to content

Commit

Permalink
Change bookeeping path
Browse files Browse the repository at this point in the history
  • Loading branch information
P-ict0 committed Jun 21, 2024
1 parent 34b8fe5 commit 4d63a07
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 16 deletions.
6 changes: 2 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ build-backend = "setuptools.build_meta"

[project]
name = "dynamic-scraper"
version = "0.4.0"
description = "Dynamic web scraper specifically designed for AnsularJS websites that runs at specified time intervals and notifies you about specific updates on the site"
version = "1.0.0"
description = "Dynamic web scraper specifically designed for websites that dynamically load elements (such as AngularJS). It runs at specified time intervals and notifies you about specific updates on the site."
readme = "README.md"
requires-python = ">=3.10"
authors = [
Expand Down Expand Up @@ -44,5 +44,3 @@ dynamic-scraper = "src.web_scraper:main"

[tool.setuptools]
packages = ["src.web_scraper", "src.web_scraper.utils"]
include-package-data = true
package-data = {"web_scraper" = ["results.json"]} # Include results.json in the package
21 changes: 19 additions & 2 deletions src/web_scraper/utils/argparse.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import argparse
import pathlib
import utils.config as config
from .helpers import is_windows
import os


def collect_arguments() -> argparse.Namespace:
Expand Down Expand Up @@ -79,12 +80,28 @@ def collect_arguments() -> argparse.Namespace:
help="(Optional) Don't run the browser in headless mode",
)

# Determine the operating system
if is_windows():
# Windows-specific default path
default_path_directory = os.path.join(os.environ["APPDATA"], "Dynamic-Scraper")
os.makedirs(os.path.dirname(default_path_directory), exist_ok=True)

# Create a default path for Windows
default_path = os.path.join(
os.environ["APPDATA"], "Dynamic-Scraper", "results.json"
)
else:
# Default path for Linux (and other Unix-like OS)
default_path = os.path.join(
os.path.expanduser("~"), ".dynamic_scraper_results.json"
)

parser.add_argument(
"--json_path",
"-j",
required=False,
type=str,
default=pathlib.Path(__file__).parent.parent.resolve() / "results.json",
default=default_path,
help="(Optional) Specific path to save the found results as JSON.",
)

Expand Down
10 changes: 10 additions & 0 deletions src/web_scraper/utils/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import os


def is_windows() -> bool:
"""
Check the OS and send the notification
:return: True if the OS is Windows, False otherwise
"""
return True if os.name == "nt" else False
11 changes: 1 addition & 10 deletions src/web_scraper/utils/notifier.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
import os
from .helpers import is_windows

try:
from win11toast import notify
except (ImportError, ModuleNotFoundError): # Linux
pass


def is_windows() -> bool:
"""
Check the OS and send the notification
:return: True if the OS is Windows, False otherwise
"""
return True if os.name == "nt" else False


def notify_user(message: str, url: str) -> None:
"""
Send a notification to the user
Expand Down

0 comments on commit 4d63a07

Please sign in to comment.