-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
209 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +0,0 @@ | ||
# Auto detect text files and perform LF normalization | ||
* text=auto | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,171 @@ | ||
import requests as req | ||
import os | ||
import shutil | ||
|
||
import version | ||
from core.functions.system.getMainPath import getMainPath | ||
|
||
try: | ||
from version import * | ||
|
||
def getGithubVersion() -> str: | ||
raw = req.get("https://raw.githubusercontent.com/DoctorFuchs/Doc/main/version.py") # request raw document | ||
if raw.status_code != 200: # if user is not online | ||
return version.version | ||
except: | ||
version = "1.1.4" | ||
|
||
return raw.text.split("version = ")[1].split("<")[0].replace("\"", "") | ||
try: | ||
import requests as req | ||
import torpy as tor | ||
from torpy.http import requests | ||
from torpy.http.adapter import TorHttpAdapter | ||
|
||
except: | ||
print("request or torpy is not installed. (install both with pip3) Please update manually") | ||
|
||
blocked = ["core/new/auths.py", "core/plugins", "core/startup.txt"] # files, that don't get update | ||
|
||
|
||
def getPath(): | ||
path = str(__file__).split("core/functions/system/updater.py") | ||
del path[len(path) - 1] | ||
|
||
path = "/".join(path).split("/") | ||
path.append("Doc-" + getGithubVersion()) | ||
|
||
del path[len(path) - 3] | ||
if not os.path.isdir("/".join(path)): | ||
os.mkdir("/".join(path)) | ||
|
||
return ("/".join(path) + "/").replace("//", "/") | ||
|
||
|
||
def getGithubVersion(session=None) -> str: | ||
if session is None: | ||
raw = req.get("https://raw.githubusercontent.com/DoctorFuchs/Doc/main/version.py") # request raw document | ||
|
||
else: | ||
raw = session.get("https://raw.githubusercontent.com/DoctorFuchs/Doc/main/version.py") | ||
|
||
if raw.status_code != 200: # if user is not online | ||
return version | ||
|
||
return raw.text.split("version = ")[1].split("<")[0].replace("\"", "").replace("\n", "") | ||
|
||
|
||
def getContent(path: str, session=None) -> str: | ||
if session is None: | ||
raw = req.get("https://raw.githubusercontent.com/DoctorFuchs/Doc/main/" + path) # request raw document | ||
|
||
else: | ||
raw = session.get("https://raw.githubusercontent.com/DoctorFuchs/Doc/main/" + path) | ||
|
||
if raw.status_code != 200: # if user is not online | ||
return "" | ||
|
||
return raw.text | ||
|
||
|
||
def getAllFilesInDictionary(path: str, session=None): | ||
if session is None: | ||
info = req.get("https://api.github.com/repos/doctorfuchs/doc/contents/" + path) | ||
|
||
else: | ||
info = session.get("https://api.github.com/repos/doctorfuchs/doc/contents/" + path) | ||
|
||
if info.status_code != 200: | ||
return [] | ||
|
||
file = {} | ||
returner = [] | ||
final = info.text.split(">")[0].split("</pre>")[0].replace("{", ",").replace("}", ",").replace("\"", "").split(",") | ||
|
||
# convert to dict | ||
for i in range(len(final)): | ||
if final[i] == "": | ||
pass | ||
|
||
if final[i].split(":", 1)[0] == "name" and file != {}: | ||
file[final[i].split(":", 1)[0]] = final[i].split(":", 1)[1] | ||
returner.append(file) | ||
file = {} | ||
|
||
else: | ||
try: | ||
file[final[i].split(":", 1)[0]] = final[i].split(":", 1)[1] | ||
|
||
except IndexError: | ||
pass | ||
|
||
returner.append(file) | ||
|
||
return returner | ||
|
||
|
||
def update(sess=None): | ||
file_paths = [] | ||
dicts = ["", ""] | ||
|
||
while True: | ||
try: | ||
act = getAllFilesInDictionary(dicts[0], session=sess) | ||
for i in range(len(act)): | ||
if act[i]["path"] in blocked: | ||
continue | ||
|
||
if act[i]["type"] == "file": | ||
file_paths.append(act[i]["path"]) | ||
|
||
elif act[i]["type"] == "dir": | ||
|
||
try: | ||
os.mkdir(getPath() + act[i]["path"]) | ||
|
||
except FileExistsError: | ||
pass | ||
|
||
dicts.append(act[i]["path"]) | ||
|
||
del dicts[0] | ||
|
||
except: | ||
break | ||
|
||
for element in range(len(file_paths)): | ||
content = getContent(file_paths[element], session=sess) | ||
|
||
if file_paths[element] in blocked: | ||
continue | ||
|
||
elif os.path.isfile(getPath() + file_paths[element]): | ||
mode = "r+t" | ||
|
||
else: | ||
mode = "w+t" | ||
|
||
file = open(getPath() + file_paths[element], mode) | ||
if "\n".join(file.readlines()) == content: | ||
pass | ||
|
||
else: | ||
file.writelines(content.split("\n")) | ||
|
||
file.close() | ||
|
||
for i in range(len(blocked)): | ||
try: | ||
shutil.copy(getMainPath() + blocked[i], getPath() + blocked[i]) | ||
|
||
except IsADirectoryError: | ||
try: | ||
shutil.copytree(getMainPath() + blocked[i], getPath() + blocked[i]) | ||
|
||
except: | ||
pass | ||
|
||
return "updated" | ||
|
||
|
||
def tor_update(): | ||
with tor.TorClient() as torc: | ||
with torc.get_guard() as guard: | ||
adapter = TorHttpAdapter(guard, 2) | ||
with requests.Session() as sess: | ||
sess.headers.update({"User-Agent": "Mozilla/5.0"}) | ||
sess.mount("https://", adapter) | ||
update(sess) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
clock c:plugins.plugincodes.clock(instance); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
def clock(instance): | ||
"""live time clock""" | ||
import time, datetime | ||
try: | ||
while True: | ||
instance.docprint("\r" + str(datetime.datetime.now().strftime("%H:%M:%S")), end="") | ||
time.sleep(1) | ||
|
||
except: | ||
instance.docprint("", end="\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
requests | ||
requests | ||
torpy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
version = "1.1.4" | ||
version = "1.1.5" |