Tell me about my question!

6

1

I'm a narcissist. (Not Really)

I'm also very lazy... (Not Really)

So I want to know the score of this question, and how many people have viewed it.

But I'm too lazy to check myself...

Challenge

Your challenge is to output the score of this question, and how many views there are. No input may be taken, and output may be given as pretty much anything as long as it's clear where the two numbers are outputted. So, all of the following are valid:

[1, 1]
score 1, 1 view
1 1
1, 1
1........1
HELLO1WORLD1

Note that pluralization matters, so "1 views" is invalid output.

I am very lazy, so I want this code to be as short as possible.
You may assume that there is an internet connection.
You may want to use the SE API. For reference, this question has id 111115.

Rules

No URL shorteners are allowed.
You may assume that votes are not expanded (for users below 1000 rep: users with at least 1000 rep can click on the score of a post to see the upvotes and downvotes individually. You may assume that this was not done).

Scoring

This is a code-golf challenge, so the shortest valid submission by March 14th (Pi Day) wins! Happy golfing!

HyperNeutrino

Posted 2017-02-24T02:11:34.240

Reputation: 26 575

Question was closed 2017-03-11T07:01:19.227

Related: Stack Exchange Vote Counter

– Dennis – 2017-02-24T02:18:32.360

@Dennis Hm. I did not find that in my search. Strange. Also, I have a question that you may be able to answer. Does the API tell you how many upvotes I have, or just the overall score? – HyperNeutrino – 2017-02-24T02:20:17.760

Is usage of the SE API required? I don't see how it's "definitely" necessary (for example, one could scrape and parse the HTML of this page). – Doorknob – 2017-02-24T02:20:43.980

@Doorknob That is true. Also, thanks for correcting my code; I forgot about being politically correct (I'm rather uncareful about that). – HyperNeutrino – 2017-02-24T02:21:17.237

@HyperNeutrino I can't find the "views" attribute on the SE api, so I don't think it's even possible to solve this with the SE api. – NoOneIsHere – 2017-02-24T02:21:30.897

@NoOneIsHere JSON.items[0].view_count. – HyperNeutrino – 2017-02-24T02:23:04.460

Related. – R. Kap – 2017-02-24T02:27:34.233

@HyperNeutrino I don't think likes is in the dump (after viewing the right dump). – NoOneIsHere – 2017-02-24T02:33:56.530

@NoOneIsHere Yeah, I can't seem to find it. You can theoretically get it, but only if you have over 1000 rep, and I don't think it's allowed to make questions only people with enough rep can answer, so I'm going to change that. – HyperNeutrino – 2017-02-24T02:36:48.350

@NoOneIsHere I've fixed the specs, so you only need to give me the overall score. It should be possible now. – HyperNeutrino – 2017-02-24T02:38:50.703

@HyperNeutrino Thanks, I posted my answer! – NoOneIsHere – 2017-02-24T02:40:25.183

Can we use http://s.tk/ ?

– zeppelin – 2017-02-24T11:07:24.500

@zeppelin I'm going to say no, because that's a URL shortener, but if you have a solution that can use that, I'd like to see (you can ping me on The Nineteenth Byte).

– HyperNeutrino – 2017-02-24T14:14:08.430

Additionally, I'm not sure s.tk works because you can't go to a specific question with it, but again, I'm not sure. – HyperNeutrino – 2017-02-24T14:14:38.013

Answers

6

T-SQL, 49 bytes

According to the FAQ the database will be updated on Sunday 0300 UTC so this is when you'll get your result. So I'm hoping you're a patient lazy (not really) narcissist (not really).

select Score,ViewCount
from Posts
where Id=111115

https://data.stackexchange.com/codegolf/query/632441/tell-me-about-my-question

ʰᵈˑ

Posted 2017-02-24T02:11:34.240

Reputation: 1 426

Haha. That's an interesting solution. :) I'm upvoting it, but I'm not considering it a valid solution for accepting, because it isn't always up to date (what if I get 10 upvotes between Sunday and Friday? I really want to see all those upvotes coming in... :P). But keep this here, good job! – HyperNeutrino – 2017-02-24T14:09:03.250

@HyperNeutrino that's fair enough :) thanks – ʰᵈˑ – 2017-02-24T14:22:05.007

3

JavaScript + jQuery, 109 bytes

$.get('//api.stackexchange.com/questions/111115?site=codegolf',x=>alert([(a=x.items[0]).view_count,a.score]))
<!-- Click run | below! -->
<!--           v        --> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

Same strategy as my answer on a related question.

NoOneIsHere

Posted 2017-02-24T02:11:34.240

Reputation: 1 916

Yay, good job! +1 – HyperNeutrino – 2017-02-24T02:41:15.383

@HyperNeutrino Editing to add comments. – NoOneIsHere – 2017-02-24T02:41:45.233

Oh, okay. I just rolled that back because you submitted, but if you edit it, I'll unrollback. – HyperNeutrino – 2017-02-24T02:45:56.210

@HyperNeutrino Actually, getting comments is a completely different request. I'm not going to add that. – NoOneIsHere – 2017-02-24T02:46:26.523

Yeah. I think it actually requires /questions/comments/{ids}, so don't bother. I've rolled back already. – HyperNeutrino – 2017-02-24T02:47:19.653

Let us continue this discussion in chat.

– HyperNeutrino – 2017-02-24T03:00:00.173

2

JavaScript, 129 105 bytes

Non-API solution.

f=(v,n)=>document.getElementsByClassName(v)[n].innerText;alert([f("vote-count-post",0),f("label-key",3)])

You should be able to run this in your browser's developer tools.

Oliver

Posted 2017-02-24T02:11:34.240

Reputation: 7 160

Yep, this works! Just one side note, when I expand out the votes (1000 rep feature), it no longer works, so I'll add into the specs that you may assume that the votes are not expanded. +1! :) – HyperNeutrino – 2017-02-24T03:02:16.560

@HyperNeutrino It should now work for expanded votes. – Oliver – 2017-02-24T15:08:42.630

Nice job! It's not necessary, but I see that you have shortened your solution as well. I've tested it and it now works as expected, giving me my upvote count, downvote count, and view count. – HyperNeutrino – 2017-02-24T15:28:57.163

2

Javascript (ES6), 128 bytes

fetch('//api.stackexchange.com/questions/111115?site=codegolf').then(x=>x.text()).then(x=>alert([(x=x.match(/\d+/g))[10],x[8]]))

nderscore

Posted 2017-02-24T02:11:34.240

Reputation: 4 912

1Huh, how long has fetch existed? I've never heard of it before... – ETHproductions – 2017-02-24T12:44:50.690

@ETHproductions it's been in Chrome and Firefox since mid-2015 :D – nderscore – 2017-02-24T16:31:03.740

Nice solution! +1 – HyperNeutrino – 2017-02-26T20:17:11.330

2

Bash + curl, 82 90 99 95 90 89 bytes

Edit 1: I had to do better searches to omit the keywords from my own answer, hence more bytes.

Edit 2: Using sed magic I got the byte count down again

curl -L codegolf.stackexchange.com/q/111115>f
grep -m1 t-post f
sed -n '/key.>\r/{n;p}' f

When curl accesses that short URL format, it receives a 302 redirection page that has this question's URL in the body section, so the -L option is needed to follow it. After that, it downloads the source code of this html page to a file named f. Then I search the keywords associated with the statistics wanted and print the answer on STDOUT.

Test: I redirect STDERR just for clarity (stats at the time of this posting)

me@LCARS:/PPCG$ ./Q_stats.sh 2> /dev/null
        <span itemprop="upvoteCount" class="vote-count-post ">7</span>
                                    <b>398 times</b>

The output is pretty verbose, but the syntax of both lines is basically junk text>VALUE<more junk text, which should be allowed according to the challenge description.

seshoumara

Posted 2017-02-24T02:11:34.240

Reputation: 2 878

Yep, since the "junk text" is always consistent, this is a valid answer. Nice job! +1 – HyperNeutrino – 2017-02-24T14:10:06.387

Removed my URL comment and explained it in the answer. – seshoumara – 2017-03-03T20:52:49.753

2

Python 3 + requests, 150 143 bytes

(__import__("requests").get("http://api.stackexchange.com/questions/111115?site=codegolf").json()['items'][0][k]for k in('score','view_count'))

7 bytes shorter thanks to notjagan.

Output: [4, 270]

L3viathan

Posted 2017-02-24T02:11:34.240

Reputation: 3 151

Good job! :) +1 – HyperNeutrino – 2017-03-03T20:54:15.883

1-7 bytes with [__import__("requests").get("http://api.stackexchange.com/questions/111115?site=codegolf").json()['items'][0][k]for k in('score','view_count')]. – notjagan – 2017-03-03T22:05:38.167

@notjagan I edited it, but I'm not sure it's correct. Is an expression a valid output? – L3viathan – 2017-03-03T22:40:54.310

1

A generator function as output is allowed. http://meta.codegolf.stackexchange.com/a/10753/34718

– mbomb007 – 2017-03-03T22:44:57.597

@mbomb007 Good point, editing it now. – L3viathan – 2017-03-03T22:45:34.490

1

Powershell, 119 Bytes

,"-po.+?>(.+?)<","(\d+) times<"|%{[Regex]::Match((irm codegolf.stackexchange.com/questions/111115),$_).Groups[1].Value}

Outputs like

enter image description here

Shortest regex I could get to match exactly the vote count and nothing else, could make it shorter but then you would need to use Matches instead of Match

irm is short for Invoke-RestMethod and returns the raw page as text, then we just regex match the line

<span itemprop="upvoteCount" class="vote-count-post " title="View upvote and downvote totals" style="cursor: pointer;">4</span>

by looking for -po in count-post, up to the next >, then everything between that and the next < is captured and retrieved.

using basic request web parsing in powershell requires calls to things like getElementsByClassName which aren't very golf friendly, so the irm method seems to be shortest.

colsw

Posted 2017-02-24T02:11:34.240

Reputation: 3 195

This isn't quite valid because it's missing the views. Additionally, could you add a link to an online Powershell emulator (I can't find one) or attach an animated image of you running your program? Thanks! – HyperNeutrino – 2017-02-24T14:06:36.233

@HyperNeutrino Powershell is standard on any windows Machine, I've put an image in showing the results though. – colsw – 2017-02-24T14:28:18.463

Yes, but I use Linux. :P – HyperNeutrino – 2017-02-24T14:28:36.233

Alright, appears to work now! +1 – HyperNeutrino – 2017-02-26T04:58:11.530