work on initial tag load
This commit is contained in:
@@ -144,3 +144,5 @@ USE_TZ = True
|
||||
# https://docs.djangoproject.com/en/2.2/howto/static-files/
|
||||
|
||||
STATIC_URL = '/static/'
|
||||
|
||||
TAXONOMY_FILE = 'shop-taxonomy.es-ES.txt'
|
||||
|
||||
@@ -15,6 +15,8 @@ logging.basicConfig(
|
||||
|
||||
class Command(BaseCommand):
|
||||
|
||||
'help' = 'Load geographic dataset'
|
||||
|
||||
def handle(self, *args, **kwargs):
|
||||
print('Deleting all instances of Country, Region, Province, City')
|
||||
logging.info('Deleting all instances of Country, Region, Province, City')
|
||||
|
||||
26
core/management/commands/addtaxonomy.py
Normal file
26
core/management/commands/addtaxonomy.py
Normal file
@@ -0,0 +1,26 @@
|
||||
import logging
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
|
||||
help = 'Load taxonomy terms into Tags'
|
||||
|
||||
def handle(self, *args, **kwargs):
|
||||
|
||||
print(self.help)
|
||||
file_path = settings.BASE_DIR + '/../datasets/' + settings.TAXONOMY_FILE
|
||||
counter = 0
|
||||
with open(file_path, 'rt') as data_file:
|
||||
print(f"Reading from {settings.TAXONOMY_FILE}")
|
||||
for line in data_file.readlines():
|
||||
try:
|
||||
tag = TagModel.objects.create(name=line)
|
||||
counter += 1
|
||||
logging.debug(f"{tag} created from {line}")
|
||||
except Exception as e:
|
||||
logging.error(f"{type(e)} while creating tags from {settings.TAXONOMY_FILE}")
|
||||
print(f"{counter} new TagModel instances created")
|
||||
print('Shutting down\n')
|
||||
@@ -22,6 +22,7 @@ logging.basicConfig(
|
||||
class Command(BaseCommand):
|
||||
|
||||
logo_url = "https://picsum.photos/200/300"
|
||||
help = 'Creates fake companies and related products in database'
|
||||
|
||||
def handle(self, *args, **kwargs):
|
||||
print("Creating fake data to populate database")
|
||||
|
||||
@@ -7,9 +7,12 @@ from django.utils.http import urlsafe_base64_encode
|
||||
from django.template.loader import render_to_string
|
||||
from django.core.mail import EmailMessage
|
||||
from django.contrib.auth.tokens import PasswordResetTokenGenerator
|
||||
from django.conf import settings
|
||||
|
||||
from rest_framework_simplejwt.tokens import RefreshToken
|
||||
|
||||
from tagulous.models import TagModel
|
||||
|
||||
User = get_user_model()
|
||||
|
||||
|
||||
@@ -74,3 +77,23 @@ def send_verification_email(request, user):
|
||||
logging.info(f"Verification email sent to {user.email}")
|
||||
except Exception as e:
|
||||
logging.error(f"Could not sent verification email to: {user.email}")
|
||||
|
||||
|
||||
def reformat_google_taxonomy(file_name):
|
||||
"""
|
||||
Read from flat text file
|
||||
Create Herarchical Tag for each line
|
||||
"""
|
||||
|
||||
base = settings.BASE_DIR + '/../datasets/'
|
||||
counter = 0
|
||||
source_file_path = base + file_name
|
||||
destination_file_path = base + 'ALT' + file_name
|
||||
|
||||
source_file = open(source_file_path, 'rt')
|
||||
destination_file = open(destination_file_path, 'wt')
|
||||
|
||||
for line in source_file.readlines():
|
||||
line = line.replace(' > ', '/')
|
||||
destination_file.write(line)
|
||||
|
||||
|
||||
5428
datasets/google-shopping-taxonomy.es-ES.txt
Executable file
5428
datasets/google-shopping-taxonomy.es-ES.txt
Executable file
File diff suppressed because it is too large
Load Diff
5428
datasets/shop-taxonomy.es-ES.txt
Normal file
5428
datasets/shop-taxonomy.es-ES.txt
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user