本文整理汇总了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")
示例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")