diff --git a/.gitignore b/.gitignore index 0bde612..cd06453 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ # Backup files generated by rustfmt. **/*.rs.bk +# The actual Sitemap, to be copied to https://tildes.net/~tildes/wiki/sitemap. sitemap.md diff --git a/Cargo.lock b/Cargo.lock index b3ba49d..b3bd41a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,11 +1,5 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -[[package]] -name = "autocfg" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2" - [[package]] name = "autocfg" version = "1.0.0" @@ -14,9 +8,9 @@ checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d" [[package]] name = "base64" -version = "0.11.0" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b41b7ea54a0c9d92199de89e20e58d49f02f8e699814ef3fdf266f6f748d15c7" +checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff" [[package]] name = "bitflags" @@ -54,15 +48,6 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" -[[package]] -name = "cloudabi" -version = "0.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" -dependencies = [ - "bitflags", -] - [[package]] name = "core-foundation" version = "0.7.0" @@ -81,32 +66,38 @@ checksum = "b3a71ab494c0b5b860bdc8407ae08978052417070c2ced38573a9157ad75b8ac" [[package]] name = "cssparser" -version = "0.25.9" +version = "0.27.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbe18ca4efb9ba3716c6da66cc3d7e673bf59fa576353011f48c4cfddbdd740e" +checksum = "754b69d351cdc2d8ee09ae203db831e005560fc6030da058f86ad60c92a9cb0a" dependencies = [ - "autocfg 0.1.7", "cssparser-macros", "dtoa-short", "itoa", "matches", "phf", "proc-macro2", - "procedural-masquerade", "quote", - "smallvec 0.6.13", + "smallvec", "syn", ] [[package]] name = "cssparser-macros" -version = "0.3.6" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bb1c84e87c717666564ec056105052331431803d606bd45529b28547b611eef" +checksum = "dfae75de57f2b2e85e8768c3ea840fd159c8f33e2b6522c7835b7abac81be16e" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "derive_more" +version = "0.99.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "298998b1cf6b5b2c8a7b023dfd45821825ce3ba8a8af55c921a0e734e4653f76" dependencies = [ - "phf_codegen", "proc-macro2", - "procedural-masquerade", "quote", "syn", ] @@ -162,12 +153,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" -[[package]] -name = "fuchsia-cprng" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" - [[package]] name = "fuchsia-zircon" version = "0.3.3" @@ -300,9 +285,9 @@ dependencies = [ [[package]] name = "html5ever" -version = "0.24.1" +version = "0.25.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "025483b0a1e4577bb28578318c886ee5f817dda6eb62473269349044406644cb" +checksum = "aafcf38a1a36118242d29b92e1b08ef84e67e4a5ed06e0a80be20e6a32bfed6b" dependencies = [ "log", "mac", @@ -393,7 +378,7 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "076f042c5b7b98f31d205f1249267e12a6518c1481e9dae9764af19b707d2292" dependencies = [ - "autocfg 1.0.0", + "autocfg", ] [[package]] @@ -405,6 +390,12 @@ dependencies = [ "libc", ] +[[package]] +name = "ipnet" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47be2f14c678be2fdcab04ab1171db51b2762ce6f0a8ee87c8dd4a04ed216135" + [[package]] name = "itoa" version = "0.4.5" @@ -459,9 +450,9 @@ checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" [[package]] name = "markup5ever" -version = "0.9.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65381d9d47506b8592b97c4efd936afcf673b09b059f2bef39c7211ee78b9d03" +checksum = "aae38d669396ca9b707bfc3db254bc382ddb94f57cc5c235f34623a669a01dab" dependencies = [ "log", "phf", @@ -480,12 +471,6 @@ version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" -[[package]] -name = "maybe-uninit" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00" - [[package]] name = "memchr" version = "2.3.3" @@ -616,7 +601,7 @@ version = "0.9.55" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7717097d810a0f2e2323f9e5d11e71608355e24828410b55b9d4f18aa5f9a5d8" dependencies = [ - "autocfg 1.0.0", + "autocfg", "cc", "libc", "pkg-config", @@ -631,18 +616,20 @@ checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" [[package]] name = "phf" -version = "0.7.24" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3da44b85f8e8dfaec21adae67f95d93244b2ecf6ad2a692320598dcc8e6dd18" +checksum = "3dfb61232e34fcb633f43d12c58f83c1df82962dcdfa565a4e866ffc17dafe12" dependencies = [ + "phf_macros", "phf_shared", + "proc-macro-hack", ] [[package]] name = "phf_codegen" -version = "0.7.24" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b03e85129e324ad4166b06b2c7491ae27fe3ec353af72e72cd1654c7225d517e" +checksum = "cbffee61585b0411840d3ece935cce9cb6321f01c45477d30066498cd5e1a815" dependencies = [ "phf_generator", "phf_shared", @@ -650,19 +637,33 @@ dependencies = [ [[package]] name = "phf_generator" -version = "0.7.24" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09364cc93c159b8b06b1f4dd8a4398984503483891b0c26b867cf431fb132662" +checksum = "17367f0cc86f2d25802b2c26ee58a7b23faeccf78a396094c13dced0d0182526" dependencies = [ "phf_shared", - "rand 0.6.5", + "rand", +] + +[[package]] +name = "phf_macros" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f6fde18ff429ffc8fe78e2bf7f8b7a5a5a6e2a8b58bc5a9ac69198bbda9189c" +dependencies = [ + "phf_generator", + "phf_shared", + "proc-macro-hack", + "proc-macro2", + "quote", + "syn", ] [[package]] name = "phf_shared" -version = "0.7.24" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "234f71a15de2288bcb7e3b6515828d22af7ec8598ee6d24c3b526fa0a80b67a0" +checksum = "c00cf8b9eafe68dde5e9eaa2cef8ee84a9336a47d566ec55ca16589633b65af7" dependencies = [ "siphasher", ] @@ -717,6 +718,12 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" +[[package]] +name = "proc-macro-hack" +version = "0.5.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99c605b9a0adc77b7211c6b1f722dcb613d68d66859a44f3d485a6da332b0598" + [[package]] name = "proc-macro2" version = "1.0.10" @@ -726,12 +733,6 @@ dependencies = [ "unicode-xid", ] -[[package]] -name = "procedural-masquerade" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a1574a51c3fd37b26d2c0032b649d08a7d51d4cca9c41bbc5bf7118fa4509d0" - [[package]] name = "quote" version = "1.0.4" @@ -741,25 +742,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "rand" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" -dependencies = [ - "autocfg 0.1.7", - "libc", - "rand_chacha 0.1.1", - "rand_core 0.4.2", - "rand_hc 0.1.0", - "rand_isaac", - "rand_jitter", - "rand_os", - "rand_pcg", - "rand_xorshift", - "winapi 0.3.8", -] - [[package]] name = "rand" version = "0.7.3" @@ -768,19 +750,10 @@ checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" dependencies = [ "getrandom", "libc", - "rand_chacha 0.2.2", - "rand_core 0.5.1", - "rand_hc 0.2.0", -] - -[[package]] -name = "rand_chacha" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef" -dependencies = [ - "autocfg 0.1.7", - "rand_core 0.3.1", + "rand_chacha", + "rand_core", + "rand_hc", + "rand_pcg", ] [[package]] @@ -790,24 +763,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" dependencies = [ "ppv-lite86", - "rand_core 0.5.1", + "rand_core", ] -[[package]] -name = "rand_core" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" -dependencies = [ - "rand_core 0.4.2", -] - -[[package]] -name = "rand_core" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" - [[package]] name = "rand_core" version = "0.5.1" @@ -817,84 +775,22 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rand_hc" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" -dependencies = [ - "rand_core 0.3.1", -] - [[package]] name = "rand_hc" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" dependencies = [ - "rand_core 0.5.1", -] - -[[package]] -name = "rand_isaac" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08" -dependencies = [ - "rand_core 0.3.1", -] - -[[package]] -name = "rand_jitter" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b" -dependencies = [ - "libc", - "rand_core 0.4.2", - "winapi 0.3.8", -] - -[[package]] -name = "rand_os" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071" -dependencies = [ - "cloudabi", - "fuchsia-cprng", - "libc", - "rand_core 0.4.2", - "rdrand", - "winapi 0.3.8", + "rand_core", ] [[package]] name = "rand_pcg" -version = "0.1.2" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" +checksum = "16abd0c1b639e9eb4d7c50c0b8100b0d0f849be2349829c740fe8e6eb4816429" dependencies = [ - "autocfg 0.1.7", - "rand_core 0.4.2", -] - -[[package]] -name = "rand_xorshift" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" -dependencies = [ - "rand_core 0.3.1", -] - -[[package]] -name = "rdrand" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" -dependencies = [ - "rand_core 0.3.1", + "rand_core", ] [[package]] @@ -914,9 +810,9 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.10.4" +version = "0.10.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02b81e49ddec5109a9dcfc5f2a317ff53377c915e9ae9d4f2fb50914b85614e2" +checksum = "12427a5577082c24419c9c417db35cfeb65962efc7675bb6b0d5f1f9d315bfe6" dependencies = [ "base64", "bytes", @@ -927,6 +823,7 @@ dependencies = [ "http-body", "hyper", "hyper-tls", + "ipnet", "js-sys", "lazy_static", "log", @@ -937,7 +834,6 @@ dependencies = [ "pin-project-lite", "serde", "serde_urlencoded", - "time", "tokio", "tokio-tls", "url", @@ -965,9 +861,9 @@ dependencies = [ [[package]] name = "scraper" -version = "0.11.0" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77e013440e2ab1c25065551adda5a9773698bb5be3dbab06ff2deac3d5c1a793" +checksum = "48e02aa790c80c2e494130dec6a522033b6a23603ffc06360e9fe6c611ea2c12" dependencies = [ "cssparser", "ego-tree", @@ -975,7 +871,7 @@ dependencies = [ "html5ever", "matches", "selectors", - "smallvec 0.6.13", + "smallvec", "tendril", ] @@ -1004,12 +900,13 @@ dependencies = [ [[package]] name = "selectors" -version = "0.21.0" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b86b100bede4f651059740afc3b6cb83458d7401cb7c1ad96d8a11e91742c86" +checksum = "df320f1889ac4ba6bc0cdc9c9af7af4bd64bb927bccdf32d81140dc1f9be12fe" dependencies = [ "bitflags", "cssparser", + "derive_more", "fxhash", "log", "matches", @@ -1017,7 +914,7 @@ dependencies = [ "phf_codegen", "precomputed-hash", "servo_arc", - "smallvec 0.6.13", + "smallvec", "thin-slice", ] @@ -1073,9 +970,9 @@ dependencies = [ [[package]] name = "siphasher" -version = "0.2.3" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b8de496cf83d4ed58b6be86c3a275b8602f6ffe98d3024a869e124147a9a3ac" +checksum = "fa8f3741c7372e75519bd9346068370c9cdaabcc1f9599cbcf2a2719352286b7" [[package]] name = "slab" @@ -1083,15 +980,6 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" -[[package]] -name = "smallvec" -version = "0.6.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7b0758c52e15a8b5e3691eae6cc559f08eee9406e548a4477ba4e67770a82b6" -dependencies = [ - "maybe-uninit", -] - [[package]] name = "smallvec" version = "1.4.0" @@ -1106,38 +994,29 @@ checksum = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" [[package]] name = "string_cache" -version = "0.7.5" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89c058a82f9fd69b1becf8c274f412281038877c553182f1d02eb027045a2d67" +checksum = "2940c75beb4e3bf3a494cef919a747a2cb81e52571e212bfbd185074add7208a" dependencies = [ "lazy_static", "new_debug_unreachable", "phf_shared", "precomputed-hash", "serde", - "string_cache_codegen", - "string_cache_shared", ] [[package]] name = "string_cache_codegen" -version = "0.4.4" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f45ed1b65bf9a4bf2f7b7dc59212d1926e9eaf00fa998988e420fd124467c6" +checksum = "f24c8e5e19d22a726626f1a5e16fe15b132dcf21d10177fa5a45ce7962996b97" dependencies = [ "phf_generator", "phf_shared", "proc-macro2", "quote", - "string_cache_shared", ] -[[package]] -name = "string_cache_shared" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1884d1bc09741d466d9b14e6d37ac89d6909cbcac41dd9ae982d4d063bbedfc" - [[package]] name = "syn" version = "1.0.18" @@ -1157,7 +1036,7 @@ checksum = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" dependencies = [ "cfg-if", "libc", - "rand 0.7.3", + "rand", "redox_syscall", "remove_dir_all", "winapi 0.3.8", @@ -1276,7 +1155,7 @@ version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5479532badd04e128284890390c1e876ef7a993d0570b3597ae43dfa1d59afa4" dependencies = [ - "smallvec 1.4.0", + "smallvec", ] [[package]] @@ -1450,9 +1329,9 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "winreg" -version = "0.6.2" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2986deb581c4fe11b621998a5e53361efe6b48a151178d0cd9eeffa4dc6acc9" +checksum = "0120db82e8a1e0b9fb3345a539c478767c0048d842860994d96113d5b667bd69" dependencies = [ "winapi 0.3.8", ] diff --git a/Cargo.toml b/Cargo.toml index e52ed66..fe5f5c9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,5 +11,8 @@ name = "tildes-wiki-sitemap" path = "source/main.rs" [dependencies] -reqwest = { version = "0.10.4", features = ["blocking"] } -scraper = "0.11.0" +scraper = "0.12.0" + +[dependencies.reqwest] +version = "0.10.7" +features = ["blocking"] diff --git a/License b/LICENSE similarity index 100% rename from License rename to LICENSE diff --git a/README.md b/README.md new file mode 100644 index 0000000..d691cd9 --- /dev/null +++ b/README.md @@ -0,0 +1,38 @@ +# Tildes Wiki Sitemap + +> Generates a Markdown file with all group wiki pages of Tildes. + +## Installation + +### Binary + +Precompiled binaries are available [here](https://git.holllo.cc/Bauke/tildes-wiki-sitemap/releases). + +### Source + +Requires [Rust and Cargo](https://www.rust-lang.org/tools/install) to be installed. + +```sh +git clone https://git.holllo.cc/Bauke/tildes-wiki-sitemap.git +cd tildes-wiki-sitemap +cargo build --release +mv target/release/tildes-wiki-sitemap ./ +``` + +## Usage + +Make sure the file is executable, then run it. A `sitemap.md` file will be created with the results. + +```sh +chmod +x ./tildes-wiki-sitemap +./tildes-wiki-sitemap +less sitemap.md +``` + +## Previous Version + +If you're looking for the previous version of this program written in Go, [click here](https://git.holllo.cc/Bauke/tildes-wiki-sitemap/src/commit/18a96e9d541fd1e231574ceec4d4bdf5783e3b5f) to go to the commit before the Rust rewrite. + +## License + +Open-sourced with the [AGPL-3.0-or-later license](https://git.holllo.cc/Bauke/tildes-wiki-sitemap/src/branch/main/LICENSE). diff --git a/ReadMe.md b/ReadMe.md deleted file mode 100644 index d568172..0000000 --- a/ReadMe.md +++ /dev/null @@ -1,24 +0,0 @@ -# Tildes Wiki Sitemap - -> Generates a Markdown file with all group wiki pages of Tildes.net - -## Usage - -Precompiled binaries are not provided, if you can't or don't know how to run this program and the sitemap is outdated please [PM me (@Bauke)](https://tildes.net/user/Bauke/new_message?subject=Tildes%20Wiki%20Sitemap&message=Update%20the%20sitemap%20you%20doofus!) and I'll update it. - -### Quick Command - -```sh -$ git clone https://gitlab.com/Bauke/tildes-wiki-sitemap.git - cd tildes-wiki-sitemap - cargo run - edit sitemap.md -``` - -## Previous Version - -If you're looking for the previous version of this program written in Go, [click here](https://gitlab.com/Bauke/tildes-wiki-sitemap/-/tree/18a96e9d541fd1e231574ceec4d4bdf5783e3b5f) to go to the commit before the Rust rewrite. - -## License - -Open-sourced with the [AGPL-3.0-or-later license](License). diff --git a/rustfmt.toml b/rustfmt.toml index 205c72c..4c1eefa 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,2 +1,2 @@ -tab_spaces = 2 max_width = 80 +tab_spaces = 2 diff --git a/source/main.rs b/source/main.rs index 1eff05f..aacc185 100644 --- a/source/main.rs +++ b/source/main.rs @@ -1,23 +1,19 @@ -use std::error::Error; -use std::fs; -use std::thread; -use std::time::Duration; +use std::{error::Error, fs, thread, time::Duration}; -use reqwest; +use reqwest::blocking::Client; use scraper::{ElementRef, Html, Selector}; fn main() -> Result<(), Box> { - let client = reqwest::blocking::Client::new(); + let client = Client::builder() + .user_agent("Tildes Wiki Sitemap") + .build()?; // Get the HTML from the groups list. - let response = client - .get("https://tildes.net/groups") - .header(reqwest::header::USER_AGENT, "Tildes Wiki Sitemap") - .send()?; + let response = client.get("https://tildes.net/groups").send()?; let body = response.text()?; // Parse the HTML. - let html = Html::parse_document(body.as_str()); + let html = Html::parse_document(&body); // Create a selector to grab all anchors that link to a group. let selector = Selector::parse(".group-list .link-group").unwrap(); @@ -26,10 +22,10 @@ fn main() -> Result<(), Box> { let group_links = html.select(&selector).collect::>(); // Create the sitemap with the info. - let mut sitemap = String::from("# Tildes Wiki Sitemap\n\n"); + let mut sitemap = "# Tildes Wiki Sitemap\n\n".to_string(); sitemap += "Automatically generated by \ - [this program](https://gitlab.com/bauke/tildes-wiki-sitemap). \ - [PM @Bauke](https://tildes.net/user/Bauke/new_message?subject=Tildes%20Wiki%20Sitemap\ + [this program](https://git.holllo.cc/Bauke/tildes-wiki-sitemap). \ + [message @Bauke](https://tildes.net/user/Bauke/new_message?subject=Tildes%20Wiki%20Sitemap\ &message=Update%20the%20sitemap%20you%20doofus!) if this page is outdated and \ you can't run the program yourself.\n\n\ This page is a temporary placeholder to help wiki contributors navigate. \ @@ -37,18 +33,17 @@ fn main() -> Result<(), Box> { for group_link in group_links { // Get the group name without the tilde. - let group_name = String::from(&group_link.inner_html()[1..]); + let group_name = group_link.inner_html()[1..].to_string(); println!("┌ Processing ~{}!", group_name); // Get the HTML from the group page. let response = client - .get(format!("https://tildes.net/~{}", group_name).as_str()) - .header(reqwest::header::USER_AGENT, "Tildes Wiki Sitemap") + .get(&format!("https://tildes.net/~{}", group_name)) .send()?; let body = response.text()?; // Parse the HTML. - let html = Html::parse_document(body.as_str()); + let html = Html::parse_document(&body); // Create a selector to grab all the anchors in the sidebar that lead to a wiki page. let selector = @@ -62,7 +57,7 @@ fn main() -> Result<(), Box> { let selector = Selector::parse("#sidebar .group-short-description").unwrap(); - // Get all the wiki URL elements from the HTML. + // Get the group description from the HTML. let group_description = html.select(&selector).collect::>(); // Add the group as a new header. @@ -78,19 +73,20 @@ fn main() -> Result<(), Box> { if wiki_links.is_empty() { sitemap += format!("There are no wiki pages for ~{} yet, \ [click here and be the first to create one](https://tildes.net/~{}/wiki/new_page), \ - if you have the necessary permission!\n", group_name, group_name).as_str(); + if you were granted the necessary permission to do so!\n", group_name, group_name).as_str(); } // Loop over the links and add them in a list. for wiki_link in wiki_links { let wiki_page_title = wiki_link.inner_html(); let wiki_page_link = wiki_link.value().attr("href").unwrap_or(""); - sitemap += - format!("* [{}]({})\n", wiki_page_title, wiki_page_link).as_str(); + sitemap += &format!("* [{}]({})\n", wiki_page_title, wiki_page_link); } sitemap += "\n"; println!("└ Processed {} wiki links.", wiki_links_amount); + + // Sleep 500ms between HTTP requests. thread::sleep(Duration::from_millis(500)); }