aboutsummaryrefslogtreecommitdiff
path: root/vkfeed.lua
diff options
context:
space:
mode:
authorSergey Nazaryev <sergey@nazaryev.ru>2020-09-27 16:53:18 +0300
committerSergey Nazaryev <sergey@nazaryev.ru>2020-09-27 16:53:18 +0300
commitf12b42a254a023ff64bc34ea4e913ae8287fba2a (patch)
tree36a38e796712a80e74ade86e98afa56aaca2cfcb /vkfeed.lua
parentbd00cf94dabd0330e3ef758a440d68541bf312d6 (diff)
downloadvk2rss-master.zip
vk2rss-master.tar.gz
vk2rss-master.tar.bz2
Move to luajit, add pubDateHEADmaster
Diffstat (limited to 'vkfeed.lua')
-rw-r--r--vkfeed.lua42
1 files changed, 42 insertions, 0 deletions
diff --git a/vkfeed.lua b/vkfeed.lua
index 767e544..8bf6cae 100644
--- a/vkfeed.lua
+++ b/vkfeed.lua
@@ -5,6 +5,38 @@ local json = require "cjson"
local API_VK_SERVER = "https://api.vk.com/"
local VK_BASE_DOMAIN = "https://vk.com/"
+local function chsize(char)
+ if not char then
+ return 0
+ elseif char > 240 then
+ return 4
+ elseif char > 225 then
+ return 3
+ elseif char > 192 then
+ return 2
+ else
+ return 1
+ end
+end
+
+local function utf8sub(str, startChar, numChars)
+ local startIndex = 1
+ while startChar > 1 do
+ local char = string.byte(str, startIndex)
+ startIndex = startIndex + chsize(char)
+ startChar = startChar - 1
+ end
+
+ local currentIndex = startIndex
+
+ while numChars > 0 and currentIndex <= #str do
+ local char = string.byte(str, currentIndex)
+ currentIndex = currentIndex + chsize(char)
+ numChars = numChars -1
+ end
+ return str:sub(startIndex, currentIndex - 1)
+end
+
function parseFeed( feedName, jsonText )
local items = {}
@@ -19,6 +51,13 @@ function parseFeed( feedName, jsonText )
local description = item["text"]
local date = os.date( "%a, %d %b %Y %X GMT", item["date"] )
+ local title = description
+ local firstLineIdx = title:find("\n")
+ if( firstLineIdx ~= nil ) then
+ title = title:sub(0, firstLineIdx-1)
+ end
+ title = os.date("[%d.%m.%Y] ", item["date"]) .. utf8sub(title, 0, 30)
+
local photos = {}
local links = {}
local videos = {}
@@ -70,9 +109,12 @@ function getFeed( domain, count, offset, access_token )
url = API_VK_SERVER .. "/method/wall.get?domain=" .. domain .. "&offset=" .. offset .. "&count=" .. count .. "&v=5.44"
end
+
if( access_token ~= nil ) then
url = url .. "&access_token=" .. access_token
end
+
+ print(url)
return os.download( url )
end