本文整理汇总了Python中monitors.Monitor.count方法的典型用法代码示例。如果您正苦于以下问题:Python Monitor.count方法的具体用法?Python Monitor.count怎么用?Python Monitor.count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类monitors.Monitor
的用法示例。
在下文中一共展示了Monitor.count方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from monitors import Monitor [as 别名]
# 或者: from monitors.Monitor import count [as 别名]
def get(self, method, lookup, rdb):
''' Lookup the user by the uid '''
if method == 'uid':
uid = lookup
elif method == 'username':
uid = self.getUID(lookup, rdb)
results = r.table('users').get(uid).run(rdb)
data = results
if data:
self.email = results['email']
self.uid = results['id']
self.username = results['username']
self.status = results['status']
self.company = results['company']
self.contact = results['contact']
self.acttype = results['acttype']
self.stripeid = results['stripeid']
self.stripe = results['stripe']
self.subplans = results['subplans']
self.payments = results['payments']
self.subscription = results['subscription']
self.creation_time = results['creation_time']
self.confirmed = results['confirmed']
## Identify number of monitors and reactions
monitor = Monitor()
reaction = Reaction()
self.monitorCount = monitor.count(self.uid, rdb)
self.reactionCount = reaction.count(self.uid, rdb)
return self
else:
return None
示例2: get
# 需要导入模块: from monitors import Monitor [as 别名]
# 或者: from monitors.Monitor import count [as 别名]
def get(self, method, lookup, rdb):
""" Lookup the user by the uid """
if method == "uid":
uid = lookup
elif method == "username":
uid = self.getUID(lookup, rdb)
results = r.table("users").get(uid).run(rdb)
data = results
if data:
self.email = results["email"]
self.uid = results["id"]
self.username = results["username"]
self.status = results["status"]
self.company = results["company"]
self.contact = results["contact"]
self.acttype = results["acttype"]
self.stripeid = results["stripeid"]
self.stripe = results["stripe"]
self.subplans = results["subplans"]
self.payments = results["payments"]
self.subscription = results["subscription"]
self.creation_time = results["creation_time"]
self.confirmed = results["confirmed"]
## Identify number of monitors and reactions
monitor = Monitor()
reaction = Reaction()
self.monitorCount = monitor.count(self.uid, rdb)
self.reactionCount = reaction.count(self.uid, rdb)
return self
else:
return None
示例3: modsub_page
# 需要导入模块: from monitors import Monitor [as 别名]
# 或者: from monitors.Monitor import count [as 别名]
def modsub_page():
'''Dashboard Modify Subscription:
This will allow a user to modify their subscription and account plan
'''
verify = verifyLogin(
app.config['SECRET_KEY'], app.config['COOKIE_TIMEOUT'], request.cookies)
if verify:
user = User()
user.get('uid', verify, g.rdb_conn)
data = startData(user)
data['active'] = 'dashboard'
data['url'] = '/dashboard/mod-subscription'
data['uid'] = user.uid
tmpl = 'member/mod-subscription.html'
data['js_bottom'].append('forms/subscribe.js')
form = []
# Stripe vs ASM stuff
if user.payments == "ASM":
headers = {
"content-type": "application/json",
"Authorization": app.config['ASSEMBLY_PRIVATE_KEY']
}
paymenturl = app.config['ASSEMBLY_PAYMENTS_URL']
else:
from base64 import b64encode
api_key = b64encode(app.config['STRIPE_PRIVATE_KEY']).decode("ascii")
headers = {
"Authorization": "Basic " + api_key,
}
paymenturl = app.config['STRIPE_PAYMENTS_URL']
from generalforms import subscribe
if data['upgraded'] is False:
# Upgrade Users
if request.method == "POST" and \
"stripeToken" in request.form and "plan" in request.form:
stripeToken = request.form['stripeToken']
plan = request.form['plan']
if stripeToken:
result = None
monitor = Monitor()
payload = {
'email': user.email,
'quantity': monitor.count(user.uid, g.rdb_conn),
'source': stripeToken,
'plan': plan
}
json_payload = json.dumps(payload)
url = paymenturl + "/customers"
print ("Making request to %s") % url
try:
# Send Request to Payment system to create user and subscribe
# them to desired plan
result = requests.post(
url=url, headers=headers,
params=payload, verify=True)
except:
print("Critical Error making request to Payments")
flash('There was an error processing \
your card details.', 'danger')
print("Got {0} status code from Payments".format(
result.status_code))
if result.status_code >= 200 and result.status_code <= 299:
rdata = json.loads(result.text)
user.stripeid = rdata['id']
user.stripe = stripeToken
user.subplans = payload['quantity']
user.subscription = payload['plan']
if "pro_plus" in plan:
user.acttype = "proplus"
else:
user.acttype = "pro"
print("Setting UID %s Subscription to: %s") % (
user.uid, user.acttype)
subres = user.setSubscription(g.rdb_conn)
stathat.ez_count(
app.config['STATHAT_EZ_KEY'],
app.config['ENVNAME'] + ' User Upgrades', 1)
if subres:
newdata = startData(user)
data['limit'] = newdata['limit']
data['rlimit'] = newdata['rlimit']
data['acttype'] = newdata['acttype']
data['subplans'] = newdata['subplans']
data['cost'] = newdata['cost']
data['subscription'] = newdata['subscription']
flash('Subscription successfully created.',
'success')
else:
flash('Subscription not successfully created.',
'danger')
else:
flash('Subscription not created got status code: %d' % result.status_code, 'danger')
# Increase subscription
if data['upgraded']:
form = subscribe.AddPackForm(request.form)
if request.method == "POST" and "stripeToken" not in request.form:
if form.validate():
add_packs = int(form.add_packs.data)
#.........这里部分代码省略.........
示例4: addcheck_page
# 需要导入模块: from monitors import Monitor [as 别名]
# 或者: from monitors.Monitor import count [as 别名]
def addcheck_page(cname):
verify = verifyLogin(
app.config['SECRET_KEY'], app.config['COOKIE_TIMEOUT'], request.cookies)
if verify:
user = User()
user.get('uid', verify, g.rdb_conn)
data = startData(user)
data['active'] = 'dashboard'
data['url'] = '/dashboard/monitors/' + cname
tmpl = 'monitors/' + cname + '.html'
data['js_bottom'] = ['monitors/monitorlist.js', 'monitors/base.js', 'monitors/' + cname + '.js']
# Check Users Status
if user.status != "active":
data['url'] = '/dashboard/mod-subscription'
tmpl = 'member/mod-subscription.html'
else:
# Get list of reactions and validate that there are some
data['reactions'] = user.getReactions(g.rdb_conn)
# Proces the form
cform = __import__(
"monitorforms." + cname, globals(), locals(), ['CheckForm'], -1)
form = cform.CheckForm(request.form)
if form.__contains__("timer"):
form.timer.choices = data['choices']
reactchoices = []
for key in data['reactions'].keys():
reactchoices.append(
(data['reactions'][key]['id'],
data['reactions'][key]['name']))
form.reactions.choices = reactchoices
if request.method == 'POST':
if form.validate():
monitor = Monitor()
monitor.name = form.name.data
monitor.ctype = cname
monitor.uid = user.uid
monitor.status = "queued"
monitor.url = None
tmpdata = {}
for item in form.__iter__():
tmpdata[item.name] = item.data
monitor.data = tmpdata
# Check if the user already exceeds their limit
if monitor.count(user.uid, g.rdb_conn) < data['limit']:
# Create the monitor if all checks out
results = monitor.createMonitor(g.rdb_conn)
else:
results = "toomany"
if results == "exists":
print("/dashboard/monitors/{0} - \
Monitor already exists".format(cname))
flash('{0} seems to already exist. \
Try using a different name.'.format(
monitor.name), 'danger')
elif results is False:
print("/dashboard/monitors/{0} - \
Monitor creation failed".format(cname))
flash('Could not create monitor.', 'danger')
elif results == 'toomany':
stathat.ez_count(
app.config['STATHAT_EZ_KEY'],
app.config['ENVNAME'] + ' Too many health checks',
1)
flash('You have too many monitors. \
Please upgrade your plan or clean \
up old ones.', 'danger')
print("/dashboard/monitors/{0} - \
Monitor creation failed: toomany".format(cname))
else:
stathat.ez_count(
app.config['STATHAT_EZ_KEY'],
app.config['ENVNAME'] + ' Monitor Added', 1)
print("/dashboard/monitors/%s - \
Monitor creation successful") % cname
flash('Monitor "{0}" successfully added.'.format(
monitor.name), 'success')
newmonitor = Monitor()
newmonitor.get(results, g.rdb_conn)
if newmonitor.uid == user.uid:
data['monitor'] = {
'cid': newmonitor.cid,
'name': newmonitor.name,
'uid': newmonitor.uid,
'ctype': newmonitor.ctype,
'url': newmonitor.url,
'data': newmonitor.data
}
else:
print("/dashboard/monitors/{0} - \
Monitor creation failed: Form invalid".format(cname))
flash('Form is not valid.', 'danger')
page = render_template(tmpl, data=data, form=form)
return page
else:
flash('Please Login.', 'warning')
return redirect(url_for('user.login_page'))
示例5: modsub_page
# 需要导入模块: from monitors import Monitor [as 别名]
# 或者: from monitors.Monitor import count [as 别名]
def modsub_page():
'''Dashboard Modify Subscription:
This will allow a user to modify their subscription and account plan
'''
verify = verifyLogin(
app.config['SECRET_KEY'], app.config['COOKIE_TIMEOUT'], request.cookies)
if verify:
user = User()
user.get('uid', verify, g.rdb_conn)
data = startData(user)
data['active'] = 'dashboard'
data['url'] = '/dashboard/mod-subscription'
data['uid'] = user.uid
tmpl = 'member/mod-subscription.html'
data['js_bottom'].append('forms/subscribe.js')
form = []
headers = {
"content-type": "application/json",
"Authorization": app.config['ASSEMBLY_PRIVATE_KEY']
}
from generalforms import subscribe
if data['acttype'] == "Lite":
# Upgrade Users
if request.method == "POST" and \
"stripeToken" in request.form and "plan" in request.form:
stripeToken = request.form['stripeToken']
plan = request.form['plan']
if stripeToken:
result = None
monitor = Monitor()
payload = {
'email': user.email,
'quantity': monitor.count(user.uid, g.rdb_conn),
'card': stripeToken,
'plan': plan
}
json_payload = json.dumps(payload)
url = app.config['ASSEMBLY_PAYMENTS_URL'] + "/customers"
print ("Making request to %s") % url
try:
# Send Request to Assembly to create user and subscribe
# them to desired plan
result = requests.post(
url=url, headers=headers,
data=json_payload, verify=True)
except:
print("Critical Error making request to ASM Payments")
data['msg'] = "There was an error processing your card details"
data['error'] = True
print(
"Got %d status code from Assembly") % result.status_code
if result.status_code >= 200 and result.status_code <= 299:
rdata = json.loads(result.text)
user.stripeid = rdata['id']
user.stripe = stripeToken
user.subplans = payload['quantity']
user.subscription = payload['plan']
user.acttype = "pro"
print("Setting UID %s Subscription to: %s") % (
user.uid, user.acttype)
subres = user.setSubscription(g.rdb_conn)
stathat.ez_count(
app.config['STATHAT_EZ_KEY'],
app.config['ENVNAME'] + ' User Upgrades', 1)
if subres:
newdata = startData(user)
data['limit'] = newdata['limit']
data['rlimit'] = newdata['rlimit']
data['acttype'] = newdata['acttype']
data['subplans'] = newdata['subplans']
data['cost'] = newdata['cost']
data['subscription'] = newdata['subscription']
data['msg'] = "Subscription successfully created"
data['error'] = False
else:
data[
'msg'] = "Subscription not successfully created"
data['error'] = True
# Increase subscription
if data['acttype'] != "Lite":
form = subscribe.AddPackForm(request.form)
if request.method == "POST" and "stripeToken" not in request.form:
if form.validate():
add_packs = int(form.add_packs.data)
# Set subscription quantity to desired monitor count
payload = {'quantity': add_packs}
json_payload = json.dumps(payload)
url = app.config[
'ASSEMBLY_PAYMENTS_URL'] + "/customers/" + user.stripeid
print("Making request to %s") % url
try:
# Get Subscription ID
result = requests.get(
url=url, headers=headers, verify=True)
if result.status_code == 200:
rdata = json.loads(result.text)
subsid = rdata['subscriptions']['data'][0]['id']
url = url + "/subscriptions/" + subsid
print("Making request to %s") % url
# Set Quantity
#.........这里部分代码省略.........