Переход на UTF8.
authorRoman Bazalevsky <rvb@rvb.name>
Fri, 22 May 2020 14:52:52 +0000 (17:52 +0300)
committerRoman Bazalevsky <rvb@rvb.name>
Fri, 22 May 2020 14:52:52 +0000 (17:52 +0300)
parsegpx.py
pyrungps.py

index 5299fe0f1da253ea79826b75c0c8ac1247b67ce5..25161c8d761517d5d46122d777c71fe8efb022e3 100644 (file)
@@ -6,7 +6,7 @@ import os
 from lxml import etree
 from urllib2 import unquote
 import pygpx
 from lxml import etree
 from urllib2 import unquote
 import pygpx
-import pyosmname
+import pygeocode
 import sqlite3
 import datetime
 
 import sqlite3
 import datetime
 
@@ -52,7 +52,7 @@ def write_parsed_to_db(db,gpx,filename):
         print "processing..."
         start = track.start()
         if start:
         print "processing..."
         start = track.start()
         if start:
-          printable = pyosmname.GeoName(start.lat,start.lon).printable
+          printable = pygeocode.GeoName(start.lat,start.lon).printable
           start_time = track.start_time()
           full_duration = track.full_duration().total_seconds()
           distance = track.distance()
           start_time = track.start_time()
           full_duration = track.full_duration().total_seconds()
           distance = track.distance()
index f6ad327a96b48dd250f812290dc684cf7d9ad3b0..d8aaa58736f9cf9146dd9dd46824afb04ed1b0ca 100644 (file)
@@ -26,7 +26,8 @@ def get_page(uname,year,month):
   trainings = []
 
   req = requests.get("http://www.gps-sport.net/services/getMonthlyTrainingDataHTML_V2.jsp?userName=%s&year=%s&month=%s&rnd=0.645673"% (uname,year,month), headers = {'User-agent': 'Mozilla/5.0'})
   trainings = []
 
   req = requests.get("http://www.gps-sport.net/services/getMonthlyTrainingDataHTML_V2.jsp?userName=%s&year=%s&month=%s&rnd=0.645673"% (uname,year,month), headers = {'User-agent': 'Mozilla/5.0'})
-  page = req.text.encode()
+  print req.text
+  page = req.text.encode('utf-8')
   dom = html.document_fromstring(page)
 
   for element, attribute, link, pos in dom.iterlinks():
   dom = html.document_fromstring(page)
 
   for element, attribute, link, pos in dom.iterlinks():
@@ -43,7 +44,7 @@ def get_gpx_track(trid,name):
   print "trid=",trid
 
   req = requests.get("http://www.gps-sport.net/services/trainingGPX.jsp?trainingID=%s&tz=-180" % (trid))
   print "trid=",trid
 
   req = requests.get("http://www.gps-sport.net/services/trainingGPX.jsp?trainingID=%s&tz=-180" % (trid))
-  xml = etree.fromstring(req.text.encode())
+  xml = etree.fromstring(req.text.encode('utf-8'))
 
   return xml
 
 
   return xml
 
@@ -53,7 +54,7 @@ def get_osm_list(username,password,year,month):
 
   req = requests.get(url,auth=(username,password))
   
 
   req = requests.get(url,auth=(username,password))
   
-  xml = etree.fromstring(req.text.encode())
+  xml = etree.fromstring(req.text.encode('utf-8'))
 
   res=[]
 
 
   res=[]
 
@@ -81,7 +82,7 @@ def get_osm_gpx(username,password,track_id):
   url = "https://www.openstreetmap.org/api/0.6/gpx/"+track_id+"/data"
 
   req = requests.get(url,auth=(username,password))
   url = "https://www.openstreetmap.org/api/0.6/gpx/"+track_id+"/data"
 
   req = requests.get(url,auth=(username,password))
-  xml = etree.fromstring(req.text.encode())
+  xml = etree.fromstring(req.text.encode('utf-8'))
 
   return xml
 
 
   return xml
 
@@ -105,7 +106,7 @@ def get_db_gpx(dbx,track_id):
   os.remove(tmp_gpx_name)  
   os.remove(tmp_tcx_name)
 
   os.remove(tmp_gpx_name)  
   os.remove(tmp_tcx_name)
 
-  xml = etree.fromstring(data.encode())
+  xml = etree.fromstring(data.encode('utf-8'))
   return xml
 
 def get_dbx_list(dbx,username,year,month):
   return xml
 
 def get_dbx_list(dbx,username,year,month):
@@ -253,6 +254,7 @@ def sync_folder(username,year,month,dir=".",verbose=False,force=False):
 
     training_list = get_page(username,year,month)
     for tr in training_list:
 
     training_list = get_page(username,year,month)
     for tr in training_list:
+     try:
 
       filename = "%s/%04d/%02d/%s_%s.gpx" % (dir,year,(month+1),tr[0],tr[1])   
       dirname = "%s/%04d/%02d" % (dir,year,(month+1))
 
       filename = "%s/%04d/%02d/%s_%s.gpx" % (dir,year,(month+1),tr[0],tr[1])   
       dirname = "%s/%04d/%02d" % (dir,year,(month+1))
@@ -277,7 +279,7 @@ def sync_folder(username,year,month,dir=".",verbose=False,force=False):
         gpx = pygpx.GPX()
         gpx.ReadTree(xml)
 
         gpx = pygpx.GPX()
         gpx.ReadTree(xml)
 
-        sport = training['sport']
+        sport = tr[0]
         timestamp = gpx.tracks[0].start_time()
         
         if check_db_for_training(db,sport,timestamp):
         timestamp = gpx.tracks[0].start_time()
         
         if check_db_for_training(db,sport,timestamp):
@@ -297,6 +299,9 @@ def sync_folder(username,year,month,dir=".",verbose=False,force=False):
         except:
           None  
 
         except:
           None  
 
+     except:
+       raise
+
 def main():
 
     global db;
 def main():
 
     global db;