mirror of
https://github.com/zedeus/nitter
synced 2026-09-06 07:09:31 +00:00
Add user search
This commit is contained in:
parent
eeae28da0c
commit
30bab22dae
16 changed files with 211 additions and 66 deletions
|
|
@ -1,93 +0,0 @@
|
|||
import strutils, strformat, sequtils
|
||||
|
||||
import types
|
||||
|
||||
const
|
||||
separators = @["AND", "OR"]
|
||||
validFilters = @[
|
||||
"media", "images", "twimg", "videos",
|
||||
"native_video", "consumer_video", "pro_video",
|
||||
"links", "news", "quote", "mentions",
|
||||
"replies", "retweets", "nativeretweets",
|
||||
"verified", "safe"
|
||||
]
|
||||
|
||||
# Experimental, this might break in the future
|
||||
# Till then, it results in shorter urls
|
||||
const
|
||||
posPrefix = "thGAVUV0VFVBa"
|
||||
posSuffix = "EjUAFQAlAFUAFQAA"
|
||||
|
||||
proc initQuery*(filters, includes, excludes, separator, text: string;
|
||||
name=""): Query =
|
||||
var sep = separator.strip().toUpper()
|
||||
Query(
|
||||
kind: custom,
|
||||
text: text,
|
||||
filters: filters.split(",").filterIt(it in validFilters),
|
||||
includes: includes.split(",").filterIt(it in validFilters),
|
||||
excludes: excludes.split(",").filterIt(it in validFilters),
|
||||
fromUser: @[name],
|
||||
sep: if sep in separators: sep else: ""
|
||||
)
|
||||
|
||||
proc getMediaQuery*(name: string): Query =
|
||||
Query(
|
||||
kind: media,
|
||||
filters: @["twimg", "native_video"],
|
||||
fromUser: @[name],
|
||||
sep: "OR"
|
||||
)
|
||||
|
||||
proc getReplyQuery*(name: string): Query =
|
||||
Query(
|
||||
kind: replies,
|
||||
includes: @["nativeretweets"],
|
||||
fromUser: @[name]
|
||||
)
|
||||
|
||||
proc genQueryParam*(query: Query): string =
|
||||
var filters: seq[string]
|
||||
var param: string
|
||||
|
||||
for i, user in query.fromUser:
|
||||
param &= &"from:{user} "
|
||||
if i < query.fromUser.high:
|
||||
param &= "OR "
|
||||
|
||||
for f in query.filters:
|
||||
filters.add "filter:" & f
|
||||
for i in query.includes:
|
||||
filters.add "include:" & i
|
||||
for e in query.excludes:
|
||||
filters.add "-filter:" & e
|
||||
|
||||
result = strip(param & filters.join(&" {query.sep} "))
|
||||
if query.text.len > 0:
|
||||
result &= " " & query.text
|
||||
|
||||
proc genQueryUrl*(query: Query): string =
|
||||
if query.kind == multi: return "?"
|
||||
|
||||
result = &"/{query.kind}?"
|
||||
if query.kind != custom: return
|
||||
|
||||
var params: seq[string]
|
||||
if query.filters.len > 0:
|
||||
params &= "filter=" & query.filters.join(",")
|
||||
if query.includes.len > 0:
|
||||
params &= "include=" & query.includes.join(",")
|
||||
if query.excludes.len > 0:
|
||||
params &= "not=" & query.excludes.join(",")
|
||||
if query.sep.len > 0:
|
||||
params &= "sep=" & query.sep
|
||||
if query.text.len > 0:
|
||||
params &= "text=" & query.text
|
||||
if params.len > 0:
|
||||
result &= params.join("&") & "&"
|
||||
|
||||
proc cleanPos*(pos: string): string =
|
||||
pos.multiReplace((posPrefix, ""), (posSuffix, ""))
|
||||
|
||||
proc genPos*(pos: string): string =
|
||||
posPrefix & pos & posSuffix
|
||||
Loading…
Reference in a new issue