commit
9b12c1da7b
@ -0,0 +1,2 @@ |
||||
/venv/ |
||||
/db.sqlite3 |
||||
@ -0,0 +1,8 @@ |
||||
# Default ignored files |
||||
/shelf/ |
||||
/workspace.xml |
||||
# Editor-based HTTP Client requests |
||||
/httpRequests/ |
||||
# Datasource local storage ignored files |
||||
/dataSources/ |
||||
/dataSources.local.xml |
||||
@ -0,0 +1,22 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<project version="4"> |
||||
<component name="PublishConfigData" remoteFilesAllowedToDisappearOnAutoupload="false"> |
||||
<serverData> |
||||
<paths name="paov@10.15.0.1:22:22 password"> |
||||
<serverdata> |
||||
<mappings> |
||||
<mapping deploy="/" local="$PROJECT_DIR$" web="/" /> |
||||
</mappings> |
||||
<excludedPaths> |
||||
<excludedPath path="/venv/include" /> |
||||
<excludedPath path="/venv/lib" /> |
||||
<excludedPath path="/venv/lib64" /> |
||||
<excludedPath path="/venv/share" /> |
||||
<excludedPath path="/venv/pyvenv.cfg" /> |
||||
<excludedPath path="/db.sqlite3" /> |
||||
</excludedPaths> |
||||
</serverdata> |
||||
</paths> |
||||
</serverData> |
||||
</component> |
||||
</project> |
||||
@ -0,0 +1,6 @@ |
||||
<component name="InspectionProjectProfileManager"> |
||||
<settings> |
||||
<option name="USE_PROJECT_PROFILE" value="false" /> |
||||
<version value="1.0" /> |
||||
</settings> |
||||
</component> |
||||
@ -0,0 +1,4 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<project version="4"> |
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Remote Python 3.8.10 (sftp://paov@10.15.0.1:22/home/paov/tea/venv/bin/python)" project-jdk-type="Python SDK" /> |
||||
</project> |
||||
@ -0,0 +1,8 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<project version="4"> |
||||
<component name="ProjectModuleManager"> |
||||
<modules> |
||||
<module fileurl="file://$PROJECT_DIR$/.idea/tea.iml" filepath="$PROJECT_DIR$/.idea/tea.iml" /> |
||||
</modules> |
||||
</component> |
||||
</project> |
||||
@ -0,0 +1,25 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<module type="PYTHON_MODULE" version="4"> |
||||
<component name="FacetManager"> |
||||
<facet type="django" name="Django"> |
||||
<configuration> |
||||
<option name="rootFolder" value="$MODULE_DIR$" /> |
||||
<option name="settingsModule" value="tea/settings.py" /> |
||||
<option name="manageScript" value="manage.py" /> |
||||
<option name="environment" value="<map/>" /> |
||||
<option name="doNotUseTestRunner" value="false" /> |
||||
<option name="trackFilePattern" value="" /> |
||||
</configuration> |
||||
</facet> |
||||
</component> |
||||
<component name="NewModuleRootManager"> |
||||
<content url="file://$MODULE_DIR$"> |
||||
<excludeFolder url="file://$MODULE_DIR$/venv" /> |
||||
</content> |
||||
<orderEntry type="jdk" jdkName="Remote Python 3.8.10 (sftp://paov@10.15.0.1:22/home/paov/tea/venv/bin/python)" jdkType="Python SDK" /> |
||||
<orderEntry type="sourceFolder" forTests="false" /> |
||||
</component> |
||||
<component name="TemplatesService"> |
||||
<option name="TEMPLATE_CONFIGURATION" value="Django" /> |
||||
</component> |
||||
</module> |
||||
@ -0,0 +1,21 @@ |
||||
from django.contrib import admin |
||||
|
||||
# Register your models here. |
||||
from choose.models import Tea, TeaType, TeaCategory |
||||
|
||||
|
||||
class TeaCategoryAdmin(admin.ModelAdmin): |
||||
list_display = ('name', 'shop_name') |
||||
|
||||
|
||||
class TeaTypeAdmin(admin.ModelAdmin): |
||||
list_display = ('name', 'shop_name', 'category') |
||||
|
||||
|
||||
class TeaAdmin(admin.ModelAdmin): |
||||
list_display = ('name', 'price', 'pic', 'type') |
||||
|
||||
|
||||
admin.site.register(Tea, TeaAdmin) |
||||
admin.site.register(TeaType, TeaTypeAdmin) |
||||
admin.site.register(TeaCategory, TeaCategoryAdmin) |
||||
@ -0,0 +1,6 @@ |
||||
from django.apps import AppConfig |
||||
|
||||
|
||||
class ChooseConfig(AppConfig): |
||||
default_auto_field = 'django.db.models.BigAutoField' |
||||
name = 'choose' |
||||
@ -0,0 +1,32 @@ |
||||
# Generated by Django 4.0.8 on 2022-10-10 12:03 |
||||
|
||||
from django.db import migrations, models |
||||
import django.db.models.deletion |
||||
|
||||
|
||||
class Migration(migrations.Migration): |
||||
|
||||
initial = True |
||||
|
||||
dependencies = [ |
||||
] |
||||
|
||||
operations = [ |
||||
migrations.CreateModel( |
||||
name='TeaType', |
||||
fields=[ |
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), |
||||
('name', models.CharField(max_length=255)), |
||||
], |
||||
), |
||||
migrations.CreateModel( |
||||
name='Tea', |
||||
fields=[ |
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), |
||||
('name', models.CharField(max_length=255)), |
||||
('price', models.IntegerField()), |
||||
('pic', models.CharField(max_length=255)), |
||||
('type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='teas', to='choose.teatype')), |
||||
], |
||||
), |
||||
] |
||||
@ -0,0 +1,19 @@ |
||||
# Generated by Django 4.0.8 on 2022-10-10 12:14 |
||||
|
||||
from django.db import migrations, models |
||||
|
||||
|
||||
class Migration(migrations.Migration): |
||||
|
||||
dependencies = [ |
||||
('choose', '0001_initial'), |
||||
] |
||||
|
||||
operations = [ |
||||
migrations.AddField( |
||||
model_name='teatype', |
||||
name='shop_name', |
||||
field=models.CharField(default='', max_length=255), |
||||
preserve_default=False, |
||||
), |
||||
] |
||||
@ -0,0 +1,27 @@ |
||||
# Generated by Django 4.0.8 on 2022-10-10 12:24 |
||||
|
||||
from django.db import migrations, models |
||||
import django.db.models.deletion |
||||
|
||||
|
||||
class Migration(migrations.Migration): |
||||
|
||||
dependencies = [ |
||||
('choose', '0002_teatype_shop_name'), |
||||
] |
||||
|
||||
operations = [ |
||||
migrations.CreateModel( |
||||
name='TeaCategory', |
||||
fields=[ |
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), |
||||
('name', models.CharField(max_length=255)), |
||||
('shop_name', models.CharField(max_length=255)), |
||||
], |
||||
), |
||||
migrations.AddField( |
||||
model_name='teatype', |
||||
name='category', |
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='tea_types', to='choose.teacategory'), |
||||
), |
||||
] |
||||
@ -0,0 +1,36 @@ |
||||
from django.db import models |
||||
|
||||
|
||||
# Create your models here. |
||||
|
||||
class TeaCategory(models.Model): |
||||
name = models.CharField(max_length=255) |
||||
shop_name = models.CharField(max_length=255) |
||||
|
||||
def __str__(self): |
||||
return self.name |
||||
|
||||
|
||||
class TeaType(models.Model): |
||||
name = models.CharField(max_length=255) |
||||
shop_name = models.CharField(max_length=255) |
||||
category = models.ForeignKey(TeaCategory, |
||||
related_name='tea_types', |
||||
on_delete=models.CASCADE, |
||||
blank=True, null=True |
||||
) |
||||
|
||||
def __str__(self): |
||||
return self.name |
||||
|
||||
|
||||
class Tea(models.Model): |
||||
name = models.CharField(max_length=255) |
||||
price = models.IntegerField() |
||||
pic = models.CharField(max_length=255) |
||||
type = models.ForeignKey(TeaType, |
||||
related_name='teas', |
||||
on_delete=models.CASCADE) |
||||
|
||||
def __str__(self): |
||||
return self.name |
||||
@ -0,0 +1,3 @@ |
||||
from django.test import TestCase |
||||
|
||||
# Create your tests here. |
||||
@ -0,0 +1,3 @@ |
||||
from django.shortcuts import render |
||||
|
||||
# Create your views here. |
||||
@ -0,0 +1,22 @@ |
||||
#!/usr/bin/env python |
||||
"""Django's command-line utility for administrative tasks.""" |
||||
import os |
||||
import sys |
||||
|
||||
|
||||
def main(): |
||||
"""Run administrative tasks.""" |
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tea.settings') |
||||
try: |
||||
from django.core.management import execute_from_command_line |
||||
except ImportError as exc: |
||||
raise ImportError( |
||||
"Couldn't import Django. Are you sure it's installed and " |
||||
"available on your PYTHONPATH environment variable? Did you " |
||||
"forget to activate a virtual environment?" |
||||
) from exc |
||||
execute_from_command_line(sys.argv) |
||||
|
||||
|
||||
if __name__ == '__main__': |
||||
main() |
||||
@ -0,0 +1,50 @@ |
||||
import django |
||||
from django.conf import settings |
||||
import requests |
||||
from bs4 import BeautifulSoup |
||||
|
||||
from pathlib import Path |
||||
|
||||
BASE_DIR = Path(__file__).resolve().parent |
||||
settings.configure( |
||||
DATABASES={ |
||||
'default': { |
||||
'ENGINE': 'django.db.backends.sqlite3', |
||||
'NAME': BASE_DIR / 'db.sqlite3', |
||||
} |
||||
}, |
||||
INSTALLED_APPS=[ |
||||
'django.contrib.admin', |
||||
'django.contrib.auth', |
||||
'django.contrib.contenttypes', |
||||
'django.contrib.sessions', |
||||
'django.contrib.messages', |
||||
'django.contrib.staticfiles', |
||||
'choose' |
||||
] |
||||
) |
||||
django.setup() |
||||
|
||||
from choose.models import TeaType, Tea, TeaCategory |
||||
|
||||
db_cats = list(TeaCategory.objects.all()) |
||||
categories = ['https://chainiisvet.ru/product-category/' + x.shop_name + '/' for x in db_cats] |
||||
r = requests.get("https://chainiisvet.ru/") |
||||
soup = BeautifulSoup(r.content) |
||||
ul = soup.find("ul", {"id": "menu-katalog"}) |
||||
for item in ul.contents: |
||||
if item.__class__.__name__ == 'Tag': |
||||
if item.contents[0].attrs['href'] in categories: |
||||
category = TeaCategory.objects.get(name=item.contents[0].contents[0]) |
||||
for i in item.contents[2]: |
||||
if i.__class__.__name__ == 'Tag': |
||||
type = i.contents[0].contents[0] |
||||
href = i.contents[0].attrs['href'] if i.contents[0].attrs['href'].startswith( |
||||
'https') else 'https://chainiisvet.ru' + i.contents[0].attrs['href'] |
||||
TeaType.objects.get_or_create(shop_name=href[href.rfind('/', 0, len(href)-1)+1:-1], |
||||
name=type, |
||||
category=category) |
||||
print(category, end=':') |
||||
print(type, end=':') |
||||
print(href) |
||||
pass |
||||
@ -0,0 +1,16 @@ |
||||
""" |
||||
ASGI config for tea project. |
||||
|
||||
It exposes the ASGI callable as a module-level variable named ``application``. |
||||
|
||||
For more information on this file, see |
||||
https://docs.djangoproject.com/en/4.1/howto/deployment/asgi/ |
||||
""" |
||||
|
||||
import os |
||||
|
||||
from django.core.asgi import get_asgi_application |
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tea.settings') |
||||
|
||||
application = get_asgi_application() |
||||
@ -0,0 +1,126 @@ |
||||
""" |
||||
Django settings for tea project. |
||||
|
||||
Generated by 'django-admin startproject' using Django 4.1.2. |
||||
|
||||
For more information on this file, see |
||||
https://docs.djangoproject.com/en/4.1/topics/settings/ |
||||
|
||||
For the full list of settings and their values, see |
||||
https://docs.djangoproject.com/en/4.1/ref/settings/ |
||||
""" |
||||
|
||||
from pathlib import Path |
||||
|
||||
# Build paths inside the project like this: BASE_DIR / 'subdir'. |
||||
BASE_DIR = Path(__file__).resolve().parent.parent |
||||
|
||||
|
||||
# Quick-start development settings - unsuitable for production |
||||
# See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/ |
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret! |
||||
SECRET_KEY = 'django-insecure-u=yu7(3@719dv(dtgy3wz_%yaw((r9-sh4exp(qf@to8o-e=e@' |
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production! |
||||
DEBUG = True |
||||
|
||||
ALLOWED_HOSTS = [ |
||||
'10.15.0.1' |
||||
] |
||||
|
||||
|
||||
# Application definition |
||||
|
||||
INSTALLED_APPS = [ |
||||
'django.contrib.admin', |
||||
'django.contrib.auth', |
||||
'django.contrib.contenttypes', |
||||
'django.contrib.sessions', |
||||
'django.contrib.messages', |
||||
'django.contrib.staticfiles', |
||||
'choose' |
||||
] |
||||
|
||||
MIDDLEWARE = [ |
||||
'django.middleware.security.SecurityMiddleware', |
||||
'django.contrib.sessions.middleware.SessionMiddleware', |
||||
'django.middleware.common.CommonMiddleware', |
||||
'django.middleware.csrf.CsrfViewMiddleware', |
||||
'django.contrib.auth.middleware.AuthenticationMiddleware', |
||||
'django.contrib.messages.middleware.MessageMiddleware', |
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware', |
||||
] |
||||
|
||||
ROOT_URLCONF = 'tea.urls' |
||||
|
||||
TEMPLATES = [ |
||||
{ |
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates', |
||||
'DIRS': [], |
||||
'APP_DIRS': True, |
||||
'OPTIONS': { |
||||
'context_processors': [ |
||||
'django.template.context_processors.debug', |
||||
'django.template.context_processors.request', |
||||
'django.contrib.auth.context_processors.auth', |
||||
'django.contrib.messages.context_processors.messages', |
||||
], |
||||
}, |
||||
}, |
||||
] |
||||
|
||||
WSGI_APPLICATION = 'tea.wsgi.application' |
||||
|
||||
|
||||
# Database |
||||
# https://docs.djangoproject.com/en/4.1/ref/settings/#databases |
||||
|
||||
DATABASES = { |
||||
'default': { |
||||
'ENGINE': 'django.db.backends.sqlite3', |
||||
'NAME': BASE_DIR / 'db.sqlite3', |
||||
} |
||||
} |
||||
|
||||
|
||||
# Password validation |
||||
# https://docs.djangoproject.com/en/4.1/ref/settings/#auth-password-validators |
||||
|
||||
AUTH_PASSWORD_VALIDATORS = [ |
||||
{ |
||||
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', |
||||
}, |
||||
{ |
||||
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', |
||||
}, |
||||
{ |
||||
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', |
||||
}, |
||||
{ |
||||
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', |
||||
}, |
||||
] |
||||
|
||||
|
||||
# Internationalization |
||||
# https://docs.djangoproject.com/en/4.1/topics/i18n/ |
||||
|
||||
LANGUAGE_CODE = 'en-us' |
||||
|
||||
TIME_ZONE = 'UTC' |
||||
|
||||
USE_I18N = True |
||||
|
||||
USE_TZ = True |
||||
|
||||
|
||||
# Static files (CSS, JavaScript, Images) |
||||
# https://docs.djangoproject.com/en/4.1/howto/static-files/ |
||||
|
||||
STATIC_URL = 'static/' |
||||
|
||||
# Default primary key field type |
||||
# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field |
||||
|
||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' |
||||
@ -0,0 +1,21 @@ |
||||
"""tea URL Configuration |
||||
|
||||
The `urlpatterns` list routes URLs to views. For more information please see: |
||||
https://docs.djangoproject.com/en/4.1/topics/http/urls/ |
||||
Examples: |
||||
Function views |
||||
1. Add an import: from my_app import views |
||||
2. Add a URL to urlpatterns: path('', views.home, name='home') |
||||
Class-based views |
||||
1. Add an import: from other_app.views import Home |
||||
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') |
||||
Including another URLconf |
||||
1. Import the include() function: from django.urls import include, path |
||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) |
||||
""" |
||||
from django.contrib import admin |
||||
from django.urls import path |
||||
|
||||
urlpatterns = [ |
||||
path('admin/', admin.site.urls), |
||||
] |
||||
@ -0,0 +1,16 @@ |
||||
""" |
||||
WSGI config for tea project. |
||||
|
||||
It exposes the WSGI callable as a module-level variable named ``application``. |
||||
|
||||
For more information on this file, see |
||||
https://docs.djangoproject.com/en/4.1/howto/deployment/wsgi/ |
||||
""" |
||||
|
||||
import os |
||||
|
||||
from django.core.wsgi import get_wsgi_application |
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tea.settings') |
||||
|
||||
application = get_wsgi_application() |
||||
Loading…
Reference in new issue