Migrate to ownlang 2
This commit is contained in:
parent
cf9890f83c
commit
08730913b3
@ -1,4 +1,4 @@
|
|||||||
use ["okhttp", "types"]
|
use okhttp, types
|
||||||
|
|
||||||
class Reddit {
|
class Reddit {
|
||||||
def Reddit(cookie) {
|
def Reddit(cookie) {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use ["std"]
|
use std
|
||||||
|
|
||||||
if (ARGS.length >= 2 && ARGS[0] == "owm") {
|
if (ARGS.length >= 2 && ARGS[0] == "owm") {
|
||||||
use ["files", "json", "java"]
|
use ["files", "json", "java"]
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use ["std", "math", "http", "json", "functional", "files", "jdbc"]
|
use std, math, http, json, functional, files, jdbc
|
||||||
conn = getConnection("jdbc:sqlite:redditimages.db")
|
conn = getConnection("jdbc:sqlite:redditimages.db")
|
||||||
include "own-modules/telegram-bot/TelegramBot.own"
|
include "own-modules/telegram-bot/TelegramBot.own"
|
||||||
include "Reddit.own"
|
include "Reddit.own"
|
||||||
@ -27,18 +27,30 @@ debug(media)
|
|||||||
while (length(media) > 0) {
|
while (length(media) > 0) {
|
||||||
r = bot.sendMediaGroupSync(config.peer, media)
|
r = bot.sendMediaGroupSync(config.peer, media)
|
||||||
if (r.ok) break
|
if (r.ok) break
|
||||||
mediaIndex = try(def() = parseInt(r.description.replaceAll(".*failed.*?#(\\d+).*", "$1")), -1)
|
println r
|
||||||
|
retryAfter = try(def() = parseInt(r.description.replaceAll(".*retry after (\d+).*", "$1")), 0)
|
||||||
|
if (retryAfter > 0) {
|
||||||
|
sleep(retryAfter * 1000 + 2800)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
mediaIndex = try(def() = parseInt(r.description.replaceAll(".*failed.*?#(\d+).*", "$1")), -1)
|
||||||
if (mediaIndex == -1) break
|
if (mediaIndex == -1) break
|
||||||
media = arraySplice(media, mediaIndex - 1, 1)
|
media = arraySplice(media, mediaIndex - 1, 1)
|
||||||
|
sleep(3000)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
thread(def() {
|
||||||
|
sleep(15000)
|
||||||
|
exit(0)
|
||||||
|
})
|
||||||
|
|
||||||
stIsPostExists.close()
|
stIsPostExists.close()
|
||||||
stAddPost.close()
|
stAddPost.close()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
// Helpers
|
// Helpers
|
||||||
def debug(r) {
|
def debug(r) {
|
||||||
// echo(jsonencode(r))
|
echo(jsonencode(r))
|
||||||
}
|
}
|
||||||
|
|
||||||
def strToHashtag(str) =
|
def strToHashtag(str) =
|
||||||
@ -58,7 +70,7 @@ def getCaption(post) {
|
|||||||
}
|
}
|
||||||
return sprintf(
|
return sprintf(
|
||||||
"<a href=\"%s\">%s</a>\n" +
|
"<a href=\"%s\">%s</a>\n" +
|
||||||
"<a href=\"https://teddit.zaggy.nl%s\">🗨 Comments</a>%s\n" +
|
"<a href=\"https://reddit.com%s\">🗨 Comments</a>%s\n" +
|
||||||
"🔎 <a href=\"https://saucenao.com/search.php?url=%s\">SauceNAO</a>, " +
|
"🔎 <a href=\"https://saucenao.com/search.php?url=%s\">SauceNAO</a>, " +
|
||||||
"<a href=\"https://www.alamy.com/search.html?imageurl=%s\">Alamy</a>",
|
"<a href=\"https://www.alamy.com/search.html?imageurl=%s\">Alamy</a>",
|
||||||
safe(post.url), safe(post.title),
|
safe(post.url), safe(post.title),
|
||||||
@ -68,7 +80,3 @@ def getCaption(post) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
sleep(4000)
|
|
||||||
use "java"
|
|
||||||
System = newClass("java.lang.System")
|
|
||||||
System.exit(0)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user