Skip to content

Commit

Permalink
refactor: 💡 rename package import
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhaoQi99 committed Aug 14, 2024
1 parent fadaca8 commit b6d81c4
Show file tree
Hide file tree
Showing 23 changed files with 87 additions and 86 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ ADD . .
RUN pip install .

EXPOSE 8001
CMD ["/bin/bash", "-c", "pagehub init;pagehub server"]
CMD ["/bin/bash", "-c", "pagesaver init;pagesaver server"]
42 changes: 21 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Pagehub
[![Python version](https://img.shields.io/pypi/pyversions/pagehub.svg?logo=python)](https://pypi.python.org/pypi/pagehub)
[![PyPI package](https://img.shields.io/pypi/v/pagehub.svg)](https://pypi.python.org/pypi/pagehub)
[![PyPI download](https://img.shields.io/pypi/dm/pagehub.svg)](https://pypi.python.org/pypi/pagehub)
[![GitHub](https://img.shields.io/github/license/ZhaoQi99/pagehub)](https://github.com/ZhaoQi99/pagehub/blob/main/LICENSE)
![GitHub last commit (by committer)](https://img.shields.io/github/last-commit/ZhaoQi99/pagehub)
# PageSaver
[![Python version](https://img.shields.io/pypi/pyversions/pagesaver.svg?logo=python)](https://pypi.python.org/pypi/pagesaver)
[![PyPI package](https://img.shields.io/pypi/v/pagesaver.svg)](https://pypi.python.org/pypi/pagesaver)
[![PyPI download](https://img.shields.io/pypi/dm/pagesaver.svg)](https://pypi.python.org/pypi/pagesaver)
[![GitHub](https://img.shields.io/github/license/ZhaoQi99/pagesaver)](https://github.com/ZhaoQi99/pagesaver/blob/main/LICENSE)
![GitHub last commit (by committer)](https://img.shields.io/github/last-commit/ZhaoQi99/pagesaver)

Archive your web page.

Expand All @@ -15,27 +15,27 @@ Archive your web page.
<summary><img height="15" src="https://www.python.org/favicon.ico"></img> pip</summary>

```shell
pip install pagehub
pip install pagesaver
✨🍰✨
```
Or you can use `pip install git+https://github.com/ZhaoQi99/PageHub.git
Or you can use `pip install git+https://github.com/ZhaoQi99/PageSaver.git
` install latest version.
</details>

<details>
<summary><img height="15" src="https://cdn.simpleicons.org/docker/338FED?viewbox=auto" /> docker</summary>

```shell
docker run -d --name pagehub -p 8001:8001 zhaoqi99/pagehub
docker run -d --name pagesaver -p 8001:8001 zhaoqi99/pagesaver
```

</details>

## Quick Start
### HTTP API
1. Init PageHub: `pagehub init`
2. Start HTTP Server: `pagehub server`
> `nohup pagehub server >> server.log 2>&1 &`
1. Init PageSaver: `pagesaver init`
2. Start HTTP Server: `pagesaver server`
> `nohup pagesaver server >> server.log 2>&1 &`
3. Examples:
```shell
~$ curl http://127.0.0.1:8001/api/record/https://www.baidu.com/?format=MHTML&format=PDF -H 'Authorization: <API_TOKEN>'
Expand All @@ -44,7 +44,7 @@ docker run -d --name pagehub -p 8001:8001 zhaoqi99/pagehub

### CLI
```shell
pagehub export https://www.baidu.com -o . -f MHTML,PDF
pagesaver export https://www.baidu.com -o . -f MHTML,PDF
```

## HTTP Usage
Expand Down Expand Up @@ -85,8 +85,8 @@ Using the Authorization header, format is: `Authorization: <API_TOKEN>`
## CLI Usage
### Export
```shell
~$ pagehub export -h
Usage: pagehub export [OPTIONS] URL
~$ pagesaver export -h
Usage: pagesaver export [OPTIONS] URL

Export page to the output file

Expand All @@ -98,19 +98,19 @@ Options:
```
### Server
```shell
~$ pagehub init
~$ pagehub server -h
Usage: pagehub server [OPTIONS]
~$ pagesaver init
~$ pagesaver server -h
Usage: pagesaver server [OPTIONS]

Run PageHub HTTP server
Run PageSaver HTTP server

Options:
-h, --help Show this message and exit.
-b, --bind TEXT The TCP host/address to bind to. [default: 0.0.0.0:8001]
```

## Configuration
Pagehub will read the configuration from `config.py` automatically.
PageSaver will read the configuration from `config.py` automatically.

### STORAGE
* type: storage type. Currently supported values are "local".
Expand All @@ -137,7 +137,7 @@ The property name in Notion to use for the MHTML file of a page.
Default: `mhtml`

## License
[GNU General Public License v3.0](https://github.com/ZhaoQi99/PageHub/blob/main/LICENSE)
[GNU General Public License v3.0](https://github.com/ZhaoQi99/PageSaver/blob/main/LICENSE)

## Author
* Qi Zhao([[email protected]](mailto:[email protected]))
2 changes: 1 addition & 1 deletion pagesaver/authorization/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

class AuthorizationConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'pagehub.authorization'
name = 'pagesaver.authorization'
5 changes: 3 additions & 2 deletions pagesaver/authorization/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Generated by Django 5.0.7 on 2024-08-12 05:28

import pagehub.authorization.models
from django.db import migrations, models

import pagesaver.authorization.models


class Migration(migrations.Migration):

Expand All @@ -18,7 +19,7 @@ class Migration(migrations.Migration):
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created', models.DateTimeField(auto_now_add=True, db_index=True)),
('updated', models.DateTimeField(auto_now=True, db_index=True)),
('expired', models.DateTimeField(default=pagehub.authorization.models._default_expire_time, verbose_name='token expire time')),
('expired', models.DateTimeField(default=pagesaver.authorization.models._default_expire_time, verbose_name='token expire time')),
('token', models.TextField(blank=True, verbose_name='token')),
],
options={
Expand Down
2 changes: 1 addition & 1 deletion pagesaver/authorization/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django.utils import timezone
from django.utils.translation import gettext_lazy as _

from pagehub.lib.base.models import BaseModel
from pagesaver.lib.base.models import BaseModel


def _default_expire_time():
Expand Down
2 changes: 1 addition & 1 deletion pagesaver/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import click

from pagehub import __version__
from pagesaver import __version__

VERSION = rf"""
____ _ _ _ _
Expand Down
8 changes: 4 additions & 4 deletions pagesaver/cli/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import click

from pagehub.cli.types import MultipleChoice
from pagehub.constants import SUPPORT_FORMATS
from pagehub.enums import ExportFormat
from pagehub.utils import export_utils
from pagesaver.cli.types import MultipleChoice
from pagesaver.constants import SUPPORT_FORMATS
from pagesaver.enums import ExportFormat
from pagesaver.utils import export_utils

SUCCESS_ANSI = click.style("successfully", fg="green")

Expand Down
14 changes: 7 additions & 7 deletions pagesaver/cli/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
from django.core.management import call_command
from django.utils import timezone

from pagehub import __version__
from pagesaver import __version__


@click.command("init")
@click.help_option("-h", "--help")
def init_command(*args, **kwargs):
"""Initialize PageHub"""
click.secho(f"[+] Initializing PageHub v{__version__}...", fg="green")
"""Initialize PageSaver"""
click.secho(f"[+] Initializing PageSaver v{__version__}...", fg="green")
click.secho("{}\n".format("-" * 30), fg="green")

click.secho("[+] Creating database and running initial migrations...", fg="green")
Expand All @@ -20,7 +20,7 @@ def init_command(*args, **kwargs):
click.secho("\n{}".format("-" * 30), fg="green")
click.secho("[√] Init successfully.", fg="green")

from pagehub.authorization.models import APIToken
from pagesaver.authorization.models import APIToken

expired = timezone.now().astimezone() + timedelta(days=365 * 100)
token = APIToken.objects.create(expired=expired)
Expand All @@ -33,7 +33,7 @@ def init_command(*args, **kwargs):

click.echo(
"""
{hint} To using PageHub, Please install dependencies with the following command:
{hint} To using PageSaver, Please install dependencies with the following command:
playwright install # browsers
playwright install-deps # dependencies to run browsers""".format(
hint=click.style("Hint:", fg="magenta")
Expand All @@ -42,8 +42,8 @@ def init_command(*args, **kwargs):

click.echo(
"""
{hint} To start PageHub, run:
pagehub server # then visit http://127.0.0.1:8000
{hint} To start PageSaver, run:
pagesaver server # then visit http://127.0.0.1:8000
""".format(
hint=click.style("Hint:", fg="magenta")
)
Expand Down
10 changes: 5 additions & 5 deletions pagesaver/cli/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from hypercorn.asyncio import serve
from hypercorn.config import Config

from pagehub.core.asgi import application
from pagehub.settings import pagehub_settings
from pagesaver.core.asgi import application
from pagesaver.settings import pagesaver_settings


@click.command("server")
Expand All @@ -15,10 +15,10 @@
"--bind",
"bind",
show_default=True,
default=pagehub_settings.SERVER_BIND,
default=pagesaver_settings.SERVER_BIND,
help="The TCP host/address to bind to.",
)
def server_command(*args, **kwargs):
"""Run PageHub HTTP server"""
config = Config.from_mapping({"bind": pagehub_settings.SERVER_BIND}, **kwargs)
"""Run PageSaver HTTP server"""
config = Config.from_mapping({"bind": pagesaver_settings.SERVER_BIND}, **kwargs)
asyncio.run(serve(application, config))
2 changes: 1 addition & 1 deletion pagesaver/constants.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from pagehub.enums import ExportFormat
from pagesaver.enums import ExportFormat

SUPPORT_FORMATS = list(ExportFormat.__members__)
4 changes: 2 additions & 2 deletions pagesaver/core/api.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from ninja import NinjaAPI, errors
from ninja.security import APIKeyHeader

from pagehub.authorization.models import APIToken
from pagehub.record.api import router as record_router
from pagesaver.authorization.models import APIToken
from pagesaver.record.api import router as record_router


class APIKey(APIKeyHeader):
Expand Down
2 changes: 1 addition & 1 deletion pagesaver/core/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'pagehub.core.settings')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'pagesaver.core.settings')

application = get_asgi_application()
8 changes: 4 additions & 4 deletions pagesaver/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
"pagehub.record",
"pagehub.authorization",
"pagesaver.record",
"pagesaver.authorization",
]

MIDDLEWARE = [
Expand All @@ -51,7 +51,7 @@
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'pagehub.core.urls'
ROOT_URLCONF = 'pagesaver.core.urls'

TEMPLATES = [
{
Expand All @@ -69,7 +69,7 @@
},
]

WSGI_APPLICATION = 'pagehub.core.wsgi.application'
WSGI_APPLICATION = 'pagesaver.core.wsgi.application'


# Database
Expand Down
2 changes: 1 addition & 1 deletion pagesaver/core/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'pagehub.core.settings')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'pagesaver.core.settings')

application = get_wsgi_application()
2 changes: 1 addition & 1 deletion pagesaver/lib/notion/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
from pathlib import Path

from pagehub.lib.base.client import RequestsBaseClient
from pagesaver.lib.base.client import RequestsBaseClient

API_BASE_URL = "https://api.notion.com/v1/"
UNOFFICIAL_BASE_URL = "https://www.notion.so/api/v3/"
Expand Down
8 changes: 4 additions & 4 deletions pagesaver/record/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

from ninja import Field, Query, Router, Schema

from pagehub.enums import ExportFormat
from pagehub.record.models import Snapshot
from pagehub.record.runner import BackgroundThreadRunner
from pagehub.record.tasks import export_task, notion_push_task
from pagesaver.enums import ExportFormat
from pagesaver.record.models import Snapshot
from pagesaver.record.runner import BackgroundThreadRunner
from pagesaver.record.tasks import export_task, notion_push_task

router = Router()

Expand Down
4 changes: 2 additions & 2 deletions pagesaver/record/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

from django.db import models

from pagehub.enums import ExportFormat
from pagehub.lib.base.models import BaseModelWithUUID
from pagesaver.enums import ExportFormat
from pagesaver.lib.base.models import BaseModelWithUUID


class Snapshot(BaseModelWithUUID):
Expand Down
2 changes: 1 addition & 1 deletion pagesaver/record/runner/thread.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import threading

from pagehub.record.runner.base import BaseRunner
from pagesaver.record.runner.base import BaseRunner


class BackgroundThreadRunner(BaseRunner):
Expand Down
16 changes: 8 additions & 8 deletions pagesaver/record/tasks.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from pathlib import Path
from typing import Optional

from pagehub.constants import SUPPORT_FORMATS
from pagehub.enums import ExportFormat
from pagehub.record.models import Snapshot, SnapshotResult
from pagehub.settings import pagehub_settings
from pagehub.utils import export_utils, notion_utils
from pagehub.utils.datetime_utils import get_now_str
from pagesaver.constants import SUPPORT_FORMATS
from pagesaver.enums import ExportFormat
from pagesaver.record.models import Snapshot, SnapshotResult
from pagesaver.settings import pagesaver_settings
from pagesaver.utils import export_utils, notion_utils
from pagesaver.utils.datetime_utils import get_now_str

STORAGE = pagehub_settings.STORAGE
STORAGE = pagesaver_settings.STORAGE


def export_task(snapshot_id: int, url: str, format: list[str]):
Expand Down Expand Up @@ -64,7 +64,7 @@ def notion_push_task(
if __name__ == "__main__":
import os

from pagehub.record.models import Snapshot
from pagesaver.record.models import Snapshot

url = "https://www.baidu.com"
snapshot = Snapshot.objects.create(url=url)
Expand Down
4 changes: 2 additions & 2 deletions pagesaver/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(self, user_settings=None, defaults=None) -> None:

def __getattr__(self, attr):
if attr not in self.defaults:
raise AttributeError("Invalid pagehub setting: '%s'" % attr)
raise AttributeError("Invalid pagesaver setting: '%s'" % attr)
try:
val = self.user_settings[attr]
except KeyError:
Expand Down Expand Up @@ -63,4 +63,4 @@ def __getattr__(self, attr):
return getattr(self._wrapped, attr)


pagehub_settings = LazySetting()
pagesaver_settings = LazySetting()
Loading

0 comments on commit b6d81c4

Please sign in to comment.