本文整理汇总了Python中DatabaseHandler.save方法的典型用法代码示例。如果您正苦于以下问题:Python DatabaseHandler.save方法的具体用法?Python DatabaseHandler.save怎么用?Python DatabaseHandler.save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DatabaseHandler
的用法示例。
在下文中一共展示了DatabaseHandler.save方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: StoreUser
# 需要导入模块: import DatabaseHandler [as 别名]
# 或者: from DatabaseHandler import save [as 别名]
class StoreUser(object):
def __init__(self, consumer_key, consumer_secret, access_key, access_secret, database, server):
self.consumer_key = consumer_key
self.consumer_secret = consumer_secret
self.access_key = access_key
self.access_secret = access_secret
self.database = database
self.server = server
self.db_users = DatabaseHandler(self.database, self.server)
def save_user(self, username):
d = '{"_id": "' + username + '", "num_tweets": 1, "harvested": "true" }'
try:
user = json.loads(d)
self.db_users.save(user)
except couchdb.http.ResourceConflict:
user = self.db_users.get_row(user['_id'])
user['num_tweets'] += 1
self.db_users.save(user)
def exists(self, username):
try:
user = self.db_users.get_row(username)
if user is None:
return False
else:
return True
except:
return False