11
\$\begingroup\$

Given a PPCG User ID, output that user's current username.

Examples

Input -> Output
61563 -> MD XF
2     -> Geoff Dalgas
12012 -> Dennis
foo   -> 
-3    -> 

Rules

  • Input/output can be taken via any allowed means.
  • The output must be the full username with proper capitalization and spacing, nothing more and nothing less.
  • If the input is not a valid UserID, or the user does not exist, your program should output nothing or error output.
  • Your program must work for any valid user, even one created after this challenge.
  • Your program does not have to work for the Community user.
  • Your program does not have to work for deleted users.
  • URL shorteners are disallowed.

Scoring

Shortest code in each language wins.

\$\endgroup\$
10
  • 5
    \$\begingroup\$ Very closely related, but since my vote is a hammer, I'm not close-voting yet. \$\endgroup\$ Commented Aug 1, 2017 at 17:43
  • \$\begingroup\$ @AdmBorkBork Yeah, those are pretty closely related, but this is significantly easier. \$\endgroup\$
    – MD XF
    Commented Aug 1, 2017 at 17:44
  • \$\begingroup\$ Oh, that one will be soooo easy in C++ \$\endgroup\$ Commented Aug 1, 2017 at 18:01
  • 1
    \$\begingroup\$ English, 3 bytes: Okx. Yes, that's my name. \$\endgroup\$
    – Okx
    Commented Aug 1, 2017 at 19:33
  • 1
    \$\begingroup\$ Everybody can save 4 bytes (in “normal” languages): xxx.stackexchange.com/u/123 redirects to xxx.stackexchange.com/users/123 \$\endgroup\$ Commented Aug 2, 2017 at 9:11

15 Answers 15

8
\$\begingroup\$

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.

  1. 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).

  2. sed -nr 's/.*User (.*) -.*/\1/p' searches for the first string User<space>, then prints up until it reaches the end of the name, found using sed 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\}$//'
  1. wget codegolf.stackexchange.com/users/$1 2>y saves the user profile HTML to a file titled with their UserID and dumps STDERR to y.

  2. cat $1 pipes the file into the parts that cut away the useless HTML.

  3. sed '6!d' (in the place of head -6 | tail -1) gets the sixth line by itself.

  4. cut -c 13- strips away the first 13 characters, getting the username to start at the first character of the string.

  5. 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

  6. 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.

\$\endgroup\$
14
  • \$\begingroup\$ ...TIO arenas can't access the internet They can, that's how you're able to access it. :P User-submitted code is not permitted access to the internet . </nitpick> \$\endgroup\$ Commented Aug 1, 2017 at 18:59
  • \$\begingroup\$ @totallyhuman You can access TIO arenas via the internet. But the arenas themselves cannot access the internet. Even Dennis' code running on an arena cannot access the internet. \$\endgroup\$
    – MD XF
    Commented Aug 1, 2017 at 19:06
  • \$\begingroup\$ @totallyhuman afaik no they can't. You give the main server your code, the main server connects to an arena and runs the code. That might be outdated info though \$\endgroup\$
    – Stephen
    Commented Aug 1, 2017 at 20:41
  • \$\begingroup\$ For userID 11259, the output is Digital Trauma - Progr \$\endgroup\$ Commented Aug 1, 2017 at 22:14
  • \$\begingroup\$ @DigitalTrauma Whoops, forgot to fix the second sed bytecount. \$\endgroup\$
    – MD XF
    Commented Aug 1, 2017 at 22:19
7
\$\begingroup\$

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 -PCRE 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[^"]+'
\$\endgroup\$
9
  • \$\begingroup\$ What is the purpose of O-? \$\endgroup\$
    – user41805
    Commented Aug 1, 2017 at 19:39
  • \$\begingroup\$ @Cowsquack -O- sends the downloaded output to STDOUT instead of a file, so it can be simply piped to grep \$\endgroup\$ Commented Aug 1, 2017 at 19:40
  • 1
    \$\begingroup\$ You can do grep -Po '"User \K[^"]+' to save 3 bytes. \$\endgroup\$
    – Arnauld
    Commented Aug 1, 2017 at 20:45
  • 1
    \$\begingroup\$ curl -L is shorter than wget -qO-. You can use /u instead of /users. \$\endgroup\$ Commented Aug 2, 2017 at 9:09
  • 1
    \$\begingroup\$ @Ferrybig I'm assuming its ok to ignore STDERR by default \$\endgroup\$ Commented Aug 2, 2017 at 18:36
6
\$\begingroup\$

Python 2 + requests, 108 bytes

from requests import*
t=get('http://codegolf.stackexchange.com/u/'+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 &amp; 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
-4 bytes thanks to Makonede

\$\endgroup\$
10
  • \$\begingroup\$ You never use re so you can drop 3 bytes \$\endgroup\$
    – user45941
    Commented Aug 1, 2017 at 17:35
  • \$\begingroup\$ You can also use http for the time being, but that will be phased out eventually when SE goes full HTTPS. \$\endgroup\$
    – user45941
    Commented Aug 1, 2017 at 17:36
  • \$\begingroup\$ @Mego I'll add that in as a side note - thanks \$\endgroup\$
    – hyperneutrino
    Commented Aug 1, 2017 at 17:36
  • \$\begingroup\$ also, from requests import* and drop r. for 113 bytes \$\endgroup\$
    – Uriel
    Commented Aug 1, 2017 at 17:39
  • \$\begingroup\$ @Uriel But it can't :) \$\endgroup\$
    – hyperneutrino
    Commented Aug 1, 2017 at 17:39
5
\$\begingroup\$

JavaScript (ES6), 111 75 bytes

Only works when run through the PPCG domain. Returns a Promise object containing the username.

i=>fetch("/users/"+i).then(r=>r.text()).then(t=>t.slice(44,t.search`&`-23))
  • Thanks to Downgoat for confirming that the alternative method I was toying with was valid, thus allowing me to save 36 bytes.
\$\endgroup\$
7
  • \$\begingroup\$ 77 bytes: i=>fetch(`/users/${i}`).then(r=>r.text()).then(s=>/"User ([^"]+)/.exec(s)[1]) \$\endgroup\$
    – Downgoat
    Commented Aug 2, 2017 at 4:30
  • \$\begingroup\$ 66 bytes: i=>$.get(`/users/${i}`).done(s=>alert(/"User ([^"]+)/.exec(s)[1])) \$\endgroup\$
    – Downgoat
    Commented Aug 2, 2017 at 4:36
  • \$\begingroup\$ you can remove the parenthesis from fetch to save 2 bytes \$\endgroup\$
    – GilZ
    Commented Aug 2, 2017 at 7:41
  • \$\begingroup\$ Thanks, @Downgoat; I'd already toyed with the idea of fetching the user's page that way but thought it might be pushing my luck. But seeing as you've suggested it too, I'll edit it in. Do any browser's currently support .done()? I tested it quickly in Chrome & FF but it didn't work there. \$\endgroup\$
    – Shaggy
    Commented Aug 2, 2017 at 9:18
  • \$\begingroup\$ @Gilz, I could only have done that if there wasn't a variable involved. \$\endgroup\$
    – Shaggy
    Commented Aug 2, 2017 at 9:21
4
\$\begingroup\$

05AB1E, 35 34 bytes

Doesn't work online because of internet restrictions.

Code

’ƒËŠˆ.‚‹º.ŒŒ/†š/ÿ’.w'>¡4è5F¦}60F¨

Explanation

The compressed string:

’ƒËŠˆ.‚‹º.ŒŒ/†š/ÿ’

pushes the following string:

codegolf.stackexchange.com/users/<input>

Whereas <input> is the user input. After this, we read all data using .w and do some string manipulation tricks on the data:

'>¡4è5F¦}60F¨

'>¡             # Split on '>' (Usernames aren't allowed to have '>' so we're safe)
   4è           # Take the 5th element (which is in the header of the HTML page)
     5F¦}       # Remove the first 5 characters, which is "User "
         60F¨   # Remove the last 60 characters, which is:
                  " - Programming Puzzles &amp; Code Golf Stack Exchange</title"
                # Implicitly output the username

When run locally, I get the following output:

enter image description here

\$\endgroup\$
7
  • \$\begingroup\$ I think that an explanation will be needed for this brand of black magic \$\endgroup\$ Commented Aug 1, 2017 at 19:49
  • \$\begingroup\$ I'm looking at my screen at an angle, am I supposed to se an outline of totallyhuman's flair and "apparently" next to your username? \$\endgroup\$ Commented Aug 1, 2017 at 19:57
  • 1
    \$\begingroup\$ @TaylorScott Done. \$\endgroup\$
    – Adnan
    Commented Aug 1, 2017 at 20:00
  • 3
    \$\begingroup\$ @NoOneIsHere Yeah, cmder is a tiny bit transparent. That is actually this answer what you are seeing. \$\endgroup\$
    – Adnan
    Commented Aug 1, 2017 at 20:00
  • \$\begingroup\$ Umm, part of your explanation is „ -¡¬. \$\endgroup\$ Commented Aug 2, 2017 at 9:17
4
\$\begingroup\$

Cubically + Bash, 1654 1336 1231 bytes

-423 bytes thanks to TehPers

This needs three Cubically scripts (named 1, 2 and 3) and 1 bash script.

The Cubically scripts are really long because I haven't thought of a good way to implement loops yet.

Bash (84 bytes):

ln -s rubiks-lang /bin/r
r 1 <<<$1 2>y|xargs wget 2>y
cat $1|r 2 2>y|rev|r 3 2>y|rev

This pipes the first Cubically script into wget, then the saved file into the second Cubically script, then reverses that output, pipes it into the third Cubically script, then reverses it.

1 (385 bytes):

+5/1+551@6:5+3/1+552@66:4/1+552@6:5+2/1+552@6:4/1+51@6:2/1+5@66:5+51@6:3/1+552@6:1/1+551@6:2/1+551@6:4/1+551@6:3/1+552@6:5+52@6:3/1+551@6:1/1+5@6:5+2/1+552@6:5+3/1+552@6:5+2/1+55@6:5+51@6:5+3/1+551@6:2/1+551@6:3/1+553@6:5+51@6:5/1+551@6:5+2/1+55@6:2/1+552@6:4/1+551@6:2/1+551@6:1/1+5@6:5+51@6:3/1+552@6:1/1+552@6:2/1+5@6:5+53@6:5+2/1+552@6:2/1+551@6:5+1/1+552@6:5+2/1+552@6:2/1+5@6$7%7

This prints https://codegolf.stackexchange.com/users/, then the first integer of input.

2 (680 505 bytes):

~7777777777777777777777777777777777777777777777777
F1R1
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6

This reads the unnecessary data from the saved file as input, then prints up until the ampersand in Programming Puzzles & Code Golf.

~7@7 reads a character and prints it. F1R1 and :5=7 check if the input is the ampersand. &6 exits if it is.

~7@7:5=7&6 is repeated 45 times because there are 15 bytes of unnecessary data and a 30-byte max StackExchange username.

3 (505 446 342 bytes):

U3D1R3L1F3B1U1D3
~777777777777777777777777
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7

Very similar to the last script, this reads the first few unnecessary bytes, then cats until EOF. This also works due to the max SE username.

\$\endgroup\$
3
  • \$\begingroup\$ For file 3, why not use :0-1/1 instead of :4+4/1-1? Also, the first instance of it can just be -1/1 because notepad starts at 0. \$\endgroup\$
    – TehPers
    Commented Aug 1, 2017 at 19:55
  • 1
    \$\begingroup\$ Might want to warn that /bin/r is overwritten. \$\endgroup\$ Commented Aug 1, 2017 at 19:59
  • \$\begingroup\$ For file 2, you can do F1R1 at the beginning, then use +5 throughout the program in place of +2/1+4 \$\endgroup\$
    – TehPers
    Commented Aug 1, 2017 at 20:00
4
\$\begingroup\$

Swift 3, 233 bytes

import Foundation;func f(i:String){let s=try!String(contentsOf:URL(string:"http://codegolf.stackexchange.com/users/"+i)!,encoding:.utf8);print(s[s.index(s.startIndex,offsetBy:44)...s.index(s.characters.index(of:"&")!,offsetBy:-24)])}

Sample runs:

f(i:"8478") // Martin Ender
f(i:"12012") // Dennis
f(i:"59487") // Mr. Xcoder
\$\endgroup\$
4
  • 1
    \$\begingroup\$ Yes! Swift! An oasis from a desert of golfing languages \$\endgroup\$ Commented Aug 1, 2017 at 20:25
  • \$\begingroup\$ @bearacuda13 Lol true :) \$\endgroup\$
    – Mr. Xcoder
    Commented Aug 1, 2017 at 20:27
  • \$\begingroup\$ You could be able to use a closure and save a lot of bytes \$\endgroup\$
    – Downgoat
    Commented Aug 2, 2017 at 4:32
  • \$\begingroup\$ @Downgoat Thanks for the tip, I'll update when I have time. \$\endgroup\$
    – Mr. Xcoder
    Commented Aug 2, 2017 at 6:19
3
\$\begingroup\$

Python 2, 116 bytes

Just thought it's nice to have a standard library answer (that's actually quite decent in length).

from urllib import*
f=urlopen('http://codegolf.stackexchange.com/users/'+input()).read()
print f[49:f.index('&')-23]

When SE goes fully https, we need to add 1 more byte, switching urlopen('http://... with urlopen('https://....

\$\endgroup\$
3
\$\begingroup\$

Stack Exchange Data Explorer, 47 bytes

SELECT DISPLAYNAME FROM USERS WHERE ID=##N##--N

Try it online!

\$\endgroup\$
2
\$\begingroup\$

PHP, 163 bytes


<?php $a=new DOMDocument;@$a->loadHTML(implode(0,file("http://codegolf.stackexchange.com/users/$argv[1]")));echo$a->getElementsByTagName('h2')->item(0)->nodeValue;
\$\endgroup\$
2
\$\begingroup\$

Powershell, 165 142 137 127 bytes

23 28 38 bytes saved thanks to AdmBorkBork!

Creates a file named 0 as a side effect.

((iwr"codegolf.stackexchange.com/u/$args").AllElements|?{$_.class-like"user-c*"})[1].innerhtml-match"(.+?) ?<|.+">0
$matches[1]

Works by going to the proper webpage, and selecting the "user-card-name" element, then extracting the proper text out of the innerhtml.

Testing

PS C:\Users\Conor O'Brien\Documents\powershell> .\whats-my-name-137085.ps1 61563
MD XF
PS C:\Users\Conor O'Brien\Documents\powershell> .\whats-my-name-137085.ps1 2
Geoff Dalgas
PS C:\Users\Conor O'Brien\Documents\powershell> .\whats-my-name-137085.ps1 12012
Dennis
PS C:\Users\Conor O'Brien\Documents\powershell> .\whats-my-name-137085.ps1 foo
Invoke-WebRequest : current community chat Programming Puzzles & Code Golf
Programming Puzzles & Code Golf Meta your communities Sign up or log in to customize your list. more stack
exchange communities company blog Stack Exchange Inbox Reputation and Badges sign up log in tour help Tour
Start here for a quick overview of the site Help Center
Detailed answers to any questions you might have Meta
Discuss the workings and policies of this site About Us
Learn more about Stack Overflow the company Business
Learn more about hiring developers or posting ads with us
Programming Puzzles & Code Golf Questions Tags Users Badges Unanswered Ask Question
 Page Not FoundWe're sorry, we couldn't find the page you requested.
Try searching for similar questions
Browse our recent questions
Browse our popular tags
If you feel something is missing that should be here, contact us.
about us tour help blog chat data legal privacy policy work here advertising info mobile contact us feedback
Technology Life / Arts Culture / Recreation Science Other
Stack Overflow
Server Fault
Super User
Web Applications
Ask Ubuntu
Webmasters
Game Development
TeX - LaTeX
Software Engineering
Unix & Linux
Ask Different (Apple)
WordPress Development
Geographic Information Systems
Electrical Engineering
Android Enthusiasts
Information Security
Database Administrators
Drupal Answers
SharePoint
User Experience
Mathematica
Salesforce
ExpressionEngine® Answers
Blender
Network Engineering
Cryptography
Code Review
Magento
Software Recommendations
Signal Processing
Emacs
Raspberry Pi
Programming Puzzles & Code Golf
Ethereum
Data Science
Arduino
more (26)
Photography
Science Fiction & Fantasy
Graphic Design
Movies & TV
Music: Practice & Theory
Worldbuilding
Seasoned Advice (cooking)
Home Improvement
Personal Finance & Money
Academia
Law
more (17)
English Language & Usage
Skeptics
Mi Yodeya (Judaism)
Travel
Christianity
English Language Learners
Japanese Language
Arqade (gaming)
Bicycles
Role-playing Games
Anime & Manga
Puzzling
Motor Vehicle Maintenance & Repair
more (32)
MathOverflow
Mathematics
Cross Validated (stats)
Theoretical Computer Science
Physics
Chemistry
Biology
Computer Science
Philosophy
more (10)
Meta Stack Exchange
Stack Apps
Area 51
Stack Overflow Talent
site design / logo © 2017 Stack Exchange Inc; user contributions licensed under cc by-sa 3.0 with attribution
required rev 2017.8.1.26652
At C:\Users\Conor O'Brien\Documents\powershell\whats-my-name-137085.ps1:1 char:3
+ ((Invoke-WebRequest -URI("codegolf.stackexchange.com/users/"+$args[0])).AllEleme ...
+   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], We
   bException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
Cannot index into a null array.
At C:\Users\Conor O'Brien\Documents\powershell\whats-my-name-137085.ps1:2 char:1
+ $matches[1]
+ ~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArray

PS C:\Users\Conor O'Brien\Documents\powershell> .\whats-my-name-137085.ps1 -3
Invoke-WebRequest : current community chat Programming Puzzles & Code Golf
Programming Puzzles & Code Golf Meta your communities Sign up or log in to customize your list. more stack
exchange communities company blog Stack Exchange Inbox Reputation and Badges sign up log in tour help Tour
Start here for a quick overview of the site Help Center
Detailed answers to any questions you might have Meta
Discuss the workings and policies of this site About Us
Learn more about Stack Overflow the company Business
Learn more about hiring developers or posting ads with us
Programming Puzzles & Code Golf Questions Tags Users Badges Unanswered Ask Question
 Page Not FoundWe're sorry, we couldn't find the page you requested.
Try searching for similar questions
Browse our recent questions
Browse our popular tags
If you feel something is missing that should be here, contact us.
about us tour help blog chat data legal privacy policy work here advertising info mobile contact us feedback
Technology Life / Arts Culture / Recreation Science Other
Stack Overflow
Server Fault
Super User
Web Applications
Ask Ubuntu
Webmasters
Game Development
TeX - LaTeX
Software Engineering
Unix & Linux
Ask Different (Apple)
WordPress Development
Geographic Information Systems
Electrical Engineering
Android Enthusiasts
Information Security
Database Administrators
Drupal Answers
SharePoint
User Experience
Mathematica
Salesforce
ExpressionEngine® Answers
Blender
Network Engineering
Cryptography
Code Review
Magento
Software Recommendations
Signal Processing
Emacs
Raspberry Pi
Programming Puzzles & Code Golf
Ethereum
Data Science
Arduino
more (26)
Photography
Science Fiction & Fantasy
Graphic Design
Movies & TV
Music: Practice & Theory
Worldbuilding
Seasoned Advice (cooking)
Home Improvement
Personal Finance & Money
Academia
Law
more (17)
English Language & Usage
Skeptics
Mi Yodeya (Judaism)
Travel
Christianity
English Language Learners
Japanese Language
Arqade (gaming)
Bicycles
Role-playing Games
Anime & Manga
Puzzling
Motor Vehicle Maintenance & Repair
more (32)
MathOverflow
Mathematics
Cross Validated (stats)
Theoretical Computer Science
Physics
Chemistry
Biology
Computer Science
Philosophy
more (10)
Meta Stack Exchange
Stack Apps
Area 51
Stack Overflow Talent
site design / logo © 2017 Stack Exchange Inc; user contributions licensed under cc by-sa 3.0 with attribution
required rev 2017.8.1.26652
At C:\Users\Conor O'Brien\Documents\powershell\whats-my-name-137085.ps1:1 char:3
+ ((Invoke-WebRequest -URI("codegolf.stackexchange.com/users/"+$args[0])).AllEleme ...
+   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], We
   bException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
Cannot index into a null array.
At C:\Users\Conor O'Brien\Documents\powershell\whats-my-name-137085.ps1:2 char:1
+ $matches[1]
+ ~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArray

PS C:\Users\Conor O'Brien\Documents\powershell>
\$\endgroup\$
1
\$\begingroup\$

Python + requests, 126 bytes

lambda n:get('http://api.stackexchange.com/users/%d?site=codegolf'%n).json()['items'][0]['display_name']
from requests import*

Accessing the API is longer than reading the actual page apparently...

\$\endgroup\$
1
  • 2
    \$\begingroup\$ That moment when standard library + page reading is shorter than requests :p \$\endgroup\$
    – Mr. Xcoder
    Commented Aug 1, 2017 at 19:54
1
\$\begingroup\$

Jelly, 37 bytes

A port of HyperNeutrino's Python 2 answer - go give credit!

“3¬ẋṙẉṀḷo°ɓẏ8YyŒÇḣðk¦»;ŒGṾṫ51ṣ”&Ḣḣ-23

A monadic link taking a number and returning a list of characters; as a full program prints the result.

Note: not sure quite why the result of ŒG needs to be forced to become a string (done here with ) :/

How?

“3¬ẋṙẉṀḷo°ɓẏ8YyŒÇḣðk¦» = compression of:
                         "code"+"golf"+"."+"stack"+"exchange"+".com/"+"user"+"s/"

codegolf.stackexchange.com/users/

“...»;ŒGṾṫ51ṣ”&Ḣḣ-23 - Main link: number, n
“...»                - "codegolf.stackexchange.com/users/"
     ;               - concatenate with n
      ŒG             - GET request (should be to string & looks like it on output)
        Ṿ            - uneval (force to a string - shrug)
         ṫ51         - tail from index 51 (seems the ŒG result is quoted too, so 51 not 50)
            ṣ”&      - split on '&'
               Ḣ     - head (get the first chunk)
                ḣ-23 - head to index -23 (discard the last 23 characters)
\$\endgroup\$
0
\$\begingroup\$

Mathematica, 126 bytes

StringTake[#&@@StringCases[Import["https://codegolf.stackexchange.com/users/"<>ToString@#,"Text"],"r "~~ __ ~~" - P"],{3,-4}]&  


input

[67961]

output

Jenny_mathy

\$\endgroup\$
0
\$\begingroup\$

Stratos, 22 bytes

f"¹⁸s/%²"r"⁷s"@0s"³_⁴"

Try it!

Explanation:

f"¹⁸s/%?"               Read the data from the URL: 
                        http://api.stackexchange.com/users/%?site=codegolf
                        where % is replaced with the input
         r              Get the JSON array named
          "⁷s"          items
              @0        Get the 0th element
                 s"³_⁴" Get the string "display_name"
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.