當前位置: 首頁>>代碼示例>>Python>>正文


Python Users.get_users_from_url方法代碼示例

本文整理匯總了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)
開發者ID:aravindavk,項目名稱:webmon,代碼行數:48,代碼來源:job.py


注:本文中的users.Users.get_users_from_url方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。