Example #1
0
 def __upload_avatar(self):
     """ Upload the avatar """
     self.image = request.files['file']
     
     if not self.message is None:
         return False
             
     if len(self.image.filename) > 3:
         up = Upload(self.user['username'], self.image)
         
         # ~
         if not up.allowed_file():
             self.message = g.users_msg('error_upload_1')
             
         # ~
         elif not up.check_aspect_ratio(1):
             self.message = g.users_msg('error_upload_2')
         
         # ~
         else:
             up.avatar_upload()
             self.list_images = up.names_list
             return True
             
     return False
Example #2
0
def handleClaim(packtpub, args, config, dir_path):
    if args.dev:
        log_json(packtpub.info)

    log_success('[+] book successfully claimed')

    upload = None
    upload_info = None

    if not args.claimOnly:
        types = parse_types(args)

        packtpub.download_ebooks(types, dir_path)

        if args.extras:
            packtpub.download_extras(dir_path)

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

        if args.upload is not None:
            upload = Upload(config, args.upload)
            upload.run(packtpub.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, packtpub.info, upload.info).store()

    if args.notify:
        if upload is not None:
            upload_info = upload.info

        Notify(config, packtpub.info, upload_info, args.notify).run()
Example #3
0
 def __init__(self, file, session, ydm, config=Config()):
     self.session = session
     self.config = config.config
     self.ydm = ydm
     self.callback = "jQuery32103773561319591048_1534950307354"
     upload = Upload(file, self.session, self.callback)
     self.info = upload.main()
     self.submit = self.submit()
Example #4
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...')
Example #5
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...')
Example #6
0
async def upload():

    print("Proceso upload inicializado")

    with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
        s.bind(("127.0.0.1", 8000))
        s.listen(0)
        while True:
            conn, addr = s.accept()
            client = Upload(conn, addr, torrent)
            client.start()
Example #7
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...")
Example #8
0
    def exec_upload(self):
        if self._module is not None:
            try:
                u = getattr(self._module.plugin, 'Upload')(self._config)
            except AttributeError:
                u = Upload(self._config)
        else:
            u = Upload(self._config)

        u.run()

        print 'Successfully uploaded the project.'
Example #9
0
def do_android_upload():
	upload = Upload('upload', ('.png','.jpg','.jpeg'), 3 * 1024 * 1024)
	if not upload.has_uploaded():
		return '-1'
	
	if not upload.check_upload_size():
		return '-1'
	
	if not upload.check_extension():
		return '-1'
	
	return str(parse_upload(upload))
Example #10
0
def loop_histroy():
    while 1:
        if gl.CREATEDQUE.empty():
            query = Upload.select().where(Upload.uploadflag == False).limit(5)
            for i in query:
                gl.CREATEDQUE.put({'fresh': False, 'path': i.path, 'id': i.id})
        time.sleep(2)
Example #11
0
def upload(name):
    """
	This page allows a user to upload a text or image file.
	"""
    error = valid_user(name)
    if error is None:
        if request.method == 'POST':
            file = request.files['file']
            if file and valid_file(file.filename):
                # Sanitize the filename, save the file to the uploads
                # folder, and add the file and owner info to the file database.
                filename = secure_filename(file.filename)
                file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
                file_instance = Upload(name, filename)

                flash('File was uploaded successfully.')
                return redirect(url_for('files', name=name))
            else:
                flash("Invalid filename or file type.")
        return render_template('upload.html')

    # If an error occurs, display the error and
    # redirect to the appropriate page.
    display(error)
    if 'logged_in' in session:
        return redirect(url_for('upload', name=session['logged_in']))
    else:
        return redirect(url_for('login'))
Example #12
0
    def saveInit(self):
        QtGui.QDialog.__init__(self)

        self.strip_path = self.cap.strip_path
        self.upld = Upload(self.strip_path)

        self.save()
Example #13
0
def do_normal_upload():
	upload = Upload('upload', ('.png','.jpg','.jpeg'), 3 * 1024 * 1024)
	if not upload.has_uploaded():
		return View('no_upload').render()	
	
	if not upload.check_upload_size():
		return View('upload_size').render()
		
	if not upload.check_extension():
		return View('upload_extension').render()
	
	id = parse_upload(upload)
	if id == -1:
		return View('recognize_failed', { 'img' : str(upload) } ).render()
	
	return View('recognize', { 'id' : id, 'name' : nn.get_name_by_id(id), 'img' : str(upload) } ).render()
Example #14
0
    def addNewTasks(self):

        if self.lock.acquire(True):
            try:
                if self.running:
                    #logging.debug("task complete! time for next task!")
                    if isinstance(self.currentTask, Upload):
                        #logging.debug('we completed a download')
                        # after downloading - we check for uploads
                        # but first we relax for 5 seconds
                        # it's important to relax - to give swfit a few
                        # seconds to catch up
                        if not self.currentTask.hadWorkToDo:
                            # if you didn't have any work to do - take a break!
                            if not self._starting:
                                self.taskList.put(Sleep(self.updateInterval))
                        else:
                            #logging.info('there was work to do - no resting!')
                            pass
                        download = Download(self.objectStore, self.outputQueue)
                        self.taskList.put(download)
                        self._starting = False
                    elif isinstance(self.currentTask, Download):
                        #logging.debug('we completed a upload')
                        if not self.currentTask.hadWorkToDo:
                            # if you didn't have any work to do - take a break!
                            if not self._starting:
                                self.taskList.put(Sleep(self.updateInterval))
                        else:
                            #logging.info('there was work to do - no resting!')
                            pass
                        upload = Upload(self.objectStore, self.outputQueue)
                        self.taskList.put(upload)
                        self._starting = False
                    elif isinstance(self.currentTask, Authenticate):
                        if self.currentTask.isAuthenticated:
                            #upload = Upload(self.objectStore,
                            #    self.outputQueue)
                            #self.taskList.put(upload)
                            download = Download(self.objectStore,
                                                self.outputQueue)
                            self.taskList.put(download)
                        else:
                            sleep = Sleep(self.currentTask.retryWait)
                            #logging.info('failed to auth'
                            #             ' - sleeping for %r'
                            #             % self.currentTask.retryWait)
                            self.taskList.put(sleep)
                            self.taskList.put(self.currentTask)
                    elif isinstance(self.currentTask, Sleep):
                        pass
                    elif isinstance(self.currentTask, update.Update):
                        if self.currentTask.hadWorkToDo:
                            self.scheduleRestart()
                    else:
                        logging.warn('unhandeled task completion!')
            finally:
                self.lock.release()
	def __init__(self):
		# Default variables that are only used in this class
		self.search_terms = [] # Empy by default (empty = don't search)
		self.search_tags = [] # Only use cards with these tags (empty = ignore)
		self.sentence_field = {} # Dictionary containing which field to
								 # use as the sentence. Only fields in
								 # models in the dictionary will be used.
								 # In the form { modelname: fieldname }
								 						 
		self.tag_strip = [		# Tags to strip from tags obtained from cards.
				'Media-Missing', # Remove anki specific tags that we don't want on the site.
				'Leech',
				'Extr',
		]
		
		
		# Call the usual __init__ function
		Upload.__init__(self)
Example #16
0
def upload():
    program = optparse.OptionParser(usage='qiniu_upload upload [OPTIONS]',
                                    add_help_option=False)
    program.add_option('--config', '-c', help='set config path')
    program.add_option('--source', '-s', help='set local file(directory) path')

    options, arguments = program.parse_args()
    if options.config and options.source:
        if not path.exists(options.config):
            program.error('config file `%s` not found' % options.config)

        if not path.exists(options.source):
            program.error('local file(directory) `%s` not found' %
                          options.source)

        upload = Upload(options.source, options.config)
        upload.run()
    else:
        program.print_help()
Example #17
0
 def __init__(self):
     super(mywindow, self).__init__()
     self.setupUi(self)
     self.setWindowTitle("七牛上传辅助工具V1.0")
     self.putFileBtn.clicked.connect(self.submit)  # 上传按钮
     self.putUnityBtn.clicked.connect(self.submitUnity)  # Unity热更新上传按钮
     self.openFileBtn.clicked.connect(self.showFileSelector)
     # self.bucketSpinner.addItem("kingmahjong-test")
     # self.bucketSpinner.addItem("kingmahjong")
     for item in self.buckets:
         self.bucketSpinner.addItem(item["bucket"])
     self.originPathEdit.setPlaceholderText('如C://aaa/abc/或C://aaa/abc.jpg')
     self.destPathEdit.setPlaceholderText(
         '如res/image/或res/image/abc.jpg(选填)')
     self.destPathEdit.textChanged.connect(self.resetUrl)
     self.originPathEdit.textChanged.connect(self.resetUrl)
     self.fileSignal.connect(self.printMsg)
     self.progressSignal.connect(self.updateProgress)
     self.upload = Upload()
Example #18
0
def upload():
    program = optparse.OptionParser(
        usage = 'qiniu_upload upload [OPTIONS]',
        add_help_option = False
    )
    program.add_option('--config', '-c', help = 'set config path')
    program.add_option('--source', '-s', help = 'set local file(directory) path')

    options, arguments = program.parse_args()
    if options.config and options.source:
        if not path.exists(options.config):
            program.error('config file `%s` not found' % options.config)

        if not path.exists(options.source):
            program.error('local file(directory) `%s` not found' % options.source)

        upload = Upload(options.source, options.config)
        upload.run()
    else:
        program.print_help()
def save2html_result(userName, root, bucket =BUCKET):
    br = webdriver.PhantomJS()
    br.get(root + "/"+ userName+"/results")
    #time.sleep(10)
    # wait until dynamic content is loaded
    try:
        element = WebDriverWait(br, 6).until(
            EC.presence_of_element_located((By.XPATH, "//tbody"))
        )
    except Exception as e:
        print("no-results: "+ userName)
    finally:
        html = br.page_source.encode('utf-8')
        br.quit()
    
    # change relative path to absolute path    
    html = html.replace(b"src=\"//", b"src=\"https://")
    html = html.replace(b"src=\"/", ("src=\""+root+"/").encode())    
    html = html.replace(b"href=\"//", b"href=\"https://")
    html = html.replace(b"href=\"/", ("href=\""+root+"/").encode())
    
    # output to html file: 
    # create directory (if not exist) and file
    """
    filename = saveDir+userName+"/"+userName+"_results.html"
    if not os.path.exists(os.path.dirname(filename)):
        try:
            os.makedirs(os.path.dirname(filename))
        except OSError as exc: # Guard against race condition
            if exc.errno != errno.EEXIST:
                raise
    with open(filename, "wb") as f:
        f.write(html)
        f.close()
    """
        
    # sent result to s3 drive TODO: clean files
    #Upload.upload(os.path.dirname(filename),userName+"/")
    userName=userName.split('/')[-1] #bug fix "/users/176217/lionel-pigou"
    Upload.upload_wo_createfile(bucket, html, '!CHECK/', userName+"_results.html")	
    return
Example #20
0
def save2html_result(userName, root, bucket=BUCKET):
    br = webdriver.PhantomJS()
    br.get(root + "/" + userName + "/results")
    #time.sleep(10)
    # wait until dynamic content is loaded
    try:
        element = WebDriverWait(br, 6).until(
            EC.presence_of_element_located((By.XPATH, "//tbody")))
    except Exception as e:
        print("no-results: " + userName)
    finally:
        html = br.page_source.encode('utf-8')
        br.quit()

    # change relative path to absolute path
    html = html.replace(b"src=\"//", b"src=\"https://")
    html = html.replace(b"src=\"/", ("src=\"" + root + "/").encode())
    html = html.replace(b"href=\"//", b"href=\"https://")
    html = html.replace(b"href=\"/", ("href=\"" + root + "/").encode())

    # output to html file:
    # create directory (if not exist) and file
    """
    filename = saveDir+userName+"/"+userName+"_results.html"
    if not os.path.exists(os.path.dirname(filename)):
        try:
            os.makedirs(os.path.dirname(filename))
        except OSError as exc: # Guard against race condition
            if exc.errno != errno.EEXIST:
                raise
    with open(filename, "wb") as f:
        f.write(html)
        f.close()
    """

    # sent result to s3 drive TODO: clean files
    #Upload.upload(os.path.dirname(filename),userName+"/")
    userName = userName.split('/')[-1]  #bug fix "/users/176217/lionel-pigou"
    Upload.upload_wo_createfile(bucket, html, '!CHECK/',
                                userName + "_results.html")
    return
Example #21
0
    def __upload_avatar(self):
        """ Upload the avatar """
        self.image = request.files['file']

        if not self.message is None:
            return False

        if len(self.image.filename) > 3:
            up = Upload(self.user['username'], self.image)

            # ~
            if not up.allowed_file():
                self.message = g.users_msg('error_upload_1')

            # ~
            elif not up.check_aspect_ratio(1):
                self.message = g.users_msg('error_upload_2')

            # ~
            else:
                up.avatar_upload()
                self.list_images = up.names_list
                return True

        return False
	def test_css_generator(self):
		'''TEST: Checking CSS File'''
		template = "@font-face {\
			\n\tfont-family: '" + 'prototypo' + "';\
			\n\tsrc: url('" + 'testfont' + ".eot');\
			\n\tsrc: url('" + 'testfont' + ".eot?#iefix') format('embedded-opentype'),\
			\n\turl('" + 'testfont' + ".woff') format('woff'),\
			\n\turl('" + 'testfont' + ".ttf') format('truetype'),\
			\n\turl('" + 'testfont' + ".svg#ywftsvg') format('svg');\
			\n\tfont-style: normal;\
			\n\tfont-weight: normal;\
			\n}\n\n"
		self.assertEqual(Upload.css_generator('.', 'testfont', 'prototypo'), template)
Example #23
0
def main():

    imgStoreQueue = Queue.Queue()
    smsQueue = Queue.Queue()

    logging.info ('Initializing Camera Module...')

    myCam = Camera('Camera', imgStoreQueue, smsQueue)
    myCam.setSaveLocation('/home/pi')

    logging.info ('Initializing Upload Module...')

    myUpload = Upload('Upload', imgStoreQueue, smsQueue)

    logging.info ('Initializing SMS Module...')

    logging.info ('App started. Press \'exit\' to quit program.')

    myCam.start()
    myUpload.start()

    try:
        while True:
            strInput = raw_input()
            if strInput == 'exit':
                if myCam.isAlive():
                    myCam.join()
                if myUpload.isAlive():
                    myUpload.join()
                break
    except KeyboardInterrupt as e:
        logging.info("Stopping...")
        if myCam.isAlive():
            myCam.join()
        if myUpload.isAlive():
            myUpload.join()
Example #24
0
def handleClaim(packtpub, args, config, dir_path):
    if args.dev:
        log_json(packtpub.info)

    log_success('[+] book successfully claimed')

    upload = None
    upload_info = None

    if not args.claimOnly:
        types = parse_types(args)

        packtpub.download_ebooks(types, dir_path)

        if args.extras:
            packtpub.download_extras(dir_path)

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

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

        if args.store is not None:
            if args.upload == SERVICE_GOOGLE_DRIVE or args.upload == SERVICE_ONEDRIVE:
                Database(config, args.store, packtpub.info, upload.info).store()
            else:
                log_warn('[-] skip store info: missing upload info')


    if args.notify:
        if upload is not None:
            upload_info = upload.info

        Notify(config, packtpub.info, upload_info, args.notify).run()
Example #25
0
 def run(self):
     while 1:
         try:
             item = gl.CREATEDQUE.get(timeout=1)
             p = self.ini.get_plate(item['path'])
             if item['fresh']:
                 t = time.mktime(time.strptime(p['datetime'], '%Y-%m-%d %H:%M:%S'))
                 query = Upload.insert(timestamp=int(t), uploadflag=True,
                                       path=item['path'],
                                       plateinfo=json.dumps(p))
                 query.execute()
             else:
                 query = Upload.update(uploadflag=True).where(Upload.id == item['id'])
                 query.execute()
             print datetime.datetime.now(), self.t_name, item['path']
             time.sleep(1)
         except Queue.Empty:
             pass
         except Exception as e:
             print e
             time.sleep(1)
         finally:
             if self.is_quit:
                 break
Example #26
0
def main():
    """Method to launch the app."""

    content = DataMgt()
    if not content.is_database_empty():  # check content of table Product
        api = Api()
        api.load_data()  # if yes, launch api request
        liste = Parser(api.api_result)  # parse api result
        liste.clean()  # clean api result
        data = Upload(liste.products_list)
        data.load_category()  # upload table categories content
        data.load_products()  # upload table products content
    session = App()
    session.start()  # launch the client app
Example #27
0
from upload import Upload

uploader = Upload()
uploader.upload('model/alphaZeroV1.h5', 'logs/alphaZeroV10.0.log',
                'logs/alphaZeroV10.0.png')
	def test_font_converter(self):
		'''TEST: Checking converted font file'''
		self.assertTrue(Upload.font_converter(self.fileinfo['filename'], self.fileinfo['format']))
Example #29
0
class mywindow(QtWidgets.QMainWindow, Ui_IndexWindow):
    upload = 0
    fileSignal = QtCore.pyqtSignal(str)
    progressSignal = QtCore.pyqtSignal(int, int)

    buckets = [{
        "bucket": "kingmahjong-test",
        "domain": "http://restest.xinxingtech.cn/"
    }, {
        "bucket": "kingmahjong",
        "domain": "http://res.xinxingtech.cn/"
    }]

    def __init__(self):
        super(mywindow, self).__init__()
        self.setupUi(self)
        self.setWindowTitle("七牛上传辅助工具V1.0")
        self.putFileBtn.clicked.connect(self.submit)  # 上传按钮
        self.putUnityBtn.clicked.connect(self.submitUnity)  # Unity热更新上传按钮
        self.openFileBtn.clicked.connect(self.showFileSelector)
        # self.bucketSpinner.addItem("kingmahjong-test")
        # self.bucketSpinner.addItem("kingmahjong")
        for item in self.buckets:
            self.bucketSpinner.addItem(item["bucket"])
        self.originPathEdit.setPlaceholderText('如C://aaa/abc/或C://aaa/abc.jpg')
        self.destPathEdit.setPlaceholderText(
            '如res/image/或res/image/abc.jpg(选填)')
        self.destPathEdit.textChanged.connect(self.resetUrl)
        self.originPathEdit.textChanged.connect(self.resetUrl)
        self.fileSignal.connect(self.printMsg)
        self.progressSignal.connect(self.updateProgress)
        self.upload = Upload()

    # 显示文件选择器
    def showFileSelector(self):
        # 如果打开文件夹
        if self.dirRadio.isChecked():
            filename = QFileDialog.getExistingDirectory(
                self, "请选择要上传的文件夹", './')
            self.originPathEdit.setText(filename)
        else:
            filename, _ = QFileDialog.getOpenFileName(self, '请选择要上传的文件', './')
            self.originPathEdit.setText(filename)

    def resetUrl(self):
        originPath = self.originPathEdit.text()
        destPath = self.destPathEdit.text()
        originPos = originPath.rfind("/")
        destPos = destPath.rfind("/")
        if self.dirRadio.isChecked():
            # ---------------------上传文件夹时----------------
            # originPath    -> C:/Users/xxx/Desktop/ttt
            # destPath      -> res/image/
            # url           -> http://xxx.cn/res/image/ttt
            # ------------------------------------------------
            url = 'http://xxx.cn/' + destPath + originPath[originPos + 1:]
        else:
            if destPos == len(destPath) - 1:
                # ---------------------上传文件时1----------------
                # originPath    -> C:/Users/xxx/Desktop/ttt/abc.jpg
                # destPath      -> res/image/
                # url           -> http://xxx.cn/res/image/abc.jpg
                # ------------------------------------------------
                url = 'http://xxx.cn/' + destPath + originPath[originPos + 1:]
            else:
                # ---------------------上传文件时2----------------
                # originPath    -> C:/Users/xxx/Desktop/ttt/abc.jpg
                # destPath      -> res/image/ccc.jpg
                # url           -> http://xxx.cn/res/image/ccc.jpg
                # ------------------------------------------------
                url = 'http://xxx.cn/' + destPath
        self.urlEdit.setText(url)

    # 打印上传数据
    def printMsg(self, str):
        self.msgTextEdit.appendPlainText(str)

    def updateProgress(self, progress, totalNum):
        radio = int((progress / totalNum) * 100)
        if progress > 0:
            self.progressLabel.setText('当前进度:' + str(radio) + "%(" +
                                       str(progress) + "/" + str(totalNum) +
                                       ")")
        else:
            self.progressLabel.setText('当前进度:' + str(radio) + "%")
        if radio == 100:
            self.putFileBtn.setEnabled(True)
            self.putUnityBtn.setEnabled(True)

    # 上传单个文件
    def putFile(self):
        # 获取源文件路径
        originPath = self.originPathEdit.text()
        # 获取保存路径
        destPath = self.destPathEdit.text()
        lastPos = destPath.rfind("/")
        # 判断保存最后一位是否为"/"
        if lastPos == len(destPath) - 1:
            # originPath    -> C:/User/xxx/Desktop/abcd.jpg
            # destPath      -> res/image/
            # key           -> res/image/abcd.jpg
            # filename      -> abcd.jpg
            filename = originPath[originPath.rfind("/") + 1:]
            # 如果最后一位是"/",则不需要修改上传文件名
            key = destPath + filename
        else:
            # originPath    -> C:/User/xxx/Desktop/abcd.jpg
            # destPath      -> res/image/bbb.png
            # key           -> res/image/bbb.png
            # 如果最后一位不是"/",则修改上传文件名
            key = destPath
        self.fileSignal.emit("上传文件:" + originPath)
        self.fileSignal.emit("访问路径:" + key)
        # 设置当前bucketName
        bucketName = self.bucketSpinner.currentText()
        self.upload.setBucketName(bucketName)
        ret, _ = self.upload.putFile(originPath, key)
        if ret['key'] == '':
            self.fileSignal.emit("上传失败!")
        else:
            self.fileSignal.emit("上传成功!")
        self.progressSignal.emit(1, 1)

    def putDir(self):
        # 设置当前bucketName
        bucketName = self.bucketSpinner.currentText()
        self.upload.setBucketName(bucketName)
        originPath = self.originPathEdit.text()
        destPath = self.destPathEdit.text()
        totalNum = sum([len(x) for _, _, x in os.walk(originPath)])
        progress = 0
        for root, dirs, files in os.walk(originPath):
            for name in files:
                # originPath->C:/User/xxx/Desktop/ttt
                # pos       ->                   ↑
                # origin    ->C:/User/xxx/Desktop/ttt/bb/cc
                # destPath  ->res/image/
                # relPath   ->ttt/bb/cc/
                # absPath   ->C:/User/xxx/Desktop/ttt/bb/cc/abc.jpg
                # key       ->res/image/ttt/bbb/cc/abc.jpg
                origin = root.replace("\\", "/")
                # 找到最后一个'/'出现的地方
                pos = originPath.rfind("/")
                relPath = origin[pos + 1:] + "/"
                absPath = origin + "/" + name
                key = destPath + relPath + name
                self.fileSignal.emit("上传文件:" + absPath)
                self.fileSignal.emit("访问路径:" + key)
                ret, _ = self.upload.putFile(absPath, key)
                if ret['key'] == '':
                    self.fileSignal.emit("上传失败!")
                else:
                    self.fileSignal.emit("上传成功!")
                progress += 1
                self.progressSignal.emit(progress, totalNum)

    def putUnity(self):
        # originPath     ->C:/User/xxx/Desktop/ttt
        # destPath       ->res/image/
        bucketName = self.bucketSpinner.currentText()
        originPath = self.originPathEdit.text()
        destPath = self.destPathEdit.text()
        # absFolder            -> C:/User/xxx/Desktop/ttt/android/StreamingAssets/
        # absTxtPath           -> C:/User/xxx/Desktop/ttt/android/StreamingAssets/files.txt
        # destRelFolder        -> res/image/ttt/android/StreamingAssets/
        # destTxtRelPath       -> res/image/ttt/android/StreamingAssets/files.txt
        absFolder = ""  # files.txt 绝对文件夹
        absTxtPath = ""  # filex.txt 绝对路径
        destRelFolder = ""  # files.txt 所在目标文件夹
        destTxtRelPath = ""  # files.txt 所在目标路径

        # 遍历文件夹,寻找files.txt文件路径
        for root, dirs, files in os.walk(originPath):
            for name in files:
                if name == "files.txt":
                    absFolder = root.replace("\\", "/") + "/"
                    absTxtPath = absFolder + "files.txt"
                    pos = originPath.rfind("/")
                    destTxtRelPath = destPath + absTxtPath[pos + 1:]
                    destRelFolder = destTxtRelPath[:destTxtRelPath.
                                                   rfind("/")] + "/"
                    break

        # 如果找不到文件,则上传失败
        if absTxtPath == "":
            self.fileSignal.emit("找不到文件:files.txt")
            self.fileSignal.emit("上传失败!")
            self.putFileBtn.setEnabled(True)
            self.putUnityBtn.setEnabled(True)
            return
        else:
            self.fileSignal.emit("找到文件:" + absTxtPath)
            domain = ""
            # 下载远程files.txt文件
            for item in self.buckets:
                if item["bucket"] == bucketName:
                    domain = item["domain"]
                    break
            fileTxtUrl = domain + destTxtRelPath + "?t=" + str(int(
                time.time()))
            self.fileSignal.emit("读取文件:" + fileTxtUrl)
            try:
                file = request.urlopen(fileTxtUrl)
            except:
                # 如果找不到远程文件,则询问是否重新上传
                self.fileSignal.emit("找不到文件:" + fileTxtUrl)
                reply = QMessageBox.information(
                    self, "提示", "找不到远程files.txt,是否新建上传?",
                    QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes)
                if reply == QMessageBox.Yes:
                    llist = []
                    # 打开本地文件,也将内容保存到一个列表中
                    localFile = open(absTxtPath)
                    for line in localFile:
                        llist.append(line)

                    dlist = []
                    for sloc in llist:
                        sloc = sloc.strip()  # 去掉两边空格
                        ploc = sloc.rfind("|")
                        self.fileSignal.emit("需要更新:" + sloc[:ploc])
                        dlist.append(sloc[:ploc])

                    _thread.start_new_thread(self.putList, (
                        dlist,
                        absFolder,
                        absTxtPath,
                        destRelFolder,
                        destTxtRelPath,
                    ))
                    # self.putList()
                    return
                else:
                    self.fileSignal.emit("下载失败!")
                    self.putFileBtn.setEnabled(True)
                    self.putUnityBtn.setEnabled(True)
                return

            if file.getcode() == 200:
                rlist = []  # 远程files.txt内容列表
                llist = []  # 本地files.txt内容列表
                # 找到该文件,将内容保存到一个列表中
                for line in file:
                    rlist.append(line.decode('utf-8'))
                # 打开本地文件,也将内容保存到一个列表中
                localFile = open(absTxtPath)
                for line in localFile:
                    llist.append(line)

                print(len(rlist), len(llist))

                # 遍历两个files.txt内容,将远程与本地不一样的行,或者远程没有的行,存储起来
                dlist = []
                num = 0
                for sloc in llist:
                    isExist = False  # 文件是否存在
                    sloc = sloc.strip()  # 去掉两边空格
                    ploc = sloc.rfind("|")
                    for srem in rlist:
                        # 根据'|'分割字符串
                        srem = srem.strip()  # 去掉两边空格
                        prem = srem.rfind("|")
                        if sloc[:ploc] == srem[:prem]:
                            isExist = True
                            if sloc[ploc + 1:] != srem[prem + 1:]:
                                num += 1
                                self.fileSignal.emit("需要更新:" + sloc[:ploc])
                                dlist.append(sloc[:ploc])
                    if not isExist:
                        self.fileSignal.emit("需要更新:" + sloc[:ploc])
                        dlist.append(sloc[:ploc])

                print(num)
                _thread.start_new_thread(self.putList, (
                    dlist,
                    absFolder,
                    absTxtPath,
                    destRelFolder,
                    destTxtRelPath,
                ))
                # self.putList(dlist, absFolder, absTxtPath, destRelFolder, destTxtRelPath)
            else:
                self.fileSignal.emit("找不到文件:" + fileTxtUrl)
                self.fileSignal.emit("下载失败!")
                self.putFileBtn.setEnabled(True)
                self.putUnityBtn.setEnabled(True)
                return
        return

    # 上传列表
    # absFolder            -> C:/User/xxx/Desktop/ttt/android/StreamingAssets/
    # absTxtPath           -> C:/User/xxx/Desktop/ttt/android/StreamingAssets/files.txt
    # destRelFolder        -> res/image/ttt/android/StreamingAssets/
    # destTxtRelPath       -> res/image/ttt/android/StreamingAssets/files.txt
    def putList(self, dlist, absFolder, absTxtPath, destRelFolder,
                destTxtRelPath):
        if len(dlist) == 0:
            self.fileSignal.emit("没有可以更新的文件...")
            self.fileSignal.emit("更新完成...")
            self.progressSignal.emit(1, 1)
            self.putFileBtn.setEnabled(True)
            self.putUnityBtn.setEnabled(True)
        else:
            dlist.append("files.txt")
            self.fileSignal.emit("需要更新文件一共:" + str(len(dlist)) + "个")
            # 上传文件
            progress = 0
            totalNum = len(dlist)
            # 设置当前bucketName
            bucketName = self.bucketSpinner.currentText()
            self.upload.setBucketName(bucketName)
            for item in dlist:
                absPath = absFolder + item
                key = destRelFolder + item
                metaPath = absPath + ".meta"
                metaKey = key + ".meta"
                self.fileSignal.emit("上传文件:" + absPath)
                self.fileSignal.emit("访问路径:" + key)
                ret, _ = self.upload.putFile(absPath, key)
                if ret['key'] == '':
                    self.fileSignal.emit("上传失败!")
                else:
                    self.fileSignal.emit("上传成功!")
                # self.fileSignal.emit("上传成功!")
                self.fileSignal.emit("上传文件:" + metaPath)
                self.fileSignal.emit("访问路径:" + metaKey)
                ret, _ = self.upload.putFile(metaPath, metaKey)
                if ret['key'] == '':
                    self.fileSignal.emit("上传失败!")
                else:
                    self.fileSignal.emit("上传成功!")
                # self.fileSignal.emit("上传成功!")
                progress += 1
                self.progressSignal.emit(progress, totalNum)

    def submit(self):
        # 清空进度条和消息框
        self.progressSignal.emit(0, 1)
        self.msgTextEdit.clear()
        # 上传的是文件夹
        if self.dirRadio.isChecked():
            path = self.originPathEdit.text()
            if os.path.isdir(path):
                self.putFileBtn.setEnabled(False)
                self.putUnityBtn.setEnabled(False)
                _thread.start_new_thread(self.putDir, ())
            else:
                self.putFileBtn.setEnabled(True)
                self.putUnityBtn.setEnabled(True)
                QMessageBox.warning(self, "提示", "文件夹不存在")
        else:
            path = self.originPathEdit.text()
            if os.path.isfile(path):
                self.putFileBtn.setEnabled(False)
                self.putUnityBtn.setEnabled(False)
                _thread.start_new_thread(self.putFile, ())
            else:
                self.putFileBtn.setEnabled(True)
                self.putUnityBtn.setEnabled(True)
                QMessageBox.warning(self, "提示", "文件不存在")

    def submitUnity(self):
        # 清空进度条和消息框
        self.progressSignal.emit(0, 1)
        self.msgTextEdit.clear()
        if not self.dirRadio.isChecked():
            QMessageBox.warning(self, "提示", "请选择文件夹上传类型")
            return
        path = self.originPathEdit.text()
        if os.path.isdir(path):
            self.putFileBtn.setEnabled(False)
            self.putUnityBtn.setEnabled(False)
            self.putUnity()
        else:
            self.putFileBtn.setEnabled(True)
            self.putUnityBtn.setEnabled(True)
            QMessageBox.warning(self, "提示", "文件夹不存在")
Example #30
0
import sys

from upload import Upload

argvs = sys.argv

test = Upload()
print(test.upload(str(argvs[1])))

Example #31
0
class Root(object):

    stream = Stream()

    video = Video()

    _cp_config = {
        'tools.sessions.on': True,
        'tools.auth.on': True,
        'tools.sessions.locking':
        'explicit',  #this and the acquire_lock and the release_lock statements in the login and logout functions are necessary so that multiple ajax requests can be processed in parallel in a single session
        'response.stream': True
    }

    upload = Upload()

    @cherrypy.expose
    def index(self):

        secrets_file = open("/home/ec2-user/secrets.txt")

        passwords = secrets_file.read().rstrip('\n')

        db_password = passwords.split('\n')[0]

        dbname = "estrewn"

        conn = MySQLdb.connect(
            host=
            'estrewn-production-instance-1.cphov5mfizlt.us-west-2.rds.amazonaws.com',
            user='******',
            passwd=db_password,
            port=3306)

        curs = conn.cursor()

        curs.execute("use " + str(dbname) + ";")

        curs.execute("select unique_id from videos order by upload_time desc;")

        videos = curs.fetchall()

        for video in videos:

            assert (len(video) == 1)

            curs.execute(
                "update videos set last_accessed_time = now(6) where unique_id="
                + str(video[0]) + ";")

            conn.commit()

            curs.execute("select IS_FREE_LOCK(\"" + str(video[0]) + "\")")

            isfreelock = bool(curs.fetchall()[0][0])

            doesfileexist = os.path.isfile('/home/ec2-user/videos/' +
                                           str(video[0]) + '.mp4')

            while not (isfreelock and doesfileexist):

                time.sleep(1)

                curs.execute("select IS_FREE_LOCK(\"" + str(video[0]) + "\")")

                isfreelock = bool(curs.fetchall()[0][0])

                doesfileexist = os.path.isfile('/home/ec2-user/videos/' +
                                               str(video[0]) + '.mp4')

                if (isfreelock and doesfileexist):
                    break
                elif not doesfileexist and isfreelock:
                    curs.execute("select GET_LOCK(\"" + str(video[0]) +
                                 "\",10)")

                    got_lock = bool(curs.fetchall()[0][0])

                    if got_lock:

                        curs.execute(
                            "select video from videos where unique_id=" +
                            str(video[0]) + ";")

                        open('/home/ec2-user/videos/' + str(video[0]) + '.mp4',
                             'w').write(curs.fetchall()[0][0])

                        curs.execute("select RELEASE_LOCK(\"" + str(video[0]) +
                                     "\")")

                        break

        conn.close()

        video_html_string = ""

        for video in videos:

            assert (len(video) == 1)

            video_html_string += "<center><video width=\"640\" height=\"480\" controls>  <source src=\"/stream/?video_id=" + str(
                video[0]) + "\" type=\"video/mp4\"></video></center>"

        is_mobile = False

        if "User-Agent" in cherrypy.request.headers and is_mobile_user_agent(
                cherrypy.request.headers['User-Agent']):
            is_mobile = True

        if is_mobile:
            html_string = """
<html>

<head>

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>
Estrewn
</title>

<style>

nav a, button {
    min-width: 48px;
    min-height: 48px;
}

html, body {
    height: 100%;
    width: 100%;
    margin-top:0;
    margin-left:0;
    margin-right:0;
}

a#menu svg {
    width: 40px;
    fill: #000;
}

main {
    width: 100%;
    height: 100%;
}

nav {
    width: 250px;
    height: 100%;
    position: fixed;
    transform: translate(-250px, 0);
    transition: transform 0.3s ease;
}

nav.open {
    transform: translate(0, 0);
}

.header {
float : right
}

.content {
padding-left:1em;
padding-right:1em;
}

.divider {
width:100%;
height:1px;
background-color:#dae1e9;
}

</style>

</head>

<body>

<nav id="drawer" style="background-color:LightGrey">
<center><h2 style="margin-top:0">Estrewn</h2></center>

<ul style="list-style:none;font-size:20px;padding-left:40px;">
<li style="padding-bottom:20px"><a href="/">Home</a></li>
<li style="padding-bottom:20px"><a href="/upload/">Upload</a></li>
</ul>

</nav>
<main>
<div style = "width:100%;top:0;left:0;">
<a id="menu">
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
    <path d="M2 6h20v3H2zm0 5h20v3H2zm0 5h20v3H2z" />
  </svg>
</a>
<div class = "header">
<h1 style="margin-top:0;margin-bottom:0">Estrewn</h1>
</div>
</div>

<center><h1> Estrewn </h1></center>
<center><h3>A pile of digital content</h3></center>

""" + video_html_string + """

<script type="text/javascript" src="https://code.jquery.com/jquery-3.1.0.js"></script>
<script type="text/javascript">
var menu = document.querySelector('#menu');
var main = document.querySelector('main');
var drawer = document.querySelector('#drawer');
menu.addEventListener('click', function(e) {
    drawer.classList.toggle('open');
    e.stopPropagation();
});
main.addEventListener('click', function() {
    drawer.classList.remove('open');
});
main.addEventListener('touchstart', function() {
    drawer.classList.remove('open');
});
</script>    

<br>

<div class="divider"></div>

<br>

<center>This website is experimental at this point. You should expect bugs, unexpected downtime, etc. Please contact [email protected] for comments, feature requests, etc.</center>

<br><br>

</body>
</html>

"""
        else:

            html_string = """
<html>

<head>
<title>
Estrewn
</title>

<style>

.divider {
width:100%;
height:0.1em;
background-color:#dae1e9;
}

.nonheader { width:960px; margin: 80px auto 0px auto;  }

h1 { 
margin-top: 0.0em; 
margin-bottom: 0.0em; 
} 

h3 { 
margin-top: 0.0em; 
} 

.header1 {width:380px; float:left;}

.nav {
float: right;
padding: 20px 0px 0px 0px;
text-align: right;
}

header {background-color: White}

header {
position:fixed;
top:0px;
left:0px;
width:100%;
height:60px;
z-index:50;
}

.page{
width:960px; 
margin:0px auto 0px auto;
}

</style>
</head>

<body>

<header>
<div class = "page">
<div class = "header1">
<h1>Estrewn</h1>
<h3>A pile of digital content</h3>
</div>
<div class="nav">
<a href="/">Home</a> / <a href="/upload/">Upload</a> 
</div>
</div>
</header>

<div class="nonheader">

<div class="divider"></div>\n

<center><h1> Estrewn </h1></center>
<center><h3>A pile of digital content</h3></center>

""" + video_html_string + """

</div>

<br>

<div class="divider"></div>

<br>

<center>This website is experimental at this point. You should expect bugs, unexpected downtime, etc. Please contact [email protected] for comments, feature requests, etc.</center>

<br><br>

</body>
</html>

"""

        return html_string
Example #32
0
class startWindow(QtGui.QWidget):

    def __init__(self):
        QtGui.QWidget.__init__(self)

        self.start()

    def start(self):
        #screen dimentions
        self.x_display = int(str(QtGui.QDesktopWidget().availableGeometry()).strip("(").strip(")").split(",")[2].strip())
        self.y_display = int(str(QtGui.QDesktopWidget().availableGeometry()).strip("(").strip(")").split(",")[3].strip())

        #start button
        self.start_button = QtGui.QPushButton(self)
        self.start_button.setText('Press Button To Start')
        self.start_button.setStyleSheet("font-size:150px;background-color:#FFFFFF; border: 15px solid #222222")
        self.start_button.setFixedSize(self.x_display,self.y_display)

        #give start button powers
        self.cap = Capture(self.x_display,self.y_display)
        self.start_button.clicked.connect(self.exeCap)

        #size and show size button
        self.showFullScreen()
        self.center()
        self.show()
        self.raise_()


    def exeCap(self):
        if not self.cap.capturing:
            self.cap.startCapture()
            time.sleep(.1)
            self.deleteLater
            self.saveInit()


        else:
            print("Currently Capturing")


    def saveInit(self):
        QtGui.QDialog.__init__(self)

        self.strip_path = self.cap.strip_path
        self.upld = Upload(self.strip_path)

        self.save()


    def save(self):

        #line edit widget
        self.le = QtGui.QLineEdit(self)
        self.le.setPlaceholderText("555-555-5555")
        self.le.setStyleSheet("font-size:150px;background-color:#FFFFFF; border: 5px solid #222222")
        self.le.setAlignment(QtCore.Qt.AlignCenter)
        self.le.setFixedWidth(self.x_display-(self.x_display*.05))

        #button widget
        self.pb = QtGui.QPushButton("Press 'Enter' to send Photostrip",self)
        self.pb.setStyleSheet("font-size:100px;background-color:#FFFFFF") #; border: 2px solid #222222"
        self.pb.setFixedWidth(self.x_display-(self.x_display*.05))

        #regular expression restrictions
        reg_ex = QtCore.QRegExp("[0-9_]+")
        validator = QtGui.QRegExpValidator(reg_ex, self.le)
        self.le.setValidator(validator)

        #move widgets
        self.le.move(round(self.x_display*.025,0),(self.y_display*(1.0/3.0)-150))
        self.pb.move(round(self.x_display*.025,0),(self.y_display*(1.0/3.0)+50))

        #give widgets powers
        self.connect(self.pb, QtCore.SIGNAL("clicked()"),self.send)
        self.setWindowTitle("Learning")
        self.showFullScreen()
        self.raise_()
        self.show()

    def send(self):
        self.number = startWindow.makeUsable(str(self.le.text()))

        if startWindow.checkKosher(self.number):
            if self.upld.link == None:
                self.upld.sendToImgur()

            while self.upld.link == None:
                time.sleep(.05)

            self.upld.link = str(self.upld.link)
            sdtxt = sendText(self.upld.link,self.number)
            #TODO: change to init start button
            QtCore.QCoreApplication.instance().quit()

        else:
            #TODO: change to remove start button
            self.saveInit()

    def center(self):
        qr = self.frameGeometry()
        cp = QtGui.QDesktopWidget().availableGeometry().center()
        qr.moveCenter(cp)
        self.move(qr.topLeft())


    @staticmethod
    def makeUsable(txt):
        NUMBERS = [str(x) for x in range(10)]

        if len(txt) == 10:
            txt = "1" + txt

        tmp_txt = ""
        for i in txt:
            if i in NUMBERS:
                tmp_txt += i

        txt = tmp_txt
        txt = "+" + txt

        return txt

    @staticmethod
    def checkKosher(txt):
        kosher = True
        if len(txt) != 12 or not txt.startswith("+1"):
            kosher = False

        return kosher
Example #33
0
#!/user/bin/python3
# -*- coding:utf-8 -*-
'''
test
'''
__author__ = 'Hijac Wu'

from upload import Upload

x = Upload()
x.setBucketName("kingmahjong-test")
originPath = './sync/bbb.png'
destPath = 'my-python-logo1.png'
x.putFile(originPath, destPath)
	def test_count_files(self):
		'''TEST : Checking zip archive completion'''
		self.assertEqual(Upload.count_files('testfont/'), 7)
Example #35
0
from hbo import HBO
from netflix import Netflix
from upload import Upload
import datetime as dt

print('hbo urls request started at: ', dt.datetime.now())

hbo = HBO()
hbo.make_url_list()
print('hbo url list produced at: ', dt.datetime.now())
# hbo.get_url_list()
# hbo.read_urls_from_json()
hbo.get_data()
print('hbo data ready at: ', dt.datetime.now())

upload = Upload()
upload.upload_file('hbo')

print('netflix urls request started at: ', dt.datetime.now())
netflix = Netflix()
netflix.make_urls()
print('netflix url list produced at: ', dt.datetime.now())
# netflix.read_urls_from_json()
netflix.get_data()
print('netflix data ready at: ', dt.datetime.now())

upload.upload_file('netflix')
Example #36
0
def test_upload():
    """upload"""
    upload = Upload()
    assert isinstance(upload.dataset, dict)
Example #37
0
 def run(self):
     time.sleep(1)
     locks.acquire()
     Upload(self.RedisServer, self.Num, self.ElasticServer)
     locks.release()
Example #38
0
from entry import login
import json


def start():
    print("Please Enter Your Name")
    name = input("> ")
    print("Welcome, {}".format(name))

    key = ""
    if name.lower() == "toby":
        path = input("Enter full key path: ")
        key = login(name.lower(), path)
    else:
        key = login(name)
    return key

if __name__ == "__main__":
    key = start()
    a = Upload(key)
    path = input("Enter file path> ")
    b,c= a.upload(path)
    print(b)
    print()
    print(c)
    




Example #39
0
def get_test():
    u = Upload.select().order_by(Upload.id.desc()).limit(10)
    for i in u:
        print i
	def test_fontpack_generator(self):
		'''TEST : Checking font-pack'''
		self.assertTrue(Upload.fontpack_generator(self.fileinfo['filename']))
Example #41
0
 def click_continue(self):
     self.selenium.find_element(*self._continue_locator).click()
     from upload import Upload
     return Upload(self.base_url, self.selenium)
	def test_zipfile(self):
		'''TEST : Checking zip archive'''
		self.assertTrue(Upload.zipdir('testfont'))
Example #43
0
print("prediction value: ")
print(prediction_value)

print("target value: ")
print(y_value_raw[example])

# generate greyscale image data from prediction data
prediction_imgdata = prediction * 255
prediction_imgdata = prediction_imgdata.astype(np.uint8)

# generate greyscale image of target data
target_imgdata = y_policy_raw[example]

# merge image data in color channels
merged_imgdata = np.stack([input_imgdata, prediction_imgdata, target_imgdata],
                          axis=2)

#create image
img = Image.fromarray(merged_imgdata, 'RGB')
img = img.resize(size=(img.size[0] * 10, img.size[1] * 10))

imgpath = logdest + "/" + os.path.basename(target_model).replace(
    '.h5', '') + "." + str(iteration) + ".png"
img.save(imgpath)

# upload results
if upload:
    uploader = Upload()
    uploader.upload(modelPath, logpath, imgpath)
    log.info('selected catalog folder: %s' % catalog_folder)

if config['actions']['transform']:
    try:
        transform = Transform(config, catalog_folder)
        transform.transform_data()
    except Exception as e:
        log.error(e)
        exit(1)
    else:
        log.info('data transformed succesfully')

if config['actions']['upload']:
    if config['debug_mode']:
        # Data with errors is logged and skipped in debug mode.
        # Do not allow potentialy broken data to be uploaded to Molgenis.
        log.warn('upload is not allowed in debug mode')
    else:
        try:
            upload = Upload(config)
            upload.delete_molgenis_entities()
            upload.zip_transformed_data()
            upload.upload_transformed_data_zip()
            upload.set_entities_permissions()
            upload.set_entity_indexing_depth('lifelines_subsection_variable')
        except Exception as e:
            log.error(e)
            exit(1)

log.info('execution time: %s' % (timedelta(seconds=time.time() - startTime)))
Example #45
0
                view_func=Main.as_view('main'),
                methods=['GET'])
app.add_url_rule('/gallery/',
                view_func=Gallery.as_view('gallery'),
                methods=['GET'])
app.add_url_rule('/login/',
                view_func=Login.as_view('login'),
                methods=['GET', 'POST'])
app.add_url_rule('/videos/',
                view_func=Videos.as_view('videos'),
                methods=['GET'])
app.add_url_rule('/tutorial/',
                view_func=Tutorial.as_view('tutorial'),
                methods=['GET'])
app.add_url_rule('/upload',
                view_func=Upload.as_view('upload'),
                methods=['GET'])
app.add_url_rule('/upload',
                view_func=Validate.as_view('validate'),
                methods=['GET'])
app.add_url_rule('/upload',
                view_func=Posted.as_view('posted'),
                methods=['GET'])


@app.errorhandler(404)
def page_not_found(error):
     return flask.render_template('404.html'), 404

app.debug = True
app.run()
Example #46
0
def add_data():
    u = Upload.insert(timestamp=1433952012, uploadflag=False,
                      path=u'ImageFile\20150611\00\交警支队卡口\进城\0000126200200000000',
                      plateinfo='{"specialpiclocalpath": "ImageFile\\20150611\\00\\\u4ea4\u8b66\u652f\u961f\u5361\u53e3\\\u8fdb\u57ce\\0000126200200000000", "platecolor": "\u84dd\u724c", "roadname": "\u4ea4\u8b66\u652f\u961f\u5361\u53e3", "speedd": "60", "platecode": "\u7ca4LQZ388", "channelid": "2", "filename": "ImageFile\\20150611\\00\\\u4ea4\u8b66\u652f\u961f\u5361\u53e3\\\u8fdb\u57ce\\0000126200200000000", "datetime": "2015-06-11 00:00:12", "passdatetime": "2015-06-11 00:00:12", "flag": "1", "carspeed": "50", "deviceid": "", "directionid": "1", "cameraip": "192.168.188.55", "channelname": "2", "speed": "50", "roadid": "", "triggermode": "196", "speedx": "80"}')
    u.execute()
Example #47
0
def get_test3():
    u = Upload.select().order_by(Upload.uploadflag,Upload.timestamp).limit(10)
    print u
    for i in u:
        print i
Example #48
0
def get_test2():
    u = Upload.select().where(Upload.uploadflag == False).limit(5)
    print u
    for i in u:
        print i.path
Example #49
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...')
Example #50
0
def update_test():
    query = Upload.update(uploadflag=True).where(Upload.id == 100115)
    query.execute()
Example #51
0
def main(argv):
    try:
        # See Python3 getopt class for details on the short option configuration string format
        # https://docs.python.org/3/library/getopt.html
        short_options_config = _OPTION_HELP[1:] + _OPTION_INPUTFILE[1:] + ':' + _OPTION_OUTPUTFILE[1:] + ':' + _OPTION_DO_NOT_UPLOAD[1:]
        opts, args = getopt.getopt(argv, short_options_config)

        inventory_report_filename = ''
        inventory_report_html_filename =  _DEFAULT_HTML_FILENAME
        upload_flag = True

        for opt, arg in opts:
            if opt == _OPTION_HELP:
                print_usage()
                sys.exit()
            elif opt == _OPTION_INPUTFILE:
                inventory_report_filename = validate_filename(arg)
            elif opt == _OPTION_OUTPUTFILE:
                inventory_report_html_filename = validate_filename(arg)
            elif opt == _OPTION_DO_NOT_UPLOAD:
                upload_flag = False

        json_inventory = read_csv_report(inventory_report_filename)
        write_json_inventory('inventory.json', json_inventory)
        write_html_inventory(inventory_report_html_filename, json_inventory)

        if upload_flag:
            upload = Upload(server='normsbeerandwine.com', username='******')
            upload.use_tls = False
            upload.filename = inventory_report_html_filename.name
            upload.password = '******'
            upload.connect()
            upload.upload_file()
            upload.disconnect()

    except Exception as e:
        print(e)
        print('')
        print_usage()
        sys.exit(2)