rams_total.py

#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2010 rambla.be
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

##
#  Shows basic usage of the RAMS 'total' resource. 

import time
import rawsc
import rawsc.service
from rawsc import rams
import rawsc.rams.service
try:
  from xml.etree import cElementTree as ElementTree
except ImportError:
  try:
    import cElementTree as ElementTree
  except ImportError:
    from elementtree import ElementTree

USER = "xxx"
PWD = "xxx"
SERVER = "rams.mon01.rambla.be"

try:
    # Create a Rass instance, passing it your login credentials and the base service uri
    client = rawsc.rams.service.RamsService(username=USER, password=PWD, server=SERVER)
    
    # get host entries, page by page, results with most volume first
    qry = rawsc.Query()
    qry["year"] = "2010"
    qry["month"] = "10"
    qry["day"] = "16"
    qry["type"] = "rtmp,http"
    feed = client.getTotalFeed(query = qry)
    for e in feed.entry:
        print "\nEntry URI: " + e.id.text
        print "Kind = %s, Type = %s" % (e.kind, e.type)
        print "Hits: " + str(e.content.params.hits.text)
        print "Volume: " + str(e.content.params.volume.text)
        print "last_modified: " + str(e.content.params.last_modified.text)
        print "events: " + str(e.content.params.events.text)
        print "unique: " + str(e.content.params.unique.text)
        
except rawsc.service.Error, e:
    print "Error Response from server, contents = %s.\n" % str(e)
    error_dict = e[0] # error dict inside the first tuple elem
    print "status code : " + str(error_dict["status"]) + "\n"
    if error_dict.has_key("body"):
        print "error body : " + error_dict["body"] + "\n"
except rawsc.RawscException, e:
    print "RawscException caught, reason = %s.\n" % str(e)
except StandardError, e:
    print "StandardError caught, reason = %s.\n" % str(e)
except:
    print "unhandled exception caught\n"


Generated on Mon Mar 28 15:03:38 2011 for rawsc by  doxygen 1.5.3