Handle withheld tweets (#429)

* Handle withheld tweets

* Fix format of parser.nim
This commit is contained in:
Vítor
2021-08-21 12:13:38 -03:00
committed by GitHub
parent 739eb12bed
commit cf47c1b8ad
5 changed files with 29 additions and 1 deletions

View File

@@ -1,5 +1,6 @@
import strutils, options, tables, times, math
import packedjson
import packedjson / deserialiser
import types, parserutils, utils
proc parseProfile(js: JsonNode; id=""): Profile =
@@ -268,6 +269,21 @@ proc parseTweet(js: JsonNode): Tweet =
result.gif = some(parseGif(m))
else: discard
let withheldInCountries = (
if js{"withheld_in_countries"}.kind == JArray:
js{"withheld_in_countries"}.to(seq[string])
else:
newSeq[string]()
)
if js{"withheld_copyright"}.getBool or
# XX - Content is withheld in all countries
"XX" in withheldInCountries or
# XY - Content is withheld due to a DMCA request.
"XY" in withheldInCountries or
(withheldInCountries.len > 0 and "withheld" in result.text):
result.available = false
proc finalizeTweet(global: GlobalObjects; id: string): Tweet =
let intId = if id.len > 0: parseBiggestInt(id) else: 0
result = global.tweets.getOrDefault(id, Tweet(id: intId))