Post ApTGBA0dtR8bJThbCi by gnomon@mastodon.social
 (DIR) More posts by gnomon@mastodon.social
 (DIR) Post #ApTGAxTEVpHcQNykSm by nev@bananachips.club
       2024-12-13T19:47:58Z
       
       0 likes, 0 repeats
       
       quick Mastodon question: is there an easy way for a user to get their account ID? The long string of numbers? I have toot installed so I can simply do, e. g., `toot whois account@mastodon.example.com` and it prints it out, but is there a way to find it in the web interface?Update: nvm found it it's `https://<server>/api/v1/accounts/lookup?acct=<username>`#MastoHelp #MastoAdmin
       
 (DIR) Post #ApTGAyTGnAuHWn0I9w by nev@bananachips.club
       2024-12-13T20:25:00Z
       
       0 likes, 0 repeats
       
       also, for #curl / #bash aficionados: how do I actually DO this, like in a scripthttps://docs.joinmastodon.org/api/guidelines/#pagination(I'm trying to get a list of all the people I follow, via the Mastodon API, but of course it paginates. I can get the "next" link with some gnarly-looking `curl -D` and `grep -Po` stuff but do I just, like, do a for loop to repeatedly do it until there isn't any response?)
       
 (DIR) Post #ApTGAz3QcjpXKvvAWG by gnomon@mastodon.social
       2024-12-13T23:54:59Z
       
       0 likes, 0 repeats
       
       @nev this particular task is a surprisingly annoying pain in the ass.If you're doing this with curl, you have to..:1. use `--dump-header [filename]` to preserve the response headers in a temp file;2. then convert those headers from DOS to unix line endings;3. then pick out the `Link: ...` header;4. then parse its `rel=...` components into key/value pairs;5. _then_ you can use the `next` k/v pair to fetch your next page of results.It's fiddly.  The GitHub REST API does this too.  👎
       
 (DIR) Post #ApTGAzHbm1Am2uYUca by nev@bananachips.club
       2024-12-14T20:26:08Z
       
       1 likes, 0 repeats
       
       @gnomon so i ended up doing curl -s -D - -o /dev/null "$url" | grep -Po '(?<=link\: \<).+(?=\>\; rel\=\"next\")' which I'm sure is terrible and non-portable but it works for me lmao
       
 (DIR) Post #ApTGAzVQwcEQjn1XAe by nev@bananachips.club
       2024-12-14T00:22:09Z
       
       0 likes, 0 repeats
       
       @gnomon thanks so much! > then convert those headers from DOS to unix line endings…of fucking course line ending differences are somehow involved
       
 (DIR) Post #ApTGB036vPAcQEmQfA by cks@mastodon.social
       2024-12-14T00:28:30Z
       
       1 likes, 0 repeats
       
       @nev @gnomon It is *extremely* cursed how approximately every text-based Internet standard (HTTP, SMTP, you name it) has mandated CRLF for line endings since ... before DOS existed, probably. I think we get to thank TOPS-20 for it or something.
       
 (DIR) Post #ApTGB0ThKYRBkhDf6W by gnomon@mastodon.social
       2024-12-14T00:34:28Z
       
       0 likes, 0 repeats
       
       @cks @nev *hides a cartoonishly large wooden mallet behind my back* I want names
       
 (DIR) Post #ApTGB15d3WmLeKxxE8 by cks@mastodon.social
       2024-12-14T00:40:17Z
       
       1 likes, 0 repeats
       
       @gnomon @nev Well, I don't have names for the CRLF thing, but allegedly the reason that IMAP specifies UTF-7 instead of UTF-8 is that Mark Crispin was still running a TOPS-20 machine (which doesn't have 8-bit bytes).
       
 (DIR) Post #ApTGB227Y3ZCZkKfOi by gnomon@mastodon.social
       2024-12-14T00:47:56Z
       
       0 likes, 0 repeats
       
       @cks @nev aww, I remember learning when Mark had passed away.  I was just getting into IMAP for professional reasons at the time (cc: @waffles ).  I can't very well apply the Mallet of Just Desserts in his direction. (Well I guess I could, he probably wouldn't dodge it very well, but it would hardly be morally satisfying.)Reminds me a bit of how one guy, Randall Becker, has been single-handedly ensuring for years that git still runs on Tandem Nonstop: https://lore.kernel.org/git/?q=rsbecker+nonstop
       
 (DIR) Post #ApTGB2hb3qkAeNjn2u by waffles@masto.yttrx.com
       2024-12-14T05:25:53Z
       
       0 likes, 0 repeats
       
       @gnomon @cks @nev I just assumed that most network protocols using crlf was a teletype thingI still remember learning Perl for that job with you gnomon— *shudders*
       
 (DIR) Post #ApTGB3S2HBtGyPSsQi by gnomon@mastodon.social
       2024-12-14T15:50:12Z
       
       1 likes, 0 repeats
       
       @waffles @cks @nev lol I'm in a round of interviews for a job tomorrow that would require me to learn Perl professionally in this the year of our flying spaghetti monster twenty twenty four (it's not _just_ a Perl job but it does involve a small and unavoidable amount of it)
       
 (DIR) Post #ApTGB3gZP9W5hUGU5I by quanin@allovertheplace.ca
       2024-12-13T20:35:34Z
       
       0 likes, 0 repeats
       
       @nev I don't think there is, but you as an admin can grab it for them. What I'm wondering is what they could possibly need it for. Nothing user-facing asks for it...
       
 (DIR) Post #ApTGB4DtPGAhMpr61Y by nev@bananachips.club
       2024-12-13T20:48:26Z
       
       1 likes, 0 repeats
       
       @quanin I'm trying to make a script for (Linux-using, I guess) users to fetch a list of users they follow, and users who follow them, from a particular server. Right now there isn't a quick and easy way to do that, except using the API and parsing the output—which requires the user ID.(You can export your following list as a CSV, and manipulate it with a spreadsheet application, but 1. that's awfully unwieldy, and 2. there isn't a way to do that with *people who follow you*.)It's for cases when I (as the admin) am going to defederate a server, so users might want to figure out what connections they have.
       
 (DIR) Post #ApTGB5SSoZQBCJgFNI by gnomon@mastodon.social
       2024-12-14T20:33:00Z
       
       0 likes, 0 repeats
       
       @nev NICE
       
 (DIR) Post #ApTGB5lbfOjY9gdXDE by gnomon@mastodon.social
       2024-12-14T20:33:54Z
       
       0 likes, 0 repeats
       
       @nev does that structure mean you're downloading each page twice, once for the content and once to throw away the content but extract the link header? (Which isn't necessarily a problem, it's fine)
       
 (DIR) Post #ApTGB5mfbRaICz8Ns0 by waffles@masto.yttrx.com
       2024-12-14T17:08:57Z
       
       1 likes, 0 repeats
       
       @gnomon @cks @nev hahahaha I’m rooting for you!!When I interviewed for my current job I did the programming solution in Perl.“I don’t think that’s valid syntax” the interviewer said 🥲
       
 (DIR) Post #ApTGB6AQB8aDOeFLtI by nev@bananachips.club
       2024-12-14T22:22:55Z
       
       1 likes, 0 repeats
       
       @gnomon yeah, I wanted to see the output in standard out as it proceeded.  But I suppose I could combine them into one? (A cursory search seems to show that I can use tee & process substitution?)
       
 (DIR) Post #ApTGB6sNXhkFayoSPI by gnomon@mastodon.social
       2024-12-14T22:43:03Z
       
       0 likes, 0 repeats
       
       @nev you could, yep!In fact you wouldn't even have to mess with tee, process substitution alone would work - something like: result=''verbose=1url_next='https://whatever_apicall_to_get_page1'until [[ ! $url_next == http* ]]; do  result=$(curl --dump-header '.headers' --url "$url_next")  if [[ $verbose == 1]]; then echo "$result"; fi  # url_next=$(grep ... '.headers.') # step to get the next link, or nothing  # step to do whatever with "$result" heredone
       
 (DIR) Post #ApTGB7PhXoOrGKP4LY by clacke@libranet.de
       2024-12-24T09:44:53Z
       
       0 likes, 0 repeats
       
       @gnomon @nev Oh, you can dump the headers to a file! Neat.
       
 (DIR) Post #ApTGB7cSmMbltuNGEq by nev@bananachips.club
       2024-12-15T17:56:21Z
       
       0 likes, 0 repeats
       
       @gnomon just making sure i have this right: this puts the header info into a file called ".headers" for separate grepping? and all "verbose" does is print $result to stdout?
       
 (DIR) Post #ApTGB8A8l9XxaM89jM by gnomon@mastodon.social
       2024-12-15T18:51:25Z
       
       0 likes, 0 repeats
       
       @nev exactly right, yeah.  The "$verbose" variable and the behavior it triggers is just so you can avoid having to mess around with tee(1) in order to see your results interactively; you could also write it that way but it's a bit messier.
       
 (DIR) Post #ApTGB8pcGwivezXHNY by nev@bananachips.club
       2024-12-15T20:42:02Z
       
       0 likes, 0 repeats
       
       @gnomon thank you so much for your help with this! this is what i eventually went with, though of course it's not carved in stone and there's likely more efficient ways to do this: https://codeberg.org/flippingrocks/pages/raw/branch/main/media/downloads/mastodon-fws.sh
       
 (DIR) Post #ApTGB9Qq2YUvWQx0Oe by gnomon@mastodon.social
       2024-12-15T21:34:51Z
       
       0 likes, 0 repeats
       
       @nev you're welcome, I'm delighted that was helpful!!
       
 (DIR) Post #ApTGBA0dtR8bJThbCi by gnomon@mastodon.social
       2024-12-15T21:35:35Z
       
       1 likes, 0 repeats
       
       @nev ooh I have a trick to show you about managing temp files, I'll pastebin up a thing for you as soon as I get off this bus
       
 (DIR) Post #ApTGBEqtt5JeKiBODI by gnomon@mastodon.social
       2024-12-26T18:07:57Z
       
       0 likes, 0 repeats
       
       @nev well this is coming a bit late, sorry about that.  I wrote you a little example about using a `trap ... EXIT` handler in a bash script to automatically remove temp directories and files on program exit, even if that exit is unclean or an error.https://paste.sr.ht/~gnomon/e3f2bd6723565d81438cffe5b993e1485d0d0652