Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
webresh
GitHub Repository: webresh/drik-panchanga
Path: blob/master/geonames.py
983 views
1
# Throw-away script for one-time use only.
2
#
3
# Generates a list of cities whose population is more than 50000
4
#
5
# Download cities15000.zip from http://download.geonames.org/export/dump/
6
#
7
8
import csv
9
import json
10
11
fin = open('/tmp/cities15000.txt', 'r')
12
reader = csv.reader(fin, 'excel-tab')
13
fout = open('/tmp/cities.csv', 'w')
14
cities = {}
15
16
for record in reader:
17
(geonameid, name, asciiname, alternatenames, latitude, longitude,
18
featureclass, featurecode, countrycode, cc2, admin1code,
19
admin2code, admin3code, admin4code, population,
20
elevation, dem, timezone, modificationdate) = record
21
22
# Ignore small cities
23
if int(population) > 50000 and asciiname:
24
cities[asciiname] = {'latitude': float(latitude),
25
'longitude': float(longitude),
26
'timezone': timezone}
27
fout.write(u'%s:%s:%s:%s\n' % (asciiname, latitude, longitude, timezone))
28
29
fout.close()
30
fjson = open('/tmp/cities.json', 'w')
31
json.dump(cities, fjson)
32
fjson.close()
33
34