Skip to content

Instantly share code, notes, and snippets.

@severak
Created January 30, 2017 16:04
Show Gist options
  • Save severak/064ee5eeba73702d7216aded3e7867ea to your computer and use it in GitHub Desktop.
Save severak/064ee5eeba73702d7216aded3e7867ea to your computer and use it in GitHub Desktop.
--Yet another SOUP.IO downloader/backup tool
--------------------------------------------------------------------------------
--Written by Severak, released with MIT license.
--Feel free to modify.
--
--Example of usage:
--
--lua5.1 soup.lua moomins.soup.io
--(last 20 from public rss)
--lua5.1 soup.lua http://www.soup.io/export/your-secret-hash.rss
--(whole your soup)
--
--Print to standart output in plaintext.
json=require "parsers.dkjson"
http=require "socket.http"
function printb(...)
local arg={...}
local o=""
for k,v in pairs(arg) do
if type(v)=="string" then
o=o..v.." "
elseif type(v)=="number" then
o=o..tostring(v).." "
end
end
print(o)
end
function header(t)
if t then
print(t)
print(string.rep("-",#t))
end
end
if arg[1] and arg[1]:match("(.*).soup.io$") then
url="http://"..arg[1].."/rss"
elseif arg[1] and arg[1]:match("http://.+%.io/export/.+.rss") then
url=arg[1]
else
url="http://everyone.soup.io/rss"
end
data,err=http.request(url)
if err==200 and data then
for k in data:gmatch("<soup:attributes>([^<]*)</soup:attributes>") do
item=json.decode(k)
if item["type"]=="quote" then
printb(item["body"])
printb("--"..item["title"])
print(" ")
elseif item["type"]=="review" then
header(item["title"])
printb(item["body"])
printb("Rating: "..string.rep("*",item["rating"]))
print(" ")
elseif item["type"]=="link" then
if item["title"] then
printb(item["title"].." ["..item["source"].."]")
else
printb(item["source"])
end
printb(item["body"])
print(" ")
elseif item["type"]=="image" then
--dont display images yet
else
header(item["title"])
printb(item["body"])
print(" ")
end
end
else
print(data,err)
print("bad plik")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment