Skip to content

Commit

Permalink
update playwright to include cookies on kth github in addition to canvas
Browse files Browse the repository at this point in the history
  • Loading branch information
nattvara committed May 1, 2024
1 parent fab593f commit aeaa910
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
25 changes: 16 additions & 9 deletions services/crawler/playwright.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from playwright.async_api import Browser, BrowserContext, Page
from playwright.async_api import Playwright

from services.crawler.url_filters import CANVAS_DOMAIN, CANVAS_PROFILE_PAGE
from services.crawler.url_filters import CANVAS_DOMAIN, CANVAS_PROFILE_PAGE, KTH_GITHUB_DOMAIN
from db.actions.cookie import find_cookie_by_identifier
import config.settings as settings
from config.logger import log
Expand All @@ -25,17 +25,24 @@ async def get_logged_in_browser_context_and_page(playwright: Playwright) -> (Bro
f"with identifier: {settings.get_settings().COOKIE_IDENTIFIER}")

cookies = cookie.value.split('; ')

prepared_cookies = []
domains_with_cookies = [CANVAS_DOMAIN, KTH_GITHUB_DOMAIN]
for cookie in cookies:
name, value = cookie.strip().split('=', 1)
prepared_cookies.append({
'name': name,
'value': value,
'domain': CANVAS_DOMAIN,
'path': '/',
'expires': -1
})

secure = False
if name.startswith('__Host-'):
secure = True

for domain in domains_with_cookies:
prepared_cookies.append({
'name': name.strip(),
'value': value,
'domain': domain,
'path': '/',
'expires': -1,
'secure': secure
})

await context.add_cookies(prepared_cookies)

Expand Down
2 changes: 2 additions & 0 deletions services/crawler/url_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

CANVAS_DOMAIN = "canvas.kth.se"

KTH_GITHUB_DOMAIN = "gits-15.sys.kth.se"

KATTIS_KTH_DOMAIN = "kth.kattis.com"

KATTIS_OPEN_DOMAIN = "open.kattis.com"
Expand Down

0 comments on commit aeaa910

Please sign in to comment.