本文整理汇总了Python中stravalib.client.Client.get_segment方法的典型用法代码示例。如果您正苦于以下问题:Python Client.get_segment方法的具体用法?Python Client.get_segment怎么用?Python Client.get_segment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stravalib.client.Client
的用法示例。
在下文中一共展示了Client.get_segment方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CartoDBAPIKey
# 需要导入模块: from stravalib.client import Client [as 别名]
# 或者: from stravalib.client.Client import get_segment [as 别名]
client.access_token = 'd47099a29b2f3539e1c21af6d820e33a109a079e'
## CartoDB connection
API_KEY ='cad54ea0c580a0c554b9e9562157e7c9bd9f37b0'
cartodb_domain = 'geodarcy'
cl = CartoDBAPIKey(API_KEY, cartodb_domain)
## remove duplicate rows
cl.sql('DELETE FROM wbstrava WHERE cartodb_id IN (SELECT cartodb_id FROM (SELECT cartodb_id, ROW_NUMBER() OVER (partition BY segment_id ORDER BY cartodb_id) AS rnum FROM wbstrava) t WHERE t.rnum > 1);')
## find segments with no geometry
queryResult = cl.sql('select segment_id from wbstrava where the_geom is null')
currentSegments = [x['segment_id'] for x in queryResult['rows']]
for id in currentSegments:
try:
segmentGeojson = PolylineCodec().decode(client.get_segment(id).map.polyline)
flippedGeojson = [[x[1], x[0]] for x in segmentGeojson]
inputGeojson = '{"coordinates": ' + str(flippedGeojson) + ', "type": "LineString", "crs":{"type":"name","properties":{"name":"EPSG:4326"}}}'
cl.sql('UPDATE wbstrava SET the_geom = ST_GeomFromGeoJSON(\'' + inputGeojson + '\') WHERE segment_id=' + str(id))
except Exception as e:
if "Not Found" in e.message:
cl.sql('DELETE FROM wbstrava WHERE segment_id= ' + str(id))
print("Deleted Strava ID: {}".format(id))
else:
print("Something's wrong with Strava ID: {}".format(id))
## get list of segments already in CartoDB
queryResult = cl.sql('select segment_id from wbstrava')
currentSegments = [x['segment_id'] for x in queryResult['rows']]
now = datetime.datetime.now()
示例2: Client
# 需要导入模块: from stravalib.client import Client [as 别名]
# 或者: from stravalib.client.Client import get_segment [as 别名]
## import libraries
from stravalib.client import Client
from polyline.codec import PolylineCodec
from cartodb import CartoDBAPIKey, CartoDBException
from geojson import Feature, LineString
## Strava connection
client = Client()
client.access_token = 'd47099a29b2f3539e1c21af6d820e33a109a079e'
## CartoDB connection
API_KEY ='cad54ea0c580a0c554b9e9562157e7c9bd9f37b0'
cartodb_domain = 'geodarcy'
cl = CartoDBAPIKey(API_KEY, cartodb_domain)
## get list of segments already in CartoDB
queryResult = cl.sql('select segment_id from wbstrava')
currentSegments = [x['segment_id'] for x in queryResult['rows']]
## get started segments from a user
segmentIDs = [x.id for x in client.get_starred_segment()]
for id in segmentIDs:
if id not in currentSegments:
segmentGeojson = PolylineCodec().decode(client.get_segment(id).map.polyline)
flippedGeojson = [[x[1], x[0]] for x in segmentGeojson]
inputGeojson = '{"coordinates": ' + str(flippedGeojson) + ', "type": "LineString", "crs":{"type":"name","properties":{"name":"EPSG:4326"}}}'
cl.sql('INSERT INTO wbstrava (the_geom, segment_id) VALUES (ST_GeomFromGeoJSON(\'' + inputGeojson + '\'), ' + str(id) + ')')