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


Python DB.record方法代碼示例

本文整理匯總了Python中db.DB.record方法的典型用法代碼示例。如果您正苦於以下問題:Python DB.record方法的具體用法?Python DB.record怎麽用?Python DB.record使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在db.DB的用法示例。


在下文中一共展示了DB.record方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: run

# 需要導入模塊: from db import DB [as 別名]
# 或者: from db.DB import record [as 別名]
    def run(self):

        def timedupdate():
            print "-- MARK --"
            auth_handler = urllib2.HTTPBasicAuthHandler()
            auth_handler.add_password( realm = "Icecast2 Server", uri = self.host + "/admin/", user = self.user, passwd = self.pw)
            opener = urllib2.build_opener(auth_handler)
            urllib2.install_opener(opener)
            # 1. retrieve all the current mount points
            # 2. for each mount point 
            #   gather information about listeners
            #   store in database
            try:
                result = urllib2.urlopen(self.host + "/admin/listmounts.xsl")
            except Exception, e:
                print "Failed update", e
                result = None

            if not result:
                return
            db = DB(self.db)
            
            mountpoints = re.findall("listclients\.xsl\?mount=/([^\"]*)", result.read())
            for mount in mountpoints:
                try:
                    result = urllib2.urlopen(self.host + "/admin/listclients.xsl?mount=/" + mount)
                except:
                    print "skipping %s" % mount
                    continue

                # the fourth table on listclients.xls is the relevant one
                table = re.findall("<table[^>]*>([^\r]*?)</table>", result.read())[3]
                listeners = re.findall("<tr[^>]*>([^\r]*?)</tr>", table)

                # the first row is the table header
                for listener in listeners[1:]:
                    fields = re.findall("<td[^>]*>([^\r]*?)</td>", listener)
                    # fields[0]: IP
                    # fields[1]: Seconds since connection
                    # fields[2]: user-agent
                    # fields[3]: useless kick link
                    db.record(mount, fields[0], int(fields[1]), fields[2])
開發者ID:moul,項目名稱:morganfreeman,代碼行數:44,代碼來源:daemon.py

示例2: timedupdate

# 需要導入模塊: from db import DB [as 別名]
# 或者: from db.DB import record [as 別名]
        def timedupdate():
            logger.info("-- MARK --")
            auth_handler = urllib2.HTTPBasicAuthHandler()
            auth_handler.add_password(realm=self.realm, uri=self.host + "/admin/", user=self.user, passwd=self.pw)
            auth_handler_mounts = urllib2.HTTPBasicAuthHandler()
            auth_handler_mounts.add_password(
                realm=self.realm, uri=self.host + "/admin/listmounts.xsl", user=self.user, passwd=self.pw
            )
            opener_mounts = urllib2.build_opener(auth_handler_mounts)
            urllib2.install_opener(opener_mounts)
            # 1. retrieve all the current mount points
            # 2. for each mount point
            #   gather information about listeners
            #   store in database
            try:
                result = urllib2.urlopen(self.host + "/admin/listmounts.xsl")
            except Exception as e:
                logger.error("Failed update: %s", e)
                result = None

            if not result:
                return
            db = DB(self.db)

            mountpoints = re.findall('listclients\.xsl\?mount=/([^"]*)', result.read())
            for mount in mountpoints:
                h_m = urllib2.HTTPBasicAuthHandler()
                h_m.add_password(
                    realm=self.realm,
                    uri=self.host + "/admin/listclients.xsl?mount=/" + mount,
                    user=self.user,
                    passwd=self.pw,
                )
                o_m = urllib2.build_opener(h_m)
                urllib2.install_opener(o_m)
                try:
                    result = urllib2.urlopen(self.host + "/admin/listclients.xsl?mount=/" + mount)
                except:
                    logger.error("skipping %s", mount)
                    continue

                resultstr = result.read()
                try:
                    # the latest (fourth in vanilla, third in -kh) table
                    # on listclients.xls is the relevant one
                    table = re.findall("<table[^>]*>([^\r]*?)</table>", resultstr)[-1]
                except:
                    # 2.4.0
                    _table = re.findall('<table[^>]*class="colortable"[^>]*>([^\r]*?)</table>', resultstr)
                    if not _table:
                        continue
                    table = _table[0]
                listeners = re.findall("<tr[^>]*>([^\r]*?)</tr>", table)

                if ICECAST_V_KH in server_version:
                    rowskip = 0
                else:
                    rowskip = 1
                # in icecast vanilla, first row is the
                # table header. in -kh, the header is enclosed in <thead>
                # without use of <tr>
                logger.debug("registering %d entries", len(listeners) - rowskip)
                for listener in listeners[rowskip:]:
                    fields = re.findall("<td[^>]*>([^\r]*?)</td>", listener)
                    if not ICECAST_V_KH in server_version:  # vanilla
                        # fields[0]: IP
                        # fields[1]: Seconds since connection
                        # fields[2]: user-agent
                        # fields[3]: action
                        db.record(mount, fields[0], int(fields[1]), fields[2])
                    else:
                        # fields[0]: IP
                        # fields[1]: Seconds since connection
                        # fields[2]: lag
                        # fields[3]: user-agent
                        # fields[4]: action
                        db.record(mount, fields[0], int(fields[1]), fields[3])
開發者ID:Impact89fm,項目名稱:morganfreeman,代碼行數:79,代碼來源:daemon.py


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