X-Git-Url: https://git.rvb.name/pyrungps.git/blobdiff_plain/81020ed69398f00cdb0564a132dfdf0285e9b844..1690b8b7c8ccfdf60be2b33b314e6c26bdef86e6:/pyrungps.py diff --git a/pyrungps.py b/pyrungps.py index 0f0dc56..ed3fce5 100644 --- a/pyrungps.py +++ b/pyrungps.py @@ -2,6 +2,9 @@ # coding: UTF-8 import requests + +from urllib3.exceptions import InsecureRequestWarning +requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning) #import sys import os @@ -25,8 +28,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() + 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'}, verify=False) + page = req.text.encode('utf-8') dom = html.document_fromstring(page) for element, attribute, link, pos in dom.iterlinks(): @@ -42,8 +45,8 @@ 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()) + req = requests.get("http://www.gps-sport.net/services/trainingGPX.jsp?trainingID=%s&tz=-180" % (trid), verify=False) + xml = etree.fromstring(req.text.encode('utf-8')) return xml @@ -53,7 +56,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 +84,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 +108,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): @@ -116,6 +119,7 @@ def get_dbx_list(dbx,username,year,month): if entry.name == u'Приложения': for entry_app in dbx.files_list_folder(entry.id).entries: if entry_app.name == u'Run.GPS': + print "id="+entry_app.id gpx_list_id=entry_app.id break break @@ -125,20 +129,29 @@ def get_dbx_list(dbx,username,year,month): if gpx_list_id: for file in dbx.files_list_folder(gpx_list_id).entries: - + filename,ext = os.path.splitext(file.name) if ext == '.tcx': try: fyear = int(filename[0:4]) fmonth = int(filename[5:7]) if fyear == year and fmonth == month: - sport = filename[18:] - timestamp = datetime.strptime(filename[0:16],'%Y-%m-%d_%H%M%S') + sport = filename[41:] + timestamp = datetime.strptime(filename[0:19],'%Y-%m-%dT%H_%M_%S') record={ 'id': file.id, 'timestamp': timestamp, 'sport': sport } res.append(record) except: - None - + try: + fyear = int(filename[0:4]) + fmonth = int(filename[5:7]) + if fyear == year and fmonth == month: + sport = filename[18:] + timestamp = datetime.strptime(filename[0:16],'%Y-%m-%d_%H%M%S') + record={ 'id': file.id, 'timestamp': timestamp, 'sport': sport } + res.append(record) + except: + None + return res @@ -253,6 +266,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,6 +291,13 @@ def sync_folder(username,year,month,dir=".",verbose=False,force=False): gpx = pygpx.GPX() gpx.ReadTree(xml) + sport = tr[0] + timestamp = gpx.tracks[0].start_time() + + if check_db_for_training(db,sport,timestamp): + print "The same training found" + continue + gpx.FixNames(tr[0]) gpx.ProcessTrackSegs() @@ -290,6 +311,9 @@ def sync_folder(username,year,month,dir=".",verbose=False,force=False): except: None + except: + raise + def main(): global db; @@ -384,7 +408,7 @@ def main(): elif dbauth: sync_db(dbx,pusername,current_year,current_month,outdir,options.verbose,options.force) - generate_image.render_all(db,'/etc/mapnik-osm-carto-data/veloroad-transparent.xml',400,400) + generate_image.render_all(db,'/etc/mapnik-osm-carto-data/veloroad-imposm.xml',640,640) if __name__ == "__main__":