# Path: mod/models/library_auth_cache.py
# class LibraryAuthCache(Base):
#     __tablename__ = 'library_auth'
#     cardnum = Column(Integer, primary_key=True)
#     cookie = Column(String(4096))
#     captcha = Column(String(4096))
#     date = Column(Integer, nullable=False)


from config import *
from tornado.httpclient import HTTPClient
from tornado.httpclient import HTTPRequest, AsyncHTTPClient
from bs4 import BeautifulSoup
from ..models.library_auth_cache import LibraryAuthCache
from sqlalchemy.orm.exc import NoResultFound
from time import time
import re
import json
import urllib
import base64
import tornado.web, tornado.gen
                    request_timeout=TIME_OUT
                    )
                response = yield tornado.gen.Task(client.fetch, request)
                soup = BeautifulSoup(response.body, 'html.parser')
                name = soup.findAll('font')[0].text
                if name:
                    flag = False
                    request = HTTPRequest(
                        LIST_URL,
                        method = 'GET',
                        headers={'Cookie': cookie},
                        request_timeout = TIME_OUT
                        )
                    response = yield tornado.gen.Task(client.fetch, request)
                    soup = BeautifulSoup(response.body, 'html.parser')
                    td = soup.findAll('td', {'class': 'whitetext'})
                    for i in range(0, len(td), 8):
                        if (barcode == td[i].text):
                            checkcode = td[i+7].input['onclick'].split('\'')[3]
                            request = HTTPRequest(
                                RENEW_URL%(barcode, checkcode, captcha, int(time()*1000)),
                                method='GET',
                                headers={'Cookie': cookie},
                                request_timeout=TIME_OUT
                                )
                            response = yield tornado.gen.Task(client.fetch, request)
                            if (response.body == 'invalid call'):
                                flag = False
                            else:
                                flag = True

# Path: mod/models/library_auth_cache.py
# class LibraryAuthCache(Base):
#     __tablename__ = 'library_auth'
#     cardnum = Column(Integer, primary_key=True)
#     cookie = Column(String(4096))
#     captcha = Column(String(4096))
#     date = Column(Integer, nullable=False)


# Path: mod/library/renewhandler.py
from config import *
from tornado.httpclient import HTTPClient
from tornado.httpclient import HTTPRequest, AsyncHTTPClient
from bs4 import BeautifulSoup
from ..models.library_auth_cache import LibraryAuthCache
from sqlalchemy.orm.exc import NoResultFound
from time import time
import re
import json
import urllib
import base64
import tornado.web, tornado.gen

                    request_timeout=TIME_OUT
                    )
                response = yield tornado.gen.Task(client.fetch, request)
                soup = BeautifulSoup(response.body, 'html.parser')
                name = soup.findAll('font')[0].text
                if name:
                    flag = False
                    request = HTTPRequest(
                        LIST_URL,
                        method = 'GET',
                        headers={'Cookie': cookie},
                        request_timeout = TIME_OUT
                        )
                    response = yield tornado.gen.Task(client.fetch, request)
                    soup = BeautifulSoup(response.body, 'html.parser')
                    td = soup.findAll('td', {'class': 'whitetext'})
                    for i in range(0, len(td), 8):
                        if (barcode == td[i].text):
                            checkcode = td[i+7].input['onclick'].split('\'')[3]
                            request = HTTPRequest(
                                RENEW_URL%(barcode, checkcode, captcha, int(time()*1000)),
                                method='GET',
                                headers={'Cookie': cookie},
                                request_timeout=TIME_OUT
                                )
                            response = yield tornado.gen.Task(client.fetch, request)
                            if (response.body == 'invalid call'):
                                flag = False
                            else:
                                flag = True

                    if flag: