Skip to content

Commit

Permalink
Make grams_gold dynamic if it's URL type
Browse files Browse the repository at this point in the history
Previously, grams_gold will fetch the value if it's URL type and the value will be use it  again and again until it's stopped. The fetch only works on first time it started, after that it doesn't fetch anymore

Now, the grams_gold will fetch the value everytime the app receive gold-rate event
  • Loading branch information
mansuf committed Jun 26, 2024
1 parent 6798f26 commit 57717fb
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions firefly_iii_treasury_id_update/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,19 @@ async def _run_main(http_session, grams_gold, api_key, transaction_id, firefly_i
)
continue

# Determine if grams_gold is a url location, a file, or just hardcoded numbers
if grams_gold.startswith("http"):
res = await http_session.get(grams_gold)
actual_gold = float(await res.text())
elif os.path.exists(grams_gold):
with open(grams_gold, "r") as o:
actual_gold = float(o.read())
else:
actual_gold = float(grams_gold)

data = json.loads(data["data"])
selling_price = get_selling_price(data)
amount = int(selling_price * grams_gold)
amount = int(selling_price * actual_gold)

# TODO: Create update request to REST API firefly-iii
log.info(
Expand Down Expand Up @@ -99,16 +109,6 @@ async def run_main():
elif grams_gold is None:
raise MissingArguments("there is no GRAMS_GOLD in environment")

# Determine if grams_gold is a url location, a file, or just hardcoded numbers
if grams_gold.startswith("http"):
res = await http_session.get(grams_gold)
grams_gold = float(await res.text())
elif os.path.exists(grams_gold):
with open(grams_gold, "r") as o:
grams_gold = float(o.read())
else:
grams_gold = float(grams_gold)

while True:
try:
await _run_main(
Expand Down

0 comments on commit 57717fb

Please sign in to comment.