This commit is contained in:
mwiegand 2022-06-01 16:56:33 +02:00
parent f86dec5676
commit c78bd5cf5d
8 changed files with 106 additions and 0 deletions

6
.envrc Normal file
View file

@ -0,0 +1,6 @@
#!/usr/bin/env bash
python3 -m venv .venv
source ./.venv/bin/activate
PATH_add .venv/bin
python3 -m pip install --upgrade pip

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
.venv
__pycache__

View file

@ -0,0 +1,6 @@
```shell
export DB_NAME=test
export DB_USER=test
export DB_PASSWORD=test
FLASK_APP=steam_chat_viewer flask run
```

2
requirements.txt Normal file
View file

@ -0,0 +1,2 @@
flask
pg8000

6
setup.py Normal file
View file

@ -0,0 +1,6 @@
from setuptools import find_packages, setup
setup(
name="steam_chat_viewer",
packages=find_packages(),
)

View file

@ -0,0 +1,20 @@
#!/usr/bin/env python3
from os import environ
from flask import Flask, request
from subprocess import check_output
import json
from .pg import query
app = Flask(__name__)
@app.route('/')
def home():
return str(query(
'''
SELECT FROM steam_chat_logger
ORDER BY date
LIMIT 10
'''
).rows)

40
steam_chat_viewer/pg.py Normal file
View file

@ -0,0 +1,40 @@
from os import environ
from collections import namedtuple
import pg8000
from flask import g
DBResult = namedtuple('Result', 'rows rowcount')
def db():
if not hasattr(g, 'db_connection'):
g.db_connection = pg8000.connect(
database=environ['DB_NAME'],
user=environ['DB_USER'],
password=environ['DB_PASSWORD'],
)
return g.db_connection
def query(query, **params):
try:
cursor = db().cursor()
cursor.paramstyle = "named"
cursor.execute(query, params)
db().commit()
if cursor._cached_rows:
columns = [x[0] for x in cursor.description]
rows = [dict(zip(columns, row)) for row in cursor.fetchall()]
# rdef = namedtuple('row', ' '.join([x[0] for x in cursor.description]))
# rows = list(map(rdef._make, cursor.fetchall()))
else:
rows = []
return DBResult(
rows=rows,
rowcount=cursor.rowcount,
)
except:
db().rollback()
raise

24
zprofile Normal file
View file

@ -0,0 +1,24 @@
# /etc/zsh/zprofile: system-wide .zprofile file for zsh(1).
#
# This file is sourced only for login shells (i.e. shells
# invoked with "-" as the first character of argv[0], and
# shells invoked with the -l flag.)
#
# Global Order: zshenv, zprofile, zshrc, zlogin
alias s='sudo su - root -s /usr/bin/zsh'
function hhtop {
# mkdir -p ~/.config/htop
# cp /etc/htoprc.global ~/.config/htop/htoprc
# cp /etc/htoprc.global ~/.htoprc
rm -rf ~/.config/htop ~/.htoprc
htop
}
ZSH_THEME=bw
DISABLE_AUTO_UPDATE=true
plugins=(
zsh-autosuggestions
)
source /etc/zsh/oh-my-zsh/oh-my-zsh.sh