You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

70 lines
2.1 KiB

# main.py
import os
import json
import requests
import browser_cookie3
from .console import console, logger
class WF:
def __init__(self):
self._data = {}
self._path = None
@property
def _cookie(self):
return self._data.get('cookie', None)
def _load(self):
if os.path.exists(self.path):
logger.info(f'Loading data from {self.path}')
with open(self.path, 'r') as f:
self._data = json.load(f)
else:
logger.warning(f'No data found at {self.path}')
self._data = {}
def _save(self):
logger.info(f'Saving data to {self.path}')
with open(self.path, 'w') as f:
json.dump(self._data, f)
def _refresh_cookie(self):
logger.info('Refreshing cookies')
cookies = browser_cookie3.chrome()
for cookie in cookies:
if cookie.name == "sessionid" and "workflowy.com" in cookie.domain:
self._data['cookie'] = cookie.value
break
logger.warning('No cookie found')
def _refresh_data(self):
if not self._cookie:
logger.warning('No cookie found')
return
logger.info('Refreshing data')
url = "https://workflowy.com/get_initialization_data?client_version=15"
headers = {"Cookie": f"sessionid={self._cookie}"}
response = requests.get(url, headers=headers)
if response.status_code == 200:
data = response.json()
data_globals = {item[0]: item[1] for item in data["globals"]}
self._data["userid"] = data_globals["USER_ID"]
self._data["joined"] = data["projectTreeData"]["mainProjectTreeInfo"]["dateJoinedTimestampInSeconds"]
self._data["transid"] = data["projectTreeData"]["mainProjectTreeInfo"]["initialMostRecentOperationTransactionId"]
self._data["pollid"] = generate_uuid() # Simulate g() + g()
storage["root"] = {"nm": "root", "ch": data["projectTreeData"]["mainProjectTreeInfo"]["rootProjectChildren"]}
save_storage(storage)
console.log("Successfully refreshed and saved Workflowy data.")