from django.utils import timezone from crawl.bunjang import get_bunjang from crawl.joongna import get_joongna from market.models import Product from graph.models import MonthlyTransaction def crawl(): 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, )