Add script for getting user info
This commit is contained in:
parent
2c687120b5
commit
82fadf9b35
|
@ -0,0 +1,47 @@
|
||||||
|
https = require "ssl.https"
|
||||||
|
json = require "dkjson"
|
||||||
|
socket = require "socket"
|
||||||
|
sqlite3 = require "lsqlite3"
|
||||||
|
|
||||||
|
authors = {}
|
||||||
|
|
||||||
|
with fin = io.open "../raw/authors.txt", "r"
|
||||||
|
while true
|
||||||
|
line = fin\read "*l"
|
||||||
|
break unless line
|
||||||
|
|
||||||
|
table.insert authors, line
|
||||||
|
|
||||||
|
assert #authors == 193
|
||||||
|
|
||||||
|
db = assert sqlite3.open "../db/posts.db"
|
||||||
|
|
||||||
|
insert_stmt = assert db\prepare "INSERT INTO Users VALUES (NULL, ?, ?, ?)"
|
||||||
|
|
||||||
|
db\exec [[ BEGIN TRANSACTION; ]]
|
||||||
|
|
||||||
|
for i, author in pairs authors
|
||||||
|
print "fetching for #{author}..."
|
||||||
|
|
||||||
|
reply, code, headers = https.request "https://derpibooru.org/profiles/#{author}.json"
|
||||||
|
if code ~= 200
|
||||||
|
db\exec [[ ROLLBACK; ]]
|
||||||
|
error reply
|
||||||
|
|
||||||
|
person, _, err = json.decode reply
|
||||||
|
if err
|
||||||
|
db\exec [[ ROLLBACK; ]]
|
||||||
|
error err
|
||||||
|
|
||||||
|
print "found #{person.name}"
|
||||||
|
|
||||||
|
do
|
||||||
|
insert_stmt\bind_values person.id, person.name, person.avatar
|
||||||
|
insert_stmt\step!
|
||||||
|
insert_stmt\reset!
|
||||||
|
|
||||||
|
print "done at #{os.date!}"
|
||||||
|
|
||||||
|
socket.sleep 1
|
||||||
|
|
||||||
|
db\exec [[ COMMIT; ]]
|
|
@ -0,0 +1,5 @@
|
||||||
|
https = require "ssl.https"
|
||||||
|
|
||||||
|
reply = https.request "https://christine.website"
|
||||||
|
|
||||||
|
print reply
|
Loading…
Reference in New Issue