diff options
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | app.py | 16 | ||||
-rw-r--r-- | database.py | 5 | ||||
-rw-r--r-- | services.py | 31 | ||||
-rw-r--r-- | static/images/greenboi.jpg | bin | 0 -> 17079 bytes | |||
-rw-r--r-- | static/index.md | 3 | ||||
-rw-r--r-- | templates/index.html | 55 | ||||
-rw-r--r-- | templates/template.html | 3 |
8 files changed, 74 insertions, 41 deletions
@@ -1,7 +1,5 @@ -!README.md edaweb.conf markdowns/ -*.md # Byte-compiled / optimized / DLL files __pycache__/ @@ -47,10 +47,15 @@ def get_template_items(title, db): @app.route("/") def index(): with database.Database() as db: - return flask.render_template( - "index.html", - **get_template_items("eda.gay", db) - ) + recentTweets = [] + with open(os.path.join("static", "index.md"), "r") as f: + return flask.render_template( + "index.html", + **get_template_items("eden's site :3", db), + markdown = parser.parse_text(f.read()), + featured_thoughts = db.get_featured_thoughts(), + tweets = services.get_recent_tweets(6) + ) @app.route("/discord") def discord(): @@ -123,9 +128,6 @@ def serve_image(filename): io_ = io.BytesIO() img.save(io_, format='JPEG') return flask.Response(io_.getvalue(), mimetype='image/jpeg') - - - else: flask.abort(404) diff --git a/database.py b/database.py index 181effb..5e50f82 100644 --- a/database.py +++ b/database.py @@ -84,6 +84,11 @@ class Database: WHERE thought_id = %s;""", (id_, )) return cursor.fetchone() + def get_featured_thoughts(self): + with self.__connection.cursor() as cursor: + cursor.execute("SELECT thought_id, title FROM thoughts WHERE featured = 1;") + return cursor.fetchall() + def update_thought_markdown(self, id_, markdown): with self.__connection.cursor() as cursor: cursor.execute("UPDATE thoughts SET markdown_text = %s WHERE thought_id = %s;", (markdown, id_)) diff --git a/services.py b/services.py index 69c0eae..2cfe394 100644 --- a/services.py +++ b/services.py @@ -1,9 +1,13 @@ +from dataclasses import dataclass +from io import StringIO +from lxml import html import multiprocessing +import pihole as ph import qbittorrent +import requests import datetime import docker import clutch -import pihole as ph import queue import json import time @@ -109,6 +113,29 @@ def get_pihole_stats(): "last_updated": str(datetime.datetime.fromtimestamp(pihole.gravity_last_updated["absolute"])) } +# @timeout +def get_recent_tweets(numToGet): + tweets = [] + domain = "http://" + app.CONFIG.get("nitter", "domain") + with app.database.Database() as db: + for title, url in db.get_header_links(): + if title == "twitter": + break + tree = html.fromstring(requests.get(url).content) + for i, tweetUrlElement in enumerate(tree.xpath('//*[@class="tweet-link"]'), 0): + if i > 0: + tweets.append(( + domain + tweetUrlElement.get("href"), + tweetUrlElement.getparent().find_class("tweet-content media-body")[0].text + )) + if len(tweets) >= numToGet: + break + return tweets + [(url, "view all tweets...")] + + if __name__ == "__main__": - print(get_qbit_stats())
\ No newline at end of file + for tweet in get_recent_tweets(): + print(tweet.get_url()) + print(tweet.get_text()) + print()
\ No newline at end of file diff --git a/static/images/greenboi.jpg b/static/images/greenboi.jpg Binary files differnew file mode 100644 index 0000000..7761c8a --- /dev/null +++ b/static/images/greenboi.jpg diff --git a/static/index.md b/static/index.md new file mode 100644 index 0000000..080a648 --- /dev/null +++ b/static/index.md @@ -0,0 +1,3 @@ +# haii +my name is eden and im a 19yo computer science undergraduate. i made my own website to encourage others to do so too. +i'll post my thoughts on here sometimes, and use this site to link to other stuff i host.
\ No newline at end of file diff --git a/templates/index.html b/templates/index.html index 93138d0..d79743b 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,31 +1,28 @@ {% extends "template.html" %} {% block content %} - <p>Haiiiiiiii, this is the index page uwu</p> - <p>Haiiiiiiii, this is the index page uwu</p> - <p>Haiiiiiiii, this is the index page uwu</p> - <p>Haiiiiiiii, this is the index page uwu</p> - <p>Haiiiiiiii, this is the index page uwu</p> - <p>Haiiiiiiii, this is the index page uwu</p> - <p>Haiiiiiiii, this is the index page uwu</p> - <p>Haiiiiiiii, this is the index page uwu</p> - <p>Haiiiiiiii, this is the index page uwu</p> - <p>Haiiiiiiii, this is the index page uwu</p> - <p>Haiiiiiiii, this is the index page uwu</p> - <p>Haiiiiiiii, this is the index page uwu</p> - <p>Haiiiiiiii, this is the index page uwu</p> - <p>Haiiiiiiii, this is the index page uwu</p> - <p>Haiiiiiiii, this is the index page uwu</p> - <p>Haiiiiiiii, this is the index page uwu</p> - <p>Haiiiiiiii, this is the index page uwu</p> - <p>Haiiiiiiii, this is the index page uwu</p> - <p>Haiiiiiiii, this is the index page uwu</p> - <p>Haiiiiiiii, this is the index page uwu</p> - <p>Haiiiiiiii, this is the index page uwu</p> - <p>Haiiiiiiii, this is the index page uwu</p> - <p>Haiiiiiiii, this is the index page uwu</p> - <p>Haiiiiiiii, this is the index page uwu</p> - <p>Haiiiiiiii, this is the index page uwu</p> - <p>Haiiiiiiii, this is the index page uwu</p> - <p>Haiiiiiiii, this is the index page uwu</p> - <p>Haiiiiiiii, this is the index page uwu</p> - {% endblock %}
\ No newline at end of file + <aside> + <section id="recent thoughts"> + <h4>recent thoughts:</h4> + <ul> + {% for id_, title in featured_thoughts %} + <li><a href={{"/thought?id=%i" % id_}}>title</a></li> + {% endfor %} + </ul> + </section> + </aside> + {{markdown|safe}} + {% if tweets != None %} + <section id="recent_tweets"> + <h1>recent tweets</h1> + <ul> + {% for url, text in tweets %} + {% if text == None %} + <li><a href={{url}}>[image only]</a></li> + {% else %} + <li><a href={{url}}>{{text}}</a></li> + {% endif %} + {% endfor %} + </ul> + </section> + {% endif %} +{% endblock %}
\ No newline at end of file diff --git a/templates/template.html b/templates/template.html index afbeefe..fd65cdb 100644 --- a/templates/template.html +++ b/templates/template.html @@ -2,7 +2,8 @@ <html> <head> <link rel='stylesheet' href="{{url_for('static', filename='style.css')}}"> - <title>edaweb :: {{title}}</title> + <link rel="shortcut icon" href="/img/greenboi.jpg?h=16&w=16"> + <title>eda.gay :: {{title}}</title> </head> <body> <div id=wrapper> |