当前位置: 首页>>代码示例>>Python>>正文


Python Client.update_activity方法代码示例

本文整理汇总了Python中stravalib.client.Client.update_activity方法的典型用法代码示例。如果您正苦于以下问题:Python Client.update_activity方法的具体用法?Python Client.update_activity怎么用?Python Client.update_activity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在stravalib.client.Client的用法示例。


在下文中一共展示了Client.update_activity方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ClientWriteTest

# 需要导入模块: from stravalib.client import Client [as 别名]
# 或者: from stravalib.client.Client import update_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')
开发者ID:LemonadeLabInc,项目名称:stravalib,代码行数:81,代码来源:test_client_write.py

示例2: elif

# 需要导入模块: from stravalib.client import Client [as 别名]
# 或者: from stravalib.client.Client import update_activity [as 别名]
		if (act.distance > units.unit("km")(5)):
			# Longer than usual. Where was I going?
			pass
		elif (1594398 in segments):
			ret["name"] = "Morning commute"
			ret["commute"] = True
		elif (1547949 in segments):
			ret["name"] = "Evening commute"
			ret["commute"] = True

	if "name" in ret and not (act.name.endswith("rit") or act.name.endswith(" Ride")):
		# May already not be the default name anymore.
		del ret["name"]

	return ret

seen = dbm.open("seen", "c")

after = datetime.datetime.now() - datetime.timedelta(days=2)
for act in act for act in client.get_activities(after=after, limit=5):
	if str(act.id) in seen:
		continue
	full = client.get_activity(act.id)
	print full
	updates = build_updates(full)
	print updates
	seen[str(act.id)] = "1"
	if updates:
		updates["activity_id"] = act.id
		print client.update_activity(**updates)
开发者ID:Wilm0r,项目名称:strava-mv,代码行数:32,代码来源:strava-mv.py


注:本文中的stravalib.client.Client.update_activity方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。