Beispiel #1
0
def main():
    now = datetime.datetime.now()
    log_info('[*] {date} - fetching today\'s eBooks'.format(
        date=now.strftime("%Y-%m-%d %H:%M")))

    packt = None

    try:
        dir_path = os.path.dirname(os.path.dirname(
            os.path.abspath(__file__))) + os.path.sep
        config = config_file(dir_path + "config\prod.cfg")
        packt = Packt(config)
        log_info(packt)

        ip_address()
        log_info('[*] Getting daily free eBook')
        try:
            packt.runDaily()
        except NoBookException as e:
            log_info('[*] ' + e.message)
        except Exception as e:
            log_debug(e)

    except KeyboardInterrupt:
        log_error('[-] Interrupted manually')

    except Exception as e:
        log_debug(e)

    log_info('[*] Done')
Beispiel #2
0
def main():
    parser = argparse.ArgumentParser(
        description='Download FREE eBook every day from www.packtpub.com',
        formatter_class=argparse.ArgumentDefaultsHelpFormatter,
        version='1.3.0')

    parser.add_argument('-c', '--config', required=True, help='configuration file')
    parser.add_argument('-d', '--dev', action='store_true', help='only for development')
    parser.add_argument('-e', '--extras', action='store_true', help='download source code (if exists) and book cover')
    parser.add_argument('-u', '--upload', choices=[SERVICE_DRIVE, SERVICE_DROPBOX], help='upload to cloud')
    parser.add_argument('-a', '--archive', action='store_true', help='compress all file')
    parser.add_argument('-n', '--notify', action='store_true', help='notify via email')
    parser.add_argument('-s', '--store', choices=[DB_FIREBASE], help='store info')

    group = parser.add_mutually_exclusive_group()
    group.add_argument('-t', '--type', choices=['pdf', 'epub', 'mobi'],
        default='pdf', help='specify eBook type')
    group.add_argument('--all', dest='types', action='store_const',
        const=['pdf', 'epub', 'mobi'], help='all eBook types')

    args = parser.parse_args()

    try:
        #ip_address()
        config = config_file(args.config)
        types = parse_types(args)

        packpub = Packpub(config, args.dev)
        packpub.run()
        log_json(packpub.info)

        packpub.download_ebooks(types)
        if args.extras:
            packpub.download_extras()

        if args.archive:
            raise NotImplementedError('not implemented yet!')

        upload = None
        if args.upload is not None:
            upload = Upload(config, args.upload)
            upload.run(packpub.info['paths'])

        if upload is None:
            log_warn('[-] skip store info: missing upload info')
            log_warn('[-] skip notification: missing upload info')
        else:
            if args.store is not None:
                Database(config, args.store, packpub.info, upload.info).store()
            if args.notify:
                Notify(config, packpub.info, upload.info).send_email()

    except KeyboardInterrupt:
        log_error('[-] interrupted manually')
    except Exception as e:
        log_debug(e)
        log_error('[-] something weird occurred, exiting...')
Beispiel #3
0
def main():
    parser = argparse.ArgumentParser(
        description='Download FREE eBook every day from www.packtpub.com',
        formatter_class=argparse.ArgumentDefaultsHelpFormatter,
        version='1.0')

    parser.add_argument('-c', '--config', required=True, help='configuration file')
    parser.add_argument('-d', '--dev', action='store_true', help='only for development')
    parser.add_argument('-e', '--extras', action='store_true', help='download source code (if exists) and book cover')
    parser.add_argument('-u', '--upload', choices=[SERVICE_DRIVE, SERVICE_DROPBOX], help='upload to cloud')
    parser.add_argument('-a', '--archive', action='store_true', help='compress all file')
    parser.add_argument('-n', '--notify', action='store_true', help='notify via email')
    parser.add_argument('-D', '--debug', action='store_true', help='only for debugging')

    group = parser.add_mutually_exclusive_group()
    group.add_argument('-t', '--type', choices=['pdf', 'epub', 'mobi'],
        default='pdf', help='specify eBook type')
    group.add_argument('--all', dest='types', action='store_const',
        const=['pdf', 'epub', 'mobi'], help='all eBook types')

    args = parser.parse_args()

    try:
        #ip_address()
        config = config_file(args.config)
        types = parse_types(args)
        
        packpub = Packpub(config, args.dev)
        if args.debug: #Dumping responses into files
            packpub.set_debug()
            
        packpub.run()
        log_json(packpub.info)

        packpub.download_ebooks(types)
        if args.extras:
            packpub.download_extras()

        if args.archive:
            raise NotImplementedError('not implemented yet!')

        upload = None
        if args.upload is not None:
            upload = Upload(config, args.upload)
            upload.run(packpub.info['paths'])

        if args.notify:
            if upload is not None:
                Notify(config, packpub.info, upload.info).send_email()
            else:
                log_warn('[-] skip notification: missing upload info')
            
    except KeyboardInterrupt:
        log_error('[-] interrupted manually')
    except Exception as e:
        log_debug(e)
        log_error('[-] something weird occurred, exiting...')
Beispiel #4
0
def main():
    parser = argparse.ArgumentParser(
        description="Download FREE eBook every day from www.packtpub.com",
        formatter_class=argparse.ArgumentDefaultsHelpFormatter,
        version="1.0",
    )

    parser.add_argument("-c", "--config", required=True, help="configuration file")
    parser.add_argument("-d", "--dev", action="store_true", help="only for development")
    parser.add_argument("-e", "--extras", action="store_true", help="download source code (if exists) and book cover")
    parser.add_argument("-u", "--upload", choices=[SERVICE_DRIVE, SERVICE_DROPBOX], help="upload to cloud")
    parser.add_argument("-a", "--archive", action="store_true", help="compress all file")
    parser.add_argument("-n", "--notify", action="store_true", help="notify via email")

    group = parser.add_mutually_exclusive_group()
    group.add_argument("-t", "--type", choices=["pdf", "epub", "mobi"], default="pdf", help="specify eBook type")
    group.add_argument(
        "--all", dest="types", action="store_const", const=["pdf", "epub", "mobi"], help="all eBook types"
    )

    args = parser.parse_args()

    try:
        # ip_address()
        config = config_file(args.config)
        types = parse_types(args)

        packpub = Packpub(config, args.dev)
        packpub.run()
        log_json(packpub.info)

        packpub.download_ebooks(types)
        if args.extras:
            packpub.download_extras()

        if args.archive:
            raise NotImplementedError("not implemented yet!")

        upload = None
        if args.upload is not None:
            upload = Upload(config, args.upload)
            upload.run(packpub.info["paths"])

        if args.notify:
            if upload is not None:
                Notify(config, packpub.info, upload.info).send_email()
            else:
                log_warn("[-] skip notification: missing upload info")

    except KeyboardInterrupt:
        log_error("[-] interrupted manually")
    except Exception as e:
        log_debug(e)
        log_error("[-] something weird occurred, exiting...")
Beispiel #5
0
def main():
    parser = argparse.ArgumentParser(
        description='Download FREE eBook every day from www.packtpub.com',
        formatter_class=argparse.ArgumentDefaultsHelpFormatter,
        version='2.2.0')

    parser.add_argument('-c',
                        '--config',
                        required=True,
                        help='configuration file')
    parser.add_argument('-d',
                        '--dev',
                        action='store_true',
                        help='only for development')
    parser.add_argument('-e',
                        '--extras',
                        action='store_true',
                        help='download source code (if exists) and book cover')
    parser.add_argument('-u',
                        '--upload',
                        choices=[SERVICE_DRIVE, SERVICE_DROPBOX, SERVICE_SCP],
                        help='upload to cloud')
    parser.add_argument('-a',
                        '--archive',
                        action='store_true',
                        help='compress all file')
    parser.add_argument('-n',
                        '--notify',
                        choices=[SERVICE_GMAIL, SERVICE_IFTTT, SERVICE_JOIN],
                        help='notify after claim/download')
    parser.add_argument('-s',
                        '--store',
                        choices=[DB_FIREBASE],
                        help='store info')
    parser.add_argument('-o',
                        '--claimOnly',
                        action='store_true',
                        help='only claim books (no downloads/uploads)')

    group = parser.add_mutually_exclusive_group()
    group.add_argument('-t',
                       '--type',
                       choices=['pdf', 'epub', 'mobi'],
                       default='pdf',
                       help='specify eBook type')
    group.add_argument('--all',
                       dest='types',
                       action='store_const',
                       const=['pdf', 'epub', 'mobi'],
                       help='all eBook types')

    args = parser.parse_args()

    now = datetime.datetime.now()
    log_info('[*] {date} - Fetching today\'s books'.format(
        date=now.strftime("%Y-%m-%d %H:%M")))

    packtpub = None

    try:
        config = config_file(args.config)

        #ip_address()
        log_info('[*] getting daily free ebook')
        packpub = Packpub(config, args.dev)
        run(packpub, args, config)

    except KeyboardInterrupt:
        log_error('[-] interrupted manually')

    except Exception as e:
        log_debug(e)
        if args.notify:
            Notify(config, None, None, args.notify).sendError(e, 'global')

    log_info('[*] done')
def main():
    parser = argparse.ArgumentParser(
        description='Download FREE eBook every day from www.packtpub.com',
        formatter_class=argparse.ArgumentDefaultsHelpFormatter,
        version='1.0')

    parser.add_argument('-c', '--config', required=True, help='configuration file')

  #  parser.add_argument('-d', '--dev', action='store_true', help='only for development')
  #  parser.add_argument('-e', '--extras', action='store_true', help='download source code (if exists) and book cover')
  #  parser.add_argument('-u', '--upload', choices=[SERVICE_DRIVE, SERVICE_DROPBOX], help='upload to cloud')
  #  parser.add_argument('-a', '--archive', action='store_true', help='compress all file')
  #  parser.add_argument('-n', '--notify', action='store_true', help='send confirmation email')

    parser.add_argument('-dump', '--dump', action='store_true', help='download all files from your account')


  #  group = parser.add_mutually_exclusive_group()
  #  group.add_argument('-t', '--type', choices=['pdf', 'epub', 'mobi'], default='pdf', help='specify eBook type')
  #  group.add_argument('--all', dest='types', action='store_const', const=['pdf', 'epub', 'mobi'], help='all eBook types')

    args = parser.parse_args()

    try:
        # ip_address()
        config = config_file(args.config)
        # types = parse_types(args)

        # packpub = Packpub(config, args.dev)
        packpub = Packpub(config, None)

        packpub.run()
        log_json(packpub.info)

        ##log_info("[+] DEBUG:     " + type)

        if args.dump:
            packpub.dump_all_library()

        #packpub.get_library_list()

        #if not os.path.exists("ebooks/" + packpub.info['filename']):
        #    log_info("[+] Creating Directory: ebooks/"+packpub.info['filename'])
        #    dirdownload = 'ebooks/' + packpub.info['filename']
        #    os.makedirs(dirdownload)
        #    packpub.download_ebooks_dir(['pdf', 'epub', 'mobi'], dirdownload)
        #    packpub.download_extras_dir(dirdownload)
        #else:
        #    dirdownload = 'ebooks/' + packpub.info['filename']
        #    log_error('[-] Download already done or directory ' + dirdownload + ' exists')

        # packpub.download_ebooks(types)

        #if args.extras:
        #    packpub.download_extras()

        #if args.archive:
        #    raise NotImplementedError('not implemented yet!')

        #if args.upload is not None:
        #    Upload(config, args.upload).run(packpub.info['paths'])

        #if args.notify:
        #    raise NotImplementedError('not implemented yet!')

    except KeyboardInterrupt:
        log_error('[-] interrupted manually')
    except Exception as e:
        log_debug(e)
        log_error('[-] something weird occurred, exiting...')
Beispiel #7
0
def main():
    parser = argparse.ArgumentParser(
        description='Download FREE eBook every day from www.packtpub.com',
        formatter_class=argparse.ArgumentDefaultsHelpFormatter,
        version='2.4.0')

    parser.add_argument('-c', '--config', required=True, help='configuration file')
    parser.add_argument('-d', '--dev', action='store_true', help='only for development')
    parser.add_argument('-e', '--extras', action='store_true', help='download source code (if exists) and book cover')
    parser.add_argument('-u', '--upload', choices=[SERVICE_GOOGLE_DRIVE, SERVICE_ONEDRIVE, SERVICE_DROPBOX, SERVICE_SCP], help='upload to cloud')
    parser.add_argument('-a', '--archive', action='store_true', help='compress all file')
    parser.add_argument('-n', '--notify', choices=[SERVICE_GMAIL, SERVICE_IFTTT, SERVICE_JOIN, SERVICE_PUSHOVER], help='notify after claim/download')
    parser.add_argument('-s', '--store', choices=[DB_FIREBASE], help='store info')
    parser.add_argument('-o', '--claimOnly', action='store_true', help='only claim books (no downloads/uploads)')

    group = parser.add_mutually_exclusive_group()
    group.add_argument('-t', '--type', choices=['pdf', 'epub', 'mobi'],
        default='pdf', help='specify eBook type')
    group.add_argument('--all', dest='types', action='store_const',
        const=['pdf', 'epub', 'mobi'], help='all eBook types')

    args = parser.parse_args()

    now = datetime.datetime.now()
    log_info('[*] {date} - fetching today\'s eBooks'.format(date=now.strftime("%Y-%m-%d %H:%M")))

    packtpub = None

    try:
        dir_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + os.path.sep

        config = config_file(dir_path + args.config)
        packtpub = Packtpub(config, args.dev)

        #ip_address()
        log_info('[*] getting daily free eBook')

        try:
            packtpub.runDaily()
            handleClaim(packtpub, args, config, dir_path)
        except NoBookException as e:
            log_info('[*] ' + e.message)
        except Exception as e:
            log_debug(e)
            if args.notify:
                Notify(config, None, None, args.notify).sendError(e, 'daily')
            return

        lastNewsletterUrlPath = dir_path + 'config/lastNewsletterUrl'
        lastNewsletterUrl = None

        if os.path.isfile(lastNewsletterUrlPath):
            with open(lastNewsletterUrlPath, 'r+') as f:
                lastNewsletterUrl = f.read().strip()

        # the default URL is generated by an Google apps script, see README for details and self-hosting
        currentNewsletterUrl = requests.get(config.get('url', 'url.bookFromNewsletter')).text.strip()

        if currentNewsletterUrl == '':
            log_info('[*] no free eBook from newsletter right now')
        elif not currentNewsletterUrl.startswith('https://www.packtpub.com'):
            log_warn('[-] invalid URL from newsletter: ' + currentNewsletterUrl)
        elif lastNewsletterUrl != currentNewsletterUrl:
            log_info('[*] getting free eBook from newsletter')
            try:
                packtpub.resetInfo()
                packtpub.runNewsletter(currentNewsletterUrl)
                handleClaim(packtpub, args, config, dir_path)

                with open(lastNewsletterUrlPath, 'w+') as f:
                    f.write(currentNewsletterUrl)

            except AlreadyClaimedException as a:
                log_info('[*] book was already claimed, skipping')
                with open(lastNewsletterUrlPath, 'w+') as f:
                    f.write(currentNewsletterUrl)
            except Exception as e:
                log_debug(e)
                if args.notify:
                    Notify(config, None, None, args.notify).sendError(e, 'newsletter')
        else:
            log_info('[*] already got latest ebook from newsletter, skipping')

    except KeyboardInterrupt:
        log_error('[-] interrupted manually')

    except Exception as e:
        log_debug(e)
        if args.notify:
            Notify(config, None, None, args.notify).sendError(e, 'global')

    log_info('[*] done')
Beispiel #8
0
def main():
    parser = argparse.ArgumentParser(
        description='Download FREE eBook every day from www.packtpub.com',
        formatter_class=argparse.ArgumentDefaultsHelpFormatter,
        version='2.1.0')

    parser.add_argument('-c',
                        '--config',
                        required=True,
                        help='configuration file')
    parser.add_argument('-d',
                        '--dev',
                        action='store_true',
                        help='only for development')
    parser.add_argument('-e',
                        '--extras',
                        action='store_true',
                        help='download source code (if exists) and book cover')
    parser.add_argument('-u',
                        '--upload',
                        choices=[SERVICE_DRIVE, SERVICE_DROPBOX, SERVICE_SCP],
                        help='upload to cloud')
    parser.add_argument('-a',
                        '--archive',
                        action='store_true',
                        help='compress all file')
    parser.add_argument('-n',
                        '--notify',
                        choices=[SERVICE_GMAIL, SERVICE_IFTTT, SERVICE_JOIN],
                        help='notify after claim/download')
    parser.add_argument('-s',
                        '--store',
                        choices=[DB_FIREBASE],
                        help='store info')
    parser.add_argument('-o',
                        '--claimOnly',
                        action='store_true',
                        help='only claim books (no downloads/uploads)')

    group = parser.add_mutually_exclusive_group()
    group.add_argument('-t',
                       '--type',
                       choices=['pdf', 'epub', 'mobi'],
                       default='pdf',
                       help='specify eBook type')
    group.add_argument('--all',
                       dest='types',
                       action='store_const',
                       const=['pdf', 'epub', 'mobi'],
                       help='all eBook types')

    args = parser.parse_args()

    now = datetime.datetime.now()
    log_info('[*] {date} - Fetching today\'s books'.format(
        date=now.strftime("%Y-%m-%d %H:%M")))

    try:
        #ip_address()
        config = config_file(args.config)
        types = parse_types(args)

        packpub = Packpub(config, args.dev)
        packpub.run()

        if args.dev:
            log_json(packpub.info)

        log_success('[+] book successfully claimed')

        upload = None

        if not args.claimOnly:
            packpub.download_ebooks(types)

            if args.extras:
                packpub.download_extras()

            if args.archive:
                raise NotImplementedError('not implemented yet!')

            if args.upload is not None:
                upload = Upload(config, args.upload)
                upload.run(packpub.info['paths'])

            if upload is not None and upload is not SERVICE_DRIVE:
                log_warn('[-] skip store info: missing upload info')
            elif args.store is not None:
                Database(config, args.store, packpub.info, upload.info).store()

        if args.notify:
            upload_info = None

            if upload is not None:
                upload_info = upload.info

            Notify(config, packpub.info, upload_info, args.notify).run()

    except KeyboardInterrupt:
        log_error('[-] interrupted manually')
    except Exception as e:
        log_debug(e)
        log_error('[-] something weird occurred, exiting...')
        # Crear cola de procesos concurrentes.
        tasks = []
        for i in range(number_of_parallel_downloads):
            loop = asyncio.get_event_loop()
            task = loop.create_task(worker('worker-{%i}' % i))
            tasks.append(task)

        # Arrancamos bot con token
        client.start(bot_token=str(bot_token))
        client.add_event_handler(handler)

        # Pulsa Ctrl+C para detener
        loop.run_until_complete(
            tg_send_message("Telethon Downloader Started: {}".format(VERSION)))
        logger.info("%s" % VERSION)
        config_file()
        logger.info("********** START TELETHON DOWNLOADER **********")

        client.run_until_disconnected()
    finally:
        # Cerrando trabajos.

        #f.close()
        for task in tasks:
            task.cancel()
        # Cola cerrada
        # Stop Telethon
        client.disconnect()
        logger.info("********** STOPPED **********")