-
Notifications
You must be signed in to change notification settings - Fork 4
/
parse.php
137 lines (80 loc) · 3.96 KB
/
parse.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
//load function to check if valid bitcoin address
require_once "checkaddress.php";
//load database
require_once "db.php";
$mysqli = new mysqli($dbserver, $dbuser, $dbpassword, $dbname);
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
//create new table template for daily stats
$tablecreate = "CREATE TABLE IF NOT EXISTS `template` ( `id` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY, `name` VARCHAR( 100 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, `token` VARCHAR( 24 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL , `address` VARCHAR( 40 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL , `totalpts` VARCHAR( 20 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL)";
//create new table for today's stats
$tablecreate = "CREATE TABLE `$day` LIKE `template`";
if ($mysqli->query($tablecreate) === TRUE) {
echo "Table created successfully<br>---<br>";
$filename = $day.".txt";
$i = 0;
//parse data from [TODAY].txt line-by-line
$handle = @fopen($filename, "r");
if ($handle) {
while (($buffer = fgets($handle, 4096)) !== false) {
//skip first two lines of data file
if($i > 1) {
$linedata = explode(" ", $buffer);
$name = $linedata[0];
$credit = $linedata[1];
//usernames must be at least 26 characters
if (strlen($name) >= 26) {
//check if member of Foldingcoin team (226728) and using bitcoin address only username
$team = trim($linedata[3]);
if ($team == "226728") {
$isvalid = checkAddress($name);
if($isvalid == 1) {
$namelinedata[0] = "---";
$namelinedata[1] = "FLDC";
$namelinedata[2] = $name;
} else {
$namelinedata = explode("_", $buffer);
}
} else {
$namelinedata = explode("_", $buffer);
}
//check for Foldingcoin user by naming convention
if (count($namelinedata) == 3 || $namelinedata[0] == "---") {
//check if token indicated in username is valid
if($namelinedata[1] == "ALL" || $namelinedata[1] == "FLDC" || $namelinedata[1] == "OCTO" || $namelinedata[1] == "MAGICFLDC" || $namelinedata[1] == "SCOTCOIN" || $namelinedata[1] == "FANTOKEN"){
$fldcname = $namelinedata[0];
$token = $namelinedata[1];
$addressdata = explode(" ",$namelinedata[2]);
$address = $addressdata[0];
//check if bitcoin address is valid
if(strlen($address) >= 26 && strlen($address) <= 35 && substr($address,0,1) == 1 ) {
if (ctype_alnum($address)) {
$isvalid = checkAddress($address);
if($isvalid == 1) {
echo $name." - ";
echo $credit."<br>";
//enter foldingcoin user information into database
$tableentry = "INSERT INTO `$dbname`.`$day` (`name`, `token`, `address`, `totalpts`) VALUES ('$fldcname','$token','$address','$credit')";
$mysqli->query($tableentry);
}
}
}
}
}
}
}
//LIMIT FOR TESTING ONLY
//if($i > 10000) {break;}
$i++;
}
fclose($handle);
}
$mysqli->close();
} else {
echo "Error creating table: " . $mysqli->error;
}
?>