diff options
author | James Taylor <user234683@users.noreply.github.com> | 2018-12-24 23:29:35 -0800 |
---|---|---|
committer | James Taylor <user234683@users.noreply.github.com> | 2018-12-24 23:29:35 -0800 |
commit | 888a850dbf399dcd7a927dd40afd982e3296a804 (patch) | |
tree | 8db123e236829aac9d5d9f1e59519719a99cb2e3 /youtube | |
parent | 59c0d76424b4df6a402a1da2d5de908c9ebd552c (diff) | |
download | yt-local-888a850dbf399dcd7a927dd40afd982e3296a804.tar.lz yt-local-888a850dbf399dcd7a927dd40afd982e3296a804.tar.xz yt-local-888a850dbf399dcd7a927dd40afd982e3296a804.zip |
Loading/saving of accounts
Diffstat (limited to 'youtube')
-rw-r--r-- | youtube/account_functions_.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/youtube/account_functions_.py b/youtube/account_functions_.py index 414f9fe..da53f99 100644 --- a/youtube/account_functions_.py +++ b/youtube/account_functions_.py @@ -8,6 +8,14 @@ import traceback import settings import http.cookiejar + +try: + with open(os.path.join(settings.data_dir, 'accounts.txt'), 'r', encoding='utf-8') as f: + accounts = json.loads(f.read()) +except FileNotFoundError: + # global var for temporary storage of account info + accounts = [] + def _post_comment(text, video_id, session_token, cookie): headers = { 'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1', @@ -191,7 +199,10 @@ textarea{ page = page, ) - +def save_accounts(): + to_save = list(account for account in accounts if account['save']) + with open(os.path.join(settings.data_dir, 'accounts.txt'), 'w', encoding='utf-8') as f: + f.write(json.dumps(to_save)) # --------------------------------- # Code ported from youtube-dl |