linkding/bookmarks/management/commands/import_netscape.py

24 lines
733 B
Python
Raw Normal View History

2019-06-29 06:42:54 +00:00
from django.contrib.auth.models import User
from django.core.management.base import BaseCommand
from bookmarks.services.importer import import_netscape_html
class Command(BaseCommand):
2024-01-27 10:29:16 +00:00
help = "Import Netscape HTML bookmark file"
2019-06-29 06:42:54 +00:00
def add_arguments(self, parser):
2024-01-27 10:29:16 +00:00
parser.add_argument("file", type=str, help="Path to file")
parser.add_argument(
"user", type=str, help="Name of the user for which to import"
)
2019-06-29 06:42:54 +00:00
def handle(self, *args, **kwargs):
2024-01-27 10:29:16 +00:00
filepath = kwargs["file"]
username = kwargs["user"]
2019-06-29 06:42:54 +00:00
with open(filepath) as html_file:
html = html_file.read()
user = User.objects.get(username=username)
import_netscape_html(html, user)