git.alexw.nyc home about git garden
    1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
import sqlite3,urllib
from jinja2 import Environment, PackageLoader, select_autoescape

con = sqlite3.connect("3cb.db")
env = Environment(
        loader=PackageLoader("buildpage"),
        autoescape=select_autoescape()
    )

def card_link(card):
    return f"https://scryfall.com/search?q={urllib.parse.quote_plus(card)}"

env.filters['card_link'] = card_link
env.filters['zip'] = zip

def rows_to_dict(res):
    desc = res.description
    column_names = [col[0] for col in desc]
    return [dict(zip(column_names, row)) for row in res.fetchall()]

def export_html():
    with open("sql/export.sql") as f:
        query = f.read()
        res = con.cursor().execute(query)
        decks = rows_to_dict(res)
        template = env.get_template("index.html")
        print(template.render(decks=decks))

if __name__ == "__main__":
    export_html()