예제 #1
0
    def run(self):
        start_mark = False
        crawler = Crawler()
        while self.flag:
            try:
                url = 'http://hw.venndata.cn/proxy?num={num}'.format(
                    num=self.num)

                response, _ = crawler.crawl(url=url)
                html = response.text
                if html:
                    data = json.loads(html)['data']
                    proxy_list = data.split('|')
                    if len(proxy_list) > 500:
                        old_len = len(PROXY_LIST)
                        PROXY_LIST.extend(proxy_list)
                        PROXY_LIST[0:old_len] = []
                    if not start_mark:
                        log.critical("代理启动成功!获取代理%s" % len(proxy_list))
                        start_mark = True
            except Exception as e:
                log.error('生成 Proxy Failed' + str(e))
            time.sleep(self.interval)

        log.info('代理关闭')
        return
예제 #2
0
    def __init__(self):
        super(MainWindow, self).__init__()
        
        self.trans = TransQ()
        self.trans.initialize(master=self)

        log.info("Set up UI")
예제 #3
0
파일: maven.py 프로젝트: davnoe/kiji
    def run(self, args):
        coord = self.flags.artifact
        if (coord is None) and (len(args) > 0):
            coord, args = args[0], args[1:]
        assert (coord is not None), "Must specify an artifact to download."

        assert (len(args) == 0), "Unexpected command-line arguments: {!r}".format(args)

        artf = artifact.parse_artifact(coord)
        log.info("Looking up artifact {!s}", artf)

        print(self.repo.get(artf))
        return os.EX_OK
예제 #4
0
파일: maven.py 프로젝트: rajeshmr/kiji
    def run(self, args):
        coord = self.flags.artifact
        if (coord is None) and (len(args) > 0):
            coord, args = args[0], args[1:]
        assert (coord is not None), "Must specify an artifact to download."

        assert (len(args) == 0
                ), "Unexpected command-line arguments: {!r}".format(args)

        artf = artifact.parse_artifact(coord)
        log.info("Looking up artifact {!s}", artf)

        print(self.repo.get(artf))
        return os.EX_OK
예제 #5
0
 def get(self, key):
     image = Image.get(key)
     if image and image.image:
         if not image.thumbnail:
             img = images.Image(image.image)
             img.resize(height=192)
             img.im_feeling_lucky()
             image.thumbnail = img.execute_transforms(output_encoding=images.JPEG)
             log.info("Creating thumbnail for %s", image.filename)
             image.put()
         self.response.headers["Content-Type"] = "image/jpeg"
         self.response.out.write(image.thumbnail)
     else:
         self.error(404)
예제 #6
0
    def setupUi(self, Dialog):
        self.widgets = []
        self.master = Dialog

        self.title = f"Challenge: {self.type}"
        Dialog.setObjectName(self.title)
        Dialog.resize(400, 300)

        self.check = QtWidgets.QPushButton(Dialog)
        self.check.setGeometry(QtCore.QRect(140, 250, 112, 32))
        self.check.setObjectName("check")
        self.check.setChecked(False)
        self.check.clicked.connect(self.check_answer)
        self.widgets.append([self.check, "Check"])

        self.label = QtWidgets.QLabel(Dialog)
        self.label.setGeometry(QtCore.QRect(30, 20, 340, 16))
        self.label.setAlignment(QtCore.Qt.AlignCenter)
        self.label.setObjectName("label")
        self.widgets.append([self.label, self.prompt])

        if self.type in implemented:
            x, y = 100, 75
            for i, c in enumerate(self.choices, start=1):
                a = f"radioBox_{i}"
                setattr(self, a, QtWidgets.QRadioButton(Dialog))
                o = getattr(self, a)
                o.setGeometry(QtCore.QRect(x, y, 300, 20))
                o.setObjectName(a)

                if self.type == "form":
                    o.clicked.connect(partial(sentence_to_audio, c))
                elif self.type == 'select':
                    o.clicked.connect(partial(play, self.tts[i - 1]))

                self.widgets.append([o, c])

                y += 30

        self.feedback = QtWidgets.QLabel(Dialog)
        self.feedback.setGeometry(QtCore.QRect(30, 230, 340, 16))
        self.feedback.setObjectName("feedback")
        self.feedback.setAlignment(QtCore.Qt.AlignCenter)
        self.widgets.append([self.feedback, ""])

        self.retranslateUi(Dialog)
        QtCore.QMetaObject.connectSlotsByName(Dialog)

        log.info(f"Loaded {self.type} challenge")
예제 #7
0
파일: maven.py 프로젝트: davnoe/kiji
    def run(self, args):
        coord = self.flags.artifact_key
        if (coord is None) and (len(args) > 0):
            coord, args = args[0], args[1:]
        assert (coord is not None), "Must specify the artifact to list versions of."

        assert (len(args) == 0), "Unexpected command-line arguments: {!r}".format(args)

        artf_key = artifact.parse_artifact_key(coord)
        log.info("Scanning artifacts matching key: {}", artf_key)

        versions = list()
        for remote in self.repo.remotes:
            versions.extend(
                remote.list_versions(group=artf_key.group_id, artifact=artf_key.artifact_id))
        print("\n".join(sorted(frozenset(versions))))
        return os.EX_OK
예제 #8
0
파일: maven.py 프로젝트: davnoe/kiji
    def run(self, args):
        coords = list()
        if self.flags.artifacts is not None:
            coords.extend(self.flags.artifacts.split(","))
        coords.extend(args)

        coords = filter(None, coords)
        artfs = map(artifact.parse_artifact, coords)
        artfs = tuple(artfs)

        for artf in artfs:
            log.info("Examining artifact: {}", artf)

        print(get_dependency_tree(
            coordinates=artfs,
            scope=self.flags.scope,
            local_repo=base.strip_optional_prefix(self.repo.local.path, "file://"),
        ))
        return os.EX_OK
예제 #9
0
파일: maven.py 프로젝트: rajeshmr/kiji
    def run(self, args):
        coord = self.flags.artifact_key
        if (coord is None) and (len(args) > 0):
            coord, args = args[0], args[1:]
        assert (coord
                is not None), "Must specify the artifact to list versions of."

        assert (len(args) == 0
                ), "Unexpected command-line arguments: {!r}".format(args)

        artf_key = artifact.parse_artifact_key(coord)
        log.info("Scanning artifacts matching key: {}", artf_key)

        versions = list()
        for remote in self.repo.remotes:
            versions.extend(
                remote.list_versions(group=artf_key.group_id,
                                     artifact=artf_key.artifact_id))
        print("\n".join(sorted(frozenset(versions))))
        return os.EX_OK
예제 #10
0
    def get(self, id):
        event = Event.get_by_id(int(id))
        if event.image:
            if not event.small_image:
                image = images.Image(event.image)
                max_size = image.width if image.width > image.height else image.height
                small_size = 250.0
                if small_size < max_size:
                    ratio = small_size / max_size
                    image.resize(int(image.width * ratio), int(image.height * ratio))
                    log.info("Creating small event image")
                    event.small_image = image.execute_transforms(output_encoding=images.JPEG)
                else:
                    event.small_image = event.image
                event.put()

            self.response.headers["Content-Type"] = "image/jpeg"
            self.response.out.write(event.small_image)
        else:
            self.error(404)
예제 #11
0
파일: maven.py 프로젝트: rajeshmr/kiji
    def run(self, args):
        coords = list()
        if self.flags.artifacts is not None:
            coords.extend(self.flags.artifacts.split(","))
        coords.extend(args)

        coords = filter(None, coords)
        artfs = map(artifact.parse_artifact, coords)
        artfs = tuple(artfs)

        for artf in artfs:
            log.info("Examining artifact: {}", artf)

        print(
            get_dependency_tree(
                coordinates=artfs,
                scope=self.flags.scope,
                local_repo=base.strip_optional_prefix(self.repo.local.path,
                                                      "file://"),
            ))
        return os.EX_OK
예제 #12
0
def callService(sdate, edate, status):
    """
    Query cninfo trading date api by call base.py callService method.

    Args:
        sdate: start date, support format:20161101 or 2016-11-01 or 2016/11/01
        edate: end date
        status: trading status,  1: trading day  2: closed day , multiple inputs is not supported.
    
    Returns:
        1. None: not data.
        2. TradeDate Object.
        3. Dict: {date:TradeDateObject, ...}
    """
    url = '/api/stock/p_public0001'
    params = {
        'sdate': sdate,
        'edate': edate,
    }
    if status != '':
        params['state'] = status
    respContent = base.callService(url, params)
    if respContent == '':
        return ''
    respContent = json.loads(respContent)
    dataDict = respContent['records']
    count = respContent['count']
    if count == 0:
        log.info('No data form serivce')
        return ''
    elif count == 1:
        return TradeDate(dataDict[0])
    else:
        dict = {}
        for item in dataDict:
            obj = TradeDate(item)
            dict[obj.date] = obj
        return dict
예제 #13
0
파일: loader.py 프로젝트: seomoz/fiji
    def run(self, args):
        action = self.flags.do
        if (action is None) and (len(args) > 0):
            action, args = args[0], args[1:]
        if action is None:
            action = "classpath"
        assert (action is not None), ("Must specify an action to perform, eg. 'classpath'.")

        local_repo = self.flags.maven_local
        if local_repo == ":wkspc:":
            wkspc = workspace.find_workspace_root(path=os.getcwd())
            if wkspc is not None:
                local_repo = os.path.join(wkspc, "output", "maven_repository")
                log.info("Using workspace local repo {!r}", local_repo)
            else:
                local_repo = os.path.join(os.environ["HOME"], ".m2", "repository")
                log.info("No workspace found, using global repo {!r}", local_repo)
        assert os.path.exists(local_repo), \
            "Maven local repository not found: {!r}".format(local_repo)

        self._repo = maven_repo.MavenRepository(
            local = local_repo,
            remotes = self.flags.maven_remotes.split(","),
            exclusions = frozenset(self.flags.maven_remote_exclusions.split(",")),
        )

        self._scanner = maven_loader.ArtifactScanner(
            repo=self.repo,
            fetch_content=self.flags.fetch,
            force_unresolved=True,
        )

        targets = list(self.flags.targets.split(",")) + list(args)
        targets = list(filter(None, targets))
        target_artifacts = map(artifact.parse_artifact, targets)

        exclusions = self.flags.exclusions.split(",")
        exclusions = filter(None, exclusions)
        exclusion_artifacts = frozenset(map(artifact.parse_artifact_name, exclusions))

        deps = list()
        for target_artifact in target_artifacts:
            dep = maven_wrapper.Dependency(
                artifact=target_artifact,
                scope=self.flags.scope,
                exclusions=exclusion_artifacts,
            )
            deps.append(dep)

        log.debug("Scanning dependencies: {!r}", deps)
        classpath = self._scanner.scan(deps)

        list_file_path = self.flags.list_file
        if list_file_path is None:
            list_file_path = '/dev/null'
        with open(list_file_path, "wt") as ofile:
            self._scanner.write_dep_list(output=ofile)

        if action == "classpath":
            print(":".join(sorted(classpath)))

        elif action == "resolve":
            for artf, dep_chains in sorted(self._scanner.versions.items()):
                chain = dep_chains[0]
                selected = chain[0]
                print(selected.artifact)

        elif action == "explain":
            self._scanner.explain(artifact.parse_artifact_name(self.flags.explain))

        else:
            raise Error("Invalid action: {!r}".format(action))
예제 #14
0
    def run(self, args):
        artifacts = list()
        if self.flags.artifacts is not None:
            artifacts.extend(self.flags.artifacts.split(","))
        if len(args) > 0:
            artifacts.extend(args)
            args = []
        artifacts = list(map(artifact.parse_artifact, artifacts))

        exclusions = tuple()
        if self.flags.exclusions is not None:
            exclusions = self.flags.exclusions.split(",")
            exclusions = filter(None, exclusions)
            exclusions = map(artifact.parse_artifact, exclusions)
            exclusions = frozenset(exclusions)

        assert (len(args) == 0
                ), "Unexpected command-line arguments: {!r}".format(args)

        # --------------------

        local_repo = self.flags.local_repo
        if local_repo == ":wkspc:":
            wkspc = workspace.find_workspace_root(path=os.getcwd())
            if wkspc is None:
                local_repo = os.path.join(os.environ["HOME"], ".m2",
                                          "repository")
                log.info("No workspace found, using global repo {!r}",
                         local_repo)
            else:
                local_repo = os.path.join(wkspc, "output", "maven_repository")
                log.info("Using workspace local repo {!r}", local_repo)
        assert os.path.exists(local_repo), \
            "Maven local repository not found: {!r}".format(local_repo)

        maven_remotes = self.flags.maven_remotes.split(",")
        repo = maven_repo.MavenRepository(local=local_repo,
                                          remotes=maven_remotes)

        # --------------------

        assert (self.flags.output is not None) and (len(self.flags.output) > 0), \
            "Must specify output path with --output=/path/to/java-binary"
        if self.flags.overwrite and os.path.exists(self.flags.output):
            os.remove(self.flags.output)

        # --------------------

        scanner = maven_loader.ArtifactScanner(repo=repo, fetch_content=True)
        deps = []
        for artf in artifacts:
            dep = maven_wrapper.Dependency(
                artifact=artf,
                scope=self.flags.scope,
                exclusions=exclusions,
            )
            deps.append(dep)
        scanner.scan(deps)
        assert (len(scanner.errors) == 0), \
            "{:d} errors while resolving Maven dependencies".format(len(scanner.errors))

        artifacts = list()
        for artf, dep_chains in scanner.versions.items():
            dep_chain = dep_chains[0]
            dep = dep_chain[0]
            artifacts.append(dep.artifact)

        # --------------------

        linker = java_linker.JavaLinker(
            output_path=self.flags.output,
            maven_repo=repo,
        )
        try:
            linker.link(
                artifacts=artifacts,
                main_class=self.flags.main_class,
            )
        finally:
            linker.close()

        return os.EX_OK
예제 #15
0
    def run(self, args):
        action = self.flags.do
        if (action is None) and (len(args) > 0):
            action, args = args[0], args[1:]
        if action is None:
            action = "classpath"
        assert (action is not None), (
            "Must specify an action to perform, eg. 'classpath'.")

        local_repo = self.flags.maven_local
        if local_repo == ":wkspc:":
            wkspc = workspace.find_workspace_root(path=os.getcwd())
            if wkspc is not None:
                local_repo = os.path.join(wkspc, "output", "maven_repository")
                log.info("Using workspace local repo {!r}", local_repo)
            else:
                local_repo = os.path.join(os.environ["HOME"], ".m2",
                                          "repository")
                log.info("No workspace found, using global repo {!r}",
                         local_repo)
        assert os.path.exists(local_repo), \
            "Maven local repository not found: {!r}".format(local_repo)

        self._repo = maven_repo.MavenRepository(
            local=local_repo,
            remotes=self.flags.maven_remotes.split(","),
            exclusions=frozenset(
                self.flags.maven_remote_exclusions.split(",")),
        )

        self._scanner = maven_loader.ArtifactScanner(
            repo=self.repo,
            fetch_content=self.flags.fetch,
            force_unresolved=True,
        )

        targets = list(self.flags.targets.split(",")) + list(args)
        targets = list(filter(None, targets))
        target_artifacts = map(artifact.parse_artifact, targets)

        exclusions = self.flags.exclusions.split(",")
        exclusions = filter(None, exclusions)
        exclusion_artifacts = frozenset(
            map(artifact.parse_artifact_name, exclusions))

        deps = list()
        for target_artifact in target_artifacts:
            dep = maven_wrapper.Dependency(
                artifact=target_artifact,
                scope=self.flags.scope,
                exclusions=exclusion_artifacts,
            )
            deps.append(dep)

        log.debug("Scanning dependencies: {!r}", deps)
        classpath = self._scanner.scan(deps)

        list_file_path = self.flags.list_file
        if list_file_path is None:
            list_file_path = '/dev/null'
        with open(list_file_path, "wt") as ofile:
            self._scanner.write_dep_list(output=ofile)

        if action == "classpath":
            print(":".join(sorted(classpath)))

        elif action == "resolve":
            for artf, dep_chains in sorted(self._scanner.versions.items()):
                chain = dep_chains[0]
                selected = chain[0]
                print(selected.artifact)

        elif action == "explain":
            self._scanner.explain(
                artifact.parse_artifact_name(self.flags.explain))

        else:
            raise Error("Invalid action: {!r}".format(action))
예제 #16
0
 def set_next(self):
     if all(self.get_line(i).text() == self.translations[i] for i in range(5)):
         self.check.setText("Next")
         self.check.repaint()
         self._reconn(self.initialize)
         log.info("All correct!")
예제 #17
0
    def run(self, args):
        assert (len(args) == 0), "Unexpected launcher command-line arguments: {!r}".format(args)

        assert os.path.exists(self.flags.java_path), \
            "JVM executable not found: {!r}".format(self.flags.java_path)

        self.extract()

        # Identify which profile to use:
        profiles = self.config["profiles"]

        if self.flags.profile is not None:
            # Profile explicitly specified by user must exist:
            assert (self.flags.profile in profiles), \
                "Invalid profile {!r}, use one of {}." \
                .format(self.flags.profile, sorted(profiles.keys()))
            profile_name = self.flags.profile
        else:
            # No explicit override, default is to use the program name if possible,
            # falling back to the configured default profile if needed.
            profile_name = base.get_program_name()
            if profile_name not in profiles:
                profile_name = self.config["default_profile"]
        profile = profiles[profile_name]

        # Compute the JVM arguments from explicit extension/overrides and from global map:
        jvm_args = list()
        if not self.flags.ignore_profile_jvm_args:
            jvm_args.extend(profile.get("jvm_args", tuple()))
        jvm_args.extend(arg_map[JVM_ARGS])

        # Recover program arguments from global map:
        program_args = arg_map[PROGRAM_ARGS]

        # Compute concrete classpath and set environment CLASSPATH accordingly:
        cp_entries = tuple(self.make_classpath_entries(profile))
        env = dict(os.environ)
        env["CLASSPATH"] = ":".join(cp_entries)

        # Handle --print-X launcher commands:
        should_exit = False  # becomes true if a special command is invoked (eg. --print-foo)
        if self.flags.print_classpath:
            print(":".join(cp_entries))
            should_exit = True
        if self.flags.print_config:
            print(base.json_encode(self.config))
            should_exit = True
        if should_exit:
            return os.EX_OK

        # Determine which Java class to invoke:
        class_name = profile["main_class"]
        if self.flags.class_name is not None:
            class_name = self.flags.class_name

        log.info("Using Java executable: {!r}", self.flags.java_path)
        log.info("Using JVM arguments: {!r}", jvm_args)
        log.info("Using Java main class: {!r}", class_name)
        log.info("Using classpath: {}", base.json_encode(cp_entries))
        log.info("Using Java program arguments: {!r}", program_args)
        log.debug("Using environment: {}", base.json_encode(env))

        args = list()
        args.append(self.flags.java_path)
        args.extend(jvm_args)
        args.append(class_name)
        args.extend(program_args)

        os.execve(self.flags.java_path, args, env)
예제 #18
0
파일: java_linker.py 프로젝트: davnoe/kiji
    def run(self, args):
        artifacts = list()
        if self.flags.artifacts is not None:
            artifacts.extend(self.flags.artifacts.split(","))
        if len(args) > 0:
            artifacts.extend(args)
            args = []
        artifacts = list(map(artifact.parse_artifact, artifacts))

        exclusions = tuple()
        if self.flags.exclusions is not None:
            exclusions = self.flags.exclusions.split(",")
            exclusions = filter(None, exclusions)
            exclusions = map(artifact.parse_artifact, exclusions)
            exclusions = frozenset(exclusions)

        assert (len(args) == 0), "Unexpected command-line arguments: {!r}".format(args)

        # --------------------

        local_repo = self.flags.local_repo
        if local_repo == ":wkspc:":
            wkspc = workspace.find_workspace_root(path=os.getcwd())
            if wkspc is None:
                local_repo = os.path.join(os.environ["HOME"], ".m2", "repository")
                log.info("No workspace found, using global repo {!r}", local_repo)
            else:
                local_repo = os.path.join(wkspc, "output", "maven_repository")
                log.info("Using workspace local repo {!r}", local_repo)
        assert os.path.exists(local_repo), \
            "Maven local repository not found: {!r}".format(local_repo)

        maven_remotes = self.flags.maven_remotes.split(",")
        repo = maven_repo.MavenRepository(local=local_repo, remotes=maven_remotes)

        # --------------------

        assert (self.flags.output is not None) and (len(self.flags.output) > 0), \
            "Must specify output path with --output=/path/to/java-binary"
        if self.flags.overwrite and os.path.exists(self.flags.output):
            os.remove(self.flags.output)

        # --------------------

        scanner = maven_loader.ArtifactScanner(repo=repo, fetch_content=True)
        deps = []
        for artf in artifacts:
            dep = maven_wrapper.Dependency(
                artifact=artf,
                scope=self.flags.scope,
                exclusions=exclusions,
            )
            deps.append(dep)
        scanner.scan(deps)
        assert (len(scanner.errors) == 0), \
            "{:d} errors while resolving Maven dependencies".format(len(scanner.errors))

        artifacts = list()
        for artf, dep_chains in scanner.versions.items():
            dep_chain = dep_chains[0]
            dep = dep_chain[0]
            artifacts.append(dep.artifact)

        # --------------------

        linker = java_linker.JavaLinker(
            output_path=self.flags.output,
            maven_repo=repo,
        )
        try:
            linker.link(
                artifacts=artifacts,
                main_class=self.flags.main_class,
            )
        finally:
            linker.close()

        return os.EX_OK