| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- import os
- from datetime import datetime
- import requests
- def create_message(name, timestamp, price, quantity, current_quantity=0, forecast_previous="",
- forecast_latest="", npc_drop=False):
- """
- Creates the string to be broadcast
- :param name:
- :param timestamp:
- :param price:
- :param quantity:
- :param current_quantity:
- :param forecast_previous:
- :param forecast_latest:
- :param npc_drop:
- :return:
- """
- this_time = datetime.utcfromtimestamp(timestamp).strftime('%Y-%m-%d %H:%M')
- this_drop_decimal = quantity * price / 1e9
- npc = ''
- if npc_drop:
- npc = '*NPC* '
- this_message = "{}: {}{} dropped {:,} shares at ${:,.2f} for a grand total of ${:,.1f}B [{:,}]".format(
- this_time, npc, name, quantity, price, this_drop_decimal, current_quantity)
- if forecast_previous and forecast_latest:
- this_message = "{}: {} changed from {} to {} with {:,} shares available at ${:,.2f}".format(
- this_time, name, forecast_previous, forecast_latest, current_quantity, price)
- return this_message
- def broadcast(this_message):
- """
- :param this_message:
- :return:
- """
- # development only
- # load_dotenv()
- url = os.environ["BROADCAST_URL"]
- json = {'content': this_message}
- response = requests.post(url, json=json)
- if response.status_code in [200, 204]:
- print("Webhook executed")
- else:
- print("status code {}: {}".format(response.status_code, response.content.decode("utf-8")))
|