-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit.php
66 lines (50 loc) · 1.66 KB
/
git.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
//Getting user ids from github
date_default_timezone_set('Europe/Amsterdam');
//the way pagination works is, you get 100 results per query, and to get the next page, you need to start from the last id you got
$next=-1;
function getUsers($next)
{
$token = "APPTOKEN";
$url = "https://api.github.com/users?since=";
$request = curl_init();
curl_setopt($request, CURLOPT_URL, $url.$next);
curl_setopt($request, CURLOPT_HTTPHEADER, array('Authorization: token '.$token, "Content-Type: application/json"));
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
$content = curl_exec($request);
$results=json_decode($content, true);
return $results;
}
//You can make 5.000 calls per hour
for($i = 0; $i < 4200; $i++){
unset($ids);
$ids=array();
$call = getUsers($next);
$con = mysql_connect('127.0.0.1','root','');
if (!$con){
die('Could not connect: ' . mysql_error());
}
foreach($call as $item)
{
//I put all the ids in an array and then get the last element to paginate
$ids[]=$item["id"];
$next=end($ids);
$login=mysql_real_escape_string($item["login"]);
$id=$item["id"];
$avatar_url=mysql_real_escape_string($item["avatar_url"]);
$url=mysql_real_escape_string($item["url"]);
$html_url=mysql_real_escape_string($item["html_url"]);
$type=mysql_real_escape_string($item["type"]);
$site_admin=$item["site_admin"];
//I am just inserting everything into a mysql table
mysql_select_db("github", $con);
$query = "INSERT into users VALUES ('$login','$id','$avatar_url','$url','$html_url','$type','$site_admin')";
$result = mysql_query($query);
if ($result === false) {
// An error has occured...
echo mysql_error();
}
}
mysql_close($con);
}
?>