Commits

Anonymous committed 43badd9

pep style

  • Participants
  • Parent commits dd679be

Comments (0)

Files changed (2)

 #!/usr/bin/env python
 # coding: utf-8
 
-
-import urllib
 import cPickle as pickle
-import pprint
-
 import simplekml
 
 DOC_ROOT = 'http://stredovek.com/'
 STYLES = {
-    'hradiste': { 'color': 'ffffffff', 'icon': 'http://maps.google.com/mapfiles/ms/micons/blue.png'},
-    'hrady': { 'color': 'ffffffff', 'icon': 'http://maps.google.com/mapfiles/ms/micons/red.png'},
-    'rozhledny': { 'color': 'ffffffff', 'icon': 'http://maps.google.com/mapfiles/ms/micons/orange.png' },
-    'jine': { 'color': 'ffffffff', 'icon': 'http://maps.google.com/mapfiles/ms/micons/yellow.png' },
+    'hradiste': {'color': 'ffffffff', 'icon': 'http://maps.google.com/mapfiles/ms/micons/blue.png'},
+    'hrady': {'color': 'ffffffff', 'icon': 'http://maps.google.com/mapfiles/ms/micons/red.png'},
+    'rozhledny': {'color': 'ffffffff', 'icon': 'http://maps.google.com/mapfiles/ms/micons/orange.png'},
+    'jine': {'color': 'ffffffff', 'icon': 'http://maps.google.com/mapfiles/ms/micons/yellow.png'},
 }
 
 
 with open('places.pkl', 'rb') as f:
     places = pickle.load(f)
 
+#import pprint
 #pprint.pprint(places)
 
+
 def format_desc(place):
-	desc = ['<p>', DOC_ROOT+place['url'], '</p>']
-	for img in place['images'][:3]:
-		desc.append('<img src="%s%s">' % (DOC_ROOT, img[0]))
-	desc.append(place['desc'])
-	return ''.join(desc)
+    desc = ['<p>', DOC_ROOT + place['url'], '</p>']
+    for img in place['images'][:3]:
+        desc.append('<img src="%s%s">' % (DOC_ROOT, img[0]))
+    desc.append(place['desc'])
+    return ''.join(desc)
 
 kml = simplekml.Kml()
 for (category, places) in places.iteritems():
-	style = simplekml.Style()
-	icon = simplekml.Icon(href=STYLES[category]['icon'])
-	color=STYLES[category]['color']
-	style.iconstyle = simplekml.IconStyle(icon=icon, color=color)
-	for place in places:
-		url = place['url'].replace('&', '&amp;')
-		point = kml.newpoint(
-			name=place['title'],
-			coords=[(place['lon'],place['lat'])],
-			description=format_desc(place),			
-			#atomlink=DOC_ROOT+url,
-		)
-		point.style = style
-
-kml.save("stredovek_com.kml")
+    style = simplekml.Style()
+    icon = simplekml.Icon(href=STYLES[category]['icon'])
+    color = STYLES[category]['color']
+    style.iconstyle = simplekml.IconStyle(icon=icon, color=color)
+    for place in places:
+        url = place['url'].replace('&', '&amp;')
+        point = kml.newpoint(
+            name=place['title'],
+            coords=[(place['lon'], place['lat'])],
+            description=format_desc(place),
+            #atomlink=DOC_ROOT+url,
+        )
+        point.style = style
+
+kml.save("stredovek_com.kml")
 #!/usr/bin/env python
 # coding: utf-8
 
-import codecs
 import urllib
 import re
-import time 
+import time
 import cPickle as pickle
 
 import requests
 
 DOC_ROOT = 'http://stredovek.com/'
 SOURCES = {
-    'hradiste': {        
+    'hradiste': {
         'url': 'list_directory.php?category=hradiste'
     },
-    'hrady': {        
+    'hrady': {
         'url': 'list_directory.php?category=hrady'
     },
     'rozhledny': {
 
 re_gps = re.compile(r'GPS:[^\d]*(\d+)[^\d]*(\d+)[^\d]*([\d\.]+)[^\d]*(\d+)[^\d]*(\d+)[^\d]*([\d\.]+)')
 
+
 def fixurl(url):
     idx = url.rfind('=')
-    return url[:idx] + '=' + urllib.quote(url[idx+1:])  
+    return url[:idx] + '=' + urllib.quote(url[idx + 1:])
+
 
 def process_index(html):
     d = pq(html)
 
     for cell in map(d, d('table').eq(0).find('td').eq(0).find('p')):
         desc.extend(['<p>', cell.text(), '</p>'])
-    place['desc'] = ''.join(desc) 
+    place['desc'] = ''.join(desc)
 
-    images = [];
+    images = []
     for cell in map(d, d('table').eq(1).find('a')):
         thmumb_url = urllib.quote(cell.find('img').attr('src')[2:])
         full_url = urllib.quote(cell.attr('href')[2:])
 
     m = re_gps.search(html)
 
-    place['lat'] = int(m.group(1)) + int(m.group(2))/60.0 + float(m.group(3))/3600.0
-    place['lon'] = int(m.group(4)) + int(m.group(5))/60.0 + float(m.group(6))/3600.0
+    place['lat'] = int(m.group(1)) + int(m.group(2)) / 60.0 + float(m.group(3)) / 3600.0
+    place['lon'] = int(m.group(4)) + int(m.group(5)) / 60.0 + float(m.group(6)) / 3600.0
     return place
 
 all_places = {}
 
-for (category, source) in SOURCES.items():    
+for (category, source) in SOURCES.items():
     index = requests.get(DOC_ROOT + source['url'])
-    index.encoding = 'windows-1250'    
+    index.encoding = 'windows-1250'
     places = process_index(index.text)
 
     for place in places:
         print place['title']
         time.sleep(0.2)
-        detail = requests.get(DOC_ROOT + place['url'])        
+        detail = requests.get(DOC_ROOT + place['url'])
         if detail.status_code != 200:
             print DOC_ROOT + place['url'], detail.status_code
             continue
-        detail.encoding = 'windows-1250'    
+        detail.encoding = 'windows-1250'
         process_detail(detail.text, place)
 
     all_places[category] = places
 with open('places.pkl', 'wb') as f:
     pickle.dump(all_places, f)
 
+# import codecs
 # with codecs.open("sample.html", "r", 'windows-1250') as f:
 #     places = process_index(f.read())
 #     print places[:3]
-    
-# with codecs.open("sample-detail.html", "r", 'windows-1250') as f:    
-#     print process_detail(f.read(), {})    
+
+# import codecs
+# with codecs.open("sample-detail.html", "r", 'windows-1250') as f:
+#     print process_detail(f.read(), {})