|
@@ -7,6 +7,7 @@ import logging
|
|
|
import re
|
|
import re
|
|
|
import time
|
|
import time
|
|
|
import requests
|
|
import requests
|
|
|
|
|
+from datetime import datetime
|
|
|
import json
|
|
import json
|
|
|
from webbot.webbot import Browser
|
|
from webbot.webbot import Browser
|
|
|
from requests_futures import sessions
|
|
from requests_futures import sessions
|
|
@@ -167,7 +168,6 @@ class Client:
|
|
|
'expires': cookie['expires'],
|
|
'expires': cookie['expires'],
|
|
|
'value': cookie['value'],
|
|
'value': cookie['value'],
|
|
|
}
|
|
}
|
|
|
- print(cookies)
|
|
|
|
|
with open('cookies.json', 'w+') as cookies_file:
|
|
with open('cookies.json', 'w+') as cookies_file:
|
|
|
json.dump(cookies, cookies_file)
|
|
json.dump(cookies, cookies_file)
|
|
|
LOGGER.info('Saved cookie for "%s"', username)
|
|
LOGGER.info('Saved cookie for "%s"', username)
|
|
@@ -175,19 +175,21 @@ class Client:
|
|
|
@classmethod
|
|
@classmethod
|
|
|
def get_cookie(cls, username):
|
|
def get_cookie(cls, username):
|
|
|
"""Read cookies for username"""
|
|
"""Read cookies for username"""
|
|
|
- LOGGER.info('Read cookie for')
|
|
|
|
|
|
|
+ LOGGER.info('Read cookie for "%s"', username)
|
|
|
try:
|
|
try:
|
|
|
with open('cookies.json', 'r') as cookies_file:
|
|
with open('cookies.json', 'r') as cookies_file:
|
|
|
cookies = json.load(cookies_file)
|
|
cookies = json.load(cookies_file)
|
|
|
for cookie_username, cookie in cookies.items():
|
|
for cookie_username, cookie in cookies.items():
|
|
|
if cookie_username == username:
|
|
if cookie_username == username:
|
|
|
- LOGGER.info('Found cookie for %s', username)
|
|
|
|
|
- print("found %s" % username)
|
|
|
|
|
|
|
+ LOGGER.info('Found cookie')
|
|
|
|
|
+ expires = datetime.fromtimestamp(int(cookie['expires']))
|
|
|
|
|
+ if datetime.now() >= expires:
|
|
|
|
|
+ LOGGER.info('Cookie is expired')
|
|
|
|
|
+ return None
|
|
|
cookie = cls.create_cookie(
|
|
cookie = cls.create_cookie(
|
|
|
cookie['expires'],
|
|
cookie['expires'],
|
|
|
cookie['value'],
|
|
cookie['value'],
|
|
|
)
|
|
)
|
|
|
- print(cookie)
|
|
|
|
|
return cookie
|
|
return cookie
|
|
|
except FileNotFoundError:
|
|
except FileNotFoundError:
|
|
|
pass
|
|
pass
|