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


Python Client.get_athlete_friends方法代码示例

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


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

示例1: main

# 需要导入模块: from stravalib.client import Client [as 别名]
# 或者: from stravalib.client.Client import get_athlete_friends [as 别名]
def main():
    reload(sys)  
    sys.setdefaultencoding('utf8')

   
        
    client = Client(access_token='76824abf6abf903eb3d8b0bde83625135c0be0ec')
    athlete = client.get_athlete()
    print("Hello, {}. I know your email is {}".format(athlete.firstname, athlete.email))
    josh_friends = client.get_athlete_friends(5991862)
    print "Starting...."        
    leaderboard = client.get_segment_leaderboard(2658830,following=True)
    print leaderboard[0].athlete_name

    friend_colour_dict = {}
    friend_colour_file = open('friend_colour.csv')
    colourreader = UnicodeDictReader(friend_colour_file)
    for line in colourreader:
        friend_colour_dict[line["name"]] = line["colour"]

    for x in friend_colour_dict:
        print str(x).encode("utf8")
开发者ID:Josh2K,项目名称:Josh2K.github.io,代码行数:24,代码来源:matwork.py

示例2: main

# 需要导入模块: from stravalib.client import Client [as 别名]
# 或者: from stravalib.client.Client import get_athlete_friends [as 别名]
def main():
    reload(sys)  
    sys.setdefaultencoding('utf8')
    
    df1 = pd.read_csv('segoutput.csv',index_col=False)
    df1 = df1.set_index(['segment_id'])
    
    segmentlist = []
    file = open('segments.csv')
    reader = csv.DictReader(file)
    for line in reader:
        segmentlist.append(line["Segment Id"])

    #get rid of badsegments
    badsegments = []
    badinfile = open('bad_segments.csv')
    badreader = csv.DictReader(badinfile)
    for line in badreader:
        badsegments.append(line["Segment Id"])
    print 'Bad Segments: '+str(badsegments)
    
    for x in badsegments:
        if x in segmentlist:
            segmentlist.remove(x)
        
    client = Client(access_token='76824abf6abf903eb3d8b0bde83625135c0be0ec')
    athlete = client.get_athlete()
    print("Hello, {}. I know your email is {}".format(athlete.firstname, athlete.email))
    josh_friends = client.get_athlete_friends(5991862)
    print "Starting...."        
    #colors
    colours = ['575757','FFCDF3','FFEE33','FF9233','29D0D0','8126C0','814A19','1D6914','2A4BD7','AD2323','000000','88C6ED','C7258E']
    
    segoutfile = open('segoutput.csv', 'w')
    segoutfile.write('id,latitude,longitude,name,type,color,segment_name,segment_id,url'+'\n')
    segoutputlist = []

    friend_colour_dict = {}
    friend_colour_file = open('friend_colour.csv')
    colourreader = csv.DictReader(friend_colour_file)
    for line in colourreader:
        friend_colour_dict[line["name"]] = line["colour"]

    friend_count_dict = {}
           
    
    for num,j in enumerate(segmentlist):
        time.sleep(3)
        segment = retry_get_segment(client,j)
                        
        try:
            leaderboard = retry_get_leaderboard(client,j)
            if not leaderboard:
                topguy = 'UNCLAIMED'
            else:
                topguy = leaderboard[0].athlete_name
                            
            if not topguy in friend_colour_dict:
                friend_colour_dict[topguy] = colours.pop()
                print str(topguy)+' not in friend_colour_dict, popping colour: '+ str(friend_colour_dict[topguy])

            if topguy in friend_count_dict:
                friend_count_dict[topguy] += 1
            else:
                friend_count_dict[topguy] = 1

                      
            
            for z in segment_details(num,segment,topguy,friend_colour_dict):
                segoutfile.write(str(z)+',')
            segoutfile.write('\n')
            
   
        except Exception:
            #badoutfile = open('bad_segments.csv', 'a+')
            #badoutfile.write(str(j)+','+'\n')
            #badoutfile.close()
            pass

    
    
    segoutfile.close()
    
    #segment count output
    segcountoutfile = open('segmentcount.csv', 'w')
    segcountoutfile.write('name,colour,count'+'\n')
    for x in friend_count_dict:
        if x != 'UNCLAIMED':
            print str(x)+': '+str(friend_count_dict[x])
            segcountoutfile.write(str(x)+','+str(friend_colour_dict[x])+','+str(friend_count_dict[x])+'\n')
    segcountoutfile.write('\n')
    segcountoutfile.close()
    json_convert_segmentcount()
    


    #segment count over time output
    segcountovertimefile = open('segmentcountovertime.csv', 'a+')
    nowdate = datetime.datetime.now().strftime('%Y-%m-%d')
    for x in friend_count_dict:
#.........这里部分代码省略.........
开发者ID:Josh2K,项目名称:Josh2K.github.io,代码行数:103,代码来源:strava1.py


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