move variables to environment.

This commit is contained in:
fiatjaf 2019-12-13 19:41:39 -03:00
parent e5dc309eb1
commit 978854fc72
4 changed files with 21 additions and 12 deletions

6
.gitignore vendored Executable file → Normal file
View File

@ -13,3 +13,9 @@ __pycache__
.pytest_cache .pytest_cache
htmlcov htmlcov
Pipfile.lock Pipfile.lock
*.swo
*.swp
*.pyo
*.pyc
*.env
venv

View File

@ -4,19 +4,17 @@ import time
from flask import Flask, jsonify, render_template, request from flask import Flask, jsonify, render_template, request
from .db import Database, DEFAULT_PATH from .db import Database
from .helpers import encrypt from .helpers import encrypt
from .settings import INVOICE_KEY, ADMIN_KEY, API_ENDPOINT, DATABASE_PATH
INVOICE_KEY = "YOUR-LNTXBOT-INVOICE-KEY" # In the lntxbot bot on telegram type "/api"
ADMIN_KEY = "YOUR-LNTXBOT-ADMIN-KEY"
API_ENDPOINT = "YOUR-LNTXBOT-API-BASE-URL"
app = Flask(__name__) app = Flask(__name__)
def db_connect(db_path=DEFAULT_PATH): def db_connect(db_path=DATABASE_PATH):
import sqlite3 import sqlite3
con = sqlite3.connect(db_path) con = sqlite3.connect(db_path)
return con return con
@ -129,7 +127,7 @@ def lnurlwallet():
cur = con.cursor() cur = con.cursor()
print(thewal) print(thewal)
cur.execute("select * from wallets WHERE user = '" + str(theid) + "'") cur.execute("select * from wallets WHERE user = '" + str(theid) + "'")
rows = cur.fetchall() # rows = cur.fetchall()
con.commit() con.commit()
cur.close() cur.close()
return render_template( return render_template(

View File

@ -1,13 +1,10 @@
import os
import sqlite3 import sqlite3
from .settings import DATABASE_PATH
LNBITS_PATH = os.path.dirname(os.path.realpath(__file__))
DEFAULT_PATH = os.path.join(LNBITS_PATH, "data", "database.sqlite3")
class Database: class Database:
def __init__(self, db_path: str = DEFAULT_PATH): def __init__(self, db_path: str = DATABASE_PATH):
self.path = db_path self.path = db_path
self.connection = sqlite3.connect(db_path) self.connection = sqlite3.connect(db_path)
self.cursor = self.connection.cursor() self.cursor = self.connection.cursor()

8
LNbits/settings.py Normal file
View File

@ -0,0 +1,8 @@
import os
INVOICE_KEY = os.getenv("INVOICE_KEY")
ADMIN_KEY = os.getenv("ADMIN_KEY")
API_ENDPOINT = os.getenv("API_ENDPOINT")
LNBITS_PATH = os.path.dirname(os.path.realpath(__file__))
DATABASE_PATH= os.getenv("DATABASE_PATH") or os.path.join(LNBITS_PATH, "data", "database.sqlite3")