From 7cc501c5efde9da7c5e4dbfd854cdeb80a8e0ce9 Mon Sep 17 00:00:00 2001 From: jwansek Date: Sat, 6 Mar 2021 01:50:05 +0000 Subject: added twitter on index page --- .gitignore | 2 -- app.py | 16 +++++++------ database.py | 5 +++++ services.py | 31 +++++++++++++++++++++++-- static/images/greenboi.jpg | Bin 0 -> 17079 bytes static/index.md | 3 +++ templates/index.html | 55 +++++++++++++++++++++------------------------ templates/template.html | 3 ++- 8 files changed, 74 insertions(+), 41 deletions(-) create mode 100644 static/images/greenboi.jpg create mode 100644 static/index.md diff --git a/.gitignore b/.gitignore index aed6835..b19bbd8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,5 @@ -!README.md edaweb.conf markdowns/ -*.md # Byte-compiled / optimized / DLL files __pycache__/ diff --git a/app.py b/app.py index 7cc97d9..60b0f03 100644 --- a/app.py +++ b/app.py @@ -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 new file mode 100644 index 0000000..7761c8a Binary files /dev/null and b/static/images/greenboi.jpg differ 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 %} -

Haiiiiiiii, this is the index page uwu

-

Haiiiiiiii, this is the index page uwu

-

Haiiiiiiii, this is the index page uwu

-

Haiiiiiiii, this is the index page uwu

-

Haiiiiiiii, this is the index page uwu

-

Haiiiiiiii, this is the index page uwu

-

Haiiiiiiii, this is the index page uwu

-

Haiiiiiiii, this is the index page uwu

-

Haiiiiiiii, this is the index page uwu

-

Haiiiiiiii, this is the index page uwu

-

Haiiiiiiii, this is the index page uwu

-

Haiiiiiiii, this is the index page uwu

-

Haiiiiiiii, this is the index page uwu

-

Haiiiiiiii, this is the index page uwu

-

Haiiiiiiii, this is the index page uwu

-

Haiiiiiiii, this is the index page uwu

-

Haiiiiiiii, this is the index page uwu

-

Haiiiiiiii, this is the index page uwu

-

Haiiiiiiii, this is the index page uwu

-

Haiiiiiiii, this is the index page uwu

-

Haiiiiiiii, this is the index page uwu

-

Haiiiiiiii, this is the index page uwu

-

Haiiiiiiii, this is the index page uwu

-

Haiiiiiiii, this is the index page uwu

-

Haiiiiiiii, this is the index page uwu

-

Haiiiiiiii, this is the index page uwu

-

Haiiiiiiii, this is the index page uwu

-

Haiiiiiiii, this is the index page uwu

- {% endblock %} \ No newline at end of file + + {{markdown|safe}} + {% if tweets != None %} +
+

recent tweets

+ +
+ {% 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 @@ - edaweb :: {{title}} + + eda.gay :: {{title}}
-- cgit v1.2.3