本文整理汇总了Python中stravalib.client.Client.create_activity方法的典型用法代码示例。如果您正苦于以下问题:Python Client.create_activity方法的具体用法?Python Client.create_activity怎么用?Python Client.create_activity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stravalib.client.Client
的用法示例。
在下文中一共展示了Client.create_activity方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: send_run_to_strava
# 需要导入模块: from stravalib.client import Client [as 别名]
# 或者: from stravalib.client.Client import create_activity [as 别名]
def send_run_to_strava():
'''Ask whether to send a run to strava if it hasn't already. Option to
add a description. Update on_strava field in database if successfully
sent or prompted to do so if not sent.'''
cfg.read(os.path.join(os.getenv('HOME'), '.config/strava.cfg'))
access_token = cfg.get('Strava', 'access_token')
client = Client()
client.access_token = access_token
runs = get_list_of_runs_not_on_strava()
for run in runs:
print run
send = raw_input("Send this run to Strava? (Y|N): ")
if (send[0] in ['Y', 'y']):
start_time = raw_input(
"What time did the activity start HH:MM:SS: ")
date_of_activity = "%sT%sZ", (run.run_date, start_time)
description = raw_input("Add an optional description: ")
client.create_activity(run.name,
ACTIVITY_TYPE,
date_of_activity,
run.time,
description,
unithelper.miles(run.distance))
mark_run_as_on_strava(run.run_date, run.route_id, run.athlete_id)
logging.info("Sent this activity to Strava: %s", run)
else:
update = raw_input("Update this run as on Strava (Y|N): ")
if (update[0] in ['Y', 'y']):
mark_run_as_on_strava(
run.run_date, run.route_id, run.athlete_id)
示例2: ClientWriteTest
# 需要导入模块: from stravalib.client import Client [as 别名]
# 或者: from stravalib.client.Client import create_activity [as 别名]
class ClientWriteTest(TestBase):
def setUp(self):
if not os.path.exists(TEST_CFG):
raise Exception("Unable to run the write tests without a tests.ini that defines an access_token with write privs.")
cfg = ConfigParser.SafeConfigParser()
with open(TEST_CFG) as fp:
cfg.readfp(fp, 'test.ini')
access_token = cfg.get('write_tests', 'access_token')
self.client = Client(access_token=access_token)
def test_create_activity(self):
"""
Test Client.create_activity simple case.
"""
now = datetime.now().replace(microsecond=0)
a = self.client.create_activity("test_create_activity#simple",
activity_type=model.Activity.RIDE,
start_date_local=now,
elapsed_time=timedelta(hours=3, minutes=4, seconds=5),
distance=uh.miles(15.2))
print a
self.assertIsInstance(a, model.Activity)
self.assertEquals("test_create_activity#simple", a.name)
self.assertEquals(now, a.start_date_local)
self.assertEquals(round(float(uh.miles(15.2)), 2), round(float(uh.miles(a.distance)), 2))
self.assertEquals(timedelta(hours=3, minutes=4, seconds=5), a.elapsed_time)
def test_update_activity(self):
"""
Test Client.update_activity simple case.
"""
now = datetime.now().replace(microsecond=0)
a = self.client.create_activity("test_update_activity#create",
activity_type=model.Activity.RIDE,
start_date_local=now,
elapsed_time=timedelta(hours=3, minutes=4, seconds=5),
distance=uh.miles(15.2))
self.assertIsInstance(a, model.Activity)
self.assertEquals("test_update_activity#create", a.name)
update1 = self.client.update_activity(a.id, name="test_update_activivty#update")
self.assertEquals("test_update_activivty#update", update1.name)
self.assertFalse(update1.private)
self.assertFalse(update1.trainer)
self.assertFalse(update1.commute)
update2 = self.client.update_activity(a.id, private=True)
self.assertTrue(update2.private)
update3 = self.client.update_activity(a.id, trainer=True)
self.assertTrue(update3.private)
self.assertTrue(update3.trainer)
def test_upload_activity(self):
"""
Test uploading an activity.
NOTE: This requires clearing out the uploaded activities from configured
writable Strava acct.
"""
with open(os.path.join(RESOURCES_DIR, 'sample.tcx')) as fp:
uploader = self.client.upload_activity(fp, data_type='tcx')
self.assertTrue(uploader.is_processing)
a = uploader.wait()
self.assertTrue(uploader.is_complete)
self.assertIsInstance(a, model.Activity)
self.assertEquals("02/21/2009 Leiden, ZH, The Netherlands", a.name)
# And we'll get an error if we try the same file again
with self.assertRaises(exc.ActivityUploadFailed):
self.client.upload_activity(fp, data_type='tcx')