diff options
| -rw-r--r-- | Dockerfile | 9 | ||||
| -rw-r--r-- | app.py | 18 | ||||
| -rw-r--r-- | database.py | 14 | ||||
| -rw-r--r-- | example.conf | 5 | ||||
| -rw-r--r-- | requirements.txt | 4 | ||||
| -rw-r--r-- | static/images/shark1.jpg | bin | 0 -> 449065 bytes | |||
| -rw-r--r-- | static/images/shark2.jpg | bin | 0 -> 433903 bytes | |||
| -rw-r--r-- | static/index.md | 2 | ||||
| -rw-r--r-- | static/style.css | 9 | ||||
| -rw-r--r-- | templates/index.html | 2 | ||||
| -rw-r--r-- | templates/template.html | 9 | ||||
| -rw-r--r-- | templates/thoughts.html | 2 | 
12 files changed, 59 insertions, 15 deletions
| diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e9d0fa4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM ubuntu:latest +MAINTAINER Eden Attenborough "eda@e.email" +RUN apt-get update -y +RUN apt-get install -y python3-pip python-dev build-essential +COPY . /app +WORKDIR /app +RUN pip3 install -r requirements.txt +ENTRYPOINT ["python3"] +CMD ["app.py", "--production"]
\ No newline at end of file @@ -1,3 +1,5 @@ +from paste.translogger import TransLogger +from waitress import serve  from PIL import Image  import configparser  import webbrowser @@ -7,6 +9,7 @@ import services  import random  import parser  import flask +import sys  import os  import io @@ -94,7 +97,8 @@ def get_thought():              thought = True,              dt = "published: " + str(dt),              category = category_name, -            othercategories = db.get_categories_not(category_name) +            othercategories = db.get_categories_not(category_name), +            related = db.get_similar_thoughts(category_name, thought_id)          )  @app.route("/thoughts") @@ -161,13 +165,12 @@ def serve_api_request(infoRequest):      else:          flask.abort(404) -  @app.route("/preview")  def preview():      if "PREVIEW" in os.environ:          with database.Database() as db:              return flask.render_template_string( -                os.environ["PREVIEW"], +                 '{% extends "template.html" %}\n{% block content %}\n' + os.environ["PREVIEW"] + '\n{% endblock %}',                  **get_template_items(os.environ["PREVIEW_TITLE"], db),                  thought = True,                  dt = "preview rendered: " + str(datetime.datetime.now()), @@ -178,4 +181,11 @@ def preview():          flask.abort(404)  if __name__ == "__main__": -    app.run(host = "0.0.0.0", debug = True)
\ No newline at end of file +    try: +        if sys.argv[1] == "--production": +            #serve(TransLogger(app), host='127.0.0.1', port = 6969) +            serve(TransLogger(app), host='0.0.0.0', port = 6969) +        else: +            app.run(host = "0.0.0.0", port = 5001, debug = True) +    except IndexError: +        app.run(host = "0.0.0.0", port = 5001, debug = True)
\ No newline at end of file diff --git a/database.py b/database.py index 06dc34d..bb870b8 100644 --- a/database.py +++ b/database.py @@ -91,6 +91,15 @@ class Database:              WHERE thought_id = %s;""", (id_, ))              return cursor.fetchone() +    def get_similar_thoughts(self, category, id_): +        with self.__connection.cursor() as cursor: +            cursor.execute(""" +            SELECT thought_id, title, dt, category_name FROM thoughts  +            INNER JOIN categories ON thoughts.category_id = categories.category_id  +            WHERE category_name = %s AND thought_id != %s;""",  +            (category, id_)) +            return cursor.fetchall() +      def get_featured_thoughts(self):          with self.__connection.cursor() as cursor:              cursor.execute("SELECT thought_id, title FROM thoughts WHERE featured = 1;") @@ -223,8 +232,5 @@ def request_recent_commits(since = datetime.datetime.now() - datetime.timedelta(      return sorted(out, key = lambda a: a["datetime"], reverse = True)   if __name__ == "__main__": -    import datetime -    start = datetime.datetime.now()      with Database() as db: -        print(db.get_cached_tweets()) -        print("Took: ", (datetime.datetime.now() - start))
\ No newline at end of file +        print(db.get_similar_thoughts("about me", 5))
\ No newline at end of file diff --git a/example.conf b/example.conf index bd16037..1cec18f 100644 --- a/example.conf +++ b/example.conf @@ -29,4 +29,7 @@ user = admin  passwd = ***********  [discord] -username = @jwnskanzkwk#9757
\ No newline at end of file +username = @jwnskanzkwk#9757 + +[github] +access_code = *******************************************
\ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 3644402..07cf1bc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,3 +9,7 @@ PiHole-api  Pillow==8.1.0  python-qbittorrent==0.4.2  PyGithub +lxml +requests +PasteScript==3.2.0 +waitress diff --git a/static/images/shark1.jpg b/static/images/shark1.jpgBinary files differ new file mode 100644 index 0000000..394846c --- /dev/null +++ b/static/images/shark1.jpg diff --git a/static/images/shark2.jpg b/static/images/shark2.jpgBinary files differ new file mode 100644 index 0000000..2c432cd --- /dev/null +++ b/static/images/shark2.jpg diff --git a/static/index.md b/static/index.md index e217a94..31707a7 100644 --- a/static/index.md +++ b/static/index.md @@ -1,4 +1,4 @@ -# haii +# haiiiiiii  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. diff --git a/static/style.css b/static/style.css index 26b337c..0e77ec0 100644 --- a/static/style.css +++ b/static/style.css @@ -100,6 +100,10 @@ article section table td {      max-width: 65%;  } +article img { +    max-width: 65%; +} +  aside {      width: 30%;      padding-left: 15px; @@ -132,8 +136,9 @@ body div article {  }  footer { -    background-color: gray; -    padding: 3px; +    padding: 300px 10px 5px 20px; +    margin-bottom: 300px; +    font-size: xx-small;  }  @media (max-width: 1023px) { diff --git a/templates/index.html b/templates/index.html index fd0bae1..91f7ded 100644 --- a/templates/index.html +++ b/templates/index.html @@ -5,7 +5,7 @@              <h4>recent thoughts:</h4>              <ul>                  {% for id_, title in featured_thoughts %} -                    <li><a href={{"/thought?id=%i" % id_}}>title</a></li> +                    <li><a href={{"/thought?id=%i" % id_}}>{{title}}</a></li>                  {% endfor %}              </ul>          </section> diff --git a/templates/template.html b/templates/template.html index fd65cdb..d72cd0f 100644 --- a/templates/template.html +++ b/templates/template.html @@ -45,6 +45,12 @@                      <ul>                          <li><b><a href={{'/thoughts#'+category.replace(' ', '_')}}>{{category}}</a></b></li>                      </ul> +                    <h5>related thoughts:</h5> +                    <ul> +                        {% for id_, title, dt, category in related %} +                            <li><a href={{"/thought?id=%i" % id_}}>{{title}}</a></li> +                        {% endfor %} +                    </ul>                      <h5>other categories:</h5>                      {% for category_name in othercategories %}                          <ul> @@ -58,7 +64,8 @@                  {% endblock %}              </article>              <footer> -                <p>Web design is my passion</p> +                <p>this site is <a href="/thought?id=3">javascript free</a></p> +                <a href="https://github.com/jwansek/edaweb">sauce code released under gplv3</a>              </footer>          </div>      </body> diff --git a/templates/thoughts.html b/templates/thoughts.html index 8717299..0d768e4 100644 --- a/templates/thoughts.html +++ b/templates/thoughts.html @@ -4,7 +4,7 @@      <h2 id={{category_name.replace(' ', '_')}}>{{category_name}}</h2>      <dl>          {% for id_, title, dt in thoughts %} -        <dt><a href={{'/thought?id=%i' % id_}}>title</a></dt> +        <dt><a href={{'/thought?id=%i' % id_}}>{{title}}</a></dt>          <dd>{{dt}}</dd>          {% endfor %}      </dl> | 
