当前位置: 首页>>代码示例>>Python>>正文


Python Users.update_state方法代码示例

本文整理汇总了Python中users.Users.update_state方法的典型用法代码示例。如果您正苦于以下问题:Python Users.update_state方法的具体用法?Python Users.update_state怎么用?Python Users.update_state使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在users.Users的用法示例。


在下文中一共展示了Users.update_state方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from users import Users [as 别名]
# 或者: from users.Users import update_state [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.update_state方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。