From 82fadf9b358e29f1736108112f4e8f9be8a8fcca Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Mon, 27 Jul 2015 20:10:46 -0700 Subject: [PATCH] Add script for getting user info --- scripts/getuserinfo.moon | 47 ++++++++++++++++++++++++++++++++++++++++ scripts/testssl.moon | 5 +++++ 2 files changed, 52 insertions(+) create mode 100644 scripts/getuserinfo.moon create mode 100644 scripts/testssl.moon diff --git a/scripts/getuserinfo.moon b/scripts/getuserinfo.moon new file mode 100644 index 0000000..fb7e096 --- /dev/null +++ b/scripts/getuserinfo.moon @@ -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; ]] diff --git a/scripts/testssl.moon b/scripts/testssl.moon new file mode 100644 index 0000000..1aab2af --- /dev/null +++ b/scripts/testssl.moon @@ -0,0 +1,5 @@ +https = require "ssl.https" + +reply = https.request "https://christine.website" + +print reply