last day (1657 days later) » 

13:56
Hello :)
user12867493
Hello!
user12867493
So say I want to get the CV count of 61930678
user12867493
user12867493
But not sure how to get the CV count from there...
I have no idea where to start with making a userscript. I think it will be best if I study it first :)
user12867493
13:58
@Scratte Same
Ahh.. but, this question doesn't have any close votes.
I'll try one that does
user12867493
Ah ok
this one: 61920329
it should have 1 vote
user12867493
user12867493
14:02
user12867493
Listed as close_vote_count in the headers
user12867493
I'll start by making a python script for it
You're fast :)
I haven't even started looking at how to do a script yet. I need to do a few tutorials on javascript :(
what is this strange thing filter=!)5IW-1CBJh-k0T7yaaeIcKxo)Nsr?
user12867493
I don't know, it was on the end of double-beep's code
user12867493
And it doesn't work if you don't use it
14:06
Yes, I noticed.. it doesn't make any sense though
user12867493
How can I extract close_vote_count from:
user12867493
{"items":[{"close_vote_count":1,"last_activity_date":1590056162,"question_id":61920329}],"has_more":false,"quota_max":300,"quota_remaining":143}
Wonder what that "quota_remaining":278 is.. and what happens when it's 0
user12867493
Every time i reload the page it goes down
So, you only get 300.. a day or for that unique filter? :)
user12867493
14:10
If I change the q ID the quota remains the same
Hmm.. but I didn't reload 22 times for that question id
ahh.. I answered it, maybe I have already spent some of my quota for it. Seems weird though
I'll try to work out how it extracts things
user12867493
I have 6 userscripts installed for a SE site, 3 for chat
I'm just guessing how this all works. I think I really need some basic knowledge :)
user12867493
I think 300 CV checks per day is fine per user, don't you?
and I also need to figure out how the developer tools work :)
I sometimes go though about 300 questions for NAA flagging
user12867493
14:21
I'll ask an experienced SE api user about the quota
and I keep them open to check that someone didn't edit their answers. if they do I remove my comment and retract the flag
But I am very curious about that strange filter
user12867493
You know there's a bit specifically for tracking posts if you flagged them?
No, I didn't :)
Hmm.. I did find something interesting here. Documentation for the api: api.stackexchange.com
user12867493
Hello @ArtOfCode
user12867493
So me and Scratte are working on a userscript to extract close votes from the api for people without the see cv privledge
user12867493
We need to extract the cv count from api.stackexchange.com/2.2/questions/…
@Daniil so what are you trying?
user12867493
import requests
ID=input()
url='https://api.stackexchange.com/2.2/questions/'+ID+'?order=desc&sort=activity&site=stackoverflow&filter=!)5IW-1CBJh-k0T7yaaeIcKxo)Nsr'
requests.get(url, headers={'close_vote_count': cvcount})
print(cvcount)
so you don't seen to work on your console all the time
@ArtOfCode Thanks :)
14:45
Ahh.. I found the filters :)
user12867493
@ArtOfCode I didn't find anything about the quota limit...
@Daniil wat
python can't do userscripts
user12867493
Yeah, I just realised I did it wrong
and in any case headers sends HTTP headers
user12867493
I know - I'm just testing how to work it
user12867493
14:52
Before doing it in js
There some information about the daily limits on api.stackexchange.com/docs/throttle
which also has a variable called "backoff". I think a script perhaps need that
user12867493
@Scratte the application needs an access token, can we get an access token considering we are doing a userscript?
No idea :) I'm new to json too :) I'm new to everything here
But I'm not sure you need an access token
If you can get a reply on the api, then I doubt you'll need it. I'm guessing you need it if you need access to some special kind of data
user12867493
But we'll need to access post data...
user12867493
Maybe there could be a button to load cvs
user12867493
15:04
So it doesn't do it for every question
user12867493
@Scratte I'm just gonna play around with my userscript maker
user12867493
See if I can get something useful
you don't need an access token, you probably don't even need a key
I need to drill some holes in my wall actually. Completely unrelated :)
though you could get a key just for extra capacity
user12867493
15:08
@ArtOfCode How do I get the cv count from api.stackexchange.com/2.2/questions/… ?
@ArtOfCode So the limit is 300 daily without a key. But goes to 10000 with one.
it's JSON
you need to parse the JSON and pull out the property you want
@Scratte yup
user12867493
Ok
user12867493
So we need a key?
user12867493
How do we get a key?
15:09
@Daniil Not if we make it a button :) we is you here.. I'm lost :)
user12867493
Should we make it a button?
user12867493
I'm gonna name the script Close Vote Retriever for now
Do we need to know the close vote count on all questions?
user12867493
I don't think we do
I rarely curate questions, so I'd only be curious if I want to: 1. Answer a question or 2: see it closed asap
user12867493
15:12
I'll put you as the author as well
I don't think my contribution here is even good enough for the -100 font footnote, to be honest
user12867493
I'll give you some credit :)
user12867493
I've inputted the metadata and am stuck now :/
user12867493
um...
heh.. you should really take the whole credit, please :) If anyone asks be about it, I'll say "Dunno, Daniil did it all" :)
Stuck in your python, or in javascript?
user12867493
15:14
Stuck in javascript
user12867493
I don't know any javascript
user12867493
Where I got to so far:
user12867493
// ==UserScript==
// @name Close Vote Retriever
// @namespace stackexchange
// @version 0.1
// @description Get's the close vote count for people without the close vote privledge
// @author Daniil, Scratte
//
// @include https://*stackoverflow.com/*
// @include https://*serverfault.com/*
// @include https://*superuser.com/*
// @include https://*askubuntu.com/*
// @include https://*mathoverflow.net/*
// @include https://*.stackexchange.com/*
//
user12867493
Right, extract the question id from the url
user12867493
I'll try and do that
15:16
I see.. that is a good start :) I need to be off for a while. I can't drill holes later this evening, so it has to be now
user12867493
Ok, bye :)
user12867493
15:26
@ArtOfCode to check whether the user is on a quesiton, is there any additional checks that need to be done apart from checking the url contains '/questions/'?
that'll tell you whether they're on a question page, yeah
user12867493
Ok, thanks
user12867493
@ArtOfCode how can I get the question id?
regex it out of the URL
or find data-questionid on the .question div
user12867493
but the question title could contain number as well?
15:38
or use StackExchange.question.getQuestionId()
user12867493
Ok, thanks
user12867493
I managed to check whether it's a question and get the question id I'm so happy
user12867493
Considering it's my first time using javascript
@Daniil yes
user12867493
@double-beep What additional checks?
15:42
the user may be in /questions/tagged/* page
user12867493
Good point
user12867493
@double-beep what does that use, an API?
nope, run it in the console
user12867493
Is there any way to so something like:
user12867493
StackExchange.type()
user12867493
15:48
To get if it's a question?
user12867493
I don't want to ask you too much or I am going to have to credit you :)
check for length of .question. There are too many ways
but why do you need to check if it's a question?
you can use regex in @include: questions/\d+/
user12867493
To know whether to show the get cv count button
user12867493
@double-beep that's not working
user12867493
@double-beep why is it not working?
16:00
isn't it really? What's your userscript manager?
user12867493
tampermonkey
// @include /^https://(?:[^/]+\.)?(?:(?:stackoverflow|serverfault|superuser|stackexchange|askubuntu|stackapps)\.com|mathoverflow\.net)/questions/\d+/ (from Stack Sidebar Question Stats)
user12867493
// @include      https://*stackoverflow.com/questions/\d+/*
that also works
user12867493
Why doesn't my one work?
user12867493
16:02
user12867493
Completely random example ^
shall I say the answer?
add /^ for regex
user12867493
Ok, thanks
user12867493
Do you want credit by the way?
user12867493
Still doesn't work...
user12867493
16:12
add /^ where?
at the start of the regex
/^https://.*stackoverflow.com/questions/\d+/.*/
@Daniil nope.
user12867493
@ArtOfCode thanks
user12867493
16:25
How can I get the close_vote_count from the API?
user12867493
I'm stuck there
have you done a GET?
user12867493
no
user12867493
I'll do that
user12867493
17:02
@double-beep I have this:
user12867493
$.get(urlneeded, results=>{results.items[0].close_vote_count})
user12867493
Is there anyway to get the last part to be saved to a variable or just output to console and read console output?
console.log(stuff)
user12867493
@double-beep I know that
user12867493
I'm asking to I have to log it to the console?
17:06
so what do you want?
user12867493
To save:
user12867493
results=>{results.items[0].close_vote_count}
user12867493
In a variable
var variable = '';
user12867493
Or do I need to log it to the console and read from the console?
17:07
@Daniil AFAIK you can't do that
user12867493
So this code:
user12867493
$.get(`api.stackexchange.com/2.2/q${id}?order=desc&sort=activity&site=stackoverflow&filter=!)5IW-1CBJh-k0T7yaaeIcKxo)Nsr`, results=>{console.log(results.items[0].close_vote_count)})
user12867493
How do I save what is logged to the console?
user12867493
Either as a variable or somehow else?
the URL should have https://
you can use var/const variable = stuff;
but it won't be accessible outside the GET request because it's declared inside a function
results => {code} == function(results) {code}
17:11
You seem to have gotten through a lot already.
Oh.. Daniil left, or maybe the count was up :)
 
2 hours later…
18:41
@Daniil ping me when you are done with the userscript, so that I can publish my own version ;)
19:00
@Daniil Can you post your progress somewhere? So we can see what you've made? I'd like to learn something :)
user12867493
19:54
@double-beep Sure, I’m done for today but I hope to have it ready within a week
user12867493
@Scratte I haven’t made much yet :) All it is is it checks whether the page is a question, if it isn’t a question it won’t run. Then it gets the question ID and outputs the close vote count to the console
user12867493
Plus I’ve passed my quota for today
@double-beep We don't have keys :) Do you mean access token?
see the link
19:59
We discussed access tokens already and kind of went with: perhaps 300 requests a day is ok.
no, no, scroll down to the example and use the key there ;)
lol!.. that's an actual valid key?!?
yes
Haaaaaaa<few minutes later>aaaaack
hehe..
but if a key is put into the script, how will the script work for others? I mean we can't all use the same one
20:04
I may use it 9998 times in a day. That only leaves 2 for Daniil
the key is per-IP
you can make 10k calls a day, Daniil another 10k, etc.
Then there's something I don't understand about keys.
plus you can register in StackApps
even if you add a random title, body, OAuth domain, etc., you will get an API token and you don't need to make a post in StackApps.
that's needed for write access (generate access tokens)
we definitely do not need that
but I really feel that there's something that I'm not understanding about keys and authentication
user12867493
@double-beep the issue was I made too many requests too quickly
user12867493
20:11
@Scratte did you drill your holes?
user12867493
@double-beep how close are your to finishing?
@Daniil Yup.. 30 in total. Only 27 were good. I need to fix 3 tomorrow. They were just empty behind the first layer, so no screws in those yet :)
user12867493
@double-beep I thought stack apps was for advertising the script?
user12867493
Why do I need another access token?
user12867493
@Scratte I will share the code by the beginning of next week for testing (hopefully)
20:15
So.. a key is not an access token?
user12867493
I’m confused as well...
@Daniil Ok. You need to remove me on the credits. I was drilling holes while you were doing the work :)
user12867493
So we need both a token and a key? @double-beep
I don't think we need an access token at all. I think that's just if you want to use it to do something, like putting comments on posts or voting on stuff
user12867493
@Scratte If you have any more ideas we can share them (privately), so double beep doesn’t steal them :)
user12867493
20:19
Then, since I already have some experience, we can work on it together
5 hours ago, by ArtOfCode
you don't need an access token, you probably don't even need a key
user12867493
@ArtOfCode We do
user12867493
I got rate-limited
emphasis probably
so you want a key in that case, you don't need an access token
user12867493
Also hello since you just popped out of nowhere :)
user12867493
20:20
@double-beep confused us
user12867493
12 mins ago, by double-beep
even if you add a random title, body, OAuth domain, etc., you will get an API token and you don't need to make a post in StackApps.
user12867493
@ArtOfCode lol
@Daniil I have lots of ideas for userscripts. But just like Questions, I need to put in some efforts and know what I'm talking about before just blurting them out :)
user12867493
What’s your email?
20:23
@Daniil it is done.
I should probably change the location of the info, but... tomorrow
user12867493
@double-beep Already, wow
Email?!? I can find one. I can't give you my login email. Are you really scared that someone will steal your idea? :)
you don't need an access token
this grants you write access to perform on behalf of a user
user12867493
Well, double-beep and Art are always watching us...
user12867493
Unless I kick them
20:25
@Daniil eh, given that I could do this userscript for myself in about 10 minutes if I wanted it...
@Daniil I don't mind.. they will even tell us if we're doing something wrong :)
user12867493
@ArtOfCode It’s my first time using Java Script, have some mercy :)
@Daniil my point exactly
you're learning, I'm not
@ArtOfCode oh, that's 5.371927366428843 5 minutes less than I did
@Daniil I haven't even figured out how to make a userscipt pop up with an alert, so..
20:28
// ==UserScript==
// put US metadata here
// ==/UserScript==

(() => {
  "use strict";

  $(() => {
    alert('hi');
  });
})();
user12867493
@Scratte so are we doing it with a key and doing it for every question?
user12867493
Without a button
night o/
@Daniil Which do you prefer?
@ArtOfCode Thank you :)
user12867493
@double-beep Don’t really get the code
user12867493
20:33
@Scratte Probably every question but have no idea as to how to use the key
@Daniil I cheat when I have no clue. I look at other userscripts.
user12867493
@ArtOfCode how do I use the key?
user12867493
Do I just add:
user12867493
SE.init({
// Parameters obtained by registering an app, these are specific to the SE
// documentation site
clientId: 1,
key: 'U4DMV*8nvpm3EOpvf69Rxw((',
// Used for cross domain communication, it will be validated
channelUrl: 'https://api.stackexchange.com/docs/proxy',
// Called when all initialization is finished
complete: function(data) {
$('#login-button')
.removeAttr('disabled')
.text('Run Example With Version '+data.version);
}
});
// () => { ... } is a function
// wrap it in () so it's self-contained and can "use strict" within its own
// context so it doesn't affect anything else
// follow the ()-wrapped function with () to call the function so it runs
// immediately after it loads
//
// functionally this: ( () => { ... } )()
//                      ^^^^^^^^^^^^^     function
//                    ^^^^^^^^^^^^^^^^^   wrapping
//                                     ^^ call it
(() => {
  // "use strict" tells the JS interpreter to use more strict rules about how
for those learning JS, that's how that alert script works
@Daniil no, you don't touch SE.init at all
oh, I see, you're using the API SDK? don't
20:41
Strangely Tampermonkey is saying that "There's an unexpected token )" at the very beginning: (() => {
make sure you've set it to use ES6
user12867493
@ArtOfCode In the nicest way possible that didn’t help at all
@Daniil not with the API issues, no, it wasn't meant to :P
user12867493
@ArtOfCode So how do I do the key thing?
6 mins ago, by ArtOfCode
oh, I see, you're using the API SDK? don't
user12867493
20:49
So how do I get past the 300 quota and rate-limit?
@ArtOfCode Heh.. where do I check that? :)
const API_KEY = 'put your key here';

const makeAPIRequest = async (url, parameters) => {
  parameters = Object.assign({
    key: API_KEY
  }, parameters);
  url = url + Object.keys(parameters).map(k => `${k}=${parameters[k]}`).join('&');
  const resp = await fetch(url);
  const data = await resp.json();
  return data;
}
@Daniil ^ stick that somewhere near the top of your script and put an API key in place of "put your key here"
then use makeAPIRequest('https://api.stackexchange.com/2.2/whatever', { ... }) to use the API
user12867493
Where do I get a API key?
@Scratte yeah, just trying to work that out
i'm not getting a syntax error from it... can you just save the script anyway and try to run it, see if that works?
@ArtOfCode I get syntax error on all scripts :) They usually run anyway :D
But this one doesn't
20:53
screenshot your editor?
user12867493
So how do I get a key from stack apps?
user12867493
Also it it one key for everyone or 1 per user?
@ArtOfCode Not sure I would call it an editor. I just pasted it into a new userscript
@Scratte what's on lines 1-12?
// ==UserScript==
// @name New Userscript
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://api.stackexchange.com/
// @grant none
// ==/UserScript==

// () => { ... } is a function
// wrap it in () so it's self-contained and can "use strict" within its own
grr.. no code block
20:59
@Scratte so that'll only run on api.stackexchange.com because of the @match line
@Scratte indent every line by 4 spaces for code
Yup :)
shrug looks like it should work to me, every time you load or refresh that page
heh.. ok. Thanks though :)
@Daniil read the docs, it's not hard to find
@Scratte only thing that comes to mind is that it looks like you're using the dev version of TM, rather than stable, which might have an effect
user12867493
@ArtOfCode What is an oauth domain?
21:03
something you need if you want write access
you don't, so stick example.com in there
@ArtOfCode I installed it quite recently. Version 4.9.6091 by derjanb. But I can try to update it :)
user12867493
So is the quota separate for all users and the key is the same for all users?
@Scratte being updated may not be the problem - the dev version is the "unstable" version that's in development. There's another version of Tampermonkey that's the "stable" version, which is tested and more stable. You're using the former, by the looks; you may want to use the latter.
@Daniil correct
@ArtOfCode Ahh.. ok. I just found whatever was there for Opera :)
@Scratte have a look for the one with the same icon, but in black not red :)
21:13
@ArtOfCode I think you're right. I just noticed it says "tampermonkey-beta" for the extension on Opera addons
aye, that's the one
But.. by the looks of it, that's all I got for Opera
there might be a way :)
heh.. Opera says this about the stable version: We've identified this extension as malicious and have blacklisted it. This means it can no longer cause any damage to your machine. You can leave it as is, or remove it.
user12867493
Don’t use Opera then :)
21:20
@Scratte and they don't give you an "advanced" or "ignore this warning" kinda button that you can click to use it anyway?
@ArtOfCode I clicked it.. it just sits there like it's disgruntled or something :D
It's not having it. It asked me if I was absolute sure about installing it.. but I can't turn it on :)
Ok, so now I installed ViolentMonkey instead. It's not complaining about any parsing errors, but the alert is not coming :)
But it does have that little 1 saying that the userscript is active on the https://api.stackexchange.com/
21:43
Oh
Ha
there's no jQuery on api.stackexchange.com
@ArtOfCode ha?
change the @match to the URL of this room and try it here instead
that worked.. with tampermonkey as well :)
excellent
what's the deal with jQuery?
21:47
what about it?
why does a site need to have it for a userscript to work?
it doesn't
but I used jQuery in that example script, so not having it means it doesn't work
you could do it without jQuery too, I just like it
Oh.. ok :)
considering I didn't know how to create an alert, there's a long way to go..
@Daniil You should consider remaining this room to "Userscript newbies and friends" or something :)
22:26
renaming.. not remaining.. pff.
user12867493
22:49
room topic changed to Userscript newbies and friends: (no tags)
user12867493
@ArtOfCode what part of the script is jquery?
user12867493
Oh ok
user12867493
Also why use match instead of include?

  last day (1657 days later) »