My favorites
▼
|
Sign in
gisgraphy
Free opensource geocoder and webservices for geonames and openstreetmap data
Project Home
Downloads
Wiki
Issues
Source
Checkout
Browse
Changes
Source path:
svn
/
trunk
/
gisgraphy
/
src
/
main
/
python
/
sitemap_generator.py
r60
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
import math
import random
""" generate a sitemap"""
MAX_SITEMAP_ENTRY_PER_FILE = 50000
SITEMAP_BASE_FILENAME = 'gisgraphy-sitemap-'
SITEMAP_INDEX_FILENAME = 'gisgraphy-sitemap-index.xml'
BUFFER_SIZE = 4500000
PRIORITY=["0.4","0.5","0.6"]
class SitemapGenerator:
def __init__(self,filePath):
"""doc"""
self.filePath = filePath
self.indexSitemapDesc = open(SITEMAP_INDEX_FILENAME,'w');
def write_index_file_header(self):
self.indexSitemapDesc.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?><sitemapindex xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">")
def write_index_file_footer(self):
self.indexSitemapDesc.write("</sitemapindex>")
def write_index_file_entry(self,filename):
self.indexSitemapDesc.write("<sitemap><loc>http://services.gisgraphy.com/"+filename+"</loc><lastmod>2009-03-01</lastmod></sitemap>")
def generate_sitemap(self):
"""doc"""
self.write_index_file_header()
self.readFile();
self.write_index_file_footer()
self.indexSitemapDesc.close();
def readFile(self):
"""doc"""
fdesc = open(self.filePath,'r');
count = 1;
while 1:
lines = fdesc.readlines(BUFFER_SIZE)
if not lines:
break
else :
if len(lines) > MAX_SITEMAP_ENTRY_PER_FILE:
raise "you should decrease the buffer size value"
count = count + 1
sitemapFilename = self.generate_sitemap_file(lines,count);
self.write_index_file_entry(sitemapFilename);
def generate_sitemap_file(self, lines, increment):
"""doc"""
filename = SITEMAP_BASE_FILENAME+str(increment)+".xml"
print "will generate "+filename+" with "+str(len(lines))+ " lines"
fileSitemap = open(filename,'w')
fileSitemap.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?><urlset xmlns=\"http://www.google.com/schemas/sitemap/0.84\">")
for line in lines:
splited = line.split('\t')
if len(splited) == 19:
featureId= splited[0]
population= splited[14]
fileSitemap.write(self.generate_sitemap_node(featureId,population))
else :
print "invalid size : "+str(len(splited))
fileSitemap.write("</urlset>")
fileSitemap.close();
return filename;
def generate_sitemap_node(self,featureId,population):
"""doc"""
return "<url><loc>http://services.gisgraphy.com/displayfeature.html?featureId="+str(featureId)+"</loc><lastmod>2009-09-30</lastmod><changefreq>monthly</changefreq><priority>"+str(self.calculate_priority(population))+"</priority></url>"
def calculate_priority(self,population):
#print int(population;
if ((int(population))==0):
#print PRIORITY[random.randint(0,2)];
return PRIORITY[random.randint(0,2)];
priority = (int(population) * 0.5)/18000;
round_priority = (math.ceil(priority*10)/10);
if (round_priority >= 1):
return 1;
if (round_priority <= 0.1):
return 0.1;
else :
#print population;
#print round_priority;
return round_priority;
def generate():
generator = SitemapGenerator("/home/david/Bureau/dist2/data/import/allCountries.txt");
generator.generate_sitemap()
generate()
Show details
Hide details
Change log
r14
by davidmasclet on Mar 17, 2012
Diff
initial import
Go to:
/trunk/gisgraphy/.amateras
/trunk/gisgraphy/.project
/trunk/gisgraphy/.pydevproject
/trunk/gisgraphy/.settings
...org.eclipse.core.resources.prefs
...tings/org.eclipse.jdt.core.prefs
...org.eclipse.wst.common.component
...st.common.project.facet.core.xml
...org.eclipse.wst.validation.prefs
/trunk/gisgraphy/COPYING
/trunk/gisgraphy/COPYING.LESSER
/trunk/gisgraphy/CREDITS
/trunk/gisgraphy/LICENSE.txt
/trunk/gisgraphy/data
/trunk/gisgraphy/data/Canada.csv.gz
/trunk/gisgraphy/data/boundaries
...ries/update_gisfeature_shape.sql
...sgraphy/data/cookbook-deploy.txt
/trunk/gisgraphy/data/cookbook-dev
...graphy/data/cookbook-distrib.txt
/trunk/gisgraphy/data/cookbook.xt
...gisgraphy/data/countries_shp.zip
...sgraphy/data/differencegmaps.txt
/trunk/gisgraphy/data/download_site
...isgraphy/data/download_site/dump
...ata/download_site/dump/index.php
...ta/download_site/dump/readme.txt
...a/download_site/dump/version_2_0
..._site/dump/version_2_0/index.php
...site/dump/version_2_0/readme.txt
...a/download_site/dump/version_3_0
..._site/dump/version_3_0/index.php
...site/dump/version_3_0/readme.txt
...y/data/download_site/favicon.ico
...sgraphy/data/download_site/flags
.../data/download_site/flags/AD.png
.../data/download_site/flags/AE.png
.../data/download_site/flags/AF.png
.../data/download_site/flags/AG.png
.../data/download_site/flags/AI.png
.../data/download_site/flags/AL.png
...load_site/flags/ALLCOUNTRIES.png
.../data/download_site/flags/AM.png
.../data/download_site/flags/AN.png
.../data/download_site/flags/AO.png
.../data/download_site/flags/AQ.png
.../data/download_site/flags/AR.png
.../data/download_site/flags/AS.png
.../data/download_site/flags/AT.png
.../data/download_site/flags/AU.png
Sign in
to write a code review
Older revisions
All revisions of this file
File info
Size: 3034 bytes, 96 lines
View raw file
Powered by
Google Project Hosting