Beispiel #1
0
    def test(cls):
        aescode = "123";
        uniqueKey = "@$sswq112$FF";
        s = "helloworld~~~";

        encoded = cls.encode(s, aescode, uniqueKey);
        Log.D("encode result = " + str(encoded));

        decoded = cls.decode(encoded, aescode, uniqueKey);
        Log.D("decode result = " + str(decoded));

        #图片测试
        from Config import Config
        import os
        jpgFile = Config.shared.outPath + os.sep + "nocover.jpg";
        jpgFd = open(jpgFile, "r");
        jpgData = jpgFd.read();
        jpgFd.close();
        
        encodeJpgData = cls.encode(jpgData, aescode, uniqueKey, False);
        jpgFd = open(Config.shared.outPath + os.sep + "nocover-encode.jpg", "w");
        jpgFd.write(encodeJpgData);
        jpgFd.flush();
        jpgFd.close();

        decodeJpgData = cls.decode(encodeJpgData, aescode, uniqueKey, False);
        jpgFd = open(Config.shared.outPath + os.sep + "nocover-decode.jpg", "w");
        jpgFd.write(decodeJpgData);
        jpgFd.flush();
        jpgFd.close();
Beispiel #2
0
def dropAllTables():
    from src.db import Db
    Db.instance.executeSql('''show tables;''')
    ret = Db.instance.fetchAll()
    for item in ret:
        for k, v in item.items():
            Db.instance.executeSql('''drop table if exists {};'''.format(v))
            Log.D("droping table " + str(v))
    Log.D("droped all tables finished")
Beispiel #3
0
 def test(self):
     self.createTable()
     self.set("testkey", None)
     self.set("testkey", "testValue")
     self.set("testkey", "testValue")
     self.set("testkey", None)
     self.set("testkey", "testValue")
     Log.D(str(self.get("testkey")))
     Log.D(str(self.get("testkey1")))
Beispiel #4
0
 def bookMuluUrl(self, bookPageSoup):
     Log.D("[D] bookMuluSoup input = None " + str(bookPageSoup == None));
     spans = Utils.findAllClassTag(bookPageSoup, "span", "btopt");
     if len(spans) <= 0 or len(spans[0].contents) <= 0:
         return None;
     span = spans[0];
     a = span.contents[0];
     url = a["href"];
     Log.D("[D] muluurl = " + str(url));
     return url;
Beispiel #5
0
    def test(self):
        self.createTable();
        visitingModel = VisitUrlModel("http://www.baidu.com", 0);

        self.insert(visitingModel);

        visitingModel.visiting = 1;

        self.update(visitingModel);

        Log.D(" -- test visiting url = " + str(self.getVisitingUrl()));
Beispiel #6
0
 def __init__(self):
     Log.D("[I] init class Db");
     connConfig = {
         'host': '127.0.0.1',
         'user': Config.shared.dbUser,
         'password': Config.shared.dbPwd,
         'db': Config.shared.dbName,
         'charset': 'utf8',
         'cursorclass': pymysql.cursors.DictCursor,
         'autocommit': True
     };
     self.conn = pymysql.connect(**connConfig);
     self.cursor = self.conn.cursor();
Beispiel #7
0
    def test(self):
        self.createTable()
        bookInfoModel = BookInfoModel()
        bookInfoModel.bookId = "123456"
        bookInfoModel.title = "斗破苍穹"
        bookInfoModel.author = "天蚕土豆"
        bookInfoModel.category = "玄幻"
        bookInfoModel.des = "斗气大法"
        bookInfoModel.setUniqueKey()

        Log.D(" --- toDict = " + str(bookInfoModel.toDict(True)))

        # self.bookInfoDelete(bookInfoModel);
        self.insert(bookInfoModel)

        bookInfoModel.title = "武动乾坤"
        bookInfoModel.setUniqueKey()

        self.update(bookInfoModel)
Beispiel #8
0
def nextBookId():
    global _lastBookId;
    global _kvDb;
    bookId = None;
    if _lastBookId == None:
        bookId = 101
    else:
        bookId = _lastBookId + 1;

    while True:
        valid = checkBookId(bookId)
        if valid:
            break;
        else:
            bookId += 1;

    _lastBookId = bookId;

    _kvDb.set("lastBookId", str(_lastBookId));

    Log.D(" generate new bookId " + str(bookId));

    return bookId;
Beispiel #9
0
 def __del__(self):
     Log.D("[I] class Db dealloc");
     self.conn.close();
Beispiel #10
0
	def __init__(self, outPath):
		Log.D("[I] FileStorge inited");
		super(FileStorge, self).__init__(outPath);
		self.filespath = self.outPath + os.sep + "files";
		Utils.createDir(self.filespath);
Beispiel #11
0
 def createInstance(self, name, *args):
     Log.D(" ----- test name = " + str(name) + ", args = " + str(args))
     if args != None and len(args) > 0:
         return eval("{}({})".format(name, *args))
     else:
         return eval("{}()".format(name))
Beispiel #12
0
def test():
    Log.D("--test--")
    dropAllTables()
    sys.exit(0)
Beispiel #13
0
 def __init__(self, outPath=None):
     Log.D("[I] Storge inited")
     self.outPath = outPath
Beispiel #14
0
 def aeskey(cls, aescode, uniqueKey):
     key = Utils.md5str(aescode + uniqueKey);
     Log.D(" md5 key = " + str(key));
     return key;
Beispiel #15
0
 def test(self):
     pat = r".+?/xiazai/\d+/\d+/?$"
     Log.D(re.compile(pat).match("https://www.ybdu.com/xiazai/15/15360/"))
     sys.exit(1)
Beispiel #16
0
    def downloadBook(self, url):
        Log.V("[I] on begin downloadBook() " + str(url))

        if url == None:
            return

        #检查是否下载过了
        if self.checkDownloadedBookUrl(url):
            return

        #设置visiting
        self.setVisitingBookUrl(url)

        #尝试获取bookInfo
        bookInfo = self.getBookinfo(url)
        sectionInfo = None
        existsBookId = None
        if bookInfo != None:
            existsBookId = bookInfo.bookId
            Log.D(" downloadBook existsBookId = " + str(existsBookId))
            sectionInfo = self.getChapter(bookInfo.bookId)
            Log.D(" downloadBook sectionInfo = " + str(sectionInfo))
            if sectionInfo == None or sectionInfo.chapters == None or len(
                    sectionInfo.chapters) == 0:
                sectionInfo = None
                bookInfo = None
            else:
                sectionInfo.bookInfo = bookInfo

        if bookInfo == None:
            Log.I("[I] on downloadBook() will get soup " + url)
            bookSoup = Utils.soupUrl(url)
            Log.I("[I] on downloadBook() did get soup (%s) %s " %
                  (str(bookSoup != None), str(url)))
            if bookSoup != None:
                Log.I("[I] on downloadBook() will get muluSoup")
                muluUrl = self.bookMuluUrl(bookSoup)
                if muluUrl != None:
                    muluSoup = Utils.soupUrl(muluUrl)
                    Log.I("[I] on downloadBook() did get muluSoup %s" %
                          (str(muluSoup != None)))
                    if muluSoup != None:
                        bookInfo = self.bookInfo(bookSoup, muluSoup)
                        Log.I("[I] on downloadBook get bookInfo " +
                              str(bookInfo))
                        if bookInfo != None:
                            bookInfo.setUniqueKey()
                            bookInfo.downBookUrl = url
                            bookInfo.downMuluUrl = muluUrl

                            #bookId
                            if existsBookId == None:
                                Log.D(" downloadBook will create new bookId")
                                BookId.init(self.kvDb)
                                bookInfo.bookId = BookId.nextBookId()
                            else:
                                Log.D(" downloadBook use exists bookId")
                                bookInfo.bookId = existsBookId

                            #获取章节信息
                            sectionInfo = self.sectionInfo(
                                bookInfo, muluUrl, muluSoup)
                            if sectionInfo != None:
                                Log.D(
                                    " downloadBook parse sectionInfo success")
                                #最新章节
                                bookInfo.chapterCount = len(
                                    sectionInfo.chapters)
                            else:
                                Log.D(
                                    " downloadBook error cant parser sectionInfo"
                                )
                                bookInfo.status = BookInfoStatus.Error
                                bookInfo.downloadStatus = BookDownloadStatus.Completed
                            Log.D(" downloadBook save BookInfo " +
                                  str(bookInfo) + ", bookId = " +
                                  str(bookInfo.bookId) + ", save chapters " +
                                  str(sectionInfo))
                            #保存bookInfo
                            self.saveBookinfo(bookInfo)
                            self.saveChapter(bookInfo.bookId, sectionInfo)

        #下载bookImg
        if bookInfo != None and bookInfo.bookImg != None:
            self.downloadBookImg(bookInfo.bookImg, bookInfo.uniqueKey)
        if sectionInfo != None:
            self.downloadSection(sectionInfo)
            self.setDownloadedForBookUrl(url)
        self.chapterDb = None

        #移除visiting book url
        self.removeBookUrl(url)

        Log.V("on finished downloadBook() " + str(url))
Beispiel #17
0
 def __init__(self):
     Log.D("init class " + str(self.__class__))
     self.db = Db.instance
     self.createTable()
Beispiel #18
0
 def __del__(self):
     if Utils != None:
         Log.D("dealloc class " + str(self.__class__))