'data source:
'http://www.maxmind.com/app/worldcities
'33meg compressed
'144meg uncompressed textfile
bstring dat=getfile "WorldCitiesPop.txt"
if len(dat)=0 then
print "need WorldCitiesPop.txt" : jmp fwd done
end if
'a=instr dat,chr(10)
'print a
'Country Code char(2) ISO 3166 Country Code,
'ASCII CityName varchar(100) Name of city or town in ASCII encoding
'City Name varchar(255) Name of city or town in ISO-8859-1 encoding. A list of cities contained in GeoIP City is available. A localized CSV file containing city names in various languages is available.
'State/Region char(2) For US, ISO-3166-2 code for the state/province name. Outside of the US, FIPS 10-4 code
'Population unsigned int Population of city (available for over 33,000 major cities only)
'Latitude numeric (float) Latitude of city where IP is located
'Longitude numeric (float)
'type CityRecord
'char CountryCode[2]
'char CityNameA[100]
'char CityNameL[255]
'dword Population
'float Latitude
'float Longitude
'end type
'#recordof CityRecord
'CityRecord *c : @c=strptr dat
'TEXT FILE FORMAT
'================
'comma delimited (44)
'line feed (10) record separator
byte *byt : @byt=strptr dat
lf=chr(10)
cm=chr(44)
i=instr dat,"eglwyswrw"
'i=instr dat, ",chicago"
'i=instr dat,"gb,london"
if i=0 then i=1
e=instr i,dat,lf
'locate start of record
'======================
do
if byt[ i ]=10 then i++ : exit do
if i=1 then exit do
i--
end do
b=i
print mid dat,b,e-b
'split into fields
'=================
i=b
pr=""
tab=chr(9)
cr=chr(13)+chr(10)
a=instr(i,dat,cm) : pr+="CountryCode: " tab mid(dat,i,a-i) cr : i=a+1
a=instr(i,dat,cm) : pr+="City Key: " tab mid(dat,i,a-i) cr : i=a+1
a=instr(i,dat,cm) : pr+="City Name: " tab mid(dat,i,a-i) cr : i=a+1
a=instr(i,dat,cm) : pr+="Region: " tab mid(dat,i,a-i) cr : i=a+1
a=instr(i,dat,cm) : pr+="Population: " tab mid(dat,i,a-i) cr : i=a+1
a=instr(i,dat,cm) : pr+="Latitude: " tab mid(dat,i,a-i) cr : i=a+1
a=instr(i,dat,lf) : pr+="Longtude: " tab mid(dat,i,a-i) cr : i=a+1
print pr
'count number of records in database
'===================================
b=strptr dat
mov ecx,b
mov edx,0
(
mov al,[ecx]
cmp al,0
jz exit
cmp al,10
(
jnz exit
inc edx
)
inc ecx
repeat
)
mov e,edx
print "Total Records: " e
frees dat
done: