Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Free Code Camp
==============

The first working attempt at creating a specialized CamperBot
for tracking KGISL FCC camper progress.

To see the output:

1. Clone the project locally
2. Open the `index.html` within your browser
3. Depending upon your bandwidth, it might even take 1-2 minutes

4 changes: 0 additions & 4 deletions Readme.md

This file was deleted.

1,904 changes: 1,903 additions & 1 deletion data.json

Large diffs are not rendered by default.

137 changes: 137 additions & 0 deletions gBot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@

var key="ae28f23f134c4364ad45e7b7355cfa91c92038bb";
var arr=[];
var points=0;
var html='<table class="table" id="data"><tr><th>SNO</th><th>Avatar</th><th>Name</th><th>User Name</th><th>Points</th></tr>';

$(document).ready(function(){
var url='https://api.gitter.im/v1/rooms?access_token='+key;
var roomId="";
var noOfUsers=0;
$.ajax({
type:'GET',
url:url,
//data:data,
async: false,
dataType: 'json',
success: function (data) {
//Do stuff with the JSON data
for(var i=0;i< data.length;i++){
if(data[i]["name"]=='kgisl/campsite'){
roomId=data[i]["id"];
noOfUsers=data[i]["userCount"];
break;
}

}
},
error:function(xhr, textStatus, errorThrown){
points=0;
}
});
var jsonData=[];

for(var i=0;i<noOfUsers;i+=30){
$.ajax({
type:'GET',
url:'https://api.gitter.im/v1/rooms/'+roomId+'/users?access_token='+key+'&skip='+i,
//data:data,
async: false,
dataType: 'json',
success: function (data) {
$.merge(jsonData,data);
//alert(jsonData);
},
error:function(xhr, textStatus, errorThrown){
points=0;
}
});
}
getData(jsonData);
});

function getData(jsonData){

//alert(json["array"].length
var len=jsonData.length;
var sum=0;
for(var i=0;i<len;i++){
if(jsonData[i]["id"]!=='546fc9f1db8155e6700d6e8c' &&
jsonData[i]["id"]!=='5433c4b0163965c9bc209625' &&
jsonData[i]["id"]!=='570a6857187bb6f0eadec072') {
points=browniePointsFetcher(jsonData[i]["username"]);
sum+=points;
arr.push({
avatar:jsonData[i]["avatarUrlSmall"],
name:jsonData[i]["displayName"],
uname:jsonData[i]["username"],
points:points
});

$('.progress-bar').css({
width: (i/len) * 100 + '%'
});
}
}
$('.progress-bar').prop("hidden",true);


arr.sort(function(a,b){
return a.points- b.points;
});

arr.reverse();
var j=0;


html+=arr.map(function (a) {
j++;
return '<tr><td>'+(j)+'</td>'+dataFormatter(a.avatar, a.name, a.uname, a.points)+'</tr>';
}).join('');
html+='</table>';

$("#data").html(html);

var a=$("#data").html();
$("#campers").html('<h2><span class="label label-info">Total Campers:- '+j+'</span></h2>');
$("#totalProblems").html('<h2><span class="label label-info">Total Problems:- '+sum+'</span></h2>');

}

function browniePointsFetcher(uname){
var points=0;
var url='https://www.freecodecamp.com/api/users/about?username='+uname.toLowerCase();
$.ajax({
type:'GET',
url:url,
//data:data,
async: false,
dataType: 'json',
success: function (data) {
//Do stuff with the JSON data
points=data["about"]["browniePoints"];
},
error:function(xhr, textStatus, errorThrown){
points=0;
}
});
return points;
}


function dataFormatter(image,name,uname,points){
var temp_html='<td>';
temp_html+='<img src='+image+' class="img-thumbnail" width="100px" ></img></td>';
temp_html+='<td>';
temp_html+='<h3>'+name+'</h3></td>';
temp_html+='<td>';
temp_html+='<h3><a href="http://freecodecamp.com/'+uname+'" target="_blank">'+uname+'</a></h3></td>';
temp_html+='<td>';
if(points===0){
temp_html+='<h3><span class="label label-warning">'+points+'</span></h3></td>';
}else{
temp_html+='<h3>'+points+'</h3></td>';
}

return temp_html;
}
Binary file added img/Screenshot - 052816 - 07:26:11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
201 changes: 36 additions & 165 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,180 +1,51 @@
<!DOCTYPE HTML>
<html>
<head>
<title>
FreeCodeCamp KGISL
</title>

<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- jQuery library -->
<script src="js/jquery-1.12.4.min.js"></script>
<script type="text/javascript">

var key="ae28f23f134c4364ad45e7b7355cfa91c92038bb";
var arr=[];
var points=0;
var html='<table class="table" id="data"><tr><th>SNO</th><th>Avatar</th><th>Name</th><th>User Name</th><th>Points</th></tr>';
$(document).ready(function(){
var url='https://api.gitter.im/v1/rooms?access_token='+key;
var roomId="";
var noOfUsers=0;
$.ajax({
type:'GET',
url:url,
//data:data,
async: false,
dataType: 'json',
success: function (data) {
//Do stuff with the JSON data
for(var i=0;i< data.length;i++){
if(data[i]["name"]=='kgisl/campsite'){
roomId=data[i]["id"];
noOfUsers=data[i]["userCount"];
break;
}

}
},
error:function(xhr, textStatus, errorThrown){
points=0;
}
});
var jsonData=[];

for(var i=0;i<noOfUsers;i+=30){
$.ajax({
type:'GET',
url:'https://api.gitter.im/v1/rooms/'+roomId+'/users?access_token='+key+'&skip='+i,
//data:data,
async: false,
dataType: 'json',
success: function (data) {
$.merge(jsonData,data);
//alert(jsonData);
},
error:function(xhr, textStatus, errorThrown){
points=0;
}
});
}
getData(jsonData);
});

function getData(jsonData){

//alert(json["array"].length
var len=jsonData.length;
var sum=0;
for(var i=0;i<len;i++){
if(jsonData[i]["id"]!=='546fc9f1db8155e6700d6e8c' && jsonData[i]["id"]!=='5433c4b0163965c9bc209625'&& jsonData[i]["id"]!=='570a6857187bb6f0eadec072'){
points=browniePointsFetcher(jsonData[i]["username"]);
sum+=points;
arr.push({avatar:jsonData[i]["avatarUrlSmall"],name:jsonData[i]["displayName"],uname:jsonData[i]["username"],points:points});
$('.progress-bar').css({
width: (i/len) * 100 + '%'
});
}
}
$('.progress-bar').prop("hidden",true);



arr.sort(function(a,b){
return a.points- b.points;
});

arr.reverse();
var j=0;


html+=arr.map(function (a) {
j++;
return '<tr><td>'+(j)+'</td>'+dataFormater(a.avatar, a.name, a.uname, a.points)+'</tr>';
}).join('');
html+='</table>';

$("#data").html(html);

var a=$("#data").html();
$("#campers").html('<h2><span class="label label-info">Total Campers:- '+j+'</span></h2>');
$("#totalProblems").html('<h2><span class="label label-info">Total Problems:- '+sum+'</span></h2>');

}

function browniePointsFetcher(uname){
var points=0;
var url='https://www.freecodecamp.com/api/users/about?username='+uname.toLowerCase();
$.ajax({
type:'GET',
url:url,
//data:data,
async: false,
dataType: 'json',
success: function (data) {
//Do stuff with the JSON data
points=data["about"]["browniePoints"];
},
error:function(xhr, textStatus, errorThrown){
points=0;
}
});
return points;
}
function dataFormater(image,name,uname,points){
var temp_html='<td>';
temp_html+='<img src='+image+' class="img-thumbnail" width="100px" ></img></td>';
temp_html+='<td>';
temp_html+='<h3>'+name+'</h3></td>';
temp_html+='<td>';
temp_html+='<h3><a href="http://freecodecamp.com/'+uname+'" target="_blank">'+uname+'</a></h3></td>';
temp_html+='<td>';
if(points===0){
temp_html+='<h3><span class="label label-warning">'+points+'</span></h3></td>';
}else{
temp_html+='<h3>'+points+'</h3></td>';
}
<head>
<meta charset="UTF-8">
<title>
CamperBot for KGISL FCC Community
</title>

<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- jQuery library -->
<script src="js/jquery-1.12.4.min.js"></script>
</head>

<body>
<div class="container-fluid well">
<div class="row text-center">
<div class="col-xs-12">
<h1><span class="label label-primary">Free Code Camp User Report</span></h1>
</div>
</div>
<div class="row text-center">
<div class="col-xs-6" id="campers">

return temp_html;
}
</script>
</div>
<div class="col-xs-6" id="totalProblems">

<style type="text/css">
.col-xs-3{
border-color:#0f0f0f;
border-width: 2px;
}
</style>
</div>

</head>
<body>
<div class="container-fluid well">
<div class="row text-center">
<div class="col-xs-12">
<h1><span class="label label-primary">Free Code Camp User Report</span></h1>
</div>
</div>
<div class="row text-center">
<div class="col-xs-6" id="campers">
<br/>
<br/>
<div class="row text-center">
<div class="col-xs-12" id="data">

</div>
</div>
<div class="col-xs-6" id="totalProblems">

<div class="progress">
<div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100" style="width: 0%">
</div>
</div>

</div>
<br/>
<br/>
<div class="row text-center">
<div class="col-xs-12" id="data">
</body>

</div>
</div>
<script type="text/javascript" src="gBot.js"></script>
<link rel="stylesheet" href="style.css">

<div class="progress">
<div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100" style="width: 0%">
</div>
</div>

</div>
</body>
</html>

</html>
1 change: 1 addition & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php header( 'Location: /index.html' ) ; ?>
6 changes: 6 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<style type="text/css">
.col-xs-3{
border-color:#0f0f0f;
border-width: 2px;
}
</style>