Expose user agent as envvar

This commit is contained in:
Midgard 2019-06-21 13:06:51 +02:00
parent da872e8aab
commit 156657a2fe
Signed by: midgard
GPG key ID: 511C112F1331BBB4

21
tab
View file

@ -6,11 +6,17 @@ import os
import requests
ME = os.getenv("TAB_ME")
TOKEN = os.getenv("TAB_TOKEN")
ME = os.getenv("TAB_ME")
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")
FOOD_ACCOUNT = os.getenv("LEDGER_FOOD_ACCOUNT", "Expenses:Zeuskelder:Food")
TAP_ACCOUNT = os.getenv("LEDGER_TAP_ACCOUNT", default="Expenses:Zeuskelder:Drinks and snacks")
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):
@ -70,8 +76,11 @@ def formatted_transactions(transactions, final_balance, me):
def main(me, token, file=sys.stdout):
def get(path):
return requests.get(
f"https://tab.zeus.gent{path}",
headers={"Accept": "application/json", "Authorization": f"Token token={token}"}
f"{BASE_URI}{path}",
headers={
"Accept": "application/json", "Authorization": f"Token token={token}",
"User-Agent": USER_AGENT
}
).json()
balance = get(f"/users/{me}")["balance"]