What's my name?
Bash, 120 112 106 102 80 76 74 bytes
-8 bytes because wget
is smart enough to redirect HTTP to HTTPS when necessary
-6 bytes thanks to another sed
suggestion from Cows quack
-26 bytes thanks to Digital Trauma
-4 bytes thanks to Gilles - codegolf.stackexchange.com/u/123
redirects
-2 bytes thanks to Digital Trauma's answer's wget
flags
wget -qO- codegolf.stackexchange.com/u/$1|sed -nr 's/.*>User (.*) -.*/\1/p'
No TIO link since the TIO arenas can't access the internet.
Thanks to the answers here and the people in chat for helping me with this. I used an approach similar to HyperNeutrino's.
wget -qO- codegolf.stackexchange.com/users/$1
downloads the user's profile page and prints the file to STDOUT.-q
does it quietly (no speed information).sed -nr 's/.*User (.*) -.*/\1/p'
searches for the first stringUser<space>
, then prints up until it reaches the end of the name, found usingsed
magic.
Previous answer that I wrote more independently (102 bytes):
wget codegolf.stackexchange.com/users/$1 2>y
sed '6!d' <$1|cut -c 13-|cut -d '&' -f1|sed 's/.\{23\}$//'
wget codegolf.stackexchange.com/users/$1 2>y
saves the user profile HTML to a file titled with their UserID and dumps STDERR toy
.cat $1
pipes the file into the parts that cut away the useless HTML.sed '6!d'
(in the place ofhead -6 | tail -1
) gets the sixth line by itself.cut -c 13-
strips away the first 13 characters, getting the username to start at the first character of the string.cut -d '&' -f1
cuts everything after the&
. This relies on the fact that an ampersand is not allowed to be in a username, nor an HTML title.
Now the string is<username> - Programming Puzzles
sed 's/.\{23\}$//'
was a suggestion from cows quack to remove the last 15 bytes of a file. This gets the username by itself.
Here's a full bash script.
Bash + GNU utilities, 66
- 3 bytes saved thanks to @Arnauld.
- 4 bytes saved thanks to @Gilles.
wget -qO- codegolf.stackexchange.com/u/$1|grep -Po '"User \K[^"]+'
Uses -P
CRE regex flavour to do a \K
match start reset for much shorter output filtering.
If your system already has curl
installed, we can use @Gilles' suggestion:
Bash + curl + GNU utilities, 64
curl -L codegolf.stackexchange.com/u/$1|grep -Po '"User \K[^"]+'
Python 2 + requests, 112 bytes
from requests import*
t=get('http://codegolf.stackexchange.com/users/'+input()).text
print t[49:t.index('&')-23]
note
once SE goes fully https
, the http
needs to be changed to https
, which will make this 113 bytes.
The beginning of a user profile looks like this:
<!DOCTYPE html>
<html>
<head>
<title>User MD XF - Programming Puzzles & Code Golf Stack Exchange</title>
The username starts at index 49 and the ampersand occurs 23 characters to the right of where it ends (- Programming Puzzles
)
-3 bytes thanks to StepHen/Mego by removing the unused re
import
-1 byte thanks to Uriel