Skip to content

Commit

Permalink
chore: Add resource_path function to handle resource loading in bundl…
Browse files Browse the repository at this point in the history
…ed applications
  • Loading branch information
techtanic committed Nov 2, 2024
1 parent 9d48375 commit 7f65497
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import os
import re
import sys
import threading
import time
import traceback
Expand Down Expand Up @@ -58,6 +59,12 @@ def join(self, timeout=None):
raise self._exc


def resource_path(relative_path):
if hasattr(sys, "_MEIPASS"):
return os.path.join(sys._MEIPASS, relative_path)
return os.path.join(os.path.abspath("."), relative_path)


class Scraper:
"""
Scrapers: RD,TB, CV, IDC, EN, DU, UF
Expand Down Expand Up @@ -437,7 +444,7 @@ def load_settings(self):
with open(f"duce-{self.interface}-settings.json") as f:
self.settings = json.load(f)
except FileNotFoundError:
with open(f"default-duce-{self.interface}-settings.json") as f:
with open(resource_path(f"default-duce-{self.interface}-settings.json")) as f:
self.settings = json.load(f)
if (
self.interface == "cli" and "use_browser_cookies" not in self.settings
Expand Down

0 comments on commit 7f65497

Please sign in to comment.