php rewrite

This commit is contained in:
Nyx 2025-04-18 09:49:46 -05:00
parent fa85ea36a7
commit 6f2a398a67
22 changed files with 90 additions and 260 deletions

View file

@ -1,7 +0,0 @@
FROM python:3-alpine
WORKDIR /site
COPY . .
RUN pip install --no-cache-dir -r requirements.txt
CMD ["waitress-serve", "--port=8000", "app.app"]

10
app.sh
View file

@ -1,10 +0,0 @@
#!/usr/bin/env sh
set -eu
main() {
cd site
waitress-serve --port=8041 'app.app' &
}
main "$@"

View file

Before

Width:  |  Height:  |  Size: 466 B

After

Width:  |  Height:  |  Size: 466 B

View file

Before

Width:  |  Height:  |  Size: 680 B

After

Width:  |  Height:  |  Size: 680 B

View file

Before

Width:  |  Height:  |  Size: 486 B

After

Width:  |  Height:  |  Size: 486 B

View file

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB

View file

Before

Width:  |  Height:  |  Size: 198 B

After

Width:  |  Height:  |  Size: 198 B

View file

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View file

Before

Width:  |  Height:  |  Size: 5.6 KiB

After

Width:  |  Height:  |  Size: 5.6 KiB

View file

Before

Width:  |  Height:  |  Size: 5.2 KiB

After

Width:  |  Height:  |  Size: 5.2 KiB

View file

Before

Width:  |  Height:  |  Size: 1 KiB

After

Width:  |  Height:  |  Size: 1 KiB

View file

Before

Width:  |  Height:  |  Size: 528 B

After

Width:  |  Height:  |  Size: 528 B

View file

Before

Width:  |  Height:  |  Size: 8.9 KiB

After

Width:  |  Height:  |  Size: 8.9 KiB

View file

Before

Width:  |  Height:  |  Size: 409 B

After

Width:  |  Height:  |  Size: 409 B

View file

@ -1,9 +0,0 @@
services:
utils:
build:
dockerfile: Dockerfile
ports:
- "8041:8000" # Will listen on port 65193, change that number to change the port
restart: unless-stopped
volumes:
- ./site:/site

View file

@ -1,4 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
@ -9,9 +8,30 @@
</head>
<body>
<p>
welcome, visitor <b>{{ visitor }}</b>!
</p>
<?php
$skip_exts = ['ico', 'png', 'jpg', 'css', 'js', 'webp', 'gif', 'svg', 'woff', 'woff2', 'ttf', 'eot', 'otf'];
$path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$ext = pathinfo($path, PATHINFO_EXTENSION);
if (in_array($ext, $skip_exts)) {
return;
}
$filename = 'visitorCount.txt';
$fp = fopen($filename, 'r+');
if (flock($fp, LOCK_EX)) {
$count = (int) fread($fp, filesize($filename));
$count++;
rewind($fp);
fwrite($fp, (string) $count);
ftruncate($fp, ftell($fp));
fflush($fp);
flock($fp, LOCK_UN);
}
fclose($fp);
// display the count
echo "welcome, visitor number <strong>$count</strong>!";
?>
<p>
<h1>Nyx Tutt</h1> is a <span class="hoverblur">trans</span>feminine
<span class="hoverblur">robot-cat-girl-</span>thing.
@ -86,9 +106,7 @@
</ul>
<h3>projects</h3>
<p>
this one has a ton of unfinished projects (and some that haven't
even had any work done yet)! its current idea is a GTK4 music player
along with a federated genius alternative. it also has a few things,
this one has a ton of unfinished projects. it also has a few things,
like skibidifetch (a fork of badapplefetch by
<a href="https://ari.lt/">Ari</a>), that are smaller.
it also made a collection of web-based tools using server-side rendering,
@ -96,12 +114,45 @@
</p>
<h4>current project</h4>
<p>
currently, it's making a web frontend for DICT (RFC2229) using Flask in the backend
and Tailwind CSS in the frontend.
learning Ruby and Rails
</p>
<h3>music</h3>
<p>
{{ np }}
<?php
$apiRoot = 'https://api.listenbrainz.org';
$user = 'everypizza';
$nowPlayingString = '';
$nowPlaying = false;
try {
$response = file_get_contents($apiRoot . "/1/user/" . urlencode($user) . "/playing-now");
if ($response === false) {
throw new Exception("Failed to fetch");
}
$data = json_decode($response, true);
if (empty($data['payload']['listens'])) {
$nowPlayingString = "nothing is playing right now.";
} else {
$track = $data['payload']['listens'][0]['track_metadata']['track_name'];
$artist = $data['payload']['listens'][0]['track_metadata']['artist_name'];
$album = $data['payload']['listens'][0]['track_metadata']['release_name'];
$nowPlaying = true;
$nowPlayingString = "now playing for <b>" . htmlspecialchars($user) . "</b>: <b>" .
htmlspecialchars($track) . "</b> by <b>" .
htmlspecialchars($artist) . "</b> from <b>" .
htmlspecialchars($album) . "</b>";
}
} catch (Exception $e) {
$nowPlayingString = "Failed to reach API";
}
echo $nowPlayingString;
?>
<br>
<small>
data is from listenbrainz.
@ -109,11 +160,36 @@
</p>
<h3>buttons</h3>
<p>
{% for image, link in buttons %}
<a href="{{ link }}">
<img src="/static/{{ image }}" alt="{{ image }}" width="88" height="31">
<a href="https://benjae.nekoweb.org">
<img src="/assets/88x31s/benjae.nekoweb.org.gif" alt="Benjae" width="88" height="31">
</a>
{% endfor %}
<a href="https://freetards.xyz">
<img src="/assets/88x31s/freetards.xyz.gif" alt="Freetards" width="88" height="31">
</a>
<a href="https://fsky.io">
<img src="/assets/88x31s/fsky.io.webp" alt="FSKY" width="88" height="31">
</a>
<a href="https://purplebored.pl">
<img src="/assets/88x31s/purplebored.pl.gif" alt="Purplebored" width="88" height="31">
</a>
<a href="https://squarebowl.club">
<img src="/assets/88x31s/squarebowl.club.gif" alt="PlateNet" width="88" height="31">
</a>
<a href="https://synth.download">
<img src="/assets/88x31s/synth.download.svg" alt="synth.download" width="88" height="31">
</a>
<a href="https://telepath.im">
<img src="/assets/88x31s/telepath.im.png" alt="Telepath" width="88" height="31">
</a>
<a href="https://voxel.fsky.io">
<img src="/assets/88x31s/voxel.fsky.io.webp" alt="voxel" width="88" height="31">
</a>
<a href="https://zayd.fsky.io">
<img src="/assets/88x31s/zayd.fsky.io.png" alt="voxel" width="88" height="31">
</a>
<br /><br />
<img src="/assets/88x31s/nyx.everypizza.im.webp" alt="Nyx" width="88" height="31">
<img src="/assets/88x31s/nyx.everypizza.im-2.png" alt="Nyx" width="88" height="31">
</p>
</body>

Binary file not shown.

View file

@ -1,94 +0,0 @@
#!/usr/bin/env python
from flask import Flask, render_template, make_response, send_from_directory
import requests
import os
apiRoot = "https://api.listenbrainz.org"
user = "everypizza"
buttons = [
("assets/88x31s/benjae.nekoweb.org.gif", "https://benjae.nekoweb.org"),
("assets/88x31s/freetards.xyz.gif", "https://freetards.xyz"),
("assets/88x31s/fsky.io.webp", "https://fsky.io"),
("assets/88x31s/purplebored.pl.gif", "https://purplebored.pl"),
("assets/88x31s/squarebowl.club.gif", "https://squarebowl.club"),
("assets/88x31s/synth.download.svg", "https://synth.download"),
("assets/88x31s/telepath.im.png", "https://telepath.im"),
("assets/88x31s/voxel.fsky.io.webp", "https://voxel.fsky.io"),
("assets/88x31s/zayd.fsky.io.png", "https://zayd.fsky.io"),
]
nyxbuttons = [
("assets/88x31s/nyx.everypizza.im.webp", "https://nyx.everypizza.im"),
("assets/88x31s/nyx.everypizza.im-2.png", "https://nyx.everypizza.im"),
]
app = Flask(__name__)
countFile = "visitorCount.txt"
def get_visitor_count():
try:
with open(countFile, "r") as f:
return int(f.read())
except FileNotFoundError:
return 0
def increment_visitor_count():
count = get_visitor_count()
count += 1
with open(countFile, "w") as f:
f.write(str(count))
return count
@app.route('/')
def index():
increment_visitor_count()
try:
data = requests.get(apiRoot + "/1/user/" + user + "/playing-now")
if not data.json()['payload']['listens']:
nowPlaying = False
nowPlayingString = "nothing is playing right now."
else:
track = data.json()['payload']['listens'][0]['track_metadata']['track_name']
artist = data.json()['payload']['listens'][0]['track_metadata']['artist_name']
album = data.json()['payload']['listens'][0]['track_metadata']['release_name']
nowPlayingString = f"now playing for <b>{user}</b>: <b>{track}</b> by <b>{artist}</b> from <b>{album}</b>"
except:
nowPlayingString = "Failed to reach API"
return render_template('index.j2', np=nowPlayingString, visitor=get_visitor_count(), buttons=buttons, nyxbuttons=nyxbuttons)
@app.route('/assets/index.css')
def indexStyle():
css = render_template('assets/index.css')
response = make_response(css)
response.mimetype = "text/css"
return response
@app.route('/assets/particles.js')
def particleJs():
js = render_template('assets/scripts/particles.js')
response = make_response(js)
response.mimetype = "text/javascript"
return response
@app.route('/assets/birds.js')
def birdJs():
js = render_template('assets/scripts/birds.js')
response = make_response(js)
response.mimetype = "text/javascript"
return response
@app.route('/static/assets/88x31s/<path:filename>')
def serve_dir(filename):
directory = 'templates/assets/88x31s'
return send_from_directory(directory, filename)
@app.route('/todo')
def todo():
return render_template('todo.html')
if __name__ == '__main__':
app.run(host="0.0.0.0", port=8080)

View file

@ -1,126 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>
Nyx's personal site
</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="assets/index.css" rel="stylesheet" type="text/css">
</head>
<body>
<center>
<p>
hello, visitor number <b>{{ visitor }}</b>! this one is glad to see you.
</p>
<br>
<small>
this counter doesn't use javascript, it's just a text file with a digit in
it that gets increased by 1 on every page load.
</small>
</center>
<h1>
Nyx Tutt
</h1>
<h2>
about it
</h2>
<p>
it is a cat-robot-girl-thing. it likes to speak about itself in the third person.
it likes linux and uses arch. it lives in texas, but hates it here. its favorite
color is pink.
</p>
<h2>
interests
</h2>
<p>
nyx has many interests. currently, it's been learning about networking, and the
C programming languages. it also likes open source software and protocols, like
XMPP. it also is a strong beliver in freedom of information, so it hosts things
like <a href="https://snowflake.torproject.org/">snowflake proxies</a>. it also
likes retro design, and it sometimes will write a blog post on something random.
theming is also fun for it.
</p>
<h2>
contact
</h2>
<p>
this one has a few forms of contact:<br>
</p>
<ul>
<li>
<a href="xmpp:nyx@everypizza.im">xmpp</a><br>
</li>
<li>
<a href="matrix:u/n:everypizza.im">matrix</a><br>
</li>
<li>
<a href="mailto:me@everypizza.im">email</a> (it has a pgp key over in <a href="https://keys.openpgp.org/search?q=me%40everypizza.im">keys.openpgp.org</a>.)<br>
</li>
<li>
<a href="https://sharkey.everypizza.im">fedi</a><br>
</li>
<li>
discord: everypizza
</li>
</ul>
<p>
please avoid using 2nd person pronouns when contacting it.
</p>
<h2>
links
</h2>
<ul>
<li>
<a href="https://listenbrainz.org/user/everypizza">listenbrainz</a>
</li>
<li>
<a href="https://everypizza.im/">everypizza.im</a>
</li>
<li>
<a href="https://git.everypizza.im/n/">git</a>
</li>
</ul>
<h2>
pages
</h2>
<ul>
<li>
<a href="todo">to-do list</a>
</li>
<li>
<a href="https://blog.everypizza.im/">blog</a>
</li>
</ul>
<h2>
now playing
</h2>
<p>
{{ np }}
<br>
<small>
data is from listenbrainz.
</small>
</p>
<h2>
88x31s
</h2>
<p>
{% for image, link in buttons %}
<a href="{{ link }}">
<img src="/static/{{ image }}" alt="{{ image }}" width="88" height="31">
</a>
{% endfor %}
</p>
<h3>
this one's 88x31
</h3>
<p>
{% for image, link in nyxbuttons %}
<a href="{{ link }}">
<img src="/static/{{ image }}" alt="{{ image }}" width="88" height="31">
</a>
{% endfor %}
</p>
</body>
</html>