Expose user agent as envvar
This commit is contained in:
parent
da872e8aab
commit
156657a2fe
1 changed files with 15 additions and 6 deletions
17
tab
17
tab
|
@ -8,9 +8,15 @@ import requests
|
|||
|
||||
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"]
|
||||
|
|
Loading…
Reference in a new issue