Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Screenshot 2024-06-02 162829.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
85 changes: 85 additions & 0 deletions news-feed-bot-$Semutireng22
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
local json = require("json")

-- t3OfBkuh99NuQu6EO1B11s_w2XKcT6BiUJ2jd8RBDoc
_0RBIT = "BaMK1dfayo75s3q1ow6AO64UDpD9SEFbeE8xYrY2fyQ"
_0RBT_TOKEN = "BUhZLMwQ6yZHguLtJYA5lLUa9LQzLXMXRfaq9FVcPJc"

-- Base URL for News API
URL = "https://saurav.tech/NewsAPI/top-headlines/category/health/in.json"
FEE_AMOUNT = "1000000000000" -- 1 $0RBT

NEWS = NEWS or {}

--[[
Function to send the latest news.
]]
function getNews(msg)
local news = json.encode(NEWS)
Handlers.utils.reply(news)(msg)
end

--[[
Function to fetch the news using the 0rbit.
]]
function fetchNews()
Send({
Target = _0RBT_TOKEN,
Action = "Transfer",
Recipient = _0RBIT,
Quantity = FEE_AMOUNT,
["X-Url"] = URL,
["X-Action"] = "Get-Real-Data"
})
print(Colors.green .. "GET Request sent to the 0rbit process.")
end

--[[
Function to update the news.
]]
function receiveData(msg)
local res = json.decode(msg.Data);
local articles;
local article;
if res.status == "ok" then
articles = res.articles;
for k, v in pairs(articles) do
article =
{
title = v.title,
description = v.description,
url = v.url
}
table.insert(NEWS, article)
end
print("News Updated")
else
print("Error in fetching news")
end
end

--[[
Handlers to get latest news.
]]
Handlers.add(
"GetNews",
Handlers.utils.hasMatchingTag("Action", "Get-News"),
getNews
)

--[[
Fetch News Handler to fetch the news using 0rbit.
]]
Handlers.add(
"FetchNews",
Handlers.utils.hasMatchingTag("Action", "Fetch-News"),
fetchNews
)

--[[
Handlers to receive data from the 0rbit process.
]]
Handlers.add(
"ReceiveData",
Handlers.utils.hasMatchingTag("Action", "Receive-Response"),
receiveData
)