From 1a80919b02cd0321e73b2370230781778a8cd7c5 Mon Sep 17 00:00:00 2001 From: Coshift <146256297+Coshift@users.noreply.github.com> Date: Thu, 23 May 2024 19:22:06 +0400 Subject: [PATCH 1/4] Create 0rbit-Price-Feed.lua --- price-feed-bot-Coshift/0rbit-Price-Feed.lua | 57 +++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 price-feed-bot-Coshift/0rbit-Price-Feed.lua diff --git a/price-feed-bot-Coshift/0rbit-Price-Feed.lua b/price-feed-bot-Coshift/0rbit-Price-Feed.lua new file mode 100644 index 00000000..d13a3a4a --- /dev/null +++ b/price-feed-bot-Coshift/0rbit-Price-Feed.lua @@ -0,0 +1,57 @@ +-- PID 8ODUlnYXLWqrxd1OXLh0rZRWyjT3PdIsCA2-Ks1FiTA + +local json = require("json") + +_ORBIT = "WSXUI2JjYUldJ7CKq9wE1MGwXs-ldzlUlHOQszwQe0s" + +function handleError(msg, errorMessage) + ao.send({ + Target = msg.From, + Tags = { + Action = "Error", + ["Message-Id"] = msg.Id, + Error = errorMessage + } + }) +end + +Handlers.add("Coshift", + Handlers.utils.hasMatchingTag("Action", "Sponsored-Get-Request"), + function(msg) + local token = msg.Tags.Token + if not token then + handleError(msg, "Token not provided") + return + end + + local url = "https://api.coingecko.com/api/v3/simple/price?ids=" .. token .. "&vs_currencies=usd" + ao.send({ + Target = _ORBIT, + Action = "Get-Real-Data", + Url = url + }) + print("Pricefetch request sent for " .. token) + end +) + +Handlers.add("ReceiveData", + Handlers.utils.hasMatchingTag("Action", "Receive-Response"), + function(msg) + print("Received data: " .. msg.Data) + local res = json.decode(msg.Data) + local token = msg.Tags.Token + if res[token] and res[token].usd then + ao.send({ + Target = msg.From, + Tags = { + Action = "Price-Response", + ["Message-Id"] = msg.Id, + Price = res[token].usd + } + }) + print("Price of " .. token .. " is " .. res[token].usd) + else + handleError(msg, "Failed to fetch price") + end + end +) From 4e249126b2169c4b1db920f62c4454c6aeb5788b Mon Sep 17 00:00:00 2001 From: Coshift <146256297+Coshift@users.noreply.github.com> Date: Thu, 23 May 2024 19:22:31 +0400 Subject: [PATCH 2/4] Create 0rbit-Price-Feed.jpg --- price-feed-bot-Coshift/0rbit-Price-Feed.jpg | 1 + 1 file changed, 1 insertion(+) create mode 100644 price-feed-bot-Coshift/0rbit-Price-Feed.jpg diff --git a/price-feed-bot-Coshift/0rbit-Price-Feed.jpg b/price-feed-bot-Coshift/0rbit-Price-Feed.jpg new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/price-feed-bot-Coshift/0rbit-Price-Feed.jpg @@ -0,0 +1 @@ + From 16613a4bcae176eb34a3115592b899e048f5166b Mon Sep 17 00:00:00 2001 From: Coshift <146256297+Coshift@users.noreply.github.com> Date: Thu, 23 May 2024 19:32:14 +0400 Subject: [PATCH 3/4] Create 0rbit-News-Feed.lua --- news-feed-bot-Coshift/0rbit-News-Feed.lua | 71 +++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 news-feed-bot-Coshift/0rbit-News-Feed.lua diff --git a/news-feed-bot-Coshift/0rbit-News-Feed.lua b/news-feed-bot-Coshift/0rbit-News-Feed.lua new file mode 100644 index 00000000..3ec0e29b --- /dev/null +++ b/news-feed-bot-Coshift/0rbit-News-Feed.lua @@ -0,0 +1,71 @@ +-- ao.id tj03skmKEdIkapH5ixKaJIla5irHLAV6s1dkCfYjf6I + +local json = require("json") +local _0RBIT = "WSXUI2JjYUldJ7CKq9wE1MGwXs-ldzlUlHOQszwQe0s" +local URL = "https://api.theblockbeats.news/v1/open-api/open-flash?size=5&page=1&type=push" +ReceivedData = ReceivedData or {} + +Handlers.add( + "Get-Request", + Handlers.utils.hasMatchingTag("Action", "Sponsored-Get-Request"), + function(msg) + Send({ + Target = _0RBIT, + Action = "Get-Real-Data", + Url = URL + }) + print("GET Request sent to the 0rbit process.") + end +) + +Handlers.add( + "Receive-Data", + Handlers.utils.hasMatchingTag("Action", "Receive-Response"), + function(msg) + if not msg.Data then + print("No data received.") + return + end + + local res = json.decode(msg.Data) + + ReceivedData1 = res.data.data + local extractedData = {} + for k, v in ipairs(ReceivedData1) do + table.insert(extractedData, { + title = v.title, + description = v.content + }) + ReceivedData = extractedData + + end + print("Processed data: " .. json.encode(ReceivedData1)) + end +) + +local function getLatestData(msg) + local data = json.encode(ReceivedData) + Handlers.utils.reply(data)(msg) + print("Latest data sent: " .. data) +end + +Handlers.add( + "GetLatestData", + Handlers.utils.hasMatchingTag("Action", "Get-Latest-Data"), + getLatestData +) + +local function fetchNewsPeriodically() + Send({ + Target = _0RBIT, + Action = "Get-Real-Data", + Url = URL + }) + print("Periodic GET Request sent to the 0rbit process.") +end + +Handlers.add( + "CronTick", + Handlers.utils.hasMatchingTag("Action", "Cron"), + fetchNewsPeriodically +) From 48df0d7e5a653fb1e163cb01ffe0720ebfb6b75f Mon Sep 17 00:00:00 2001 From: Coshift <146256297+Coshift@users.noreply.github.com> Date: Thu, 23 May 2024 19:33:35 +0400 Subject: [PATCH 4/4] Create 0rbit-News-Feed.jpg --- news-feed-bot-Coshift/0rbit-News-Feed.jpg | 1 + 1 file changed, 1 insertion(+) create mode 100644 news-feed-bot-Coshift/0rbit-News-Feed.jpg diff --git a/news-feed-bot-Coshift/0rbit-News-Feed.jpg b/news-feed-bot-Coshift/0rbit-News-Feed.jpg new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/news-feed-bot-Coshift/0rbit-News-Feed.jpg @@ -0,0 +1 @@ +