本文整理汇总了Python中users.Users.get_users_from_url方法的典型用法代码示例。如果您正苦于以下问题:Python Users.get_users_from_url方法的具体用法?Python Users.get_users_from_url怎么用?Python Users.get_users_from_url使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类users.Users
的用法示例。
在下文中一共展示了Users.get_users_from_url方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from users import Users [as 别名]
# 或者: from users.Users import get_users_from_url [as 别名]
def main():
webmon = Users()
state_changes = []
for row in webmon.get_distinct_urls():
# For each distinct URLs do HTTP GET request
# and collect the status code
try:
resp = requests.get(row[0])
status_code = resp.status_code
except requests.exceptions.ConnectionError:
status_code = -1
# State Changed: If current state is not
# equal to previous state, collect as state_changes
if status_code != row[1]:
state_changes.append((row[0], row[1], status_code))
for url, old_state, new_state in state_changes:
# For each state changes, send notification to all the
# users who subscribed to that URL and enabled.
if new_state == 200:
# Good status, Website is Healty
title = "Status: Healthy"
subtitle = "%s is Up" % (url)
warning = False
else:
# Bad status, may be temporary add error message along
# with the actual message
title = "Status: Faulty"
subtitle = "%s is Down, Error code: %s" % (url, new_state)
warning = True
for user in webmon.get_users_from_url(url):
# If multiple users subscribed to same URL
# Send notification to all enabled users.
resp = timeline.send_notification(user.token, title,
subtitle, warning)
print "[%s] URL: %s, Status: %s => %s, %s" % (datetime.utcnow(),
url,
old_state,
new_state,
resp)
# Update the current status in db
webmon.update_state(url, new_state)