Commit 6e4fde56 authored by cividesk's avatar cividesk

Adding more fields to SE extraction

parent a1ef42b7
...@@ -717,11 +717,18 @@ CREATE TABLE IF NOT EXISTS `stackexchange_history` ( ...@@ -717,11 +717,18 @@ CREATE TABLE IF NOT EXISTS `stackexchange_history` (
DROP TABLE IF EXISTS `stackexchange_users`; DROP TABLE IF EXISTS `stackexchange_users`;
CREATE TABLE IF NOT EXISTS `stackexchange_users` ( CREATE TABLE IF NOT EXISTS `stackexchange_users` (
`user_id` INT(10) NOT NULL,
`account_id` INT(10) NOT NULL, `account_id` INT(10) NOT NULL,
`display_name` VARCHAR(64) NOT NULL, `display_name` VARCHAR(64) NOT NULL,
`user_type` VARCHAR(32) NOT NULL, `user_type` VARCHAR(32) NOT NULL,
`location` VARCHAR(255) NULL, `location` VARCHAR(255) NULL,
`creation_date` DATE NOT NULL,
`last_access_date` DATE NOT NULL,
`reputation` INT(10) NOT NULL, `reputation` INT(10) NOT NULL,
`reputation_change_week` INT(10) NOT NULL,
`reputation_change_month` INT(10) NOT NULL,
`reputation_change_quarter` INT(10) NOT NULL,
`reputation_change_year` INT(10) NOT NULL,
`accept_rate` INT(10) NULL, `accept_rate` INT(10) NULL,
`badges_gold` INT(10) NOT NULL, `badges_gold` INT(10) NOT NULL,
`badges_silver` INT(10) NOT NULL, `badges_silver` INT(10) NOT NULL,
......
...@@ -22,7 +22,7 @@ if ($result->items) { ...@@ -22,7 +22,7 @@ if ($result->items) {
// Get civicrm SE site users // Get civicrm SE site users
$dbh->query("TRUNCATE stackexchange_users"); $dbh->query("TRUNCATE stackexchange_users");
$url = "https://api.stackexchange.com/2.2/users?site=civicrm&pagesize=100"; $url = "https://api.stackexchange.com/2.2/users?site=civicrm&pagesize=100"; // Max pagezise is 100: https://api.stackexchange.com/docs/paging
$fields = $se_fields['users']; $fields = $se_fields['users'];
$page = 1; $count = 1; $page = 1; $count = 1;
do { do {
...@@ -34,6 +34,8 @@ do { ...@@ -34,6 +34,8 @@ do {
if (substr($field, 0, 6) == 'badges') { if (substr($field, 0, 6) == 'badges') {
$badge = substr($field, 7); $badge = substr($field, 7);
$line[$field] = $item->badge_counts->$badge; $line[$field] = $item->badge_counts->$badge;
} elseif (substr($field, -5) == '_date') {
$line[$field] = "FROM_UNIXTIME({$item->$field})";
} elseif (isset($item->$field)) { } elseif (isset($item->$field)) {
$line[$field] = is_numeric($item->$field) ? $item->$field : $dbh->quote($item->$field); $line[$field] = is_numeric($item->$field) ? $item->$field : $dbh->quote($item->$field);
} else } else
......
...@@ -18,5 +18,5 @@ function stackapi($url) { ...@@ -18,5 +18,5 @@ function stackapi($url) {
$se_fields = array( $se_fields = array(
'site' => array('total_users', 'total_badges', 'total_questions', 'total_answers', 'total_unanswered', 'total_accepted', 'total_votes', 'total_comments'), 'site' => array('total_users', 'total_badges', 'total_questions', 'total_answers', 'total_unanswered', 'total_accepted', 'total_votes', 'total_comments'),
'users' => array('account_id', 'display_name', 'user_type', 'location', 'reputation', 'accept_rate', 'badges_gold', 'badges_silver', 'badges_bronze'), 'users' => array('user_id', 'account_id', 'display_name', 'user_type', 'location', 'creation_date', 'last_access_date', 'reputation', 'reputation_change_week', 'reputation_change_month', 'reputation_change_quarter', 'reputation_change_year', 'accept_rate', 'badges_gold', 'badges_silver', 'badges_bronze'),
); );
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment