utils.nim 696 B

12345678910111213141516171819202122
  1. # SPDX-License-Identifier: AGPL-3.0-only
  2. import std/[sugar, strutils, times]
  3. import ../types/common
  4. import ../../utils as uutils
  5. template parseTime(time: string; f: static string; flen: int): DateTime =
  6. if time.len != flen: return
  7. parse(time, f, utc())
  8. proc parseIsoDate*(date: string): DateTime =
  9. date.parseTime("yyyy-MM-dd\'T\'HH:mm:ss\'Z\'", 20)
  10. proc parseTwitterDate*(date: string): DateTime =
  11. date.parseTime("ddd MMM dd hh:mm:ss \'+0000\' yyyy", 30)
  12. proc getImageUrl*(url: string): string =
  13. url.dup(removePrefix(twimg), removePrefix(https))
  14. template handleErrors*(body) =
  15. if json.startsWith("{\"errors"):
  16. for error {.inject.} in json.fromJson(Errors).errors:
  17. body