scraper.factor
1 ! Copyright (C) 2024 Aleksander "olus2000" Sabak. 2 ! See https://factorcode.org/license.txt for BSD license. 3 USING: ascii formatting http.client kernel regexp 4 sequences splitting strings ; 5 IN: esolang_games.botc.scraper 6 7 8 ERROR: scraping-failed url ; 9 10 11 : scrape-short-description ( url -- short-desc ) 12 dup http-get nip 13 R/ (?<=Summary<\/span><\/h2>\n<p>["”]).*(?=["”])/ first-match 14 [ nip >string ] [ scraping-failed ] if* ; 15 16 17 : >role-url ( role -- url ) 18 " " "_" replace 19 "https://wiki.bloodontheclocktower.com/" prepend ; 20 21 22 : generate-description ( role -- description ) 23 dup >role-url dup scrape-short-description 24 "* [%s](%s): %s" sprintf ; 25 26 27 : generate-descriptions ( roles -- descriptions ) 28 [ generate-description ] map "\n" join ; 29 30 31 CONSTANT: good-intro " 32 This means you are **Good**: you win when there are no more Demons alive." 33 34 CONSTANT: evil-intro " 35 This means you are **Evil**: you win when there are only two people (including the Demon) left alive." 36 37 38 : generate-introduction ( role -- role-intro ) 39 dup >role-url dup scrape-short-description 40 "You are the [%s](%s): %s" sprintf ; 41 42 43 : generate-introductions ( roles alignment-blurb -- intros ) 44 '[ _ [ generate-introduction ] dip append ] map ;