From 4a0587e23a6e38121143768b4f61b02bb54ce6ba Mon Sep 17 00:00:00 2001 From: Joseph Nuthalapati Date: Sun, 12 Jan 2020 13:23:05 +0530 Subject: [PATCH] Make extractTitlesAndUrls a func with some convincing of course! Signed-off-by: Joseph Nuthalapati --- lib.nim | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib.nim b/lib.nim index fc00385..de088b4 100644 --- a/lib.nim +++ b/lib.nim @@ -31,10 +31,11 @@ proc getYoutubePage*(searchQuery: string): string = let response = get(client, &"https://www.youtube.com/results?hl=en&search_query={queryParam}") return $response.body -proc extractTitlesAndUrls*(html: string): seq[SearchResult] = - parseHtml(html).findAll("a"). - filter(a => "watch" in a.attrs["href"] and a.attrs.hasKey "title"). - map(a => (a.attrs["title"], "https://www.youtube.com" & a.attrs["href"]))[..(limit-1)] +func extractTitlesAndUrls*(html: string): seq[SearchResult] = + {.noSideEffect.}: + parseHtml(html).findAll("a"). + filter(a => "watch" in a.attrs["href"] and a.attrs.hasKey "title"). + map(a => (a.attrs["title"], "https://www.youtube.com" & a.attrs["href"]))[..(limit-1)] proc presentVideoOptions*(searchResults: seq[SearchResult]) = echo "" -- 2.43.0