Fixed Mystery to detect Windows Paths over URLs

This commit is contained in:
codemann8
2022-08-17 14:09:02 -05:00
parent e5cff2e773
commit 6455cad361

View File

@@ -4,6 +4,8 @@ import RaceRandom as random
import urllib.request
import urllib.parse
import yaml
import os
from pathlib import Path
from DungeonRandomizer import parse_cli
from Main import main as DRMain
@@ -107,10 +109,11 @@ def main():
def get_weights(path):
try:
if urllib.parse.urlparse(path).scheme:
if os.path.exists(Path(path)):
with open(path, "r", encoding="utf-8") as f:
return yaml.load(f, Loader=yaml.SafeLoader)
elif urllib.parse.urlparse(path).scheme in ['http', 'https']:
return yaml.load(urllib.request.urlopen(path), Loader=yaml.FullLoader)
with open(path, 'r', encoding='utf-8') as f:
return yaml.load(f, Loader=yaml.SafeLoader)
except Exception as e:
raise Exception(f'Failed to read weights file: {e}')