def main() -> int:
    formula_body = []

    with open(os.path.join("docs", "pages", "introduction", "summary.txt"),
              encoding="utf8") as f:
        formula_body.append('desc "{}"'.format(f.read().strip()))

    base_url = "https://github.com/thombashi/{pkg}/releases/download/v{version}".format(
        pkg=sqlitebiter.__name__, version=sqlitebiter.__version__)
    response = retryrequests.get("{base}/{pkg}_macos_sha256.txt".format(
        base=base_url, pkg=sqlitebiter.__name__))
    response.raise_for_status()

    formula_body.extend([
        'homepage "https://github.com/thombashi/{}"'.format(
            sqlitebiter.__name__),
        'url "{bin_url}"'.format(
            bin_url="{base}/{pkg}_macos_amd64.tar.gz".format(
                base=base_url, pkg=sqlitebiter.__name__)),
        'version "{}"'.format(sqlitebiter.__version__),
        'sha256 "{sha256}"'.format(sha256=response.text.split()[0]),
        "",
        "def install",
        '  bin.install "{}"'.format(sqlitebiter.__name__),
        "end",
    ])

    print("class Sqlitebiter < Formula")
    print(indent("\n".join(formula_body), "  "))
    print("end")

    return 0
Exemplo n.º 2
0
def load_ipynb_url(url, proxies):
    response = retryrequests.get(url, proxies=proxies)
    response.raise_for_status()

    try:
        return (nbformat.reads(response.text, as_version=4), len(response.content))
    except IOError as e:
        _schema_not_found_error_handler(e)
        raise
Exemplo n.º 3
0
    def fetch_event(self, id: int) -> Event:
        response = retryrequests.get(
            url=self.__make_url(endpoint="schedule/events", id=id),
            headers=self.__make_headers(),
            params=self.__make_params(),
        )
        response.raise_for_status()

        return Event(**response.json())
Exemplo n.º 4
0
    def fetch_users(
        self,
        offset: int,
    ) -> Tuple[List[User], bool]:
        response = retryrequests.get(
            url=self.__make_url(endpoint="base/users"),
            headers=self.__make_headers(),
            params={
                "limit": LIMIT,
                "offset": offset
            },
        )
        response.raise_for_status()
        data = response.json()

        return ([User(**user) for user in data["users"]], data["hasNext"])
Exemplo n.º 5
0
    def _fetch_source(self, loader_class):
        import requests
        import retryrequests

        dummy_loader = loader_class("")
        loader_source_type = dummy_loader.source_type

        if loader_source_type not in [SourceType.TEXT, SourceType.FILE]:
            raise ValueError(
                "unknown loader source: type={}".format(loader_source_type))

        r = retryrequests.get(self.__url, proxies=self.__proxies)

        try:
            r.raise_for_status()
        except requests.HTTPError as e:
            raise HTTPError(e)

        if typepy.is_null_string(self._encoding):
            self._encoding = r.encoding

        logger.debug("\n".join([
            "_fetch_source: ",
            "  source-type={}".format(loader_source_type),
            "  content-type={}".format(r.headers["Content-Type"]),
            "  encoding={}".format(self._encoding),
            "  status-code={}".format(r.status_code),
        ]))

        if loader_source_type == SourceType.TEXT:
            self._source = r.text
        elif loader_source_type == SourceType.FILE:
            self.__temp_dir_path = tempfile.mkdtemp()
            if dummy_loader.format_name == "excel":
                ext = "xlsx"
            elif dummy_loader.format_name == "sqlite":
                ext = "sqlite"

            self._source = "{:s}.{}".format(
                make_temp_file_path_from_url(self.__temp_dir_path, self.__url),
                ext)
            with open(self._source, "wb") as f:
                f.write(r.content)
Exemplo n.º 6
0
    def fetch_events(
        self,
        start: Optional[datetime],
        target: Optional[str] = None,
        target_type: Optional[str] = None,
    ) -> Tuple[List[Event], bool]:
        params = self.__make_params(start=start)
        if target:
            params["target"] = target
        if target_type:
            params["targetType"] = target_type

        response = retryrequests.get(
            url=self.__make_url(endpoint="schedule/events"),
            headers=self.__make_headers(),
            params=params,
        )
        response.raise_for_status()
        data = response.json()

        return ([Event(**event) for event in data["events"]], data["hasNext"])
Exemplo n.º 7
0
    def __fetch_pypi_info(self, pypi_pkg_name):
        cache_filepath = self.__pypi_cache_mgr.get_pkg_cache_filepath(
            pypi_pkg_name, "pypi_desc")

        if self.__pypi_cache_mgr.is_cache_available(cache_filepath):
            logger.debug("load PyPI info cache: {}".format(cache_filepath))

            cache_data = self.__pypi_cache_mgr.load_json(cache_filepath)
            if cache_data:
                return cache_data

        r = retryrequests.get(
            "https://pypi.org/pypi/{}/json".format(pypi_pkg_name))
        if r.status_code != 200:
            return None

        pypi_info = r.json().get("info")

        with cache_filepath.open(mode="w") as f:
            logger.debug("write PyPI info cache: {}".format(cache_filepath))
            f.write(json.dumps(pypi_info))

        return pypi_info