Skip to content

Commit

Permalink
more stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
ajskateboarder committed Aug 1, 2023
1 parent 57852c3 commit ecb84bc
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 69 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ DAZZLE_DIR=".dazzle-archive"
# change SERVER_MODE to "yes" if running a public server
SERVER_MODE="no"
# change this to the IP:PORT that you're going to expose
SERVER_HOST="http://localhost:3000"
SERVER_HOST="http://localhost:5000"

DB_LOCATION="users.sqlite"
DB_TABLE="users"
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
# Snazzle

A better frontend for Scratch, built by the community, for the community

Snazzle is my attempt at a better Scratch website. It aims to be feature-rich and easy and quick to use, incorporating many things that the Scratch community has been wanting for years.

Basically, this is a Scratch website just for <s>MagicCrayon9342</s> power users.
Basically, this is a Scratch website just for ~~MagicCrayon9342~~ power users.

> If you're more than a casual user of the Scratch website for whatever reason, then you'll like Snazzle.
> It's like a giant vat of coffee brewed with ingredients from the Scratch community.
-- Snazzle's website

## Running your own instance locally

Since Snazzle is very much still in development, this won't be representative of the final product's build steps.

But for now, this is how you do it:

1. Clone the repo
2. (optional but recommended) Create a Python virtual environment. We recommend Python 3.11 or later.
3. Run `pip3 install -r requirements.txt`.
> If you are on an Arch based linux distro, you will have to run "sudo pacman -S python-flask
> If you are on an Arch based linux distro, you will have to run `sudo pacman -S python-flask`
4. If you are using Replit or another website blocked from Scratch's API, change the variable "REPLIT_MODE" at the top of `main.py` to True.
5. Once deps are installed, run `python3 main.py`. This will set up a Flask server at `localhost:3000`. If you find any bugs, please report them.
> If you're on Windows, run `py main.py` instead.
6. Go to `localhost:3000` in your favourite browser and play around with it!
5. Once deps are installed, run `flask run`. This will set up a Flask server at `localhost:5000`. If you find any bugs, please report them.
6. Go to `localhost:5000` in your favourite browser and play around with it!

## Hosting on Replit

Some features currently won't work properly due to usage of Scratch's API. With this in mind, [there's a version on replit that works around these limitations.](https://snazzle-repl.redstonescratch.repl.co/) However, because of these limitations, there are the following disadvantages to using the repl:

1. No projects or studios on the front page
2. All profile pictures are the default one
3. May be slower
11 changes: 3 additions & 8 deletions main.py → app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

REPLIT_MODE = False
USE_SCRATCHDB = True
HOST, PORT = "localhost", 3000

debug = True

"""
Expand Down Expand Up @@ -335,23 +335,18 @@ def unpin_sub(sf):

@app.get("/handle-scratch-auth")
def scratch_auth():
# TODO: test this on a machine
if not request.args:
if sa_login := dazzle.get_redirect_url():
return redirect(sa_login)
else:
return "<script>alert('Auth failed');history.back()</script>"
else:
code = request.args.get("privateCode")
data = dazzle.login(code)
return "done"
dazzle.login(code)
return "<h1>Login successful</h1><script>window.location.href = `${window.location.protocol}//${window.location.host}`</script>"


@app.errorhandler(werkexcept.NotFound)
def err404(e: Exception):
# route for error
return render_template("_error.html", errdata=e), 404


# CHANGE THIS IF YOU'RE RUNNING A PUBLIC SERVER
app.run(host="localhost", port=3000, debug=True)
5 changes: 2 additions & 3 deletions dazzle.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ def get_redirect_url() -> str:
not env["SERVER_MODE"] or not env["SERVER_MODE"]
), "Snazzle must be run in server mode for Scratch Auth to work. See https://tinyurl.com/snazzle-server"
redir_loc = base64.b64encode(
"http://localhost:3000/handle-scratch-auth".encode()
f"http://{env['SERVER_HOST']}/handle-scratch-auth".encode()
).decode()
return f"https://auth.itinerary.eu.org/auth?name=snazzle&redirect={redir_loc}"

Expand All @@ -333,15 +333,14 @@ def login(code: str):
cursor.execute(
f"CREATE TABLE IF NOT EXISTS {env['DB_TABLE']}( username, token )"
)
# TODO: insert only if user doesn't exist
cursor.execute(
f"INSERT INTO {env['DB_TABLE']} VALUES (?, ?)",
(data["username"], session_id),
)
conn.commit()
conn.close()

return None


# Below this line is all stuff used for the REPL debugging mode
# Generally, don't touch this, unless there's a severe flaw or something
Expand Down
56 changes: 4 additions & 52 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,66 +1,18 @@
anyio==3.7.1
bleach==6.0.0
blinker==1.6.2
certifi==2023.7.22
cffi==1.15.1
charset-normalizer==3.2.0
click==8.1.6
click-log==0.4.0
colorama==0.4.6
cryptography==41.0.2
deprecation==2.1.0
docutils==0.20.1
dotty-dict==1.3.1
exceptiongroup==1.1.2
Flask==2.3.2
gitdb==4.0.10
GitPython==3.1.32
gotrue==1.0.2
h11==0.14.0
httpcore==0.16.3
httpx==0.23.3
idna==3.4
importlib-metadata==6.8.0
importlib-resources==6.0.0
invoke==1.7.3
itsdangerous==2.1.2
jaraco.classes==3.3.0
jeepney==0.8.0
Jinja2==3.1.2
keyring==24.2.0
MarkupSafe==2.1.3
more-itertools==10.0.0
numpy==1.24.4
packaging==23.1
pkginfo==1.9.6
postgrest==0.10.6
pycparser==2.21
pydantic==1.10.12
Pygments==2.15.1
pandas==2.0.3
python-dateutil==2.8.2
python-dotenv==1.0.0
python-gitlab==3.15.0
python-semantic-release==7.33.2
readme-renderer==40.0
realtime==1.0.0
pytz==2023.3
requests==2.31.0
requests-toolbelt==1.0.0
rfc3986==1.5.0
SecretStorage==3.3.3
semver==2.13.0
six==1.16.0
smmap==5.0.0
sniffio==1.3.0
storage3==0.5.3
StrEnum==0.4.15
supabase==1.0.3
supafunc==0.2.2
tomlkit==0.12.1
tqdm==4.65.0
twine==3.8.0
typing-extensions==4.7.1
tzdata==2023.3
urllib3==2.0.4
webencodings==0.5.1
websockets==10.4
Werkzeug==2.3.6
zipp==3.16.2
numpy==1.24.4

0 comments on commit ecb84bc

Please sign in to comment.