From: Roman Bazalevsky Date: Fri, 22 May 2020 14:52:52 +0000 (+0300) Subject: Переход на UTF8. X-Git-Url: https://git.rvb.name/pyrungps.git/commitdiff_plain/efbf2acd157a4b92e2de85da4879ec7b34af18d8 Переход на UTF8. --- diff --git a/parsegpx.py b/parsegpx.py index 5299fe0..25161c8 100644 --- a/parsegpx.py +++ b/parsegpx.py @@ -6,7 +6,7 @@ import os from lxml import etree from urllib2 import unquote import pygpx -import pyosmname +import pygeocode import sqlite3 import datetime @@ -52,7 +52,7 @@ def write_parsed_to_db(db,gpx,filename): 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() diff --git a/pyrungps.py b/pyrungps.py index f6ad327..d8aaa58 100644 --- a/pyrungps.py +++ b/pyrungps.py @@ -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'}) - 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(): @@ -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)) - xml = etree.fromstring(req.text.encode()) + xml = etree.fromstring(req.text.encode('utf-8')) return xml @@ -53,7 +54,7 @@ def get_osm_list(username,password,year,month): req = requests.get(url,auth=(username,password)) - xml = etree.fromstring(req.text.encode()) + xml = etree.fromstring(req.text.encode('utf-8')) 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)) - xml = etree.fromstring(req.text.encode()) + xml = etree.fromstring(req.text.encode('utf-8')) return xml @@ -105,7 +106,7 @@ def get_db_gpx(dbx,track_id): 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): @@ -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: + try: 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) - sport = training['sport'] + sport = tr[0] 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: + raise + def main(): global db;