HiPhone_BE/crawl/methods.py

31 lines
850 B
Python
Raw Normal View History

2023-11-13 19:52:35 +09:00
from django.utils import timezone
from crawl.bunjang import get_bunjang
from crawl.joongna import get_joongna
from market.models import Product
from .models import MonthlyTransaction
def crawl(self, request, queryset):
today = timezone.now()
month = today.month - 1
year = today.year
if month == 0:
month = 12
year -= 1
for product in Product.objects.all():
name = product.name
print(name)
bunjang_result = get_bunjang(name)
joongna_result = get_joongna(name)
print("----------------")
print(bunjang_result, joongna_result)
print("----------------")
avg = (bunjang_result + joongna_result) / 2
MonthlyTransaction.objects.create(
product=product,
year=year,
month=month,
price=avg,
)