コード例 #1
0
ファイル: yp-test.py プロジェクト: anthcp/components
def main():

    try:
        params = process_options()
        client = YouTubeClient(params)

        log.info(client)
        (success,metrics) = client.run()
        print("Done: %s" % str(client))

    except KeyboardInterrupt:
        # give the right exit status, 128 + signal number
        # signal.SIGINT = 2
        sys.exit(128 + 2)
    except EnvironmentError as e:
        (errno, strerror) = e.args
        try:
            print(strerror, file=sys.stderr)
        except Exception:
            pass
        sys.exit(2)

    if success:
        sys.exit(0)
    else:
        sys.exit(1)
コード例 #2
0
ファイル: yp-test.py プロジェクト: zhihaoli666/components
def main():

    try:
        params = process_options()
        client = YouTubeClient(params)

        log.info(client)
        (success, metrics) = client.run()
        print("Done: %s" % str(client))

    except KeyboardInterrupt:
        # give the right exit status, 128 + signal number
        # signal.SIGINT = 2
        sys.exit(128 + 2)
    except EnvironmentError as e:
        (errno, strerror) = e.args
        try:
            print(strerror, file=sys.stderr)
        except Exception:
            pass
        sys.exit(2)

    if success:
        sys.exit(0)
    else:
        sys.exit(1)
コード例 #3
0
    def run(self, spec, check_interrupt):
        # unpack parameters
        youtube_id = spec.get_parameter_value("youtube.video.id")

        # TODO - here you invoke yc in a try - catch block

        start_time = datetime.utcnow()

        params = { 'video_id': youtube_id, 'bwlimit': 0 }
        # not supposed to throw any exception, just better safe than sorry
        try:
            probe = YouTubeClient(params)
            (success, metrics) = probe.run()
            print("Metrics: %s" % str(metrics))
        except Exception as e:
            metrics = {}

        end_time = datetime.utcnow()

        # derive a result from the specification
        res = mplane.model.Result(specification=spec)

        # put actual start and end time into result
        res.set_when(mplane.model.When(a = start_time, b = end_time))

        for m in YouTubeMetrics:
            e = mplane.model.element(m)
            # some numbers are returned as floats: need to int() them
            if  str(e._prim) == 'natural':
                r = int(metrics[m])
            else:
                r = metrics[m]

            res.set_result_value(m, r)

        return res