diff --git a/Screenshot 2024-06-02 162829.png b/Screenshot 2024-06-02 162829.png new file mode 100644 index 00000000..c90d3314 Binary files /dev/null and b/Screenshot 2024-06-02 162829.png differ diff --git a/news-feed-bot-$Semutireng22 b/news-feed-bot-$Semutireng22 new file mode 100644 index 00000000..2294cf7b --- /dev/null +++ b/news-feed-bot-$Semutireng22 @@ -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 +) \ No newline at end of file