|
|
@ -46,6 +46,16 @@ type |
|
|
|
image_height*: int |
|
|
|
image_height*: int |
|
|
|
created_at*: string |
|
|
|
created_at*: string |
|
|
|
updated_at*: string |
|
|
|
updated_at*: string |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proc filterTags*(p: var seq[dbPost], tags: string): seq[dbPost] = |
|
|
|
|
|
|
|
let stags: seq[string] = tags.split(" ") |
|
|
|
|
|
|
|
p.filter((dbPost) => ( |
|
|
|
|
|
|
|
for tag in stags: |
|
|
|
|
|
|
|
if not ((tag in dbPost.tag_string.split(" ")) or (tag[0] == '-' and tag[1 .. ^1] notin dbPost.tag_string.split(" "))): |
|
|
|
|
|
|
|
return false |
|
|
|
|
|
|
|
return true |
|
|
|
|
|
|
|
)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proc newDanbooru*(): danbooru = |
|
|
|
proc newDanbooru*(): danbooru = |
|
|
@ -55,15 +65,19 @@ proc newDanbooru*(): danbooru = |
|
|
|
proc post*(d: danbooru, id: int): dbPost = |
|
|
|
proc post*(d: danbooru, id: int): dbPost = |
|
|
|
to(d.c.getContent(d.endpoint&fmt"/posts/{id}.json").parseJson(), dbPost) |
|
|
|
to(d.c.getContent(d.endpoint&fmt"/posts/{id}.json").parseJson(), dbPost) |
|
|
|
|
|
|
|
|
|
|
|
proc searchPosts*(d: danbooru, tags: string, random: bool = false): seq[dbPost] = |
|
|
|
proc searchPosts*(d: danbooru, tags: string, random: bool = false, page: string = "1"): seq[dbPost] = |
|
|
|
to(d.c.getContent(d.endpoint&fmt"/posts.json?tags="&tags&"&random=" & $random).parseJson(), seq[dbPost]) |
|
|
|
to(d.c.getContent(d.endpoint&fmt"/posts.json?tags="&tags&"&random=" & $random & "&page=" & $page).parseJson(), seq[dbPost]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proc filterTags*(p: var seq[dbPost], tags: string): seq[dbPost] = |
|
|
|
proc returnTaggedPosts*(d: danbooru, tags: string, filterTags: string, num: int = 10): seq[dbPost] = |
|
|
|
let stags: seq[string] = tags.split(" ") |
|
|
|
var page: int = 1 |
|
|
|
p.filter((dbPost) => ( |
|
|
|
while result.len < num: |
|
|
|
for tag in stags: |
|
|
|
var tmp: seq[dbPost] |
|
|
|
if not ((tag in dbPost.tag_string.split(" ")) or (tag[0] == '-' and tag[1 .. ^1] notin dbPost.tag_string.split(" "))): |
|
|
|
try: |
|
|
|
return false |
|
|
|
tmp = d.searchPosts(tags, random = false, page = $page) |
|
|
|
return true |
|
|
|
except: |
|
|
|
)) |
|
|
|
discard |
|
|
|
|
|
|
|
tmp = tmp.filterTags(filterTags) |
|
|
|
|
|
|
|
result &= tmp |
|
|
|
|
|
|
|
page += 1 |
|
|
|
|
|
|
|
result = result[0 ..< num] |
|
|
|