File size: 1,258 Bytes
9e30224
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import json
import os

SETTINGS_FILE = "settings.json"

class Udemy:
    def __init__(self, mode):
        self.mode = mode
        self.settings = {}

    def load_settings(self):
        """Load user settings from JSON, handle errors if file is empty or corrupted."""
        try:
            if not os.path.exists(SETTINGS_FILE) or os.stat(SETTINGS_FILE).st_size == 0:
                print("⚠️ Settings file missing or empty. Creating default settings...")
                self.create_default_settings()
            with open(SETTINGS_FILE, "r") as f:
                self.settings = json.load(f)
        except (json.JSONDecodeError, ValueError):
            print("⚠️ Settings file is corrupted. Resetting to default settings...")
            self.create_default_settings()

    def create_default_settings(self):
        """Create a default settings file if it's missing or corrupted."""
        self.settings = {
            "use_browser_cookies": False,
            "email": "",
            "password": "",
            "scraper_sites": ["DiscUdemy", "Udemy Freebies", "Tutorial Bar"],
        }
        with open(SETTINGS_FILE, "w") as f:
            json.dump(self.settings, f, indent=4)
        print("✅ Default settings file created.")