Skip to content

Commit

Permalink
fix: obsidian_setup.py can not download files when there are no corre…
Browse files Browse the repository at this point in the history
…sponding resources the latest release
  • Loading branch information
Rookiecom committed Feb 6, 2024
1 parent feb3db2 commit c924fc8
Showing 1 changed file with 26 additions and 19 deletions.
45 changes: 26 additions & 19 deletions obstoanki_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,35 @@
import subprocess
import os

SCRIPT_URL = "".join(
[
"https://github.com/Pseudonium/Obsidian_to_Anki/releases/latest",
"/download/obsidian_to_anki.py"
]
)
SCRIPT_URL = [
"https://github.com/ObsidianToAnki/Obsidian_to_Anki/releases/latest/download/obsidian_to_anki.py",
"https://raw.githubusercontent.com/ObsidianToAnki/Obsidian_to_Anki/master/obsidian_to_anki.py",
]

REQUIRE_URL = "".join(
[
"https://github.com/Pseudonium/Obsidian_to_Anki/releases/latest",
"/download/requirements.txt"
]
)

with urllib.request.urlopen(SCRIPT_URL) as script:
with open("obsidian_to_anki.py", "wb") as f:
f.write(script.read())
REQUIRE_URL = [
"https://github.com/ObsidianToAnki/Obsidian_to_Anki/releases/latest/download/requirements.txt",
"https://raw.githubusercontent.com/ObsidianToAnki/Obsidian_to_Anki/master/requirements.txt",
]

with urllib.request.urlopen(REQUIRE_URL) as require:
with open("obstoankirequire.txt", "wb") as f:
f.write(require.read())
def download_file(urls, filename) :
for url in urls:
try:
with urllib.request.urlopen(url) as response:
with open(filename, "wb") as f:
f.write(response.read())
print(f"Successfully downloaded {filename}.")
return True
except Exception as e:
print(f"An error occurred while downloading {filename} from {url}: {e}")

print(f"Failed to download {filename} using all provided URLs.")
return False

download_file(SCRIPT_URL, "obsidian_to_anki.py")

if download_file(REQUIRE_URL, "obstoankirequire.txt"):
subprocess.check_call(
[sys.executable, "-m", "pip", "install", "-r", "obstoankirequire.txt"]
)
os.remove("obstoankirequire.txt")
os.remove("obstoankirequire.txt")

0 comments on commit c924fc8

Please sign in to comment.