Expose user agent as envvar
This commit is contained in:
parent
da872e8aab
commit
156657a2fe
1 changed files with 15 additions and 6 deletions
21
tab
21
tab
|
@ -6,11 +6,17 @@ import os
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
|
||||||
ME = os.getenv("TAB_ME")
|
ME = os.getenv("TAB_ME")
|
||||||
TOKEN = os.getenv("TAB_TOKEN")
|
TOKEN = os.getenv("TAB_TOKEN")
|
||||||
|
BASE_URI = os.getenv("TAB_BASE_URI", default="https://tab.zeus.gent")
|
||||||
|
|
||||||
TAP_ACCOUNT = os.getenv("LEDGER_TAP_ACCOUNT", "Expenses:Zeuskelder:Drinks and snacks")
|
TAP_ACCOUNT = os.getenv("LEDGER_TAP_ACCOUNT", default="Expenses:Zeuskelder:Drinks and snacks")
|
||||||
FOOD_ACCOUNT = os.getenv("LEDGER_FOOD_ACCOUNT", "Expenses:Zeuskelder:Food")
|
FOOD_ACCOUNT = os.getenv("LEDGER_FOOD_ACCOUNT", default="Expenses:Zeuskelder:Food")
|
||||||
|
|
||||||
|
TAB2LEDGER_NAME = "tab2ledger"
|
||||||
|
TAB2LEDGER_VERSION = "1.0"
|
||||||
|
TAB2LEDGER_URL = "https://git.zeus.gent/midgard/tab2ledger"
|
||||||
|
USER_AGENT = os.getenv("TAB2LEDGER_USER_AGENT", default=f"{TAB2LEDGER_NAME} {TAB2LEDGER_VERSION} ({TAB2LEDGER_URL})")
|
||||||
|
|
||||||
|
|
||||||
def formatted_price(cents):
|
def formatted_price(cents):
|
||||||
|
@ -70,8 +76,11 @@ def formatted_transactions(transactions, final_balance, me):
|
||||||
def main(me, token, file=sys.stdout):
|
def main(me, token, file=sys.stdout):
|
||||||
def get(path):
|
def get(path):
|
||||||
return requests.get(
|
return requests.get(
|
||||||
f"https://tab.zeus.gent{path}",
|
f"{BASE_URI}{path}",
|
||||||
headers={"Accept": "application/json", "Authorization": f"Token token={token}"}
|
headers={
|
||||||
|
"Accept": "application/json", "Authorization": f"Token token={token}",
|
||||||
|
"User-Agent": USER_AGENT
|
||||||
|
}
|
||||||
).json()
|
).json()
|
||||||
|
|
||||||
balance = get(f"/users/{me}")["balance"]
|
balance = get(f"/users/{me}")["balance"]
|
||||||
|
|
Loading…
Reference in a new issue