Access World Data

obscurum

Guest
There is a post made about World Data, but many of the features have changes since then.

Available Data
Alliances -- http://en1.grepolis.com/data/alliances.txt
Players -- http://en1.grepolis.com/data/players.txt
Towns -- http://en1.grepolis.com/data/towns.txt
Islands -- http://en1.grepolis.com/data/islands.txt Only download once!
Conquest -- http://en1.grepolis.com/data/conquers.txt
units -- http://en1.grepolis.com/data/units.json

Here is a sample of how I handled a data import:

Code:
<?php

$dbh=mysql_connect ("localhost", "dbuser",
"dbpass") or die('Cannot connect to the database because: ' . mysql_error());
mysql_select_db ("dbdatabase");
ini_set("memory_limit","100M");
mysql_query("Truncate Table players");
$datafile = file('http://en1.grepolis.com/data/players.txt');
if(!is_array($datafile)) die("File could not be opened");

foreach($datafile as $datum){
	list($id, $name, $alliance_id, $points, $rank, $towns) = explode(',', $datum);

	If (isset($alliance_id)){ $alliance_id=0; }
	If (isset($points)){ $points=0; }
	If (isset($rank)){ $rank=0; }
	If (isset($towns)){ $towns=0; }
	$INSERT = "INSERT INTO `players` (`id`, `name`, `ally`, `points`, `rank`, `villages`) VALUES ($id, '$name', $alliance_id, $points, $rank, $towns)";

	$result = mysql_query("$INSERT");
	if (!$result) {
	print"$id, $name, $alliance_id, $points, $rank, $towns <br> alliance_id='$alliance_id' <br>";
		print"$INSERT <br>";
		die('Invalid query: ' . mysql_error());
	}

}
print "The database has been updated";

mysql_close($dbh);

?>
 

obscurum

Guest
Well it still has a sample. Thanks for providing the list of all the tables ac04! I was busy editing my scripts to changes from json to txt and did not see your post. My apologies.
 

Ac04

Strategos
Haha, no worries. Also, please use the .txt.gz files, as they are the compressed version, and will use less resources when downloading them from the server.

Use the function gzfile() to access the datafiles, and then list and explode.
 

obscurum

Guest
I am familiar with that function...want me to change the sample or is this thread getting tossed?
 

Ac04

Strategos
I can add a sample into the announcement I made, as it's probably easier to find than this one here. Rather than creating my own code for this, mind if I plagarise your code, and put it into the announcement? I can deal with the editing of the code.
 

obscurum

Guest
Please do . . . and then delete this. I am not sure of a leaner means for getting the data than my code.
 

obscurum

Guest
If you find one, I will be impressed. Note that there are some features included here that increase the memory buffer, which is a requirement unfortunately.
 

Ac04

Strategos
I know that, I'm aware of the ini_set() function.

I have to use it regularly on my webserver, as I don't have access to the php.ini file.
 

rev087

Guest
Hmm, are you sure that code works? You're testing the variables with isset() then assigning a value of zero if true?
Code:
	If (isset($alliance_id)){ $alliance_id=0; }
	If (isset($points)){ $points=0; }
	If (isset($rank)){ $rank=0; }
	If (isset($towns)){ $towns=0; }