-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1ef9df9
commit 80531dd
Showing
10 changed files
with
144 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
|
||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
pip-wheel-metadata/ | ||
share/python-wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.Phony: run | ||
run: | ||
@echo "Running..." | ||
@gunicorn -b 0.0.0.0:4444 'app:server' | ||
|
||
.Phony: run-dev | ||
run-dev: | ||
@echo "Running..." | ||
@python -m app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from app.server import server | ||
from os import environ | ||
|
||
def main(): | ||
print("Running server") | ||
port = int(environ.get("PORT", 4444)) | ||
|
||
server.run(debug=True, port=port) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from app import main | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import requests | ||
|
||
def fetch_top_news(): | ||
response = requests.get('https://hacker-news.firebaseio.com/v0/topstories.json') | ||
return response.json() | ||
|
||
def fetch_details_for_story(story_id): | ||
response = requests.get(f'https://hacker-news.firebaseio.com/v0/item/{story_id}.json') | ||
return response.json() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from flask import Flask, render_template | ||
from app.api import fetch_top_news, fetch_details_for_story | ||
|
||
server = Flask(__name__) | ||
|
||
@server.route("/") | ||
def root(): | ||
news = fetch_top_news() | ||
return render_template("index.html", posts=news[:10]) | ||
|
||
@server.route("/story/<item_id>/link") | ||
def story_link(item_id): | ||
details = fetch_details_for_story(item_id) | ||
return render_template("_story_link.html", details=details) | ||
|
||
@server.route("/story/<item_id>/details") | ||
def story_details(item_id): | ||
details = fetch_details_for_story(item_id) | ||
return render_template("_story_details.html", details=details) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<h2>Story Details</h2> | ||
<div> | ||
<div>{{details.title}}</div> | ||
<div>{{details.text}}</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<li class="p-2"> | ||
<a href="{{ details.url }}">{{ details.title }}</a> | ||
<button class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-1 px-2 rounded" | ||
hx-get="/story/{{ details.id }}/details" hx-target="#story-details" hx-swap="innerHTML" hx-trigger="click" | ||
hx-indicator="#loading"> | ||
Show preview | ||
</button> | ||
</li> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
|
||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width" /> | ||
|
||
<script src="https://unpkg.com/[email protected]"></script> | ||
<script src="https://unpkg.com/htmx.org/dist/ext/ws.js"></script> | ||
<script src="https://cdn.tailwindcss.com"></script> | ||
|
||
<style type="text/css"> | ||
.htmx-indicator { | ||
opacity: 0; | ||
transition: opacity 500ms ease-in; | ||
} | ||
|
||
.htmx-request .htmx-indicator { | ||
opacity: 1 | ||
} | ||
</style> | ||
|
||
<title>Latest Tech News</title> | ||
</head> | ||
|
||
<body> | ||
<div class="w-2/3 mx-auto p-4"> | ||
<h1 class="uppercase text-blue-400 font-bold"> | ||
Latest Stories | ||
</h1> | ||
|
||
<ul> | ||
{% for post in posts %} | ||
<li hx-get="/story/{{ post }}/link" hx-target="this" hx-swap="outerHTML" hx-trigger="load">loading...</li> | ||
{% endfor %} | ||
</ul> | ||
</div> | ||
|
||
<section class="w-1/2 mx-auto p-4"> | ||
<div id="story-details"></div> | ||
<span id="loading" class="htmx-indicator">Loading details...</span> | ||
</section> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Flask==2.3.3 | ||
requests==2.31.0 | ||
gunicorn==21.2.0 |