Преглед на файлове

Add mentions and id to stocks

Foppe Hemminga преди 5 години
родител
ревизия
0a4184537b
променени са 3 файла, в които са добавени 27 реда и са изтрити 18 реда
  1. 8 1
      main.py
  2. 14 14
      stocks.py
  3. 5 3
      view.py

+ 8 - 1
main.py

@@ -28,6 +28,7 @@ def process_drop(this_stock):
     current_price = float(data_latest.current_price)
     quantity = data_latest.available_shares - data_previous.available_shares
     stock_name = this_stock[0]
+    stock_id = this_stock[5]
     npc_drop = False
     total_stocks = data_latest.total_shares
     previous_available_shares = '{:,} / {:,}'.format(data_latest.available_shares,
@@ -35,7 +36,13 @@ def process_drop(this_stock):
     if model.is_npc_drop(data_previous, data_latest):
         npc_drop = True
     message = view.create_message(
-        stock_name, timestamp_latest, current_price, quantity, current_quantity=previous_available_shares, npc_drop=npc_drop)
+        stock_name,
+        timestamp_latest,
+        current_price,
+        quantity,
+        current_quantity=previous_available_shares,
+        npc_drop=npc_drop,
+        stock_id=stock_id)
     print(message)
     if is_drop:
         view.broadcast(message)

+ 14 - 14
stocks.py

@@ -1,23 +1,23 @@
 # stock name, stock number, max price, min(price * drop) in B
 # So this means: stock name, stock # 15 (FHC), max price $335  and a > $10B drop
-d_fhg = ("FHG", 15, 335, 10, "DROP")
-d_yaz = ("YAZ", 8, 60, 10, "DROP")
-d_cnc = ("CNC", 10, 480, 10, "DROP")
-d_wlt = ("WLT", 30, 550, 10, "DROP")
-d_hrg = ("HRG", 22, 355, 10, "DROP")
-d_sym = ("SYM", 16, 480, 10, "DROP")
-d_slag = ("SLAG", 4, 190, 10, "DROP")
-d_grn = ("GRN", 6, 230, 10, "DROP")
-d_tcp = ("TCP", 13, 240, 10, "DROP")
-d_tcb = ("TCB", 2, 420, 10, "DROP")
-d_tct = ("TCT", 9, 195, 10, " DROP")
+d_fhg = ("FHG", 15, 335, 10, "DROP", "703590842170081360")
+d_yaz = ("YAZ", 8, 60, 10, "DROP", "703592171445551256")
+d_cnc = ("CNC", 10, 480, 10, "DROP", "703590841939132477")
+d_wlt = ("WLT", 30, 550, 10, "DROP", "703590836662698025")
+d_hrg = ("HRG", 22, 355, 10, "DROP", "705080339772473486")
+d_sym = ("SYM", 16, 480, 10, "DROP", "703590842006503505")
+d_slag = ("SLAG", 4, 190, 10, "DROP", "703590847220023338")
+d_grn = ("GRN", 6, 230, 10, "DROP", "703590843717648885")
+d_tcp = ("TCP", 13, 240, 10, "DROP", "703590842673266718")
+d_tcb = ("TCB", 2, 420, 10, "DROP", "703590838177103952")
+d_tct = ("TCT", 9, 195, 10, "DROP", "703590846762844160")
 
 # FORECAST
 # Forecast turns >= good from <= average
 # Name, stock_id, max price, min available
-f_fhg = ("FHG", 15, 335, 0, "FORECAST")
-f_wlt = ("WLT", 30, 555, 0, "FORECAST")
-f_sym = ("SYM", 16, 485, 0, "FORECAST")
+f_fhg = ("FHG", 15, 335, 0, "FORECAST", "703590842170081360")
+f_wlt = ("WLT", 30, 555, 0, "FORECAST", "703590836662698025")
+f_sym = ("SYM", 16, 485, 0, "FORECAST", "703590842006503505")
 
 # Put all stocks in this set
 stocks = (d_fhg, d_yaz, d_cnc, d_wlt, d_hrg, d_sym, d_slag, d_grn, d_tcp, d_tcb, f_fhg, f_wlt, f_sym)

+ 5 - 3
view.py

@@ -7,7 +7,7 @@ base_url = 'https://discordapp.com/api/webhooks/'
 
 
 def create_message(name, timestamp, price, quantity, current_quantity=0, forecast_previous="",
-                   forecast_latest="", npc_drop=False):
+                   forecast_latest="", npc_drop=False, stock_id=""):
     """
     Creates the string to be broadcast
     :param name:
@@ -18,6 +18,7 @@ def create_message(name, timestamp, price, quantity, current_quantity=0, forecas
     :param forecast_previous:
     :param forecast_latest:
     :param npc_drop:
+    :param stock_id:
     :return:
     """
     this_time = datetime.utcfromtimestamp(timestamp).strftime('%Y-%m-%d %H:%M')
@@ -25,10 +26,11 @@ def create_message(name, timestamp, price, quantity, current_quantity=0, forecas
     npc = ''
     if npc_drop:
         npc = '*NPC* '
-    this_message = "{}: {}@{} dropped {:,} shares at ${:,.2f} for a grand total of ${:,.1f}B [{}]".format(
+    name = ('<@!'+stock_id+'>' if stock_id else name)
+    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_message = "{}: {} changed from {} to {} with {:,} shares available at ${:,.2f}".format(
             this_time, name, forecast_previous, forecast_latest, current_quantity, price)
     return this_message