本文整理汇总了Python中rethinkdb.table函数的典型用法代码示例。如果您正苦于以下问题:Python table函数的具体用法?Python table怎么用?Python table使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了table函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: check_owner
def check_owner(checkid):
"""claim or unclaim a given check"""
if request.method == 'GET':
check = r.table("checks").get(checkid).run(rdb.conn)
if check:
check['id'] = str(check['id'])
return jsonify({'check': check})
else:
abort(404)
elif request.method == 'POST':
if not request.json:
abort(400)
try:
if request.json.get('owner'):
q = r.table("checks").get(checkid).update({"owner": str(request.json["owner"])}).run(rdb.conn)
else:
abort(400)
if q["replaced"] != 0:
return jsonify({'success': True})
else:
abort(404)
except Exception as err:
logger.error(err)
abort(400)
elif request.method == 'DELETE':
try:
q = r.table("checks").get(checkid).update({"owner": ""}).run(rdb.conn)
if q["replaced"] != 0:
return jsonify({'success': True})
else:
abort(404)
except Exception as err:
logger.error(err)
abort(400)
开发者ID:thrawn01,项目名称:stalker,代码行数:34,代码来源:views.py
示例2: signup
def signup():
email = request.form.get('email')
name = request.form.get("name")
password = None
if not is_columbia_email(email):
flash("Not a valid columbia ID!", "danger")
else:
email = email.strip()
curr = r.table('users').filter(r.row["email"].eq(email)).run(g.rdb_conn)
if curr.items:
user = curr.items[0]
password = user["password"]
else:
password = generate_password(email)
inserted = r.table('users').insert({
'email': email,
'name': name,
'password': password
}).run(g.rdb_conn)
if inserted["generated_keys"]:
password = password
resp = send_email(email, password)
if resp.status_code == 200:
flash("Email sent! Check your inbox for your login details", "success")
else:
flash("Error sending email. Please try again or contact admin", "danger")
return redirect(url_for('login'))
开发者ID:prakhar1989,项目名称:instabase,代码行数:27,代码来源:app.py
示例3: save
def save(self):
self._run_callbacks('before_save')
fields_dict = self.fields.as_dict()
try:
# Attempt update
id_ = fields_dict['id']
result = (r.table(self._table).get(id_).replace(r.row
.without(r.row.keys().difference(list(fields_dict.keys())))
.merge(fields_dict), return_changes=True).run())
except KeyError:
# Resort to insert
result = (r.table(self._table).insert(fields_dict, return_changes=True)
.run())
if result['errors'] > 0:
raise OperationError(result['first_error'])
# RethinkDB 2.0 doesn't add the 'changes' key in the result if the
# document hasn't been modified
# TODO: Follow on the discussion at linkyndy/remodel#23 and change this
# accordingly
if 'changes' in result:
# Force overwrite so that related caches are flushed
self.fields.__dict__ = result['changes'][0]['new_val']
self._run_callbacks('after_save')
开发者ID:natebeacham,项目名称:remodel,代码行数:28,代码来源:models.py
示例4: sendPartition
def sendPartition(iter):
connection = createNewConnection()#todo: use-connection-pool
for record in iter:
# r.table(RDB_TABLE).insert(record).run(connection)
#print(record[1])
r.table(RDB_TABLE).insert(json.loads(record[1])).run(connection)
connection.close()
开发者ID:donachys,项目名称:SerIoTics,代码行数:7,代码来源:SparkStreamingKafkaAvroSumRDB.py
示例5: validate_tx
def validate_tx(self, tx):
"""Validate a transaction.
Also checks if the transaction already exists in the blockchain. If it
does, or it's invalid, it's deleted from the backlog immediately.
Args:
tx (dict): the transaction to validate.
Returns:
The transaction if valid, ``None`` otherwise.
"""
if self.bigchain.transaction_exists(tx['id']):
# if the transaction already exists, we must check whether
# it's in a valid or undecided block
tx, status = self.bigchain.get_transaction(tx['id'],
include_status=True)
if status == self.bigchain.TX_VALID \
or status == self.bigchain.TX_UNDECIDED:
# if the tx is already in a valid or undecided block,
# then it no longer should be in the backlog, or added
# to a new block. We can delete and drop it.
r.table('backlog').get(tx['id']) \
.delete(durability='hard') \
.run(self.bigchain.conn)
return None
tx_validated = self.bigchain.is_valid_transaction(tx)
if tx_validated:
return tx
else:
# if the transaction is not valid, remove it from the
# backlog
r.table('backlog').get(tx['id']) \
.delete(durability='hard') \
.run(self.bigchain.conn)
return None
开发者ID:CsterKuroi,项目名称:Charitychain,代码行数:34,代码来源:block.py
示例6: setSubscription
def setSubscription(self, rdb):
'''
This will set a users subscription
to the specified subscription plan
'''
# Get User id
results = r.table('users').get(self.uid).update(
{
'acttype': self.acttype,
'stripeid': self.stripeid,
'stripe': self.stripe,
'subscription': self.subscription,
'subplans': self.subplans
}
).run(rdb)
if results:
loginfo = {}
loginfo['type'] = "setSubscription"
loginfo['uid'] = self.uid
loginfo['acttype'] = self.acttype
loginfo['subplans'] = self.subplans
loginfo['subscription'] = self.subscription
loginfo['time'] = time.time()
logresult = r.table('subscription_history').insert(
loginfo).run(rdb)
return True
else:
return False
开发者ID:tjcunliffe,项目名称:runbook,代码行数:28,代码来源:users.py
示例7: createMonitor
def createMonitor(self, rdb):
'''
This will create a health check with
the supplied domain information
'''
mondata = {
'name': self.name,
'ctype': self.ctype,
'uid': self.uid,
'url': self.url,
'failcount': 0,
'status': self.status,
'data': self.data}
if self.exists(mondata['name'], mondata['uid'], rdb):
return 'exists'
else:
mondata['status'] = 'queued'
results = r.table('monitors').insert(mondata).run(rdb)
if results['inserted'] == 1:
qdata = {}
qdata['item'] = mondata
qdata['action'] = 'create'
qdata['type'] = 'monitor'
qdata['item']['cid'] = results['generated_keys'][0]
self.cid = results['generated_keys'][0]
urlchk = self.genURL(self.cid, rdb)
if urlchk:
qdata['item']['url'] = self.url
for dc in ["dc1queue", "dc2queue"]:
q1 = r.table(dc).insert(qdata).run(rdb)
return results['generated_keys'][0]
else:
return False
开发者ID:EzanLTD,项目名称:cloudroutes-service,代码行数:33,代码来源:monitors.py
示例8: put
def put(self, character_id, webhook_id):
# if request.token['character_id'] != character_id:
# abort(403)
result = r.table(RDB_TABLE).get(webhook_id).run(db.conn)
if result is None or result['character'] != character_id:
abort(404)
parser = reqparse.RequestParser()
parser.add_argument('name', type=str, required=True, help='Name of the new webhook')
parser.add_argument('url', type=str, required=True, help='URL for the Slack webhook')
parser.add_argument('value', type=int, help='')
parser.add_argument('ids', type=int, help='', action='append')
args = parser.parse_args(strict=True)
update = {
'id': webhook_id,
'character': character_id,
'name': args['name'],
'url': args['url'],
}
if args['value'] is not None:
update['value'] = args['value']
if args['ids'] is not None:
update['ids'] = args['ids']
result = r.table(RDB_TABLE).get(webhook_id).replace(update).run(db.conn)
return update, 200
开发者ID:Regner,项目名称:settings-slack-webhooks,代码行数:31,代码来源:main.py
示例9: list_notes
def list_notes(hostname):
"""Retrieve a list of notes associated with a host. Or given
{'user': 'username', 'note': 'some message'} post a note."""
if request.method == 'GET':
try:
#someday i should probably add offset support here and in the statelog
limit = request.args.get('limit', 50, type=int)
except ValueError:
abort(400)
notes = list(r.table("notes").filter({"hostname": hostname}).order_by(r.desc("ts")).limit(limit).run(rdb.conn))
if notes:
return jsonify({'notes': sorted(notes, key=lambda k: k['ts'])})
else:
abort(404)
elif request.method == 'POST':
if not request.json:
abort(400)
if not request.json.get("user") or not request.json.get("note"):
abort(400)
if not r.table("hosts").get_all(hostname, index="hostname").run(rdb.conn):
abort(404)
alerting = [x["check"] for x in r.table("checks").filter({"h stname": hostname, "status": False}).run(rdb.conn)]
q = r.table("notes").insert({'hostname': hostname, 'user': request.json.get("user"),
'note': request.json.get("note"), 'ts': time(), 'alerting': alerting}).run(rdb.conn)
if q["inserted"] == 1:
return jsonify({'success': True})
else:
logger.error(q)
abort(500)
else:
abort(400)
开发者ID:thrawn01,项目名称:stalker,代码行数:31,代码来源:views.py
示例10: history
def history(
self, method=None, hid=None,
time=None, start=None, limit=None, rdb=None):
''' This will pull a monitors history from rethinkDB '''
retdata = False
if method == "mon-history":
retdata = []
monitors = r.table('history').filter(
(r.row['cid'] == self.cid) & (r.row['starttime'] >= time) & (r.row['type'] == "monitor")).order_by(
r.desc('starttime')).pluck('starttime', 'id', 'cid', 'zone', 'status', 'failcount', 'method', 'name').skip(start).limit(limit).run(rdb)
for mon in monitors:
mon['starttime'] = datetime.datetime.fromtimestamp(
mon['starttime']).strftime('%Y-%m-%d %H:%M:%S')
retdata.append(mon)
elif method == "detail-history":
retdata = []
mon = r.table('history').get(hid).pluck(
'starttime', 'cid', 'zone', 'status',
'failcount', 'method', 'name').run(rdb)
mon['reactions'] = []
reactions = r.table('history').filter(
(r.row['cid'] == self.cid) & (r.row['starttime'] == mon['starttime']) & (r.row['zone'] == mon['zone']) & (r.row['type'] == "reaction")).pluck('name', 'rstatus', 'time', 'starttime').run(rdb)
for react in reactions:
react['starttime'] = datetime.datetime.fromtimestamp(
react['starttime']).strftime('%Y-%m-%d %H:%M:%S')
react['time'] = datetime.datetime.fromtimestamp(
react['time']).strftime('%Y-%m-%d %H:%M:%S')
mon['reactions'].append(react)
mon['starttime'] = datetime.datetime.fromtimestamp(
mon['starttime']).strftime('%Y-%m-%d %H:%M:%S')
retdata.append(mon)
elif method == "count":
retdata = r.table('history').filter(
(r.row['cid'] == self.cid) & (r.row['starttime'] >= time) & (r.row['type'] == "monitor")).count().run(rdb)
return retdata
开发者ID:EzanLTD,项目名称:cloudroutes-service,代码行数:35,代码来源:monitors.py
示例11: check_state
def check_state(state):
"""List of checks in cluster in a given state [alerting/pending/suspended]"""
if state == 'alerting':
q = list(r.table("checks").get_all(False, index="status").run(rdb.conn))
if q:
return jsonify({'alerting': q})
else:
return jsonify({'alerting': []})
elif state == 'pending':
q = list(r.table("checks").get_all(True, index="pending").run(rdb.conn))
if q:
return jsonify({'pending': q})
else:
return jsonify({'pending': []})
elif state == 'in_maintenance':
q = list(r.table("checks").get_all(True, index="in_maintenance").run(rdb.conn))
if q:
return jsonify({'in_maintenance': q})
else:
return jsonify({'in_maintenance': []})
elif state == 'suspended':
q = list(r.table("checks").get_all(True, index="suspended").run(rdb.conn))
if q:
return jsonify({'suspended': q})
else:
return jsonify({'suspended': []})
else:
abort(400)
开发者ID:thrawn01,项目名称:stalker,代码行数:28,代码来源:views.py
示例12: check_suspended
def check_suspended(checkid):
"""Suspend a given check"""
if request.method == 'GET':
check = r.table("checks").get(checkid).run(rdb.conn)
if check:
check['id'] = str(check['id'])
return jsonify({'check': check})
else:
abort(404)
elif request.method == 'POST':
if not request.json:
abort(400)
try:
if not request.json.get('suspended'):
abort(400)
if request.json.get('suspended') is True:
q = r.table("checks").get(checkid).update({"suspended": True}).run(rdb.conn)
elif request.json.get('suspended') is False:
q = r.table("checks").get(checkid).update({"suspended": False}).run(rdb.conn)
else:
abort(400)
if q['replaced'] != 0:
return jsonify({'success': True})
else:
abort(404)
except Exception as err:
logger.error(err)
abort(400)
开发者ID:thrawn01,项目名称:stalker,代码行数:28,代码来源:views.py
示例13: check_next
def check_next(checkid):
"""Reschedule a given check"""
if request.method == 'GET':
check = r.table("checks").get(checkid).run(rdb.conn)
if check:
check['id'] = str(check['id'])
return jsonify({'check': check})
else:
abort(404)
elif request.method == 'POST':
if not request.json:
abort(400)
try:
if not request.json.get('next'):
abort(400)
if request.json.get('next') == 'now':
q = r.table("checks").get(checkid).update({"next": time() - 1}).run(rdb.conn)
else:
q = r.table("checks").get(checkid).update({"next": int(request.json["next"])}).run(rdb.conn)
if q["replaced"] != 0:
return jsonify({'success': True})
else:
abort(404)
except Exception as err:
logger.error(err)
abort(400)
开发者ID:thrawn01,项目名称:stalker,代码行数:26,代码来源:views.py
示例14: delete_transactions
def delete_transactions(self):
"""
Delete transactions from the backlog
"""
# create bigchain instance
b = Bigchain()
stop = False
while True:
# try to delete in batch to reduce io
tx_to_delete = []
for i in range(1000):
try:
tx = self.q_tx_delete.get(timeout=5)
except queue.Empty:
break
# poison pill
if tx == 'stop':
stop = True
break
tx_to_delete.append(tx)
if tx_to_delete:
r.table('backlog').get_all(*tx_to_delete).delete(durability='soft').run(b.conn)
if stop:
return
开发者ID:codeaudit,项目名称:bigchaindb,代码行数:29,代码来源:block.py
示例15: post
def post(self, *args):
#post body must be a list
#jobs = []
#jobs = tornado.escape.json_decode(self.request.body)
c = yield self.dbconnection
jobs = json.loads(self.request.body)
logger.info("Received %s" % (jobs,))
ts = time.time()
# Adding additional info to the json
for data in jobs:
data["jobstatus"] = "waiting"
data["message"] = "waiting to be executed"
data["created"] = datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
data["started"] = ""
data["completed"] = ""
data["returnstatus"] = ""
data["stdout"] = ""
data["stderr"] = ""
json.dumps(data)
yield r.table('jobs').run(c)
rows = yield r.table("jobs").insert(jobs).run(c)
ids =[]
# getting the generated keys from the DB
for key in rows['generated_keys']:
ids.append(key)
self.finish(json.dumps({"id": ids}))
开发者ID:onelab-eu,项目名称:myslice-mooc,代码行数:35,代码来源:rest.py
示例16: confirm_email
def confirm_email(token):
verify = verifyLogin(app.config["SECRET_KEY"], app.config["COOKIE_TIMEOUT"], request.cookies)
if verify:
user = User()
user.config = app.config
user.get("uid", verify, g.rdb_conn)
if user.confirmed:
flash("Account already confirmed. Thank you.", "success")
return redirect(url_for("member.dashboard_page"))
else:
try:
email = confirm_token(token)
if user.email == email[0]:
r.table("users").get(verify).update({"confirmed": True}).run(g.rdb_conn)
flash("You have confirmed your account. Thanks!", "success")
return redirect(url_for("member.dashboard_page"))
else:
flash("The confirmation link is invalid.", "danger")
return redirect(url_for("user.login_page"))
except:
flash("The confirmation link is invalid or has expired.", "danger")
return redirect(url_for("user.login_page"))
else:
flash("Please Login.", "warning")
return redirect(url_for("user.login_page"))
开发者ID:pathcl,项目名称:runbook,代码行数:25,代码来源:views.py
示例17: load_ebook
def load_ebook(self, ebook_id):
# query returns dict with ebook->versions->formats nested document
# versions are ordered by popularity
try:
ebook = (
r.table("ebooks")
.get(ebook_id)
.merge(
lambda ebook: {
"versions": r.table("versions")
.get_all(ebook["ebook_id"], index="ebook_id")
.order_by(r.desc("ranking"))
.coerce_to("array")
.merge(
lambda version: {
"formats": r.table("formats")
.get_all(version["version_id"], index="version_id")
.coerce_to("array")
}
)
}
)
.run()
)
except RqlRuntimeError as e:
if "Cannot perform merge on a non-object non-sequence `null`" in str(e):
return None
else:
raise e
return ebook
开发者ID:oii,项目名称:ogre,代码行数:32,代码来源:datastore.py
示例18: _signal
def _signal(self, qry, locale, profile, country=None):
page = 1
start_time = time.time()
print "Simply Hired"
html = self._html(qry, page, locale, country)
listings = self._listings(html)
#print listings
if listings.empty: return "none found"
while 'day' not in listings.date.tolist()[-1]:
page = page + 1
html = self._html(qry, page, locale, country)
listings = listings.append(self._listings(html))
print page
listings = listings[~listings.date.str.contains('day')]
listings["keyword"] = qry
listings = listings.drop_duplicates('company_name')
listings['source'] = 'Simply Hired'
listings["profile"] = profile
#print listings
companies = listings
keys = [row.company_name.lower().replace(" ","")+"_"+profile for i, row in companies.iterrows()]
companies["company_key"] = keys
companies["createdAt"] = arrow.now().timestamp
conn = rethink_conn.conn()
#r.table("hiring_signals").insert(companies.to_dict('r')).run(conn)
r.table("triggers").insert(companies.to_dict('r')).run(conn)
bitmapist.mark_event("function:time:simplyhired_job_scrape",
int((time.time() - start_time)*10**6))
rd.zadd("function:time:simplyhired_job_scrape",
str((time.time() - start_time)*10**6),
arrow.now().timestamp)
开发者ID:john2x,项目名称:triggerselling,代码行数:33,代码来源:simply_hired.py
示例19: find_missing_formats
def find_missing_formats(self, fmt, limit=None):
"""
Find ebook versions missing supplied format. Ignores non-fiction ebooks.
Each ebook should have several formats available for download (defined
in config['EBOOK_FORMATS']). This method is called nightly by a celery
task to ensure all defined formats are available.
Objects are returned where supplied fmt is missing (ie, needs creating)
Params:
fmt (str) Required ebook format that might be missing
limit (int) Limit number of results returned
Returns
version_id: [
{format, original_format, file_hash, ebook_id, s3_filename, uploaded},
...
]
"""
q = (
r.table("formats")
.group(index="version_id")
.filter({"is_fiction": True})
.filter(
lambda row: r.table("formats").filter({"format": fmt})["version_id"].contains(row["version_id"]).not_()
)
.eq_join("version_id", r.table("versions"), index="version_id")
.zip()
.pluck("format", "original_format", "file_hash", "ebook_id", "s3_filename", "uploaded")
)
if limit:
q = q.limit(limit)
return q.run()
开发者ID:oii,项目名称:ogre,代码行数:33,代码来源:datastore.py
示例20: createReaction
def createReaction(self, rdb):
''' This will create a reaction with the supplied information '''
reactdata = {
'name': self.name,
'rtype': self.rtype,
'uid': self.uid,
'trigger': self.trigger,
'frequency': self.frequency,
'lastrun': 0,
'data': self.data}
if self.exists(reactdata['name'], reactdata['uid'], rdb):
return 'exists'
else:
results = r.table('reactions').insert(reactdata).run(rdb)
if results['inserted'] == 1:
qdata = {}
qdata['item'] = reactdata
qdata['action'] = 'create'
qdata['type'] = 'reaction'
qdata['item']['rid'] = results['generated_keys'][0]
q1 = r.table('dc1queue').insert(qdata).run(rdb)
q2 = r.table('dc2queue').insert(qdata).run(rdb)
return results['generated_keys'][0]
else:
return False
开发者ID:podviaznikov,项目名称:cloudroutes-service,代码行数:25,代码来源:reactions.py
注:本文中的rethinkdb.table函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论