Topic: [Feature] User Credit API

Posted under Site Bug Reports & Feature Requests

Requested feature overview description.

Provide a simpler way to get hourly and total credit limits via API. It could be at /user/credit.

The way it could work is when user sends username and api key would return a list of credit names and remaining amounts (uploads hourly, uploads total, note edits, flags,...) like

[{"tag_edits":150},{"flags":10},...]

Why would it be useful?

It would be simpler and more accurate for app makers to implement limits into their apps.

What part(s) of the site page(s) are affected?

API

Updated by savageorange

Pup

Privileged

I don't believe there's an API endpoint for it, but you could parse:

https://e621.net/user/upload_limit

Though it would be awkward to check it with a program, as you still need to log in to see it..

Updated by anonymous

Pupslut said:
I don't believe there's an API endpoint for it, but you could parse:

https://e621.net/user/upload_limit

Though it would be awkward to check it with a program, as you still need to log in to see it..

Yes, that + more and make it an api.

There are alternative ways that don't require login but take a while.

Updated by anonymous

Pupslut said:
I don't believe there's an API endpoint for it, but you could parse:

https://e621.net/user/upload_limit

This seemed like an interesting problem, so here's my solution.

You can get all the relevant elements with the xpath /html/body/div[4]/div[1]/ul/li (although it might be better to change this into a class based check rather than indexing). This is a slight modification of one produced by Firefox's Inspector.

so, Python+LXML solution:

import lxml.html as lh
# put in download code here.. for my test I just saved using the browser.
h = lh.parse(downloaded_html) 
nodes = h.xpath('/html/body/div[4]/div[1]/ul/li')
d = {}
for v in nodes:
    nodes = h.xpath('/html/body/div[4]/div[1]/ul/li')
    # filter out the 'Formula:' line
    if not val.isdigit():
        continue
    d[id.lower()] = int(val)

The result (d) looks like this:

{'approved': 1, 'deleted': 3, 'pending/flagged': 0, 'remaining hourly uploads': 30, 'remaining hourly tag edits': 150}

Login would be trivial if there was an API endpoint, but it seems like urls which are not API endpoints ignore the usual login / passwordhash POST parameters (meaning that requesting /user/upload_limit does return a legible page, but all limits are set to a value of 0).

So you'd probably have to use something like the mechanize module to pretend to be a browser. Not especially hard, but it does slow things down, since you need to wait for two requests from the server, instead of one).

Updated by anonymous

  • 1