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
|
2023-11-14 02:11:09 +09:00
|
|
|
from graph.models import MonthlyTransaction
|
2023-11-13 19:52:35 +09:00
|
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
)
|