當前位置: 首頁>>代碼示例>>Python>>正文


Python Stage.put方法代碼示例

本文整理匯總了Python中stage.Stage.put方法的典型用法代碼示例。如果您正苦於以下問題:Python Stage.put方法的具體用法?Python Stage.put怎麽用?Python Stage.put使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在stage.Stage的用法示例。


在下文中一共展示了Stage.put方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: generate_tour_data

# 需要導入模塊: from stage import Stage [as 別名]
# 或者: from stage.Stage import put [as 別名]
def generate_tour_data():
    urlfetch.set_default_fetch_deadline(45)
    data_order=["date","stage-icons","stage-link","name","stage-winner","stage-leader","km"]
    page = urllib2.urlopen("http://www.procyclingstats.com/race/Tour_de_France_2015-stages")
    soup = BeautifulSoup(page, "html.parser")
    tabulka = soup.find("table", {"id" : "list5"})
    data={}
    stage_count=0
    for row in tabulka.findAll('tr'):
        col = row.findAll('td')
        data={}
        images=[]
        count=1
        for td in col:
            #Looking for the date
            if(td.string):
                if(count==1):
                    data["date"]=td.string
                    count+=1
            #Do we have icons?
            imgs=td.findAll('img')
            if imgs:
                for img in imgs:
                    images.append(img["src"])
                data["stage_icons"]=images
            #Names for the winner and the leader
            links = td.findAll('a')

            for link in links:
                if count==2:
                    if(link.string):
                        data["name"]=link.string
                        data["stage-link"]="http://www.procyclingstats.com/"+link['href']
                    else:
                        data["stage-link"]=""
                if count==3:
                    if(link.string):
                        data["stage-winner"]=link.string
                    else:
                        data["stage-winner"]=""
                if count==4:
                    if(link.string):
                        try:
                            km = float(link.string)
                            data["km"]=link.string
                            data["stage-leader"]=""
                        except ValueError:
                            data["stage-leader"]=link.string
                    else:
                        data["stage-leader"]=""
                if count==5:
                    if(link.string):
                        data["km"]=link.string
                    else:
                        data["km"]=""

                count+=1

        if data:
            stage_count+=1
            data["stage"]=str(stage_count)
            if(stage_count<22):
                stage = Stage(id=stage_count,data=json.dumps(data))
                stage.put()
開發者ID:pedrofraca,項目名稱:tourapp,代碼行數:66,代碼來源:main.py


注:本文中的stage.Stage.put方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。