Skip to content

Commit

Permalink
fix: timezone for crawl_view
Browse files Browse the repository at this point in the history
  • Loading branch information
retroinspect committed Jan 9, 2024
1 parent 35003d8 commit c6a0ae6
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions apps/core/management/scripts/portal_crawler.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import hashlib
import re
import uuid
from pytz import timezone as pytz_timezone
from datetime import timedelta, datetime
from datetime import datetime, timedelta

import boto3
import requests
Expand All @@ -11,19 +10,19 @@
from django.db import transaction
from django.utils import timezone
from django.utils.translation import gettext
from pytz import timezone as pytz_timezone
from tqdm import tqdm

from apps.core.models import Article
from apps.core.models.portal_view_count import PortalViewCount
from apps.user.models import UserProfile
from ara.log import log
from ara.settings import (
AWS_S3_BUCKET_NAME,
PORTAL_ID,
PORTAL_JSESSIONID,
PORTAL_PASSWORD,
)
from ara.log import log


LOGIN_INFO_SSO2 = {
"userid": PORTAL_ID,
Expand All @@ -45,6 +44,7 @@
KST = pytz_timezone("Asia/Seoul")
PORTAL_NOTICE_BOARD_ID = 1


def _login_kaist_portal():
session = requests.Session()
response = session.get(
Expand Down Expand Up @@ -425,8 +425,8 @@ def crawl_view():
now = timezone.datetime.today().date()
log.info(f"crawl_view running on {now}")

week_ago = timezone.get_current_timezone().localize(
datetime.today() - timedelta(days=7)
week_ago = (
(datetime.today() - timedelta(days=7)).astimezone(KST).astimezone(timezone.utc)
)

session = _login_kaist_portal()
Expand All @@ -443,8 +443,10 @@ def _get_board_week(page_num):
for row in table.find("tbody").find_all("tr"):
cells = row.find_all("td")
created_at_str = cells[4].text.strip()
created_at = timezone.get_current_timezone().localize(
created_at = (
datetime.strptime(created_at_str, "%Y.%m.%d")
.astimezone(KST)
.astimezone(timezone.utc)
)

if week_ago > created_at:
Expand Down

0 comments on commit c6a0ae6

Please sign in to comment.