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


Python Base.add_field方法代码示例

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


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

示例1: likeconvert

# 需要导入模块: from pydblite import Base [as 别名]
# 或者: from pydblite.Base import add_field [as 别名]
def likeconvert(likesRoot):
    histPath = likesRoot + '/history'
    convertcsv2db(likesRoot + '/totals.csv', likesRoot + '/likes.pdl')
    db = Base(likesRoot + '/likes.pdl')
    db.open()
    db.add_field('history', "")
    db.add_field('liked', "")
    dirContents = os.listdir(histPath)
    histFiles = []

    for File in dirContents:
        if ".csv" in File:
            histFiles.append(File)
    for histFile in histFiles:
        try:
            csvfile = open(histPath + '/' + histFile, 'rb')
            reader = csv.DictReader(csvfile)
            for row in reader:
                if histFile.endswith('history.csv'):
                    recName = histFile[:-11]
                    print(recName)
                if db(userID=recName):
                    rec = db(userID=recName).pop()
                    if not rec['liked']:
                        db.update(rec, liked=row['liked'])
                    else:
                        tmpLiked = rec['liked']
                        tmpLiked += " " + row['liked']
                        db.update(rec, liked=tmpLiked)
                    if not rec['history']:
                        db.update(rec, history=row['messageID'])
                    else:
                        tmpHist = rec['history']
                        tmpHist += " " + row['messageID']
                        db.update(rec, history=tmpHist)
                db.commit()
        except csv.Error:
                print("Could not open CSV file")
开发者ID:noisemaster,项目名称:AdamTestBot,代码行数:40,代码来源:utils.py

示例2: likeconvert

# 需要导入模块: from pydblite import Base [as 别名]
# 或者: from pydblite.Base import add_field [as 别名]
def likeconvert(likesRoot):
    histPath = likesRoot + "/history"
    convertcsv2db(likesRoot + "/totals.csv", likesRoot + "/likes.pdl")
    db = Base(likesRoot + "/likes.pdl")
    db.open()
    db.add_field("history", "")
    db.add_field("liked", "")
    dirContents = os.listdir(histPath)
    histFiles = []

    for File in dirContents:
        if ".csv" in File:
            histFiles.append(File)
    for histFile in histFiles:
        try:
            csvfile = open(histPath + "/" + histFile, "rb")
            reader = csv.DictReader(csvfile)
            for row in reader:
                if histFile.endswith("history.csv"):
                    recName = histFile[:-11]
                    print(recName)
                if db(userID=recName):
                    rec = db(userID=recName).pop()
                    if not rec["liked"]:
                        db.update(rec, liked=row["liked"])
                    else:
                        tmpLiked = rec["liked"]
                        tmpLiked += " " + row["liked"]
                        db.update(rec, liked=tmpLiked)
                    if not rec["history"]:
                        db.update(rec, history=row["messageID"])
                    else:
                        tmpHist = rec["history"]
                        tmpHist += " " + row["messageID"]
                        db.update(rec, history=tmpHist)
                db.commit()
        except csv.Error:
            print("Could not open CSV file")
开发者ID:agincel,项目名称:AdamTestBot,代码行数:40,代码来源:utils.py


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