本文整理匯總了Python中users.Users.get_distinct_urls方法的典型用法代碼示例。如果您正苦於以下問題:Python Users.get_distinct_urls方法的具體用法?Python Users.get_distinct_urls怎麽用?Python Users.get_distinct_urls使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類users.Users
的用法示例。
在下文中一共展示了Users.get_distinct_urls方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: main
# 需要導入模塊: from users import Users [as 別名]
# 或者: from users.Users import get_distinct_urls [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)