コード例 #1
0
 def configure(self, ctx):
     config = ctx.service.config
     if not hasattr(config, 'configure'):
         return
     configure = config.configure
     if hasattr(configure, 'patch'):
         patchConfig = configure.patch
         destination = ctx.service.config.install.destination
         #resourceDir = tempfile.gettempdir() + "/" + server.hostname + "_patch"
         resourceDir = self.getWorkingDir(
         ) + "/" + ctx.server.hostname + "_patch"
         try:
             FileUtil.cptree(patchConfig.resourceDir, resourceDir)
             self.modifyResources(ctx, patchConfig, resourceDir)
             self.info("Patch the configuration from " +
                       patchConfig.resourceDir)
             ctx.platform.scp(ctx.account, ctx.server, resourceDir + "/*",
                              destination)
             self.execConfigureExecute(ctx, ctx.service.config.configure)
             customServiceConfigPerServer = getattr(ctx.server.services,
                                                    ctx.service.name)
             if hasattr(customServiceConfigPerServer, "configure"):
                 self.execConfigureExecute(
                     ctx, customServiceConfigPerServer.configure)
         finally:
             FileUtil.rmtree(resourceDir)
コード例 #2
0
ファイル: main.py プロジェクト: haluomao/crawler
	def getHomePage(self):
		url = "http://roll.finance.sina.com.cn/finance/zq1/ssgs/index_1.shtml";
		saveFile=TimeUtil.prefix()+"home.txt"
		FileUtil.put(saveFile, '');	
		res=getPage(url)
		for (k,v) in res.items():
			FileUtil.appendline(saveFile, k+'|'+v );
コード例 #3
0
ファイル: finance_main.py プロジェクト: haluomao/crawler
	def getHomePage(self):				
		FileUtil.put(self.saveFile, '');	
		page = HttpUtil.getPage(self.url);
		res = HtmlUtil.select_href_text(page, '.mainCont .listBox .list ul li a')
		for (k,v) in res.items():
			#print k+'|'+v
			FileUtil.appendline(saveFile, k+'|'+v );
コード例 #4
0
    def run(enrich_data_params, update_dataset_params):

        enrich_out_dir = enrich_data_params["enrich_out_dir"]
        enrich_out_archive_dir = enrich_data_params["enrich_out_archive_dir"]
        update_in_dir = update_dataset_params["update_in_dir"]
        update_in_archive_dir = update_dataset_params["update_in_archive_dir"]
        dataset_file = update_dataset_params["dataset_file"]

        # copy correlate data out to enrich in
        # move correlate out to correlate out archive
        FileUtil.copy_and_move_files(enrich_out_dir, update_in_dir,
                                     enrich_out_archive_dir, "*.csv")

        print("\nLoading Data to be added to Dataset from Filesystem...")
        df_update = FileUtil.get_df_from_csv_dir(update_in_dir, "*.csv")
        print("Complete. Count: " + str(df_update.shape[0]))

        # get header
        header = ','.join(df_update.columns) + '\n'
        # print(header)

        # add header if file does not exist
        if not FileUtil.file_exists(dataset_file):
            FileUtil.write_to_file(dataset_file, header)

        # append to file
        FileUtil.add_df_to_csv_file(df_update, dataset_file)

        # move enrich in to enrich in archive
        FileUtil.move_files(update_in_dir, update_in_archive_dir, "*.csv")
コード例 #5
0
 def modifyResources(self, ctx, patchConfig, resourceDir):
   if not hasattr(patchConfig, 'resources'):
     return
   for resource in patchConfig.resources:
     self.info("Modify resource " + resource.file)
     resourcePath = resourceDir + "/" + resource.file
     resourceFile = open(resourcePath, 'r')
     resourceContent = resourceFile.read()
     resourceFile.close()
     resourceContent = self.modifyResourceProperties(ctx, resource, resourceContent)
     resourceContent = self.modifyResourceAppend(ctx, resource, resourceContent)
     FileUtil.writeText(resourcePath, resourceContent)
コード例 #6
0
 def modifyResources(self, ctx, patchConfig, resourceDir):
     if not hasattr(patchConfig, 'resources'):
         return
     for resource in patchConfig.resources:
         self.info("Modify resource " + resource.file)
         resourcePath = resourceDir + "/" + resource.file
         resourceFile = open(resourcePath, 'r')
         resourceContent = resourceFile.read()
         resourceFile.close()
         resourceContent = self.modifyResourceProperties(
             ctx, resource, resourceContent)
         resourceContent = self.modifyResourceAppend(
             ctx, resource, resourceContent)
         FileUtil.writeText(resourcePath, resourceContent)
コード例 #7
0
 def testUpdateWithProperties(self):
   workingDir = dirname(realpath(__file__)) + "/working";
   FileUtil.mkdirs(workingDir)
   properties = { "account.dev": "dev" }
   source      = workingDir + "/test-properties.txt"
   FileUtil.writeText(source, "account.dev=${account.dev}")
   destination = workingDir + "/test-properties-update.txt"
   FileUtil.updateWithProperties(source, destination, properties)
   content = FileUtil.readAsText(destination)
   self.assertEqual("account.dev=dev", content)
   FileUtil.rmtree(workingDir)
コード例 #8
0
ファイル: TestFileUtil.py プロジェクト: tuan08/NeverwinterDP
 def testUpdateWithProperties(self):
     workingDir = dirname(realpath(__file__)) + "/working"
     FileUtil.mkdirs(workingDir)
     properties = {"account.dev": "dev"}
     source = workingDir + "/test-properties.txt"
     FileUtil.writeText(source, "account.dev=${account.dev}")
     destination = workingDir + "/test-properties-update.txt"
     FileUtil.updateWithProperties(source, destination, properties)
     content = FileUtil.readAsText(destination)
     self.assertEqual("account.dev=dev", content)
     FileUtil.rmtree(workingDir)
コード例 #9
0
ファイル: main.py プロジェクト: haluomao/crawler
	def getPageMore(self, url):
		"获取第二页的内容,返回文件"
		#page2 = HttpUtil.getPage(url)
		#FileUtil.append('2.txt', page2);
		page = FileUtil.read('2.txt')
		#区域1
		try:	
			timeValue = HtmlUtil.select(page, '.time-source')
			timeValue = StrUtil.trim(str(timeValue))
			print timeValue
			self.saveToFile(timeValue+"\n")
		except:
			msg= u"获取时间信息失败,你敢信?"
			print msg
			self.saveToFile(str(msg)+"\n")
		#区域2
		try:
			contentValue = HtmlUtil.select_all(page, '#articleContent p')		
			for src in contentValue:
				print src
				self.saveToFile(str(src)+"\n")
		except:
			msg= u"获取内容失败,你敢信?"
			print msg
			self.saveToFile(str(msg)+"\n")
コード例 #10
0
 def updateLanguageStringToAllFiles(key, englishTranslation):
     codes = LanguageUtil.getCodesSupportedLanguages()
     translator = Translator()
     for code in codes:
         translation = LanguageUtil.loadTranslation(code)
         if key in translation.keys():
             filename = "lang/language_" + code + ".py"
             if code[:2] == "en":
                 result = englishTranslation
             else:
                 result = translator.translate(
                     englishTranslation, "en",
                     "zh-TW" if code == "zh_HANT" else code[:2])
             data = '    "{0}": "{1}",\n'.format(key, result)
             FileUtil.updateStringIntoFile(filename, data)
             print("updated '{0}' into {1}".format(result, code))
コード例 #11
0
ファイル: CatalogUtil.py プロジェクト: mwatts/UniqueBible
 def loadLocalFiles(type, folder, extension):
     data = []
     files = FileUtil.getAllFilesWithExtension(folder, extension)
     for file in files:
         path = os.path.dirname(file)
         filename = os.path.basename(file)
         data.append((file, type, path, filename, folder, "", "", ""))
         CatalogUtil.folderLookup[filename] = path
     return data
コード例 #12
0
 def updateLanguageFile(lang):
     filename = "lang/language_" + lang + ".py"
     if not path.exists(filename):
         print(filename + " does not exist")
     else:
         english = LanguageUtil.loadTranslation("en_US")
         target = LanguageUtil.loadTranslation(lang)
         missing = ""
         translator = Translator()
         count = 0
         for key in english.keys():
             if key not in target.keys():
                 count += 1
                 print(count)
                 text = english[key]
                 result = translator.translate(text, "en", lang[:2])
                 missing += '    "{0}": "{1}",\n'.format(key, result)
         FileUtil.insertStringIntoFile(filename, missing, -1)
         print("{0} lines inserted into {1}".format(count, filename))
コード例 #13
0
 def resetItems(self):
     self.isUpdating = True
     self.dataViewModel.clear()
     filterEntry = self.filterEntry.text().lower()
     rowCount = 0
     colCount = 0
     catalogData = self.localCatalogData
     if self.location == "remote":
         catalogData = self.remoteCatalogData
     for id, value in catalogData.items():
         id2, filename, type, directory, file, description, repo, installDirectory, sha = value
         if (filterEntry == "" or filterEntry in filename.lower()
                 or filterEntry in description.lower()):
             if (not self.pdfCheckbox.isChecked() and type == "PDF") or \
                     (not self.mp3Checkbox.isChecked() and type == "MP3") or \
                     (not self.mp4Checkbox.isChecked() and type == "MP4") or \
                     (not self.bookCheckbox.isChecked() and type == "BOOK") or \
                     (not self.docxCheckbox.isChecked() and type == "DOCX") or \
                     (not self.devotionalCheckbox.isChecked() and type == "DEVOTIONAL") or \
                     (not self.commCheckbox.isChecked() and type == "COMM"):
                 continue
             enable = True
             if self.location == "remote":
                 installDirectory = os.path.join(config.marvelData,
                                                 installDirectory)
                 if FileUtil.regexFileExists(
                         "{0}.*".format(GithubUtil.getShortname(filename)),
                         installDirectory):
                     enable = False
             item = QStandardItem(id)
             item.setEnabled(enable)
             self.dataViewModel.setItem(rowCount, colCount, item)
             colCount += 1
             item = QStandardItem(file)
             item.setEnabled(enable)
             self.dataViewModel.setItem(rowCount, colCount, item)
             colCount += 1
             item = QStandardItem(directory)
             item.setEnabled(enable)
             self.dataViewModel.setItem(rowCount, colCount, item)
             colCount += 1
             # item = QStandardItem(description)
             # self.dataViewModel.setItem(rowCount, colCount, item)
             # colCount += 1
             # add row count
             rowCount += 1
             colCount = 0
     self.dataViewModel.setHorizontalHeaderLabels([
         "#",
         config.thisTranslation["file"],
         config.thisTranslation["directory"],
         # config.thisTranslation["description"]
     ])
     self.dataView.resizeColumnsToContents()
     self.isUpdating = False
コード例 #14
0
def exitApplication():
    config.mainWindow.textCommandParser.stopTtsAudio()
    # Run shutdown plugins
    if config.enablePlugins:
        for plugin in FileUtil.fileNamesWithoutExtension(
                os.path.join("plugins", "shutdown"), "py"):
            if not plugin in config.excludeShutdownPlugins:
                script = os.path.join(os.getcwd(), "plugins", "shutdown",
                                      "{0}.py".format(plugin))
                config.mainWindow.execPythonFile(script)
    ConfigUtil.save()
コード例 #15
0
def exitApplication():
    config.mainWindow.textCommandParser.stopTtsAudio()
    # Run shutdown plugins
    if config.enablePlugins:
        for plugin in FileUtil.fileNamesWithoutExtension(os.path.join("plugins", "shutdown"), "py"):
            if not plugin in config.excludeShutdownPlugins:
                script = os.path.join(os.getcwd(), "plugins", "shutdown", "{0}.py".format(plugin))
                config.mainWindow.execPythonFile(script)
    ConfigUtil.save()
    if config.restartUBA and hasattr(config, "cli"):
        subprocess.Popen("{0} uba.py gui".format(sys.executable), shell=True)
コード例 #16
0
 def configure(self, ctx):
   config = ctx.service.config
   if not hasattr(config, 'configure'): 
     return
   configure = config.configure;
   if hasattr(configure, 'patch'): 
     patchConfig = configure.patch
     destination = ctx.service.config.install.destination
     #resourceDir = tempfile.gettempdir() + "/" + server.hostname + "_patch"
     resourceDir = self.getWorkingDir() + "/" + ctx.server.hostname + "_patch"
     try:
       FileUtil.cptree(patchConfig.resourceDir, resourceDir)
       self.modifyResources(ctx, patchConfig, resourceDir)
       self.info("Patch the configuration from " + patchConfig.resourceDir)
       ctx.platform.scp(ctx.account, ctx.server, resourceDir + "/*", destination)
       self.execConfigureExecute(ctx, ctx.service.config.configure)
       customServiceConfigPerServer = getattr(ctx.server.services, ctx.service.name)
       if hasattr(customServiceConfigPerServer, "configure"):
         self.execConfigureExecute(ctx, customServiceConfigPerServer.configure)
     finally:
       FileUtil.rmtree(resourceDir)
コード例 #17
0
  def imageBuild(self, cluster):
    self.title("Build images")
    self.info("Copy ssh resources");
    home = os.path.expanduser("~");
    currentDir = os.path.dirname(os.path.realpath(__file__));
    ubuntuDir = currentDir + "/ubuntu"
    workingDir = ubuntuDir + "/working"
    workingSSHDir = workingDir + "/ssh";
    
    FileUtil.mkdirs(workingSSHDir)
    
    FileUtil.updateWithProperties(ubuntuDir + "/Dockerfile", workingDir + "/Dockerfile", {"account.dev": 'dev'})
    shutil.copy2(home + "/.ssh/id_rsa.pub", workingSSHDir + "/authorized_keys")
    
    images = cluster.getImages()
    for name, imageConfig in images.iteritems():
      imageTag = imageConfig['repository'] + ':' + name
      imageId = self.imageFindIdByTag(imageTag)
      if not imageId:
        cmd = 'docker build -t ' + imageTag + ' ' + workingDir;
        ShellProcess(cmd).run().exitIfFail()

    shutil.rmtree(workingDir)
コード例 #18
0
ファイル: main.py プロジェクト: hspearman/mimick.me
def main():

    # Init variables
    source = SourceFactory.get_source()
    parser = ParserFactory.get_parser()

    # Load config data
    username = FileUtil.load_config(parser)

    # Get posts by username from source
    posts = source.get_user_posts(username)

    # Print generated string that mimics user's speech
    str_mimic = parser.mimic_user(posts)
    print(str_mimic)
コード例 #19
0
ファイル: LibraryLauncher.py プロジェクト: mwatts/UniqueBible
 def bookOrFileSelected(self, selection):
     self.parent.isRefreshing = True
     self.selectedBook = selection[0].indexes()[0].data()
     if config.book != self.selectedBook:
         if self.selectedBook.endswith("/"):
             config.booksFolder = FileUtil.normalizePath(os.path.join(config.booksFolder, self.selectedBook))
             self.reloadBookListModel()
         else:
             config.book = self.selectedBook
             topicList = self.getBookTopicList()
             self.chapterModel.setStringList(topicList)
             config.bookChapter = topicList[0] if topicList else ""
             self.scrollChapterList(topicList)
             command = "SEARCHBOOK:::{0}:::".format(config.book)
             self.parent.commandField.setText(command)
コード例 #20
0
 def itemClicked(self, index):
     selectedRow = index.row()
     self.catalogEntryId = self.dataViewModel.item(selectedRow, 0).text()
     if self.location == "remote":
         item = self.remoteCatalogData[self.catalogEntryId]
         id, filename, type, directory, file, description, repo, installDirectory, sha = item
         installDirectory = os.path.join(config.marvelData,
                                         installDirectory)
         if FileUtil.regexFileExists(
                 "{0}.*".format(GithubUtil.getShortname(filename)),
                 installDirectory):
             self.downloadButton.setEnabled(False)
             self.downloadButton.setStyleSheet("")
         else:
             self.downloadButton.setEnabled(True)
             self.downloadButton.setStyleSheet(self.textButtonStyle)
コード例 #21
0
def addMenuLayoutItems(parent, menu):
    items = (
        ("menu1_aleph_menu_layout", lambda: parent.setMenuLayout("aleph")),
        ("menu1_focus_menu_layout", lambda: parent.setMenuLayout("focus")),
        ("menu1_classic_menu_layout", lambda: parent.setMenuLayout("classic")),
    )
    for feature, action in items:
        addMenuItem(menu, feature, parent, action)
    layouts = FileUtil.fileNamesWithoutExtension(
        os.path.join("plugins", "layout"), "py")
    if layouts:
        menu.addSeparator()
        for pluginLayout in layouts:
            addMenuItem(menu,
                        pluginLayout,
                        parent,
                        lambda: parent.setMenuLayout(pluginLayout),
                        translation=False)
コード例 #22
0
ファイル: InfoDialog.py プロジェクト: mwatts/UniqueBible
    def __init__(self, content=None, description=None):
        super(InfoDialog, self).__init__()

        self.wikiLink = "https://github.com/eliranwong/UniqueBible/wiki"

        self.setMinimumWidth(500)
        self.setMinimumHeight(500)
        self.setWindowTitle(config.thisTranslation["info"])
        self.layout = QVBoxLayout()

        self.appName = QLabel("UniqueBible.app - {:.2f}".format(
            config.version))
        self.appName.setStyleSheet("QLabel {font-size: 30px;}")
        self.appName.mouseReleaseEvent = self.openWiki
        self.layout.addWidget(self.appName)

        filesHBox = QHBoxLayout()

        filesVBox1 = QVBoxLayout()
        count = len(
            FileUtil.getAllFilesWithExtension(config.marvelData + "/bibles",
                                              ".bible"))
        filesVBox1.addWidget(
            QLabel("{0}: {1}".format(config.thisTranslation["menu5_bible"],
                                     count)))
        count = len(
            FileUtil.getAllFilesWithExtension(config.marvelData + "/lexicons",
                                              ".lexicon"))
        filesVBox1.addWidget(
            QLabel("{0}: {1}".format(config.thisTranslation["lexicons"],
                                     count)))
        count = len(
            FileUtil.getAllFilesWithExtension(
                config.marvelData + "/devotionals", ".devotional"))
        filesVBox1.addWidget(
            QLabel("{0}: {1}".format(config.thisTranslation["devotionals"],
                                     count)))
        count = len(FileUtil.getAllFilesWithExtension("music", ".mp3"))
        filesVBox1.addWidget(
            QLabel("{0}: {1}".format(config.thisTranslation["menu11_music"],
                                     count)))
        filesVBox1.addWidget(
            QLabel("{0}: {1}".format(
                config.thisTranslation["menu1_menuLayout"],
                config.menuLayout)))
        filesHBox.addLayout(filesVBox1)

        filesVBox2 = QVBoxLayout()
        count = len(
            FileUtil.getAllFilesWithExtension(
                config.marvelData + "/commentaries", ".commentary"))
        filesVBox2.addWidget(
            QLabel("{0}: {1}".format(config.thisTranslation["commentaries"],
                                     count)))
        count = len(
            FileUtil.getAllFilesWithExtension(config.marvelData + "/books",
                                              ".book"))
        filesVBox2.addWidget(
            QLabel("{0}: {1}".format(config.thisTranslation["menu10_books"],
                                     count)))
        count = len(FileUtil.getAllFilesWithExtension("video", ".mp4"))
        filesVBox2.addWidget(
            QLabel("{0}: {1}".format(config.thisTranslation["menu11_video"],
                                     count)))
        filesVBox2.addWidget(
            QLabel("{0}: {1}".format(config.thisTranslation["menu_language"],
                                     config.displayLanguage)))
        filesVBox2.addWidget(
            QLabel("{0}: {1}".format(config.thisTranslation["menu_shortcuts"],
                                     config.menuShortcuts)))
        filesHBox.addLayout(filesVBox2)

        filesVBox3 = QVBoxLayout()
        count = len(
            FileUtil.getAllFilesWithExtension(config.marvelData + "/pdf",
                                              ".pdf"))
        filesVBox3.addWidget(QLabel("{0}: {1}".format("PDF", count)))
        count = len(
            FileUtil.getAllFilesWithExtension(config.marvelData + "/epub",
                                              ".epub"))
        filesVBox3.addWidget(QLabel("{0}: {1}".format("EPUB", count)))
        count = len(
            FileUtil.getAllFilesWithExtension(config.marvelData + "/docx",
                                              ".docx"))
        filesVBox3.addWidget(QLabel("{0}: {1}".format("DOCX", count)))
        filesVBox3.addWidget(
            QLabel("{0}: {1}".format(config.thisTranslation["menu_window"],
                                     config.windowStyle)))
        filesVBox3.addWidget(
            QLabel("{0}: {1}".format(config.thisTranslation["menu_theme"],
                                     config.theme)))
        filesHBox.addLayout(filesVBox3)

        self.layout.addLayout(filesHBox)

        if content is None:
            with open("latest_changes.txt", "r",
                      encoding="utf-8") as fileObject:
                text = fileObject.read()
        else:
            text = content
        html = text
        urls = re.compile(
            r"((https?):((//)|(\\\\))+[\w\d:#@%/;$~_?\+-=\\\.&]*)",
            re.MULTILINE | re.UNICODE)
        html = urls.sub(r'<a href="\1" >\1</a>', html)
        html = html.replace("\n", "<br>")
        latest = QLabel("{0}:".format(config.thisTranslation["latest_changes"]
                                      if description is None else description))
        latest.setStyleSheet("QLabel {font-size: 20px;}")
        self.layout.addWidget(latest)
        self.latestChanges = QTextBrowser()
        self.latestChanges.setOpenExternalLinks(True)
        self.latestChanges.insertHtml(html)
        self.latestChanges.setReadOnly(True)
        cursor = self.latestChanges.textCursor()
        cursor.setPosition(0)
        self.latestChanges.setTextCursor(cursor)
        self.layout.addWidget(self.latestChanges)

        buttons = QDialogButtonBox.Ok
        self.buttonBox = QDialogButtonBox(buttons)
        self.buttonBox.accepted.connect(self.accept)
        self.layout.addWidget(self.buttonBox)
        self.setLayout(self.layout)
コード例 #23
0
ファイル: main.py プロジェクト: haluomao/crawler
	def getDetailPage(self):
		srcFile=TimeUtil.prefix()+".txt"
		content=FileUtil.readlines(srcFile)
		for str in content:
			url=str.split('|')[1]
			print url
コード例 #24
0
ファイル: Blockchain.py プロジェクト: kidistAL/voting
class Blockchain:

    def __init__(self, PORT):
        self.chain = []
        self.pendingTransaction = []
        self.networkNodes = []
        self.file = FileUtil('json/' + str(PORT) + '.json')
        self.file.store_genesis_block(Block(1, '0000x', '0000x', 1, []))

    def create_block(self, nonce, prev_hash, block_hash):
        block = Block(nonce, prev_hash, block_hash, len(self.chain) + 1, self.pendingTransaction)
        if block.is_block_valid():
            self.chain.append(block)
            self.pendingTransaction = []
            return block
        return False

    def get_last_block(self):
        return self.chain[-1]

    def find_block_by_id(self, block_id):
        return self.chain[block_id - 1]

    def receive_block(self, other):
        last_block = self.get_last_block()
        print(other)
        if last_block == other:
            return False

        block_data = {
            'transactions': jsonpickle.encode(other.transaction),
            'index': last_block.index + 1
        }
        block_hash = self.hash_block(block_data, other.nonce)
        if block_hash != other.hash:
            return False

        if other.is_block_valid():
            if last_block.index + 1 == other.index:
                if last_block.hash == other.previousBlockHash:
                    self.chain.append(other)
                    self.pendingTransaction = []
                    self.store_block(other)
                    return True
        return False

    def store_block(self, block):
        self.file.write(block)

    def read_chain(self):
        self.chain = self.file.read()

    def replace(self, best_chain):
        self.file.replace(best_chain)

    def add_to_pending_transaction(self, transaction):
        if not transaction.is_valid():
            return False
        if self.transaction_exist(transaction.id):
            return False
        self.pendingTransaction.append(transaction)
        return True

    @staticmethod
    def hash_block(block_data, nonce):
        block_data['nonce'] = nonce
        encoded_block = json.dumps(block_data, sort_keys=True).encode()
        return hashlib.sha256(encoded_block).hexdigest()

    def proof_of_work(self, block_data):
        nonce = 0
        block_hash = self.hash_block(block_data, nonce)
        while block_hash[:4] != '0000':
            nonce += 1
            block_hash = self.hash_block(block_data, nonce)

        return nonce

    def is_chain_valid(self, blockchain):
        for i in range(1, len(blockchain)):
            current_block = blockchain[i]
            prev_block = blockchain[i - 1]
            if not self.has_valid_transaction(current_block):
                return False

            block_data = {
                'transactions': jsonpickle.encode(current_block.transaction),
                'index': prev_block.index + 1
            }
            block_hash = self.hash_block(block_data, current_block.nonce)
            if block_hash[:4] != '0000':
                return False
            correct_hash = current_block.previousBlockHash == prev_block.hash
            correct_index = current_block.index == prev_block.index + 1
            if not (correct_hash and correct_index):
                return False
        return True

    def add_node(self, address):
        self.networkNodes.append(address)

    def serialize_chain(self):
        if len(self.chain) == 0:
            return
        display = []
        for block in self.chain:
            display.append(block.serialize())
        return display

    @staticmethod
    def calculate_vote(chain):
        vote = 0
        for block in chain:
            for tx in block.transaction:
                if tx.to_address == '00f23132c7bc626122a6878bbb0b916e5a2bbc26':
                    vote += 1
        return vote

    @staticmethod
    def has_valid_transaction(block):
        if block.is_block_valid():
            return True
        else:
            return False

    def transaction_exist(self, tx_id):
        for tx in self.pendingTransaction:
            if tx.id == tx_id:
                return True

        for block in self.chain:
            for tx in block.transaction:
                if tx.id == tx_id:
                    return True

        return False

    def find_tx_by_id(self, tx_id):
        for tx in self.pendingTransaction:
            if tx.id == tx_id:
                return tx.serialize()

        for block in self.chain:
            for tx in block.transaction:
                if tx.id == tx_id:
                    return tx.serialize()

        return str(tx_id) + "not found"
コード例 #25
0
ファイル: main.py プロジェクト: haluomao/crawler
	def saveToFile(self, value):
		FileUtil.append(self.saveFile, value);
コード例 #26
0
ファイル: Blockchain.py プロジェクト: kidistAL/voting
 def __init__(self, PORT):
     self.chain = []
     self.pendingTransaction = []
     self.networkNodes = []
     self.file = FileUtil('json/' + str(PORT) + '.json')
     self.file.store_genesis_block(Block(1, '0000x', '0000x', 1, []))
コード例 #27
0
def runStartupPlugins():
    if config.enablePlugins:
        for plugin in FileUtil.fileNamesWithoutExtension(os.path.join("plugins", "startup"), "py"):
            if not plugin in config.excludeStartupPlugins:
                script = os.path.join(os.getcwd(), "plugins", "startup", "{0}.py".format(plugin))
                config.mainWindow.execPythonFile(script)
コード例 #28
0
            print("最小可靠度是: %s" % min_rel)

            maxRelAlgorithm = MaxRelAlgorithm(workflow, lambda_list)
            max_rel = maxRelAlgorithm.rel
            print("最大可靠度是: %s" % max_rel)

            for percentage in [0.2, 0.4, 0.6, 0.8]:
            # for percentage in [0.5]:
                rel_restraint = min_rel + percentage * (max_rel - min_rel)
                print("可靠度下限是: %s" % rel_restraint)

                print("Random")
                # RANDOM算法
                randomAlgorithm = RandomAlgorithm(workflow, rel_restraint, lambda_list)
                random_result_sort_by_makespan = sort_result_by_makespan(randomAlgorithm.pareto_result)
                FileUtil.dump_result_to_file(random_result_sort_by_makespan, randomAlgorithm.name, workflow.name,
                                             percentage)

                print("mows")
                # MOWS算法
                mowsDtmAlgorithm = GeneticAlgorithm(workflow, rel_restraint, lambda_list)
                mowsDtmAlgorithm.process()
                mows_dtm_result_sort_by_makespan = sort_result_by_makespan(mowsDtmAlgorithm.pareto_result)
                FileUtil.dump_result_to_file(mows_dtm_result_sort_by_makespan, mowsDtmAlgorithm.name, workflow.name,
                                             percentage)

                print("Moheft")
                # MOHEFT算法
                moheftAlgorithm = MOHEFTAlgorithm(workflow, rel_restraint, lambda_list)
                moheftAlgorithm.process(maxRelAlgorithm.individual, max_rel)
                moheft_result_sort_by_makespan = sort_result_by_makespan(moheftAlgorithm.pareto_result)
                FileUtil.dump_result_to_file(moheft_result_sort_by_makespan, moheftAlgorithm.name, workflow.name,
コード例 #29
0
# a cross-platform desktop bible application
# For more information on this application, visit https://BibleTools.app or https://UniqueBible.app.
import glob
import os, platform, logging, re, sys, subprocess
import logging.handlers as handlers
from util.FileUtil import FileUtil
from util.NetworkUtil import NetworkUtil

# Change working directory to UniqueBible directory
thisFile = os.path.realpath(__file__)
wd = thisFile[:-7]
if os.getcwd() != wd:
    os.chdir(wd)

# Create custom files
FileUtil.createCustomFiles()

# Make sure config.py exists before importing config and all other scripts which depends on config
import config
# Setup config values
from util.ConfigUtil import ConfigUtil
ConfigUtil.setup()

# Check argument passed to UBA as a parameter
initialCommand = " ".join(sys.argv[1:]).strip()
config.noQt = False
config.cli = False
if initialCommand == "cli":
    config.cli = True
elif initialCommand == "gui":
    initialCommand = ""
コード例 #30
0
ファイル: finance_main.py プロジェクト: haluomao/crawler
	def getDetailPage(self):
		content=FileUtil.readlines(self.saveFile)
		for s in content:
			title=s.split('|')[0] #标题
			url=s.split('|')[1]	#url
			print url			
			page = HttpUtil.getPage(url);
			arr = HtmlUtil.select_all(page, '.newText .Info span')
			date=''
			source=''
			#获取时间/来源
			for k in arr:
				if k is not None:
					if "年" in str(k):
						date=str(k);
					if "来源" in str(k):
						source=str(k);
			content_review = HtmlUtil.select_v(page, '#ContentBody .c_review')
			
			if content_review is None:
				content_review=''
			arr = HtmlUtil.select_text(page, '#ContentBody p')
			#记录到文件
			newFile="data/finance"+url.split(',')[1][:-6]+".txt"
			FileUtil.put(newFile, '')
			FileUtil.appendline(newFile, title+"\n")
			FileUtil.appendline(newFile, url)
			FileUtil.appendline(newFile, date+"\n")
			FileUtil.appendline(newFile, source+"\n")
			FileUtil.appendline(newFile, content_review+"\n")
			for k in arr:
				try:
					FileUtil.appendline(newFile, str(k))
				except:
					continue;
コード例 #31
0
# For more information on this application, visit https://BibleTools.app or https://UniqueBible.app.

import os, platform, logging, re, sys, socket
import logging.handlers as handlers
from util.FileUtil import FileUtil
if not platform.system() == "Windows":
    import readline

# Change working directory to UniqueBible directory
thisFile = os.path.realpath(__file__)
wd = thisFile[:-7]
if os.getcwd() != wd:
    os.chdir(wd)

# Create custom files
FileUtil.createCustomFiles()

# Make sure config.py exists before importing config and all other scripts which depends on config
import config
# Setup config values
from util.ConfigUtil import ConfigUtil
ConfigUtil.setup()
# Check for dependencies and other essential elements
from checkup import *

# Check argument passed to UBA as a parameter
initialCommand = " ".join(sys.argv[1:]).strip()
if initialCommand == "cli":
    config.cli = True
elif initialCommand == "gui":
    initialCommand = ""
コード例 #32
0
    def setupUI(self):
        mainLayout = QVBoxLayout()

        mainLayout.addWidget(QLabel(self.translation[0]))

        subLayout = QHBoxLayout()

        layout = QVBoxLayout()
        layout.addWidget(QLabel(self.translation[1]))
        dataView1 = QListView()
        dataView1.setEditTriggers(QAbstractItemView.NoEditTriggers)
        dataViewModel1 = QStandardItemModel(dataView1)
        dataView1.setModel(dataViewModel1)
        for plugin in FileUtil.fileNamesWithoutExtension(
                os.path.join("plugins", "startup"), "py"):
            item = QStandardItem(plugin)
            item.setToolTip(plugin)
            item.setCheckable(True)
            item.setCheckState(
                Qt.CheckState.Unchecked if plugin in
                config.excludeStartupPlugins else Qt.CheckState.Checked)
            dataViewModel1.appendRow(item)
        dataViewModel1.itemChanged.connect(self.itemChanged1)
        layout.addWidget(dataView1)
        subLayout.addLayout(layout)

        layout = QVBoxLayout()
        layout.addWidget(QLabel(self.translation[2]))
        dataView2 = QListView()
        dataView2.setEditTriggers(QAbstractItemView.NoEditTriggers)
        dataViewModel2 = QStandardItemModel(dataView2)
        dataView2.setModel(dataViewModel2)
        for plugin in FileUtil.fileNamesWithoutExtension(
                os.path.join("plugins", "menu"), "py"):
            item = QStandardItem(plugin)
            item.setToolTip(plugin)
            item.setCheckable(True)
            item.setCheckState(Qt.CheckState.Unchecked if plugin in config.
                               excludeMenuPlugins else Qt.CheckState.Checked)
            dataViewModel2.appendRow(item)
        dataViewModel2.itemChanged.connect(self.itemChanged2)
        layout.addWidget(dataView2)
        subLayout.addLayout(layout)

        layout = QVBoxLayout()
        layout.addWidget(QLabel(self.translation[3]))
        dataView3 = QListView()
        dataView3.setEditTriggers(QAbstractItemView.NoEditTriggers)
        dataViewModel3 = QStandardItemModel(dataView3)
        dataView3.setModel(dataViewModel3)
        for plugin in FileUtil.fileNamesWithoutExtension(
                os.path.join("plugins", "context"), "py"):
            item = QStandardItem(plugin)
            item.setToolTip(plugin)
            item.setCheckable(True)
            item.setCheckState(
                Qt.CheckState.Unchecked if plugin in
                config.excludeContextPlugins else Qt.CheckState.Checked)
            dataViewModel3.appendRow(item)
        dataViewModel3.itemChanged.connect(self.itemChanged3)
        layout.addWidget(dataView3)
        subLayout.addLayout(layout)

        layout = QVBoxLayout()
        layout.addWidget(QLabel(self.translation[4]))
        dataView4 = QListView()
        dataView4.setEditTriggers(QAbstractItemView.NoEditTriggers)
        dataViewModel4 = QStandardItemModel(dataView4)
        dataView4.setModel(dataViewModel4)
        for plugin in FileUtil.fileNamesWithoutExtension(
                os.path.join("plugins", "shutdown"), "py"):
            item = QStandardItem(plugin)
            item.setToolTip(plugin)
            item.setCheckable(True)
            item.setCheckState(
                Qt.CheckState.Unchecked if plugin in
                config.excludeShutdownPlugins else Qt.CheckState.Checked)
            dataViewModel4.appendRow(item)
        dataViewModel4.itemChanged.connect(self.itemChanged4)
        layout.addWidget(dataView4)
        subLayout.addLayout(layout)

        mainLayout.addLayout(subLayout)

        self.setLayout(mainLayout)
コード例 #33
0
 def writeException(strException):
     FileUtil(Config.LOG_FILE_NAME, "a+").writeLine(str(strException))
コード例 #34
0
 def writeLog(strLog):
     FileUtil(Config.LOG_FILE_NAME, "a+").writeLine(
         TimeUtil.getFormatTime("%Y/%m/%d-%H:%M:%S") + Config.AND_STRING + strLog)
コード例 #35
0
    def run(debug, get_data_params, correlate_data_params):

        sumologic_out_dir = get_data_params["sumologic_out_dir"]
        sumologic_out_archive_dir = get_data_params["sumologic_out_archive_dir"]
        correlate_in_current_cycle_dir = correlate_data_params["correlate_in_current_cycle_dir"]
        correlate_in_previous_cycle_dir = correlate_data_params["correlate_in_previous_cycle_dir"]
        correlate_in_archive_dir = correlate_data_params["correlate_in_archive_dir"]
        correlate_out_dir = correlate_data_params["correlate_out_dir"]

        # copy sumologic out to correlate in current cycle
        # move sumologic out to sumologic out archive
        FileUtil.copy_and_move_files(sumologic_out_dir,
                                     correlate_in_current_cycle_dir,
                                     sumologic_out_archive_dir, "*.csv")

        # now in milliseconds
        now_timestamp = TimeUtil.get_current_milli_time()
        correlate_filename = 'Correlate_'+str(now_timestamp)+".csv"

        print("\nLoading Open Shift Requests from Filesystem...")
        # correlate apply with requests in current and previoud cycle
        df_requests = FileUtil.get_df_from_csv_dirs(correlate_in_current_cycle_dir,
                                                    correlate_in_previous_cycle_dir,
                                                    "Requests*")
        print("Complete. Count: " + str(df_requests.shape[0]))
        if(debug):
            for index, row in df_requests.iterrows():
                print(row)

        print("\nLoading Apply to Open Shifts from Filesystem...")
        df_apply = FileUtil.get_df_from_csv_dir(correlate_in_current_cycle_dir,
                                                    "Apply*")
        print("Complete. Count: " + str(df_apply.shape[0]))

        print("\nCorrelating Apply Open Shifts with Open Shifts Requests... ")

        fields = ['loggedinuser', 'companyid',
                  'query_datetime', 'apply_datetime', 'numberofopenshifts',
                  'locationid', 'eventid', 'applied']

        CorrelateData.add_header(correlate_out_dir+correlate_filename, fields)

        for index, row in df_apply.iterrows():

            apply_datetime = row['datetime']
            loggedinuser = row['loggedinuser']
            companyid = row['companyid']
            locationid = row['locationid']
            eventid = row['eventid']

            df_filtered = df_requests.loc[
                    (df_requests['loggedinuser'] == loggedinuser) &
                    (df_requests['companyid'] == companyid) &
                    (df_requests['datetime'] < apply_datetime) &
                    (df_requests['eventandlocationids'].str.contains(str(eventid)+","+str(locationid)))
                    ].drop_duplicates().sort_values(by=['datetime'], ascending=False).head(1)

            if df_filtered.shape[0] > 0:

                # lets first get rid of ', ' and replace it with '|' and then split
                # Example text: (3714cb1e-4839-4d8c-818e-9d01c655cd86,328038), (d87a2bb7-05e0-465e-8b6c-aa18d89a9c9f,328038), (e7bee5c5-8f4e-457f-95e7-b1ec82e8ab21,328038), (f04d14c1-68c3-4dda-8698-3d95eb3a4b9d,328038)
                events_and_locations = df_filtered.iloc[0]['eventandlocationids'].replace(', ','|').split('|')

                for event_location in events_and_locations:

                    # lets get rid of paranthesis and split text by ','
                    # Example text: (3714cb1e-4839-4d8c-818e-9d01c655cd86,328038)
                    eventid_in_request, locationid_in_request = event_location.replace('(','').replace(')','').split(',')

                    applied = False
                    if str(eventid) == str(eventid_in_request) and str(locationid) == str(locationid_in_request):
                        applied = True

                    row = {'loggedinuser': loggedinuser,
                           'companyid': companyid,
                           'query_datetime': df_filtered.iloc[0]['datetime'],
                           'apply_datetime': apply_datetime,
                           'numberofopenshifts': df_filtered.iloc[0]['numberofopenshifts'],
                           'locationid': locationid_in_request,
                           'eventid': eventid_in_request,
                           'applied': applied}

                    CorrelateData.add_row(correlate_out_dir+correlate_filename, fields, row)

        print("Complete. Results written to: {} \n".format(correlate_out_dir+correlate_filename))

        # move correlate in previous cycle to correlate in archive
        FileUtil.move_files(correlate_in_previous_cycle_dir,
                            correlate_in_archive_dir, "*.csv")

        # move correlate in current cycle (Apply) to
        # correlate in archive cycle
        FileUtil.move_files(correlate_in_current_cycle_dir,
                            correlate_in_archive_dir, "Apply*")

        # move correlate in current cycle (Requests) to
        # correlate in previous cycle
        FileUtil.move_files(correlate_in_current_cycle_dir,
                            correlate_in_previous_cycle_dir, "Requests*")
コード例 #36
0
ファイル: GetData.py プロジェクト: edipdemirbilek/Corvid
    def run(num_days,
            accesId,
            accessKey,
            env,
            get_data_params,
            remove_timestamp_files=False):

        sumologic_timestamp_dir = get_data_params["sumologic_timestamp_dir"]
        sumologic_out_dir = get_data_params["sumologic_out_dir"]

        # now in milliseconds
        now_timestamp = TimeUtil.get_current_milli_time()

        requests_timestamp_filename = 'Requests.timestamp'
        apply_timestamp_filename = 'Apply.timestamp'

        requests_filename = 'Requests_' + str(now_timestamp) + ".csv"
        apply_filename = 'Apply_' + str(now_timestamp) + ".csv"

        # temporary: remove files
        if remove_timestamp_files:
            FileUtil.delete_if_exist(sumologic_timestamp_dir +
                                     requests_timestamp_filename)
            FileUtil.delete_if_exist(sumologic_timestamp_dir +
                                     apply_timestamp_filename)

        # fromTime for open shift requests
        past_requests_timestamp = FileUtil.read_timestamp_or_deafult(
            sumologic_timestamp_dir + requests_timestamp_filename,
            TimeUtil.get_past_milli_time(num_days))

        # fromTime for open shift apply
        past_apply_timestamp = FileUtil.read_timestamp_or_deafult(
            sumologic_timestamp_dir + apply_timestamp_filename,
            TimeUtil.get_past_milli_time(num_days))

        # get open shift requests and write to file
        print("\nDownloading Open Shift Requests from SumoLogic...")
        open_shift_requests = OpenShiftRequestsAPI(accesId, accessKey)
        open_shift_requests.get_sumologic_content(past_requests_timestamp,
                                                  now_timestamp, 10000)

        open_shift_requests.write_response_to_file(sumologic_out_dir +
                                                   requests_filename)
        print("Complete. Results written to " + sumologic_out_dir +
              requests_filename)

        # get open shift apply and write to file
        print("\nDownloading Apply to Open Shifts from SumoLogic...")
        open_shift_apply = OpenShiftApplyAPI(accesId, accessKey)
        open_shift_apply.get_sumologic_content(past_apply_timestamp,
                                               now_timestamp, 10000)

        open_shift_apply.write_response_to_file(sumologic_out_dir +
                                                apply_filename)
        print("Complete. Results written to {}: \n".format(sumologic_out_dir +
                                                           apply_filename))

        print("\nUpdating time stamp files.")
        # write timestamps
        FileUtil.write_timestamp(
            sumologic_timestamp_dir + requests_timestamp_filename,
            now_timestamp)
        FileUtil.write_timestamp(
            sumologic_timestamp_dir + apply_timestamp_filename, now_timestamp)
コード例 #37
0
ファイル: WebEngineView.py プロジェクト: imbi7py/UniqueBible
    def addMenuActions(self):

        subMenu = QMenu()

        for text in self.parent.parent.textList:
            action = QAction(self)
            action.setText(text)
            action.triggered.connect(
                partial(self.openReferenceInBibleVersion, text))
            subMenu.addAction(action)

        separator = QAction(self)
        separator.setSeparator(True)
        subMenu.addAction(separator)

        action = QAction(self)
        action.setText(config.thisTranslation["all"])
        action.triggered.connect(self.compareAllVersions)
        subMenu.addAction(action)

        action = QAction(self)
        action.setText(config.thisTranslation["openReferences"])
        action.setMenu(subMenu)
        self.addAction(action)

        subMenu = QMenu()

        for text in self.parent.parent.textList:
            action = QAction(self)
            action.setText(text)
            action.triggered.connect(
                partial(self.compareReferenceWithBibleVersion, text))
            subMenu.addAction(action)

        separator = QAction(self)
        separator.setSeparator(True)
        subMenu.addAction(separator)

        action = QAction(self)
        action.setText(config.thisTranslation["all"])
        action.triggered.connect(self.compareAllVersions)
        subMenu.addAction(action)

        action = QAction(self)
        action.setText(config.thisTranslation["compareReferences"])
        action.setMenu(subMenu)
        self.addAction(action)

        subMenu = QMenu()

        for text in self.parent.parent.textList:
            action = QAction(self)
            action.setText(text)
            action.triggered.connect(
                partial(self.parallelReferenceWithBibleVersion, text))
            subMenu.addAction(action)

        separator = QAction(self)
        separator.setSeparator(True)
        subMenu.addAction(separator)

        action = QAction(self)
        action.setText(config.thisTranslation["all"])
        action.triggered.connect(self.compareAllVersions)
        subMenu.addAction(action)

        action = QAction(self)
        action.setText(config.thisTranslation["parallelReferences"])
        action.setMenu(subMenu)
        self.addAction(action)

        separator = QAction(self)
        separator.setSeparator(True)
        self.addAction(separator)

        subMenu = QMenu()

        searchBibleReferences = QAction(self)
        searchBibleReferences.setText(
            config.thisTranslation["openOnNewWindow"])
        searchBibleReferences.triggered.connect(self.displayVersesInNewWindow)
        subMenu.addAction(searchBibleReferences)

        searchBibleReferences = QAction(self)
        searchBibleReferences.setText(config.thisTranslation["bar1_menu"])
        searchBibleReferences.triggered.connect(
            self.displayVersesInBibleWindow)
        subMenu.addAction(searchBibleReferences)

        searchBibleReferences = QAction(self)
        searchBibleReferences.setText(config.thisTranslation["bottomWindow"])
        searchBibleReferences.triggered.connect(
            self.displayVersesInBottomWindow)
        subMenu.addAction(searchBibleReferences)

        action = QAction(self)
        action.setText(config.thisTranslation["displayVerses"])
        action.setMenu(subMenu)
        self.addAction(action)

        if self.name in ("main", "study"):

            subMenu = QMenu()

            if hasattr(config, "cli"):
                action = QAction(self)
                action.setText(config.thisTranslation["cli"])
                action.triggered.connect(self.switchToCli)
                subMenu.addAction(action)

            action = QAction(self)
            action.setText(config.thisTranslation["openOnNewWindow"])
            action.triggered.connect(self.openOnNewWindow)
            subMenu.addAction(action)

            action = QAction(self)
            action.setText(config.thisTranslation["pdfDocument"])
            action.triggered.connect(self.exportToPdf)
            subMenu.addAction(action)

            action = QAction(self)
            action.setText(config.thisTranslation["displayContent"])
            action.setMenu(subMenu)
            self.addAction(action)

        separator = QAction(self)
        separator.setSeparator(True)
        self.addAction(separator)

        subMenu = QMenu()

        copyText = QAction(self)
        copyText.setText(config.thisTranslation["text"])
        copyText.triggered.connect(self.copySelectedText)
        subMenu.addAction(copyText)

        copyReferences = QAction(self)
        copyReferences.setText(config.thisTranslation["bibleReferences"])
        copyReferences.triggered.connect(self.copyAllReferences)
        subMenu.addAction(copyReferences)

        copyHtml = QAction(self)
        copyHtml.setText(config.thisTranslation["htmlCode"])
        copyHtml.triggered.connect(self.copyHtmlCode)
        subMenu.addAction(copyHtml)

        action = QAction(self)
        action.setText(config.thisTranslation["context1_copy"])
        action.setMenu(subMenu)
        self.addAction(action)

        separator = QAction(self)
        separator.setSeparator(True)
        self.addAction(separator)

        if self.name == "main":
            subMenu = QMenu()

            # Instant highlight feature
            action = QAction(self)
            action.setText(config.thisTranslation["menu_highlight"])
            action.triggered.connect(self.instantHighlight)
            subMenu.addAction(action)

            action = QAction(self)
            action.setText(config.thisTranslation["remove"])
            action.triggered.connect(self.removeInstantHighlight)
            subMenu.addAction(action)

            action = QAction(self)
            action.setText(config.thisTranslation["instantHighlight"])
            action.setMenu(subMenu)
            self.addAction(action)

            separator = QAction(self)
            separator.setSeparator(True)
            self.addAction(separator)

        action = QAction(self)
        action.setText(config.thisTranslation["context1_search"])
        action.triggered.connect(self.searchPanel)
        self.addAction(action)

        subMenu = QMenu()

        self.searchText = QAction(self)
        self.searchText.setText("{0} [{1}]".format(
            config.thisTranslation["context1_search"], config.mainText))
        self.searchText.triggered.connect(self.searchSelectedText)
        subMenu.addAction(self.searchText)

        self.searchTextInBook = QAction(self)
        self.searchTextInBook.setText(
            config.thisTranslation["context1_current"])
        self.searchTextInBook.triggered.connect(self.searchSelectedTextInBook)
        subMenu.addAction(self.searchTextInBook)

        searchFavouriteBible = QAction(self)
        searchFavouriteBible.setText(
            config.thisTranslation["context1_favourite"])
        searchFavouriteBible.triggered.connect(
            self.searchSelectedFavouriteBible)
        subMenu.addAction(searchFavouriteBible)

        action = QAction(self)
        action.setText(config.thisTranslation["cp0"])
        action.setMenu(subMenu)
        self.addAction(action)

        subMenu = QMenu()

        bibleVerseParser = BibleVerseParser(config.parserStandarisation)
        for bookNo in range(1, 67):
            action = QAction(self)
            action.setText(bibleVerseParser.standardFullBookName[str(bookNo)])
            action.triggered.connect(
                partial(self.searchSelectedTextInBook, bookNo))
            subMenu.addAction(action)

        action = QAction(self)
        action.setText(config.thisTranslation["bibleBook"])
        action.setMenu(subMenu)
        self.addAction(action)

        subMenu = QMenu()

        for text in self.parent.parent.textList:
            action = QAction(self)
            action.setText(text)
            action.triggered.connect(partial(self.searchSelectedText, text))
            subMenu.addAction(action)

        action = QAction(self)
        action.setText(config.thisTranslation["bibleVersion"])
        action.setMenu(subMenu)
        self.addAction(action)

        # Search Strong's number bibles, if installed
        if self.parent.parent.strongBibles:
            subMenu = QMenu()
            for text in self.parent.parent.strongBibles:
                action = QAction(self)
                action.setText(text)
                action.triggered.connect(partial(self.searchStrongBible, text))
                subMenu.addAction(action)

            separator = QAction(self)
            separator.setSeparator(True)
            subMenu.addAction(separator)

            action = QAction(self)
            action.setText(config.thisTranslation["all"])
            action.triggered.connect(self.searchAllStrongBible)
            subMenu.addAction(action)

            action = QAction(self)
            action.setText(config.thisTranslation["bibleConcordance"])
            action.setMenu(subMenu)
            self.addAction(action)

        subMenu = QMenu()
        for keyword in ("SEARCHBOOKNOTE", "SEARCHCHAPTERNOTE",
                        "SEARCHVERSENOTE"):
            action = QAction(self)
            action.setText(config.thisTranslation[keyword])
            action.triggered.connect(partial(self.searchBibleNote, keyword))
            subMenu.addAction(action)

        separator = QAction(self)
        separator.setSeparator(True)
        subMenu.addAction(separator)

        action = QAction(self)
        action.setText(config.thisTranslation["removeNoteHighlight"])
        action.triggered.connect(self.removeNoteHighlight)
        subMenu.addAction(action)

        action = QAction(self)
        action.setText(config.thisTranslation["menu6_notes"])
        action.setMenu(subMenu)
        self.addAction(action)

        subMenu = QMenu()

        searchBibleCharacter = QAction(self)
        searchBibleCharacter.setText(
            config.thisTranslation["menu5_characters"])
        searchBibleCharacter.triggered.connect(self.searchCharacter)
        subMenu.addAction(searchBibleCharacter)

        searchBibleName = QAction(self)
        searchBibleName.setText(config.thisTranslation["menu5_names"])
        searchBibleName.triggered.connect(self.searchName)
        subMenu.addAction(searchBibleName)

        searchBibleLocation = QAction(self)
        searchBibleLocation.setText(config.thisTranslation["menu5_locations"])
        searchBibleLocation.triggered.connect(self.searchLocation)
        subMenu.addAction(searchBibleLocation)

        subSubMenu = QMenu()

        action = QAction(self)
        action.setText(config.thisTranslation["previous"])
        action.triggered.connect(self.searchTopic)
        subSubMenu.addAction(action)

        separator = QAction(self)
        separator.setSeparator(True)
        subSubMenu.addAction(separator)

        for module in self.parent.parent.topicListAbb:
            action = QAction(self)
            action.setText(module)
            action.triggered.connect(partial(self.searchResource, module))
            subSubMenu.addAction(action)

        action = QAction(self)
        action.setText(config.thisTranslation["menu5_topics"])
        action.setMenu(subSubMenu)
        subMenu.addAction(action)

        subSubMenu = QMenu()

        action = QAction(self)
        action.setText(config.thisTranslation["previous"])
        action.triggered.connect(self.searchDictionary)
        subSubMenu.addAction(action)

        separator = QAction(self)
        separator.setSeparator(True)
        subSubMenu.addAction(separator)

        for module in self.parent.parent.dictionaryListAbb:
            action = QAction(self)
            action.setText(module)
            action.triggered.connect(partial(self.searchResource, module))
            subSubMenu.addAction(action)

        action = QAction(self)
        action.setText(config.thisTranslation["context1_dict"])
        action.setMenu(subSubMenu)
        subMenu.addAction(action)

        subSubMenu = QMenu()

        action = QAction(self)
        action.setText(config.thisTranslation["previous"])
        action.triggered.connect(self.searchEncyclopedia)
        subSubMenu.addAction(action)

        separator = QAction(self)
        separator.setSeparator(True)
        subSubMenu.addAction(separator)

        for module in self.parent.parent.encyclopediaListAbb:
            action = QAction(self)
            action.setText(module)
            action.triggered.connect(partial(self.searchResource, module))
            subSubMenu.addAction(action)

        action = QAction(self)
        action.setText(config.thisTranslation["context1_encyclopedia"])
        action.setMenu(subSubMenu)
        subMenu.addAction(action)

        subSubMenu = QMenu()

        action = QAction(self)
        action.setText(config.thisTranslation["previous"])
        action.triggered.connect(self.searchHebrewGreekLexicon)
        subSubMenu.addAction(action)

        separator = QAction(self)
        separator.setSeparator(True)
        subSubMenu.addAction(separator)

        for module in self.parent.parent.lexiconList:
            action = QAction(self)
            action.setText(module)
            action.triggered.connect(
                partial(self.searchHebrewGreekLexiconSelected, module))
            subSubMenu.addAction(action)

        action = QAction(self)
        action.setText(config.thisTranslation["menu5_lexicon"])
        action.setMenu(subSubMenu)
        subMenu.addAction(action)

        subSubMenu = QMenu()

        action = QAction(self)
        action.setText(config.thisTranslation["previous"])
        action.triggered.connect(self.searchThirdPartyDictionary)
        subSubMenu.addAction(action)

        separator = QAction(self)
        separator.setSeparator(True)
        subSubMenu.addAction(separator)

        for module in self.parent.parent.thirdPartyDictionaryList:
            action = QAction(self)
            action.setText(module)
            action.triggered.connect(
                partial(self.searchThirdPartyDictionarySelected, module))
            subSubMenu.addAction(action)

        action = QAction(self)
        action.setText(config.thisTranslation["menu5_3rdDict"])
        action.setMenu(subSubMenu)
        subMenu.addAction(action)

        action = QAction(self)
        action.setText(config.thisTranslation["bibleResources"])
        action.setMenu(subMenu)
        self.addAction(action)

        subMenu = QMenu()

        action = QAction(self)
        action.setText(config.thisTranslation["previous"])
        action.triggered.connect(self.searchPreviousBook)
        subMenu.addAction(action)

        separator = QAction(self)
        separator.setSeparator(True)
        subMenu.addAction(separator)

        subSubMenu = QMenu()

        for module in config.favouriteBooks:
            action = QAction(self)
            action.setText(module)
            action.triggered.connect(partial(self.searchSelectedBook, module))
            subSubMenu.addAction(action)

        separator = QAction(self)
        separator.setSeparator(True)
        subSubMenu.addAction(separator)

        action = QAction(self)
        action.setText(config.thisTranslation["all"])
        action.triggered.connect(self.searchFavouriteBooks)
        subSubMenu.addAction(action)

        action = QAction(self)
        action.setText(config.thisTranslation["context1_favouriteBooks"])
        action.setMenu(subSubMenu)
        subMenu.addAction(action)

        action = QAction(self)
        action.setText(config.thisTranslation["context1_allBooks"])
        action.triggered.connect(self.searchAllBooks)
        subMenu.addAction(action)

        separator = QAction(self)
        separator.setSeparator(True)
        subMenu.addAction(separator)

        action = QAction(self)
        action.setText(config.thisTranslation["removeBookHighlight"])
        action.triggered.connect(self.removeBookHighlight)
        subMenu.addAction(action)

        action = QAction(self)
        action.setText(config.thisTranslation["installBooks"])
        action.setMenu(subMenu)
        self.addAction(action)

        separator = QAction(self)
        separator.setSeparator(True)
        self.addAction(separator)

        # TEXT-TO-SPEECH feature
        languages = self.parent.parent.getTtsLanguages()
        tts = QAction(self)
        tts.setText("{0} [{1}]".format(
            config.thisTranslation["context1_speak"],
            languages[config.ttsDefaultLangauge][1].capitalize()))
        tts.triggered.connect(self.textToSpeech)
        self.addAction(tts)

        if config.isTtsInstalled:
            ttsMenu = QMenu()
            languageCodes = list(languages.keys())
            items = [languages[code][1] for code in languageCodes]
            for index, item in enumerate(items):
                languageCode = languageCodes[index]
                action = QAction(self)
                action.setText(item.capitalize())
                action.triggered.connect(
                    partial(self.textToSpeechLanguage, languageCode))
                ttsMenu.addAction(action)

            tts = QAction(self)
            tts.setText(config.thisTranslation["context1_speak"])
            tts.setMenu(ttsMenu)
            self.addAction(tts)

        separator = QAction(self)
        separator.setSeparator(True)
        self.addAction(separator)

        # IBM-Watson Translation Service

        # Translate into User-defined Language
        userLanguage = config.userLanguage
        translateText = QAction(self)
        translateText.setText("{0} [{1}]".format(
            config.thisTranslation["context1_translate"], userLanguage))
        translateText.triggered.connect(self.checkUserLanguage)
        self.addAction(translateText)

        translateMenu = QMenu()
        for index, item in enumerate(Translator.toLanguageNames):
            languageCode = Translator.toLanguageCodes[index]
            action = QAction(self)
            action.setText(item)
            action.triggered.connect(
                partial(self.selectedTextToSelectedLanguage, languageCode))
            translateMenu.addAction(action)

        translate = QAction(self)
        translate.setText(config.thisTranslation["watsonTranslator"])
        translate.setMenu(translateMenu)
        self.addAction(translate)

        translateMenu = QMenu()
        for language, languageCode in Languages.googleTranslateCodes.items():
            action = QAction(self)
            action.setText(language)
            action.triggered.connect(
                partial(self.googleTranslate, languageCode))
            translateMenu.addAction(action)

        translate = QAction(self)
        translate.setText(config.thisTranslation["googleTranslate"])
        translate.setMenu(translateMenu)
        self.addAction(translate)

        # Context menu plugins
        if config.enablePlugins:

            separator = QAction(self)
            separator.setSeparator(True)
            self.addAction(separator)

            subMenu = QMenu()

            for plugin in FileUtil.fileNamesWithoutExtension(
                    os.path.join("plugins", "context"), "py"):
                if not plugin in config.excludeContextPlugins:
                    action = QAction(self)
                    if "_" in plugin:
                        feature, shortcut = plugin.split("_", 1)
                        action.setText(feature)
                        # The following line does not work
                        #action.setShortcut(QKeySequence(shortcut))
                        self.parent.parent.addContextPluginShortcut(
                            plugin, shortcut)
                    else:
                        action.setText(plugin)
                    action.triggered.connect(partial(self.runPlugin, plugin))
                    subMenu.addAction(action)

            separator = QAction(self)
            separator.setSeparator(True)
            subMenu.addAction(separator)

            action = QAction(self)
            action.setText(config.thisTranslation["enableIndividualPlugins"])
            action.triggered.connect(
                self.parent.parent.enableIndividualPluginsWindow)
            subMenu.addAction(action)

            action = QAction(self)
            action.setText(config.thisTranslation["menu_plugins"])
            action.setMenu(subMenu)
            self.addAction(action)
コード例 #38
0
    def run(debug, env, username, password, correlate_data_params,
            enrich_data_params):

        correlate_out_dir = correlate_data_params["correlate_out_dir"]
        correlate_out_archive_dir = correlate_data_params[
            "correlate_out_archive_dir"]
        enrich_in_dir = enrich_data_params["enrich_in_dir"]
        enrich_in_archive_dir = enrich_data_params["enrich_in_archive_dir"]
        enrich_out_dir = enrich_data_params["enrich_out_dir"]

        # copy correlate data out to enrich in
        # move correlate out to correlate out archive
        FileUtil.copy_and_move_files(correlate_out_dir, enrich_in_dir,
                                     correlate_out_archive_dir, "*.csv")

        wj_api = WorkjamAPI(debug, env, username, password)

        # now in milliseconds
        now_timestamp = TimeUtil.get_current_milli_time()
        enrich_filename = 'Enrich_' + str(now_timestamp) + ".csv"

        print("\nLoading Data to be enriched from Filesystem...")
        df_enrich = FileUtil.get_df_from_csv_dir(enrich_in_dir, "*.csv")
        print("Complete. Count: " + str(df_enrich.shape[0]))

        # write header to the file

        response_user_header = wj_api.get_user_details(True, '', '')
        response_event_header = wj_api.get_event_details(True, '', '', '')

        FileUtil.write_to_file(
            enrich_out_dir + enrich_filename,
            'loggedin_user,company_id,query_datetime,apply_datetime,number_of_open_shifts,location_id,event_id,'
            + response_user_header + ',' + response_event_header +
            ',applied\n')

        print("\nEnriching User and Event info...")

        num_records_written_to_file = 0

        for index, row in df_enrich.iterrows():
            loggedinuser = row['loggedinuser']
            companyid = row['companyid']
            query_datetime = row['query_datetime']
            apply_datetime = row['apply_datetime']
            numberofopenshifts = row['numberofopenshifts']
            locationid = row['locationid']
            eventid = row['eventid']
            applied = row['applied']

            try:
                # Get Info for the Event in context
                response_event_csv = wj_api.get_event_details(
                    False, companyid, locationid, eventid)

                # Get Info for the User in context
                response_user_csv = wj_api.get_user_details(
                    False, companyid, loggedinuser)

                # # write enriche data to out dir with timestamp
                FileUtil.append_to_file(
                    enrich_out_dir + enrich_filename,
                    str(loggedinuser) + ',' + str(companyid) + ',' +
                    str(query_datetime) + ',' + str(apply_datetime) + ',' +
                    str(numberofopenshifts) + ',' + str(locationid) + ',' +
                    str(eventid) + ',' + response_user_csv + ',' +
                    response_event_csv + ',' + str(applied) + '\n')

                num_records_written_to_file += 1

            except Exception as e:
                print(e)

        print("Complete. Found: {} Written: {}\n".format(
            str(df_enrich.shape[0]), num_records_written_to_file))

        # move enrich in to enrich in archive
        FileUtil.move_files(enrich_in_dir, enrich_in_archive_dir, "*.csv")