Commit 3fe0daba authored by nazarf's avatar nazarf

add asset price to notify

parent 13b20f8f
...@@ -6,7 +6,9 @@ class Notify < ApplicationRecord ...@@ -6,7 +6,9 @@ class Notify < ApplicationRecord
require 'telegram/bot' require 'telegram/bot'
token = '1711433709:AAFn8Yczyc435Dz7aIDph2fptpGU0doRLhk' token = '1711433709:AAFn8Yczyc435Dz7aIDph2fptpGU0doRLhk'
Telegram::Bot::Client.run(token) do |bot| Telegram::Bot::Client.run(token) do |bot|
bot.api.sendMessage(chat_id: "@MarketGrab", text: "collection: #{trigger.name}\nrarity: #{trigger.rarity}\nprice: #{trigger.price}\n#{sale_link}") # 396098026
# @MarketGrab
bot.api.sendMessage(chat_id: "396098026", text: "collection: #{trigger.name}\nrarity: #{trigger.rarity}\nprice: #{price}\n#{sale_link}")
end end
end end
......
...@@ -31,9 +31,11 @@ ...@@ -31,9 +31,11 @@
%thead %thead
%tr %tr
%th= "name" %th= "name"
%th= "price"
%th Actions %th Actions
%tbody %tbody
- @trigger.notify.each do |user| - @trigger.notify.each do |trigger|
%tr %tr
%td= link_to user.sale_id, user.sale_link, target: :_blank %td= link_to trigger.sale_id, trigger.sale_link, target: :_blank
%td= trigger.price.present? if trigger.price
%td %td
\ No newline at end of file
class AddPriceToNotify < ActiveRecord::Migration[5.2]
def change
add_column :notifies, :price, :string
end
end
...@@ -10,11 +10,12 @@ ...@@ -10,11 +10,12 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2021_05_15_143911) do ActiveRecord::Schema.define(version: 2021_05_17_085301) do
create_table "notifies", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| create_table "notifies", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.string "sale_id" t.string "sale_id"
t.bigint "trigger_id" t.bigint "trigger_id"
t.string "price"
t.index ["trigger_id"], name: "index_notifies_on_trigger_id" t.index ["trigger_id"], name: "index_notifies_on_trigger_id"
end end
......
...@@ -3,12 +3,12 @@ namespace :atomic_market do ...@@ -3,12 +3,12 @@ namespace :atomic_market do
task grep_sale: :environment do task grep_sale: :environment do
Trigger.enable.pluck(:collection_name).uniq.each do |collection_name| Trigger.enable.pluck(:collection_name).uniq.each do |collection_name|
triggers = Trigger.find_by(collection_name: collection_name) triggers = Trigger.find_by(collection_name: collection_name)
http = Curl.post("http://wax.api.atomicassets.io/atomicmarket/v1/sales", { :collection_name => triggers.collection_name, :order => "desc", :sort => "created", :symbol => "WAX" }) # http = Curl.post("http://wax.api.atomicassets.io/atomicmarket/v1/sales", { :collection_name => triggers.collection_name, :order => "desc", :sort => "created", :symbol => "WAX" })
parsed = JSON.parse(http.body_str) # parsed = JSON.parse(http.body_str)
# file = open("test.json") file = open("test.json")
# json = file.read json = file.read
# parsed = JSON.parse(json) parsed = JSON.parse(json)
parsed["data"].each do |shop| parsed["data"].each do |shop|
name = shop["assets"][0]["template"]["immutable_data"]["name"] name = shop["assets"][0]["template"]["immutable_data"]["name"]
...@@ -22,7 +22,7 @@ namespace :atomic_market do ...@@ -22,7 +22,7 @@ namespace :atomic_market do
if trigger.rarity == rarity if trigger.rarity == rarity
if trigger.price.to_i >= price if trigger.price.to_i >= price
if Notify.find_by(sale_id: sale_id).blank? if Notify.find_by(sale_id: sale_id).blank?
Notify.create(sale_id: sale_id, trigger: trigger) Notify.create(sale_id: sale_id, trigger: trigger, price: price)
end end
end end
end end
......
...@@ -5,6 +5,7 @@ Telegram::Bot::Client.run(token) do |bot| ...@@ -5,6 +5,7 @@ Telegram::Bot::Client.run(token) do |bot|
case message.text case message.text
when '/start' when '/start'
bot.api.sendMessage(chat_id: message.chat.id, text: "Hello, #{message.from.first_name}") bot.api.sendMessage(chat_id: message.chat.id, text: "Hello, #{message.from.first_name}")
p message.chat.id
end end
end end
end end
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment