This commit is contained in:
Baitur 2023-09-11 16:49:08 +06:00
commit 2e44175ce9
41 changed files with 408 additions and 0 deletions

8
.idea/.gitignore vendored Normal file
View File

@ -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

11
.idea/Transparency.iml Normal file
View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/main" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

4
.idea/misc.xml Normal file
View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11 (Transparency)" project-jdk-type="Python SDK" />
</project>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/Transparency.iml" filepath="$PROJECT_DIR$/.idea/Transparency.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

0
README.md Normal file
View File

28
kgroad Normal file
View File

@ -0,0 +1,28 @@
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAACmFlczI1Ni1jdHIAAAAGYmNyeXB0AAAAGAAAABAWGM7tCg
qA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Q3w7zMOtcac9FAu+A4Q+CZ0alFUm+2odFEfA3n8ABG/uaQZY6S70pT baiturtashbaev@MacBook-Pro-Baitur.local

BIN
main/db.sqlite3 Normal file

Binary file not shown.

0
main/main/__init__.py Normal file
View File

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

16
main/main/asgi.py Normal file
View File

@ -0,0 +1,16 @@
"""
ASGI config for main 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.2/howto/deployment/asgi/
"""
import os
from django.core.asgi import get_asgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'main.settings')
application = get_asgi_application()

125
main/main/settings.py Normal file
View File

@ -0,0 +1,125 @@
"""
Django settings for main project.
Generated by 'django-admin startproject' using Django 4.2.1.
For more information on this file, see
https://docs.djangoproject.com/en/4.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.2/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.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-w^pg5f=r=ex8d)-ez0&n6b2b8)uawa7myx+kkdxc+13@(jp8*0'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'parser',
'rest_framework'
]
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 = 'main.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 = 'main.wsgi.application'
# Database
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
# Password validation
# https://docs.djangoproject.com/en/4.2/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.2/topics/i18n/
LANGUAGE_CODE = 'ru'
TIME_ZONE = 'Asia/Bishkek'
USE_I18N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.2/howto/static-files/
STATIC_URL = 'static/'
# Default primary key field type
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

24
main/main/urls.py Normal file
View File

@ -0,0 +1,24 @@
"""
URL configuration for main project.
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/4.2/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, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include("parser.urls")),
]

16
main/main/wsgi.py Normal file
View File

@ -0,0 +1,16 @@
"""
WSGI config for main 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.2/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'main.settings')
application = get_wsgi_application()

22
main/manage.py Executable file
View File

@ -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', 'main.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()

BIN
main/me1.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

0
main/parser/__init__.py Normal file
View File

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

5
main/parser/admin.py Normal file
View File

@ -0,0 +1,5 @@
from django.contrib import admin
from .models import Road
admin.site.register(Road)

6
main/parser/apps.py Normal file
View File

@ -0,0 +1,6 @@
from django.apps import AppConfig
class ParserConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'parser'

View File

@ -0,0 +1,24 @@
# Generated by Django 4.2.5 on 2023-09-08 08:47
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Road',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=100)),
('image', models.ImageField(upload_to='')),
('title_text', models.CharField(max_length=100, null=True)),
('link', models.CharField(max_length=255, null=True)),
],
),
]

View File

11
main/parser/models.py Normal file
View File

@ -0,0 +1,11 @@
from django.db import models
class Road(models.Model):
title = models.CharField(max_length=100)
image = models.ImageField(upload_to='')
title_text = models.CharField(max_length=100, null=True)
link = models.CharField(max_length=255, null=True)
def __str__(self):
return self.title

49
main/parser/parser.py Normal file
View File

@ -0,0 +1,49 @@
import requests
from bs4 import BeautifulSoup as BS
from django.views.decorators.csrf import csrf_exempt
URL = 'https://www.krsu.edu.kg/'
HEADERS = {
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:107.0) Gecko/20100101 Firefox/107.0'
}
@csrf_exempt
def get_html(url, params=''):
req = requests.get(url, headers=HEADERS)
return req
@csrf_exempt
def get_data(html):
soup = BS(html, 'html.parser')
items = soup.find_all('div', class_='news-column-block')
movies = []
for item in items:
movies.append(
{
'link': URL + item.find('a').get('href'),
'title': URL + item.find('a').get('href'),
'title_text': item.find('div', class_='views-field views-field-field-data-publikacii').find(
'div').get_text(),
'image': URL + item.find('div', class_='field-content news-img').find('img').get('src')
}
)
return movies
@csrf_exempt
def parser():
html = get_html(URL)
if html.status_code == 200:
movies1 = []
for page in range(0, 1):
html = get_html(f'https://www.krsu.edu.kg/', params=page)
movies1.extend(get_data(html.text))
return movies1
else:
raise Exception('Error in parser func........')

View File

@ -0,0 +1,9 @@
from rest_framework import serializers
from .models import Road
class RoadSerializer(serializers.ModelSerializer):
class Meta:
model = Road
fields = '__all__'

3
main/parser/tests.py Normal file
View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

9
main/parser/urls.py Normal file
View File

@ -0,0 +1,9 @@
from django.urls import path
from .views import ParserItemListView, ParserView
urlpatterns = [
path('list_parser/', ParserItemListView.as_view(), name='parser-list'),
path('create_parser/', ParserView.as_view(), name='parser-list_create'),
]

17
main/parser/views.py Normal file
View File

@ -0,0 +1,17 @@
from rest_framework import generics, status
from rest_framework.response import Response
from bs4 import BeautifulSoup as BS
from .models import Road
from .serializers import RoadSerializer
class ParserItemListView(generics.ListCreateAPIView):
queryset = Road.objects.all()
serializer_class = RoadSerializer
class ParserView(generics.CreateAPIView):
queryset = Road.objects.all()
serializer_class = RoadSerializer