Add script for getting user info

This commit is contained in:
Christine Dodrill 2015-07-27 20:10:46 -07:00
parent 2c687120b5
commit 82fadf9b35
2 changed files with 52 additions and 0 deletions

47
scripts/getuserinfo.moon Normal file
View File

@ -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; ]]

5
scripts/testssl.moon Normal file
View File

@ -0,0 +1,5 @@
https = require "ssl.https"
reply = https.request "https://christine.website"
print reply