Skip to content

Commit

Permalink
New auto-updates system
Browse files Browse the repository at this point in the history
  • Loading branch information
ThaaoBlues authored Mar 13, 2021
1 parent b99454d commit 7297c11
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 21 deletions.
28 changes: 7 additions & 21 deletions copypasta.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#from flaskwebgui import FlaskUI
from image_proc import start_image_proc
from text_proc import start_text_proc
from util import make_qr_url
from util import make_qr_url, get_private_ip, download_templates, check_updates
from webbrowser import open as display_website
from multiprocessing import Process, freeze_support
from time import sleep
Expand All @@ -35,31 +35,14 @@
mkdir("static")
open("static/hist.Blue","w")
open("static/dates.Blue","w")
with open("static/update.Blue","w") as f:
f.write("1")



if not path.exists("templates/"):
mkdir("templates")

r = get("https://raw.githubusercontent.com/thaaoblues/copypasta/master/templates/index.html",allow_redirects=True)
with open("templates/index.html","wb") as f:
f.write(r.content)

r = get("https://raw.githubusercontent.com/thaaoblues/copypasta/master/templates/scan_preview.html",allow_redirects=True)
with open("templates/scan_preview.html","wb") as f:
f.write(r.content)

r = get("https://raw.githubusercontent.com/thaaoblues/copypasta/master/templates/img_preview.html",allow_redirects=True)
with open("templates/img_preview.html","wb") as f:
f.write(r.content)

r = get("https://raw.githubusercontent.com/thaaoblues/copypasta/master/templates/settings.html",allow_redirects=True)
with open("templates/settings.html","wb") as f:
f.write(r.content)

r = get("https://raw.githubusercontent.com/thaaoblues/copypasta/master/templates/favicon.ico",allow_redirects=True)
with open("templates/favicon.ico","wb") as f:
f.write(r.content)
download_templates()



Expand Down Expand Up @@ -235,6 +218,9 @@ def open_tab():
start_image_proc()
start_text_proc()

#check if the templates are up-to-date
check_updates()

#open tab in web browser
Process(target=open_tab).start()

Expand Down
36 changes: 36 additions & 0 deletions util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from getpass import getuser
from random import randint
from json import dumps
from requests import get

def get_private_ip():
"""
Expand All @@ -20,3 +21,38 @@ def make_qr_url():
return dumps(url,indent=4)


def check_updates():
with open("static/update.Blue","r") as f:
n = int(f.read())
if n == 10:
download_templates()
else:
with open("static/update.Blue","w") as f:
f.write(str(n+1))



def download_templates():
r = get("https://raw.githubusercontent.com/thaaoblues/copypasta/master/templates/index.html",allow_redirects=True)
with open("templates/index.html","wb") as f:
f.write(r.content)

r = get("https://raw.githubusercontent.com/thaaoblues/copypasta/master/templates/scan_preview.html",allow_redirects=True)
with open("templates/scan_preview.html","wb") as f:
f.write(r.content)

r = get("https://raw.githubusercontent.com/thaaoblues/copypasta/master/templates/img_preview.html",allow_redirects=True)
with open("templates/img_preview.html","wb") as f:
f.write(r.content)

r = get("https://raw.githubusercontent.com/thaaoblues/copypasta/master/templates/settings.html",allow_redirects=True)
with open("templates/settings.html","wb") as f:
f.write(r.content)

r = get("https://raw.githubusercontent.com/thaaoblues/copypasta/master/templates/favicon.ico",allow_redirects=True)
with open("templates/favicon.ico","wb") as f:
f.write(r.content)

with open("static/update.Blue","w") as f:
f.write("1")

0 comments on commit 7297c11

Please sign in to comment.