Beispiel #1
0
class Gocomics(object):

    def __init__(self, comic=None, path=None, archive=None, full=None, useComix=None,
                 url=None):
        """ Init variables"""
        self.comic = comic.replace(' ',  '_')
        self.path = path
        self.archive = archive
        self.full = full
        self.useComix = useComix
        self.url = url
        self.comic_url = self.url.replace('http://www.gocomics.com/', '')

        self.headers = { 'User-Agent' : 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)' }

        """ Look for the comic html page and get informations"""
        self.parse_comic()


        if self.full == "False":
            self.single_dl()
        else:
            self.sqlite = Sqlite()
            self.init_dl_rule()
            self.full_dl()

        if self.archive == "True":
            self.control_path(self.path+"/archives/"+self.comic)
            self.create_archive()

    def init_dl_rule(self):
        """ Look for last comic downloaded"""
        self.sqlite.connect()
        self.sqlite.c.execute("select * from dl_rule where comic='%s'"
                              % self.comic)
        row = self.sqlite.c.fetchall()
        if not row:
            self.sqlite.c.execute("insert into dl_rule values(?,?)",
                                  (self.comic, self.first[0]))
            self.sqlite.conn.commit()
            self.start = self.first[0]
        else:
            self.start = row[0][1]
            self.unpack_archive(self.start)
        self.sqlite.c.close

    def control_path(self, path):
        """ Check if download path exists"""
        if not os.path.exists(path):
            try:
                os.makedirs(path, mode=0755)
            except OSError, e:
                print e.errno, e.strerror, e.filename
Beispiel #2
0
class Sp(object):
    def __init__(self, url, key, Queue, dbfile, deep=2):
        #threading.Thread.__init__(self)
        self.url = url
        self.deep = deep
        self.key = key
        self.dbfile = dbfile
        self.queue = Queue
        self.sq = Sqlite(dbfile)

    def run(self):
        print 'job start'
        self.queue.add_job(self.get_url, self.url, self.deep)
        self.queue.wait_for_complete()

    def get_soup(self, url):
        html = urllib.urlopen(url).read()
        soup = BeautifulSoup(html)
        print soup.title
        return soup

    def get_url(self, start, kwargs):
        start_url, deep = start
        urls = []
        soup = self.get_soup(start_url)
        links = soup.find_all('a')
        self.if_has_key(soup.get_text())
        deep = deep - 1
        for link in links:
            _url = link.get('href')
            print _url
            if re.match('^(javascript|:;|#)', _url) or _url is None \
                or re.match('.(jpg|png|bmp|mp3|wma|wmv|gz|zip|rar|iso\
                             |pdf|txt|db)$', _url):
                continue
            if re.match('^(http|https)', _url):
                if sq.find_url(_url) or deep < 0:
                    continue
                else:
                    print _url
                    sq.insert_url(_url)
                    self.queue.add_job(get_url, _url, deep)

    def if_has_key(self, soup_text):
        findpage = soup_text.encode('utf-8')
        if self.key is None:
            self.sq.insert_page(None, findpage)
        if re.findall(self.key, findpage) != []:
            self.sq.insert_page(self.key, find_page)
Beispiel #3
0
    def __init__(self, comic=None, path=None, archive=None, full=None, useComix=None,
                 url=None):
        """ Init variables"""
        self.comic = comic.replace(' ',  '_')
        self.path = path
        self.archive = archive
        self.full = full
        self.useComix = useComix
        self.url = url
        self.comic_url = self.url.replace('http://www.gocomics.com/', '')

        self.headers = { 'User-Agent' : 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)' }

        """ Look for the comic html page and get informations"""
        self.parse_comic()


        if self.full == "False":
            self.single_dl()
        else:
            self.sqlite = Sqlite()
            self.init_dl_rule()
            self.full_dl()

        if self.archive == "True":
            self.control_path(self.path+"/archives/"+self.comic)
            self.create_archive()
Beispiel #4
0
def main():
    # Create directory if it doesn't exist
    futil = FileUtil(".opendoord")

    # Get access to the database handler
    logger = Logger.get(verbose=True)
    db = Sqlite(futil.path + "/opendoor.db", logger)
    port = Port(logger)
    pipes = Pipes(logger, port, db)

    i = 0
    logger.debug("Send commands via pipe with 10 sec delay")
    while i < 100:
        i += 1
        pipes.send_to_app("OPEN DOOR\n", i)
        logger.debug("OPEN DOOR")
        time.sleep(10)
        i += 1
        pipes.send_to_app("DOORBELL PRESSED\n", i)
        logger.debug("DOORBELL PRESSED")
        time.sleep(10)
        i += 1
        pipes.send_to_app("DOW RING WITH AUTO OPEN\n", i)
        logger.debug("DOW RING WITH AUTO OPEN")
        time.sleep(10)
Beispiel #5
0
    def __init__(self, manga=None, path=None, archive=None, full=None, useComix=None, url=None, pdf=None):
        """ Init variables"""
        self.manga = manga.replace(' ', '_')
        self.path = path
        self.archive = archive
        self.full = full
        self.useComix = useComix
        self.url = url
        self.pdf= pdf

        self.headers = { 'User-Agent' : 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)' }

        if self.archive == "True":
            self.control_path(self.path+"/archives/"+self.manga)
        if self.pdf == "True":
            self.control_path(self.path+"/pdf/"+self.manga)
        self.parseManga = self.parse_manga()

        """ Look if manga folder contains Chapters"""
        if not self.parseManga[1]:
            print "Le manga ne contient aucun chapitre"
            print "Téléchargement arrêté"
        else:
            self.sqlite = Sqlite()

            if self.full == "False":
                self.prepare_download()
                self.single_dl()
            else:
                self.prepare_download()
                self.full_dl()
Beispiel #6
0
    def __init__(self):
        QDialog.__init__(self)
        preferences_ui.Ui_Dialog.__init__(self)
        Dialog_Preferences = QDialog()
        self.setupUi(Dialog_Preferences)

        self.sqlite = Sqlite()
        self.initialise()

        """ Configuration SLOT"""
        self.connect(self.radioButton, SIGNAL("clicked()"), self.ajouter_comic)
        self.connect(self.radioButton_2, SIGNAL("clicked()"),
                     self.ajouter_manga)
        self.connect(self.pushButton_3, SIGNAL("clicked()"),
                     self.ajouter_sqlite)
        self.connect(self.radioButton_3, SIGNAL("clicked()"),
                     self.supprimer_comic)
        self.connect(self.radioButton_4, SIGNAL("clicked()"),
                     self.supprimer_manga)
        self.connect(self.pushButton_4, SIGNAL("clicked()"),
                     self.supprimer_sqlite)
        self.connect(self.pushButton_5, SIGNAL("clicked()"), self.update_prefs)
        self.connect(self.pushButton, SIGNAL("clicked()"), self.choix_path)
        self.connect(self.pushButton_2,  SIGNAL("clicked()"), Dialog_Preferences.accept)

        Dialog_Preferences.exec_()
Beispiel #7
0
    def __init__(self):
        QMainWindow.__init__(self)
        dlcomix_ui.Ui_DLComix.__init__(self)

        self.headers = { 'User-Agent' : 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)' }

        self.sqlite = Sqlite()
        self.setupUi(self)
        self.init_options()
        self.statusbar.showMessage(self.trUtf8("Prêt"))


        """ Configuration SLOT"""
        self.connect(self.pushButton, SIGNAL("clicked()"),
                     self.update_database)
        self.connect(self.actionQuitter, SIGNAL("triggered()"), qApp,
                     SLOT("quit()"))
        self.connect(self.actionPreferences, SIGNAL("triggered()"),
                     self.preferences)
        self.connect(self.actionA_Propos, SIGNAL("triggered()"),
                     self.apropos)
        self.connect(self.radioButton, SIGNAL("clicked()"), self.combo_comic)
        self.connect(self.radioButton_2, SIGNAL("clicked()"), self.combo_manga)
        self.connect(self.pushButton_2,  SIGNAL("clicked()"),  self.telecharger_prefs)
        self.connect(self.pushButton_3, SIGNAL("clicked()"), self.telecharger)
        self.connect(self.pushButton_4, SIGNAL("clicked()"), self.init_options)
class HistPlot:
    def __init__(self):
        self.__fig = plt.figure()
        self.__ax = self.__fig.add_subplot(1, 1, 1)
        self.__sqlite = Sqlite()

    def show(self):
        rows = self.__sqlite.query_bytime('hist_data')
Beispiel #9
0
def isRun(data):
    sql_con = Sqlite()
    ID = data.get('Id')
    is_run = data.get('isRun')
    sql_con.cur.execute(UPDATE_SQL.format(table_name, f'is_valid = {is_run}, update_time = {int(time.time())}', ID))
    sql_con.con.commit()
    logger.info(f'{ID} 设置为 {is_run}')
    del sql_con
Beispiel #10
0
 def __init__(self, url, key, Queue, dbfile, deep=2):
     #threading.Thread.__init__(self)
     self.url = url
     self.deep = deep
     self.key = key
     self.dbfile = dbfile
     self.queue = Queue
     self.sq = Sqlite(dbfile)
Beispiel #11
0
def main():
    global log, port, pipes, db, test_mode

    # Be sure we have root privileges
    if os.geteuid() != 0:
        exit("You need to have root privileges. Exiting.")

    # Ctrl-C and SIGTERM handler
    signal.signal(signal.SIGINT, signal_handler)
    signal.signal(signal.SIGTERM, signal_handler)

    # Parse arguments, use file docstring as a parameter definition
    args = docopt.docopt(__doc__, version='0.1a')

    # Create directory if it doesn't exist
    futil = FileUtil(".opendoord")

    print("Path: %s, args: %s" % (futil.path, args))
    # Create a logger
    if args["--console"]:
        log = Logger.get(verbose=True)
    else:
        log = Logger.get(futil.path + "/opendoor.log",
                         verbose=args["--verbose"])
    log.info("*** Start OpenDoor ***")

    # Get access to the database handler
    db = Sqlite(futil.path + "/opendoor.db", log)
    if not db.exist():
        log.info("No database found. Will create one.")
        db.create_tables()  # if not already created
        db.reset_tables()  # and initialize

    if args["--test"]:
        test_mode = True

    # Let's initialize the gpio's
    port = Port(log, test_mode)

    # Open the pipes
    pipes = Pipes(log, port, db)

    if args["--resetdb"]:
        db.reset_tables()
        log.info("Database has been reset.")
    else:
        log.info("Watch door events in an endless loop.")
        opendoor_endless_loop()
Beispiel #12
0
    def gerar_sqlite(self, caminho_sqlite, nome, legal_terms):
        base_sqlite = Sqlite(caminho_sqlite, nome, legal_terms)

        while True:
            self.__capitulo_atual = self.__get_capitulo()
            self.__processar_capitulo(base_sqlite)
            if self.__tem_proximo():
                self.__referencia_atual = self.__get_proxima_referencia()
            else:
                break
Beispiel #13
0
 def getNewMessages(self, questionAsker, type = 'All', progressBroadcaster = None):
     """
         Downloads the new messages of all the users’s accounts, and stores them
         in the database.
     """
     db = Sqlite(self.username)
     
     if type in ('All', 'iPhone messages'):
         for getter in self.iPhoneGetters:
             getter.downloadNewMessages(db, progressBroadcaster)
     
     if type in ('All', 'IM logs'):
         if self.imLogGetter:
             self.imLogGetter.downloadNewConversations(db, questionAsker, progressBroadcaster)
     
     if type in ('All', 'IMAP emails'):
         for getter in self.imapGetters:
             getter.downloadNewMessages(db, progressBroadcaster)
             
     db.close()
Beispiel #14
0
 def __init__(self, username, password):
     """
         Takes the user’s owl credentials. Checks them (for the sake of paranoia)
         and initialises any getters for the users’s accounts.
         
         It will raise a NotAuthenticatedException if the authentication failed.
     """
     
     self.username = username
     db = Sqlite(self.username)
     
     self.accountDecriptionKey = settings.settings['userPasswordEncryptionSalt'] + password
     self.encryptionKey = settings.settings['userDataEncryptionSalt'] + password
     
     if not login.checkLogin(username, password):
         raise NotAuthenticatedException('The username or password was not valid')
     
     self.imapGetters = self.checkForImap(db)
     self.iPhoneGetters = self.checkForIPhone(db)
     self.imLogGetter = self.checkForIMLogs(db)
     
     db.close()
Beispiel #15
0
    def gerarSqlite(self, caminhoSqlite, nome, copyright):
        baseSqlite = Sqlite(caminhoSqlite, nome, copyright)

        # cont = 0

        while True:

            # cont += 1
            # if cont == 5:
            #     break

            self.__capituloAtual = self.__getCapitulo()
            self.__processarCapitulo(baseSqlite)
            if self.__temProximo():
                self.__referenciaAtual = self.__getProximaReferencia()
            else:
                break
Beispiel #16
0
def save(data):
    sql_con = Sqlite()
    name = data.get('name')
    domain_name = data.get('domain_name')
    url_path = data.get('url_path')
    method = data.get('method')
    is_re = data.get('is_re')
    status_code = data.get('status_code') if method == '0' else 'null'
    response = data.get('response') if method == '0' else data.get('fields')
    is_file = data.get('is_file') if method == '0' else 'null'
    is_valid = 1

    insert_date = (int(time.time()*1000), name, domain_name, url_path, status_code, response,
                   is_file, is_re, method, is_valid, int(time.time()))
    sql_con.cur.execute(INSERT_SQL.format(table_name, FIELD, insert_date))
    sql_con.con.commit()
    logger.info(f'{name}保存成功')
    del sql_con
Beispiel #17
0
def update(data):
    sql_con = Sqlite()
    ID = data.get('ID')
    name = data.get('name')
    domain_name = data.get('domain_name')
    url_path = data.get('url_path')
    is_re = data.get('is_re')
    method = data.get('method')
    status_code = data.get('status_code') if method == '0' else 'null'
    response = data.get('response') if method == '0' else data.get('fields')
    is_file = data.get('is_file') if method == '0' else 'null'


    update_date = f"name = '{name}', domain_name = '{domain_name}', url_path = '{url_path}', status_code = {status_code}, " \
                  f"response = '{response}', is_file = {is_file}, is_regular = {is_re}, method = {method}, update_time = {int(time.time())}"

    sql_con.cur.execute(UPDATE_SQL.format(table_name, update_date, ID))
    sql_con.con.commit()
    logger.info(f'{ID}更新成功')
    del sql_con
Beispiel #18
0
def main():
    # try:
    sqlite = Sqlite(sqlite_settings)
    log_file, log_pos = sqlite.getPositionorCreate()
    print("from sqlite info: {},{}".format(log_file, log_file))
    stream = create_stream(log_file, log_pos)
    stream = create_stream()
    for binlogevent in stream:
        print(binlogevent.event_type)
        log_file, log_pos = sqlite.getPositionorCreate()
        print("from sqlite info: {},{}".format(log_file, log_pos))

        handler = GeneralHandler(binlogevent)
        results = handler.toKafka()
        if results:
            sqlite.updatePosition(stream.log_file, stream.log_pos)
        print('stream info {},{}'.format(stream.log_file, stream.log_pos))
        print('success one')

    stream.close()
Beispiel #19
0
 def __init__(self):
   Sqlite.__init__(self)
Beispiel #20
0
 def todb(self):
     db = Sqlite(sqlite_settings)
     # print(db.getPositionorCreate(self.log_file,self.position))
     db.updatePosition(self.log_file, self.position)
 def __init__(self):
   Sqlite.__init__(self)
   #This table must be included in the default schema (see evolutions)
Beispiel #22
0
def home(request):
    sql_con = Sqlite()
    sql_con.cur.execute(SELECT_SQL.format(table_name))
    data = sql_con.cur.fetchall()
    del sql_con
    return data
Beispiel #23
0
class Preferences(QDialog, preferences_ui.Ui_Dialog):

    def __init__(self):
        QDialog.__init__(self)
        preferences_ui.Ui_Dialog.__init__(self)
        Dialog_Preferences = QDialog()
        self.setupUi(Dialog_Preferences)

        self.sqlite = Sqlite()
        self.initialise()

        """ Configuration SLOT"""
        self.connect(self.radioButton, SIGNAL("clicked()"), self.ajouter_comic)
        self.connect(self.radioButton_2, SIGNAL("clicked()"),
                     self.ajouter_manga)
        self.connect(self.pushButton_3, SIGNAL("clicked()"),
                     self.ajouter_sqlite)
        self.connect(self.radioButton_3, SIGNAL("clicked()"),
                     self.supprimer_comic)
        self.connect(self.radioButton_4, SIGNAL("clicked()"),
                     self.supprimer_manga)
        self.connect(self.pushButton_4, SIGNAL("clicked()"),
                     self.supprimer_sqlite)
        self.connect(self.pushButton_5, SIGNAL("clicked()"), self.update_prefs)
        self.connect(self.pushButton, SIGNAL("clicked()"), self.choix_path)
        self.connect(self.pushButton_2,  SIGNAL("clicked()"), Dialog_Preferences.accept)

        Dialog_Preferences.exec_()

    def initialise(self):
        """ Look for preferences in database, and check CheckBox with good options"""
        self.sqlite.connect()
        self.sqlite.c.execute('''select value from glob_prefs where \
                              param="full"''')
        row = self.sqlite.c.fetchall()
        if row:
            if row[0][0] == "True":
                self.checkBox.setChecked(True)
                self.full = 1
            else:
                self.full = 0
        self.sqlite.c.execute('''select value from glob_prefs where \
                              param="archive"''')
        row = self.sqlite.c.fetchall()
        if row:
            if row[0][0] == "True":
                self.checkBox_2.setChecked(True)
                self.archive = 1
            else:
                self.archive = 0
        self.sqlite.c.execute('''select value from glob_prefs where \
                              param="optimise"''')
        row = self.sqlite.c.fetchall()
        if row:
            if row[0][0] == "True":
                self.checkBox_3.setChecked(True)
                self.optimise = 1
            else:
                self.optimise = 0
        self.sqlite.c.execute('''select value from glob_prefs where \
                              param="pdf"''')
        row = self.sqlite.c.fetchall()
        if row:
            if row[0][0] == "True":
                self.checkBox_4.setChecked(True)
                self.pdf = 1
            else:
                self.pdf = 0
        self.sqlite.c.close()

    def ajouter_comic(self):
        """ Put prefered comics in comboBox"""
        i = 0
        self.ajout = "comics"
        self.comboBox.clear()
        self.sqlite.connect()
        self.sqlite.c.execute('''select name from comics order by name''')
        row = self.sqlite.c.fetchall()
        lenght = len(row)-1
        while i <= lenght:
            item =  row[i][0]
            self.sqlite.c.execute('''select name from preferences where
                                  name="%s"''' % item)
            row_2 = self.sqlite.c.fetchall()
            if not row_2:
                self.comboBox.addItem(row[i][0])
            i += 1
        self.sqlite.c.close()

    def ajouter_manga(self):
        """ Put prefered mangas in comboBox"""
        i= 0
        self.ajout = "mangas"
        self.comboBox.clear()
        self.sqlite.connect()
        self.sqlite.c.execute('''select name from mangas order by name''')
        row = self.sqlite.c.fetchall()
        lenght = len(row)-1
        while i <= lenght:
            self.sqlite.c.execute("""select name from preferences where
                                  name='%s'""" % (row[i][0]))
            row_2 = self.sqlite.c.fetchall()
            if not row_2:
                self.comboBox.addItem(row[i][0])
            i += 1
        self.sqlite.c.close()

    def ajouter_sqlite(self):
        """ Add a comic/manga in preferences table"""
        self.sqlite.connect()
        name = (self.comboBox.currentText())
        self.sqlite.c.execute("""insert into preferences values(?,?)""",
                              (self.ajout,str(name)))
        self.sqlite.conn.commit()
        self.sqlite.c.close()
        if self.ajout == "mangas":
            self.ajouter_manga()
        else:
            self.ajouter_comic()

    def supprimer_comic(self):
        """ Delete a comic in preferences table in database"""
        i = 0
        self.comboBox_2.clear()
        self.suppression = "comics"
        self.sqlite.connect()
        self.sqlite.c.execute("""select name from preferences where \
                              table_ref='comics'""")
        row = self.sqlite.c.fetchall()
        lenght = len(row) -1
        while i<= lenght:
            self.comboBox_2.addItem(row[i][0])
            i += 1
        self.sqlite.c.close()

    def supprimer_manga(self):
        """ Delete a manga in preferences table"""
        i = 0
        self.comboBox_2.clear()
        self.suppression = "mangas"
        self.sqlite.connect()
        self.sqlite.c.execute('''select name from preferences where \
                              table_ref="mangas"''')
        row = self.sqlite.c.fetchall()
        lenght = len(row) -1
        while i<= lenght:
            self.comboBox_2.addItem(row[i][0])
            i += 1
        self.sqlite.c.close()


    def supprimer_sqlite(self):
        """ Delete a comic/manga in preference table in database"""
        self.sqlite.connect()
        item = str(self.comboBox_2.currentText())
        self.sqlite.c.execute('''delete from preferences where name="%s"''' % item)
        self.sqlite.conn.commit()
        if self.suppression == "mangas":
            self.supprimer_manga()
        else:
            self.supprimer_comic()



    def update_prefs(self):
        """ Update preferences in database"""
        self.sqlite.connect()
        if self.checkBox.isChecked():
            if self.full == 0:
                self.sqlite.c.execute('''update glob_prefs set value="True" where \
                                      param="full"''')
                self.full = 1
        else:
            if self.full == 1:
                self.sqlite.c.execute('''update glob_prefs set value="False" where \
                                      param="full"''')
                self.full = 0
        if self.checkBox_2.isChecked():
            if self.archive == 0:
                self.sqlite.c.execute('''update glob_prefs set value="True" where \
                                      param="archive"''')
                self.archive = 1
        else:
            if self.archive == 1:
                self.sqlite.c.execute('''update glob_prefs set value="False" where \
                                      param="archive"''')
                self.archive = 0
        if self.checkBox_3.isChecked():
            if self.optimise == 0:
                self.sqlite.c.execute('''update glob_prefs set value="True" where \
                                      param="optimise"''')
                self.optimise = 1
        else:
            if self.optimise == 1:
                self.sqlite.c.execute('''update glob_prefs set value="False" where \
                                      param="optimise"''')
                self.optimise = 0
        if self.checkBox_4.isChecked():
            if self.pdf == 0:
                self.sqlite.c.execute('''update glob_prefs set value="True" where \
                                      param="pdf"''')
                self.pdf = 1
        else:
            if self.pdf == 1:
                self.sqlite.c.execute('''update glob_prefs set value="False" where \
                                      param="pdf"''')
                self.pdf = 0
        self.sqlite.conn.commit()
        self.sqlite.c.close()

    def choix_path(self):
        """ Choose download path"""
        self.sqlite.connect()
        self.sqlite.c.execute('''select value from glob_prefs where \
                              param="path"''')
        row = self.sqlite.c.fetchall()
        if row:
            path = row[0][0]
        choix_path = QFileDialog.getExistingDirectory(self)
        if row:
            print str(choix_path)
            self.sqlite.c.execute('''update glob_prefs set value="%s" \
                              where param="path"''' % choix_path)
        self.sqlite.conn.commit()
        self.sqlite.c.close()
 def __init__(self):
     self.__fig = plt.figure()
     self.__ax = self.__fig.add_subplot(1, 1, 1)
     self.__sqlite = Sqlite()
Beispiel #25
0
def delete(ID):
    sql_con = Sqlite()
    sql_con.cur.execute(DELETE_SQL.format(table_name, ID))
    sql_con.con.commit()
    logger.info(f'{ID} 删除成功')
    del sql_con
Beispiel #26
0
def edit(ID):
    sql_con = Sqlite()
    sql_con.cur.execute(EDIT_SQL.format(table_name, ID))
    data = sql_con.cur.fetchall()
    return data[0]
Beispiel #27
0
class Manga(object):

    def __init__(self, manga=None, path=None, archive=None, full=None, useComix=None, url=None, pdf=None):
        """ Init variables"""
        self.manga = manga.replace(' ', '_')
        self.path = path
        self.archive = archive
        self.full = full
        self.useComix = useComix
        self.url = url
        self.pdf= pdf

        self.headers = { 'User-Agent' : 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)' }

        if self.archive == "True":
            self.control_path(self.path+"/archives/"+self.manga)
        if self.pdf == "True":
            self.control_path(self.path+"/pdf/"+self.manga)
        self.parseManga = self.parse_manga()

        """ Look if manga folder contains Chapters"""
        if not self.parseManga[1]:
            print "Le manga ne contient aucun chapitre"
            print "Téléchargement arrêté"
        else:
            self.sqlite = Sqlite()

            if self.full == "False":
                self.prepare_download()
                self.single_dl()
            else:
                self.prepare_download()
                self.full_dl()

    def init_dl_rule(self):
        """ Look for last chapter downloaded in database"""
        self.sqlite.connect()
        self.sqlite.c.execute("select * from dl_rule where comic='%s'" % self.manga)
        row = self.sqlite.c.fetchall()
        if not row:
            self.sqlite.c.execute("insert into dl_rule values(?,?)",(self.manga, '0'))
            self.sqlite.conn.commit()
            self.start_i = 0
            self.start = self.parseManga[1][0]
            return True
        else:
            self.start_i = int(row[0][1])
            nbr_l = len(self.parseManga[1]) - 1
            if self.start_i <= nbr_l :
                self.start = self.parseManga[1][self.start_i]
                return True
            else:
                return False
        self.sqlite.c.close

    def prepare_download(self):
        """ define local paths for download"""
        test_dl = self.init_dl_rule()
        if test_dl is not False :
            self.normalize_chapter()
            self.urlDl = self.url+self.chapter+"/"
            self.pathDl = self.path+"/download/"+self.manga+"/"+self.chapter
            self.control_path(self.pathDl)


    def single_dl(self):
        """ Single chapter download"""
        self.download()
        self.start_i += 1
        self.sqlite.connect()
        self.sqlite.c.execute("update dl_rule set data=(?) where comic=(?)", (self.start_i, self.manga))
        self.sqlite.conn.commit()
        self.sqlite.c.close()
        if self.pdf == "True":
            self.make_pdf()
        if self.archive == "True":
            self.make_archive()



    def full_dl(self):
        """All chapter dowload """
        while self.start_i <= self.parseManga[0] - 1:
            self.single_dl()
            self.prepare_download()

    def control_path(self, path):
        """ Check if download path exists"""
        if not os.path.exists(path):
            try:
                os.makedirs(path, mode=0755)
            except OSError, e:
                print e.errno, e.strerror, e.filename
Beispiel #28
0
def reload(request):
    sql_con = Sqlite()
    sql_con.cur.execute("SELECT * FROM {} WHERE is_valid = 1 ORDER BY UPDATE_TIME DESC;".format(table_name))
    data = sql_con.cur.fetchall()
    del sql_con
    return data
Beispiel #29
0
class DLComix(QMainWindow, dlcomix_ui.Ui_DLComix):

    def __init__(self):
        QMainWindow.__init__(self)
        dlcomix_ui.Ui_DLComix.__init__(self)

        self.headers = { 'User-Agent' : 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)' }

        self.sqlite = Sqlite()
        self.setupUi(self)
        self.init_options()
        self.statusbar.showMessage(self.trUtf8("Prêt"))


        """ Configuration SLOT"""
        self.connect(self.pushButton, SIGNAL("clicked()"),
                     self.update_database)
        self.connect(self.actionQuitter, SIGNAL("triggered()"), qApp,
                     SLOT("quit()"))
        self.connect(self.actionPreferences, SIGNAL("triggered()"),
                     self.preferences)
        self.connect(self.actionA_Propos, SIGNAL("triggered()"),
                     self.apropos)
        self.connect(self.radioButton, SIGNAL("clicked()"), self.combo_comic)
        self.connect(self.radioButton_2, SIGNAL("clicked()"), self.combo_manga)
        self.connect(self.pushButton_2,  SIGNAL("clicked()"),  self.telecharger_prefs)
        self.connect(self.pushButton_3, SIGNAL("clicked()"), self.telecharger)
        self.connect(self.pushButton_4, SIGNAL("clicked()"), self.init_options)


    def init_options(self):
        """ Look for  preferences in database and check the checkBox with available options  """
        self.check_preferences()
        if self.full == "True":
            self.checkBox.setChecked(True)
        if self.archive == "True":
            self.checkBox_2.setChecked(True)
        if self.optimise == "True":
            self.checkBox_3.setChecked(True)
        if self.pdf == "True":
            self.checkBox_4.setChecked(True)

    def update_database(self):
        """ Update database with available comics and mangas"""
        self.initialise_comic()
        self.initialise_manga()
        self.sqlite.c.close()

    def telecharger(self):
        """ Make a download of the comic/manga selected in the main window """

        """ Define preferences"""
        if self.checkBox.isChecked():
            self.full = "True"
        else:
            self.full = "False"
        if self.checkBox_2.isChecked():
            self.archive = "True"
        else:
            self.archive = "False"
        if self.checkBox_3.isChecked():
            self.optimise = "True"
        else:
            self.optimise = "False"
        if self.checkBox_4.isChecked():
            self.pdf = "True"

        self.sqlite.connect()
        """ Define if target is Manga or Comic and launch appropriate Class"""
        if self.radioButton_2.isChecked():
            self.sqlite.c.execute("select * from mangas where name='%s'" %
                                  self.comboBox.currentText())
            for row in self.sqlite.c:
                manga = Manga(row[0], self.path, self.archive, self.full,
                              self.optimise, row[1],  self.pdf)
        elif self.radioButton.isChecked():
            self.sqlite.c.execute("select * from comics where name='%s'" %
                                  self.comboBox.currentText())
            for row in self.sqlite.c:
                comic = Gocomics(row[0], self.path, self.archive, self.full,
                              self.optimise, row[1])
        elif not self.radioButton.isChecked() and not self.radioButton_2.isChecked():
            QMessageBox.warning(None,
                self.trUtf8("Téléchargement"),
                self.trUtf8("""Veuillez sélectionner un manga ou comic avant de lancer le téléchargement"""))
        self.sqlite.c.close()


    def telecharger_prefs(self):
        """ Launch download of manga/comic recorded in preferences"""
        i = 0
        self.check_preferences()
        self.sqlite.connect()
        self.sqlite.c.execute('''select * from preferences''')
        row = self.sqlite.c.fetchall()
        lenght = len(row) -1
        while i <= lenght:
            if row[i][0] == "mangas":
                self.sqlite.c.execute("select * from mangas where name='%s'" %
                                      row[i][1])
                row_2 = self.sqlite.c.fetchall()
                manga = Manga(row_2[0][0],  self.path,  self.archive,  self.full,
                              self.optimise, row_2[0][1],  self.pdf )
            if row[i][0] == "comics":
                self.sqlite.c.execute("select * from comics where name='%s'" %
                                      row[i][1])
                row_2 = self.sqlite.c.fetchall()
                comic = Gocomics(row_2[0][0],  self.path,  self.archive,  self.full,
                                 self.optimise,  row_2[0][1])
            i += 1
        if not row:
            msgPreferences = QMessageBox.question(None,
                self.trUtf8("Téléchargement"),
                self.trUtf8("""Vous n'avez par encore ajouté de comics ou mangas dans les préférences

Souhaitez vous le faire maintenant ?"""),
                QMessageBox.StandardButtons(\
                    QMessageBox.No | \
                    QMessageBox.Yes))
            if (msgPreferences == QMessageBox.Yes):
                self.preferences()
        self.sqlite.c.close()


    def combo_comic(self):
        """ Generate the Comic List in the comboBox"""
        i= 0
        self.checkBox_3.setEnabled(False)
        self.checkBox_4.setEnabled(False)
        self.comboBox.clear()
        self.sqlite.connect()
        self.sqlite.c.execute('''select name from comics order by name''')
        row = self.sqlite.c.fetchall()
        lenght = len(row)-1
        while i <= lenght:
            self.comboBox.addItem(row[i][0])
            i += 1
        self.sqlite.c.close()

    def combo_manga(self):
        """ Generate the Manga list in ComboBox"""
        i = 0
        self.checkBox_3.setEnabled(True)
        self.checkBox_4.setEnabled(True)
        self.comboBox.clear()
        self.sqlite.connect()
        self.sqlite.c.execute('''select name from mangas order by name''')
        row = self.sqlite.c.fetchall()
        lenght = len(row)-1
        while i <= lenght:
            self.comboBox.addItem(row[i][0])
            i += 1
        self.sqlite.c.close()
    """ Fonctions tierces"""

    def check_preferences(self):
        """ Select Preferences in database"""

        """ Look if database exist. If not, initialise it"""
        sqliteFile = os.path.expanduser ('~')+'/.dlcomix/dlcomix.sqlite'
        if not os.path.exists(sqliteFile):
            QMessageBox.information(None,
                self.trUtf8("Information"),
                self.trUtf8("""DLComix effectue une mise a jour necessaire de la base \
                de données avant de démarrer.

Cela peut prendre un peu de temps"""))
            self.sqlite.initialise_sqlite()
            self.update_database()
        self.sqlite.connect()
        self.sqlite.c.execute('''select * from glob_prefs''')
        row = self.sqlite.c.fetchall()
        if not row:
            QMessageBox.information(None,
                self.trUtf8("Information"),
                self.trUtf8("""DLComix effectue une mise a jour necessaire de la base \
                de données avant de démarrer.

Cela peut prendre un peu de temps"""))
            self.update_database()
            self.check_preferences()
        else:
            self.full = row[0][1]
            self.archive = row[1][1]
            self.optimise = row[2][1]
            self.path = row[3][1]
            if len(row)<5:
                self.sqlite.c.execute('''insert into glob_prefs values (?,?)''',
                                      ("pdf","false"))
                self.sqlite.conn.commit()
                self.pdf = "False"
            else:
                self.pdf = row[4][1]
        self.sqlite.c.close()

    def initialise_manga(self):
        """ Initialise the manga list in the database"""
        i = 0
        self.sqlite.connect()
        print ("Initialisation de la liste de manga").decode('utf-8')
        print ("Cela peu prendre un peu de temps").decode('utf-8')
        print ("Connection au serveur").decode('utf-8')
        req = urllib2.Request('http://99.198.113.68/manga', headers = self.headers)
        response = urllib2.urlopen(req)
        source = response.read()
        link = re.findall('<li><a href="(.*?)">',source)
        link.remove(link[0])
        n = len(link)-1
        while i <= n:
            if link[i].count('.jpg')>0:
                link.remove(link[i])
                n -= 1
                i -= 1
            i += 1
        mangaList = re.findall('"> (.*?)/</a></li>',source)
        n = len(mangaList)-1
        self.sqlite.c.execute('delete from mangas')
        i= 0
        while i <= n:
            if mangaList[i].count('_') > 0:
                mangaList[i] = mangaList[i].replace('_',' ')
            tmpManga = str(mangaList[i])
            linkManga = "http://99.198.113.68/manga/"+link[i]
            self.sqlite.c.execute("""insert into mangas values(?,?)""", (tmpManga,linkManga))
            i += 1
        """ TODO : make an update an not a complete insertion to purpose a new manga window"""
        self.sqlite.c.execute('delete from mangas where name like "Chapter-%"')
        self.sqlite.conn.commit()
        self.sqlite.c.close()
        print ("Fin de l'initialisation de la liste de manga").decode('utf-8')

    def initialise_comic(self):
        """ Initialise comic list in database"""
        i = 0
        self.sqlite.connect()
        """ TODO : make an update an not a complete insertion to purpose a new comic window"""
        self.sqlite.c.execute('delete from comics')
        print ("Initialisation de la liste de comic").decode('utf-8')
        print ("Connection au serveur").decode('utf-8')
        req = urllib2.Request('http://www.gocomics.com/features',  headers = self.headers)
        response = urllib2.urlopen(req)
        self.comicList = self.parse_comic(response)
        self.comic_db()
        req = urllib2.Request('http://www.gocomics.com/explore/editorial_lists',  headers = self.headers)
        response = urllib2.urlopen(req)
        self.comicList = self.parse_comic(response)
        self.comic_db()
        req = urllib2.Request('http://www.gocomics.com/explore/sherpa_list',  headers = self.headers)
        response = urllib2.urlopen(req)
        self.comicList = self.parse_comic(response)
        self.comic_db()
        self.sqlite.c.close()
        print ("Fin de l'initialisation de la liste de comic").decode('utf-8')

    def parse_comic(self,  response):
        """ Parse gocomics html page to get necessary informations"""
        source = response.read()
        test = re.findall('<a href="/(.*?)" class="alpha_list updated">(.*?)</a>', source)
        name = ['']*len(test)
        link = ['']*len(test)
        for i in range (0, len(test)):
            name[i] = test[i][1].decode('utf-8').capitalize()
            lk = (test[i][0]).replace(' ','')
            link[i] = ("http://www.gocomics.com/"+lk).decode('utf-8')
        return name, link

    def comic_db(self):
        """ Insert comic list in database"""
        n = len(self.comicList[0])-1
        i = 0
        while i <= n:
            self.sqlite.c.execute("""insert into comics values(?,?)""",
                           (self.comicList[0][i],self.comicList[1][i]))
            i += 1
        self.sqlite.conn.commit()

    """Appel de fenetres"""

    def apropos(self):
        """ Call About window"""
        apropos.Apropos()

    def preferences(self):
        """ Call preferences window"""
        preferences.Preferences()
Beispiel #30
0
#!/usr/bin/python3

from sqlite import Sqlite

obj_s = Sqlite()
obj_s.output_names()