Skip to content

Commit 174ca83

Browse files
authored
Add ability to export/import cookie in PiazzaRPC class to allow saving it to a file (#54)
* Add ability to export/import cookie in PiazzaRPC class to allow saving it to a file after logging in * Add arg/return types for get_cookies and set_cookies to docstring
1 parent 6adfd2c commit 174ca83

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

piazza_api/rpc.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,25 @@ def __init__(self, network_id=None):
3333
}
3434
self.session = requests.Session()
3535

36+
def get_cookies(self):
37+
"""Export the session cookies.
38+
39+
Only works if user_login or demo_login has been completed already.
40+
41+
:returns: Dictionary containing all session cookies associated with current login.
42+
:rtype: dict
43+
"""
44+
return self.session.cookies.get_dict()
45+
46+
def set_cookies(self, cookies):
47+
"""Import the session cookies.
48+
49+
:type cookies: dict
50+
:param cookies: The session cookies (obtained using get_cookies or from a browser)
51+
"""
52+
for name, val in cookies.items():
53+
self.session.cookies.set(name, val, domain="piazza.com")
54+
3655
def user_login(self, email=None, password=None):
3756
"""Login with email, password and get back a session cookie
3857

0 commit comments

Comments
 (0)