Skip to content

Commit

Permalink
feat: code quality (#11)
Browse files Browse the repository at this point in the history
* feat: code quality
* fixus
  • Loading branch information
dni committed Aug 30, 2024
1 parent 1ca189d commit d4cdf8e
Show file tree
Hide file tree
Showing 22 changed files with 2,921 additions and 158 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: lint
on:
push:
branches:
- main
pull_request:

jobs:
lint:
uses: lnbits/lnbits/.github/workflows/lint.yml@dev
15 changes: 7 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+"
- 'v[0-9]+.[0-9]+.[0-9]+'

jobs:

release:
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -34,12 +33,12 @@ jobs:
- name: Create pull request in extensions repo
env:
GH_TOKEN: ${{ secrets.EXT_GITHUB }}
repo_name: "${{ github.event.repository.name }}"
tag: "${{ github.ref_name }}"
branch: "update-${{ github.event.repository.name }}-${{ github.ref_name }}"
title: "[UPDATE] ${{ github.event.repository.name }} to ${{ github.ref_name }}"
body: "https://github.com/lnbits/${{ github.event.repository.name }}/releases/${{ github.ref_name }}"
archive: "https://github.com/lnbits/${{ github.event.repository.name }}/archive/refs/tags/${{ github.ref_name }}.zip"
repo_name: '${{ github.event.repository.name }}'
tag: '${{ github.ref_name }}'
branch: 'update-${{ github.event.repository.name }}-${{ github.ref_name }}'
title: '[UPDATE] ${{ github.event.repository.name }} to ${{ github.ref_name }}'
body: 'https://github.com/lnbits/${{ github.event.repository.name }}/releases/${{ github.ref_name }}'
archive: 'https://github.com/lnbits/${{ github.event.repository.name }}/archive/refs/tags/${{ github.ref_name }}.zip'
run: |
cd lnbits-extensions
git checkout -b $branch
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
__pycache__
node_modules
.mypy_cache
.venv
12 changes: 12 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"semi": false,
"arrowParens": "avoid",
"insertPragma": false,
"printWidth": 80,
"proseWrap": "preserve",
"singleQuote": true,
"trailingComma": "none",
"useTabs": false,
"bracketSameLine": false,
"bracketSpacing": false
}
47 changes: 47 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
all: format check

format: prettier black ruff

check: mypy pyright checkblack checkruff checkprettier

prettier:
poetry run ./node_modules/.bin/prettier --write .
pyright:
poetry run ./node_modules/.bin/pyright

mypy:
poetry run mypy .

black:
poetry run black .

ruff:
poetry run ruff check . --fix

checkruff:
poetry run ruff check .

checkprettier:
poetry run ./node_modules/.bin/prettier --check .

checkblack:
poetry run black --check .

checkeditorconfig:
editorconfig-checker

test:
PYTHONUNBUFFERED=1 \
DEBUG=true \
poetry run pytest
install-pre-commit-hook:
@echo "Installing pre-commit hook to git"
@echo "Uninstall the hook with poetry run pre-commit uninstall"
poetry run pre-commit install

pre-commit:
poetry run pre-commit run --all-files


checkbundle:
@echo "skipping checkbundle"
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Gerty - <small>[LNbits](https://github.com/lnbits/lnbits) extension</small>

<small>For more about LNBits extension check [this tutorial](https://github.com/lnbits/lnbits/wiki/LNbits-Extensions)</small>

### Your Desktop Bitcoin Assistant
Expand Down
18 changes: 6 additions & 12 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from fastapi import APIRouter

from lnbits.db import Database
from lnbits.helpers import template_renderer

db = Database("ext_gerty")
from .crud import db
from .views import gerty_generic_router
from .views_api import gerty_api_router

gerty_static_files = [
{
Expand All @@ -12,13 +11,8 @@
}
]


gerty_ext: APIRouter = APIRouter(prefix="/gerty", tags=["Gerty"])
gerty_ext.include_router(gerty_generic_router)
gerty_ext.include_router(gerty_api_router)


def gerty_renderer():
return template_renderer(["gerty/templates"])


from .views import * # noqa: F401,F403
from .views_api import * # noqa: F401,F403
__all__ = ["db", "gerty_ext", "gerty_static_files"]
22 changes: 12 additions & 10 deletions crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
from typing import List, Optional, Union

import httpx
from loguru import logger

from lnbits.db import Database
from lnbits.helpers import urlsafe_short_hash
from loguru import logger

from . import db
from .models import CreateGerty, Gerty, MempoolEndpoint

db = Database("ext_gerty")


async def create_gerty(wallet_id: str, data: CreateGerty) -> Gerty:
gerty_id = urlsafe_short_hash()
Expand Down Expand Up @@ -83,17 +84,17 @@ async def delete_gerty(gerty_id: str) -> None:
#############MEMPOOL###########


async def get_mempool_info(endPoint: str, gerty) -> dict:
logger.debug(endPoint)
async def get_mempool_info(end_point: str, gerty) -> dict:
logger.debug(end_point)
endpoints = MempoolEndpoint()
url = ""
for endpoint in endpoints:
if endPoint == endpoint[0]:
if end_point == endpoint[0]:
url = endpoint[1]
row = await db.fetchone(
"SELECT * FROM gerty.mempool WHERE endpoint = ? AND mempool_endpoint = ?",
(
endPoint,
end_point,
gerty.mempool_endpoint,
),
)
Expand All @@ -116,7 +117,7 @@ async def get_mempool_info(endPoint: str, gerty) -> dict:
(
mempool_id,
json.dumps(response.json()),
endPoint,
end_point,
time.time(),
gerty.mempool_endpoint,
),
Expand All @@ -126,11 +127,12 @@ async def get_mempool_info(endPoint: str, gerty) -> dict:
async with httpx.AsyncClient() as client:
response = await client.get(gerty.mempool_endpoint + url)
await db.execute(
"UPDATE gerty.mempool SET data = ?, time = ? WHERE endpoint = ? AND mempool_endpoint = ?",
"UPDATE gerty.mempool SET data = ?, time = ? "
"WHERE endpoint = ? AND mempool_endpoint = ?",
(
json.dumps(response.json()),
time.time(),
endPoint,
end_point,
gerty.mempool_endpoint,
),
)
Expand Down
2 changes: 1 addition & 1 deletion description.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ Gerty, a Bitcoin Assistant controlled from your LNbits wallet.

This extension can be used as a standalone to display a dashboard of Bitcoin information or you can build / buy the Gerty hardware to display the information on an eink display.

Buy assembled from the LNbits shop https://shop.lnbits.com/product/gerty-a-bitcoin-assistant
Buy assembled from the LNbits shop https://shop.lnbits.com/product/gerty-a-bitcoin-assistant
Loading

0 comments on commit d4cdf8e

Please sign in to comment.