{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Make a new Gateways (`_pass2journal`)" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Translation-Gummy ver.3.4.4\n", "\u001b[32m[success]\u001b[0m local driver can be built.\n", "\u001b[31m[failure]\u001b[0m remote driver can't be built.\n", "DRIVER_TYPE: \u001b[32mlocal\u001b[0m\n" ] } ], "source": [ "from gummy.utils import get_driver\n", "from gummy import gateways\n", "from gummy.gateways import *" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "utokyo\n" ] } ], "source": [ "gateway = gateways.get(input())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Show Journals supported by Translation-Gummy" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['nature',\n", " 'sciencedirect',\n", " 'springer',\n", " 'wiley',\n", " 'ieee',\n", " 'oxfordacademic',\n", " 'rsc',\n", " 'nejm']" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "gateway.supported_journals" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Show Journals supported by Gateway Survice" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "# from bs4 import BeautifulSoup\n", "# soup = BeautifulSoup(driver.page_source)\n", "# for aTag in soup.find(name=\"ul\", class_=\"SS_DataBaseIndex\").find_all(name=\"a\"):\n", "# print(f\"- {aTag.get_text()}: {aTag.get('href')}\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Create `_pass2journal`" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "- ex) NEJM: https://www.nejm.org/" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "DRIVER_TYPE: \u001b[32mlocal\u001b[0m\n", "\u001b[32mSucceeded to \u001b[0mlocate element with \u001b[32mid\u001b[0m=\u001b[34musername\u001b[0m\n", "\u001b[32mSucceeded to \u001b[0mfill \u001b[34m\u001b[0m in element with \u001b[32mid\u001b[0m=\u001b[34musername\u001b[0m\n", "\u001b[32mSucceeded to \u001b[0mlocate element with \u001b[32mid\u001b[0m=\u001b[34mpassword\u001b[0m\n", "\u001b[32mSucceeded to \u001b[0mfill \u001b[34m\u001b[0m in element with \u001b[32mid\u001b[0m=\u001b[34mpassword\u001b[0m\n", "\u001b[32mSucceeded to \u001b[0mlocate element with \u001b[32mid\u001b[0m=\u001b[34mbtnSubmit_6\u001b[0m\n", "\u001b[32mSucceeded to \u001b[0mclick the element with \u001b[32mid\u001b[0m=\u001b[34mbtnSubmit_6\u001b[0m\n", "\u001b[32mSucceeded to \u001b[0mlocate element with \u001b[32mid\u001b[0m=\u001b[34mbtnContinue\u001b[0m\n", "\u001b[32mSucceeded to \u001b[0mclick the element with \u001b[32mid\u001b[0m=\u001b[34mbtnContinue\u001b[0m\n" ] } ], "source": [ "driver = get_driver()\n", "driver = gateway._passthrough_base(driver)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "* current_url: https://gateway.itc.u-tokyo.ac.jp/,DanaInfo=www.nejm.org,SSL+\n", "* url : https://gateway.itc.u-tokyo.ac.jp/\n", "* dana_info : DanaInfo=www.nejm.org\n", "\n" ] } ], "source": [ "driver.get(\"https://gateway.itc.u-tokyo.ac.jp/,DanaInfo=www.nejm.org,SSL\")\n", "current_url = driver.current_url\n", "url, dana_info, _ = current_url.split(\",\")\n", "print(f\"\"\"\n", "* current_url: {current_url}\n", "* url : {url}\n", "* dana_info : {dana_info}\n", "\"\"\")" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "def fmt_url_func(cano_url, *args, **kwargs):\n", " gateway_fmt_url = re.sub(\n", " pattern=r\"^https?:\\/\\/www\\.nejm\\.org\\/(doi\\/.+)\\/(.+)$\", \n", " repl=fr\"{url}\\1/,{dana_info},SSL+\\2\", \n", " string=cano_url\n", " )\n", " return gateway_fmt_url" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "cano_url = \"https://www.nejm.org/doi/full/10.1056/NEJMcpc1913472\"\n", "gateway_fmt_url = \"https://gateway.itc.u-tokyo.ac.jp/doi/full/10.1056/,DanaInfo=www.nejm.org,SSL+NEJMcpc1913472\"" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "assert gateway_fmt_url == fmt_url_func(cano_url=cano_url)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "hide_input": false, "kernelspec": { "display_name": "Python 3 (/usr/local/bin/)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.5" } }, "nbformat": 4, "nbformat_minor": 4 }