Skip to content

Commit

Permalink
fix cookies loading (#90)
Browse files Browse the repository at this point in the history
* fix cookies loading

* Fix code style issues with Black

* fix formatting

* fix cookies

* revalidate on start

* remove revalidation on start

---------

Co-authored-by: Lint Action <[email protected]>
  • Loading branch information
maxus2004 and lint-action authored Sep 16, 2024
1 parent 369ca9c commit 13a557a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/database.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from http.cookies import SimpleCookie
import logging as log
from sqlite3 import connect
from json import dumps, loads
Expand All @@ -14,7 +15,7 @@ def map_context_to_dict(context: Context) -> dict:
"login": context.samoware_login,
"ack_seq": context.polling_context.ack_seq,
"command_id": context.polling_context.command_id,
"cookies": context.polling_context.cookies,
"cookies": context.polling_context.cookies.output(header=""),
"last_revalidate": context.last_revalidate.isoformat(),
"request_id": context.polling_context.request_id,
"session": context.polling_context.session,
Expand All @@ -23,11 +24,13 @@ def map_context_to_dict(context: Context) -> dict:


def map_context_from_dict(d: dict, telegram_id: int) -> Context:
cookies = SimpleCookie()
cookies.load(d["cookies"])
return Context(
polling_context=SamowarePollingContext(
ack_seq=d["ack_seq"],
command_id=d["command_id"],
cookies=d["cookies"],
cookies=cookies,
rand=d["rand"],
session=d["session"],
request_id=d["request_id"],
Expand Down
5 changes: 3 additions & 2 deletions src/samoware_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import html
from datetime import datetime
from http.client import HTTPResponse
from http.cookies import SimpleCookie
from typing import Self

import re
Expand Down Expand Up @@ -36,7 +37,7 @@ def __init__(
rand: int = 0,
command_id: int = 0,
ack_seq: int = 0,
cookies: dict = {},
cookies: SimpleCookie = SimpleCookie(),
) -> None:
self.session = session
self.request_id = request_id
Expand All @@ -52,7 +53,7 @@ def make_next(
rand: int | None = None,
command_id: int | None = None,
ack_seq: int | None = None,
cookies: dict | None = None,
cookies: SimpleCookie | None = None,
) -> Self:
return SamowarePollingContext(
session=self.session if session is None else session,
Expand Down

0 comments on commit 13a557a

Please sign in to comment.