Commit 3fe0daba authored by nazarf's avatar nazarf

add asset price to notify

parent 13b20f8f
......@@ -6,7 +6,9 @@ class Notify < ApplicationRecord
require 'telegram/bot'
token = '1711433709:AAFn8Yczyc435Dz7aIDph2fptpGU0doRLhk'
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
......
......@@ -31,9 +31,11 @@
%thead
%tr
%th= "name"
%th= "price"
%th Actions
%tbody
- @trigger.notify.each do |user|
- @trigger.notify.each do |trigger|
%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
\ 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 @@
#
# 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|
t.string "sale_id"
t.bigint "trigger_id"
t.string "price"
t.index ["trigger_id"], name: "index_notifies_on_trigger_id"
end
......
......@@ -3,12 +3,12 @@ namespace :atomic_market do
task grep_sale: :environment do
Trigger.enable.pluck(:collection_name).uniq.each do |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" })
parsed = JSON.parse(http.body_str)
# 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)
# file = open("test.json")
# json = file.read
# parsed = JSON.parse(json)
file = open("test.json")
json = file.read
parsed = JSON.parse(json)
parsed["data"].each do |shop|
name = shop["assets"][0]["template"]["immutable_data"]["name"]
......@@ -22,7 +22,7 @@ namespace :atomic_market do
if trigger.rarity == rarity
if trigger.price.to_i >= price
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
......
......@@ -5,6 +5,7 @@ Telegram::Bot::Client.run(token) do |bot|
case message.text
when '/start'
bot.api.sendMessage(chat_id: message.chat.id, text: "Hello, #{message.from.first_name}")
p message.chat.id
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