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


Python Client.create_activity方法代码示例

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


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

示例1: main

# 需要导入模块: from stravalib import Client [as 别名]
# 或者: from stravalib.Client import create_activity [as 别名]

#.........这里部分代码省略.........

	# We open the cardioactivities CSV file and start reading through it
	with open('cardioActivities.csv', 'rb') as csvfile:
		activities = csv.reader(csvfile)
		activity_counter = 0
		for row in activities:
			if activity_counter >= 599:
				logger("Upload count at 599 - pausing uploads for 15 minutes to avoid rate-limit")
				time.sleep(900)
				activity_counter = 0
			else:
				pass
			if row[0] == "Date":
				pass
			else:
				# if there is a gpx file listed, find it and upload it
				if ".gpx" in row[11]:
					gpxfile = row[11]
					strava_activity_type = activity_translator(str(row[1]))
					if gpxfile in os.listdir('.'):
						logger("Uploading " + gpxfile)
						try:
							upload = client.upload_activity(
								activity_file = open(gpxfile,'r'),
								data_type = 'gpx',
								private = False,
								description = row[10],
								activity_type = strava_activity_type
								)
						except exc.ActivityUploadFailed as err:
							logger("Uploading problem raised: {}".format(err))
							errStr = str(err)
							# deal with duplicate type of error, if duplicate then continue with next file, else stop
							if errStr.find('duplicate of activity'):
								logger("Moving dulicate activity file {}".format(gpxfile))
								shutil.move(gpxfile,archive)
								isDuplicate = True
								logger("Duplicate File " + gpxfile)
							else:
								exit(1)

						except ConnectionError as err:
							logger("No Internet connection: {}".format(err))
							exit(1)

						logger("Upload succeeded.\nWaiting for response...")

						try:
							upResult = upload.wait()
						except HTTPError as err:
							logger("Problem raised: {}\nExiting...".format(err))
							exit(1)
						except:
							logger("Another problem occured, sorry...")
							exit(1)
						
						logger("Uploaded " + gpxfile + " - Activity id: " + str(upResult.id))
						activity_counter += 1

						shutil.move(gpxfile, archive)
					else:
						logger("No file found for " + gpxfile + "!")

				#if no gpx file, upload the data from the CSV
				else:
					if row[0] not in log:
						logger("Manually uploading " + row[0])
						dur = duration_calc(row[4])
						dist = float(row[3])*1609.344
						starttime = datetime.strptime(str(row[0]),"%Y-%m-%d %H:%M:%S")
						strava_activity_type = activity_translator(str(row[1]))

						# designates part of day for name assignment above, matching Strava convention for GPS activities
						if 3 <= starttime.hour <= 11:
							part = "Morning "
						elif 12 <= starttime.hour <= 4:
							part = "Afternoon "
						elif 5 <= starttime.hour <=7:
							part = "Evening "
						else:
							part = "Night "
						
						try:
							upload = client.create_activity(
								name = part + strava_activity_type + " (Manual)",
								start_date_local = starttime,
								elapsed_time = dur,
								distance = dist,
								description = row[10],
								activity_type = strava_activity_type
								)

							logger("Manually created " + row[0])
							activity_counter += 1

						except ConnectionError as err:
							logger("No Internet connection: {}".format(err))
							exit(1)

		logger("Complete! Logged " + str(activity_counter) + " activities.")
开发者ID:mehagel,项目名称:strava-uploader,代码行数:104,代码来源:uploader.py

示例2: activity_translator

# 需要导入模块: from stravalib import Client [as 别名]
# 或者: from stravalib.Client import create_activity [as 别名]
					strava_activity_type = activity_translator(str(row[1]))

					# designates part of day for name assignment above, matching Strava convention for GPS activities
					if 3 <= starttime.hour <= 11:
						part = "Morning "
					elif 12 <= starttime.hour <= 4:
						part = "Afternoon "
					elif 5 <= starttime.hour <=7:
						part = "Evening "
					else:
						part = "Night "
					
					try:
						upload = client.create_activity(
							name = part + strava_activity_type + " (Manual)",
							start_date_local = starttime,
							elapsed_time = dur,
							distance = dist,
							description = row[10],
							activity_type = strava_activity_type
							)

						logger("Manually created " + row[0])
						activity_counter += 1

					except ConnectionError as err:
						logger("No Internet connection: {}".format(err))
						exit(1)

	logger("Complete! Logged " + str(activity_counter) + " activities.")
开发者ID:SpideRaY,项目名称:strava-uploader,代码行数:32,代码来源:uploader.py


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