def takeSnapshot(self): self.answer.delete('0', 'end') proimg = self.frame.copy() ts = datetime.datetime.now() filename = "{}.jpg".format(ts.strftime("%Y-%m-%d_%H-%M-%S")) #print("Output", self.frame.copy()) #print("Type", type(self.frame.copy())) """ img = Image.open("images/25.jpg") text = pytesseract.image_to_string(self.frame.copy()) print("answer", text) p = os.path.sep.join((self.outputPath, filename)) #print(type(self.frame.copy())) # save the file """ p = os.path.sep.join((self.outputPath, filename)) cv2.imwrite(p, proimg) img = cv2.imread(p) text = extractor.main(img) print("[INFO] saved {}".format(filename)) if text is '': self.answer.insert(1, "no data found") else: self.answer.insert(1, text)
def post(self, request, *args, **kwargs): if request.is_ajax(): form = self.form_class(request.POST) ''' reCAPTCHA validation ''' recaptcha_response = request.POST.get('recaptcha-response') data = { 'secret': CAPTCHA_KEY, 'response': recaptcha_response } r = requests.post('https://www.google.com/recaptcha/api/siteverify', data=data) result = r.json() ''' reCAPTCHA validation ends''' if form.is_valid() and result.get('success', ''): contact_list = main(form.cleaned_data["textarea"]) saved, notsaved = separeate(contact_list) contacts = "You Have {} Saved Contacts\n\n".format(len(saved)) contacts += "\r\n".join(saved) contacts += "\r\n\r\nYou have {} Contacts which are not saved\n\n".format(len(notsaved)) contacts += "\r\n".join(notsaved) return JsonResponse({"contacts": contacts, "count": len(contact_list)}) else: return JsonResponse({"error": "extraction failed!"}) else: return JsonResponse({"status": False})
def extract_files(projno, funcno, studentdir): """ Extract function(s) from files. If funcno < 0, extracts all functions from the given project. """ cwd = os.getcwd() sys.path.insert(0, cwd + "/projects/project" + str(projno)) info = importlib.import_module('description') ## Remove the path to avoid keeping old paths sys.path.pop(0) if funcno < 0: numfuncs = len(info.funclist) funcnos = range(numfuncs) else: funcnos = [funcno] outputdir = cwd + "/extracted_files/proj" + str(projno) + "_func" funcnames = [info.funclist[int(fno)] for fno in funcnos] extractor.main(os.path.abspath(studentdir), outputdir, funcnos, funcnames)
def gen_rels(seeds, test=False): exps = ["S1D1", "S1D2", "S4D1", "S4D2"] gen_folder = "test" if test else "valid" for seed in seeds: for exp in exps: sysname = get_sys(exp) avg = sysname == "S1" midstr = "_avg" if avg else "" datafile = get_datafile_path(exp) dict_pfx = get_dict_pfx(exp) ignore_idx = get_ignore_idx(exp) eval_models = get_eval_models(exp) pred_files = get_predictions(seed, exp, test) for pred_file in pred_files: step = get_model_steps(pred_file) preddata = "experiments/exp-seed-{}/exp-{}/gens/{}_ex/predictions{}_{}.h5".format( seed, exp, gen_folder, midstr, step) tupfile = preddata + "-tuples.txt" if os.path.exists(tupfile): logger.info("tuple file already exists:{}".format(tupfile)) continue sys.argv = [ sys.argv[0], "-datafile", datafile, "-preddata", preddata, "-dict_pfx", dict_pfx, "-ignore_idx", str(ignore_idx), "-eval_models", eval_models, "-just_eval" ] if test: sys.argv.append("-test") gtag = generate_h5(seed, exp, step, test, avg) if gtag: main() remove_h5(seed, exp, step, test, avg) else: logger.info( "gen h5 file error, seed:{} exp:{} step:{} test:{}". format(seed, exp, step, test))
#!/usr/bin/python import extractor #Importing extractor Class from sys import argv #Importing argv support (script, argument) = argv extractor.main(argument)
from extractor import main from pprint import pprint main()
def main(flag): global current_directory, extract_directory, cache_directory, scripts_directory, main_files # Получение имени папки проекта file_name = re.findall(r'\\\w+\.[\.\w\d-]*$', sys.argv[1]) project_folder = 'Decompiled_' + file_name[0].split('.', 1)[0].replace( '\\', '') + '_' + str(uuid4())[:5] print(Fore.YELLOW + '[>] Project folder name: %s' % project_folder) # Получение текущей директории current_directory = join(root, project_folder) # Папка в которой будет содержимое ехе файла extract_directory = join(current_directory, 'Extracted') # Если установлен флаг ехе начнется распаковка приложения if flag == '.exe': # Папка в которой будет хранится байт-код подключаймых модулей cache_directory = join(current_directory, 'Pycache') # Объявление папки для сохранения скриптов используймых модулей modules_directory = join(current_directory, 'Modules') # Объявление папки для сохранения основных скриптов программы scripts_directory = join(current_directory, 'Main') # Создание папок create_directory(current_directory, extract_directory, modules_directory, cache_directory, scripts_directory) # Передача extractor'у пути для сохранения кеша модулей extractor.set_cache_path(cache_directory) # Передача extractor'у пути для сохранения содержимого ехе файла extractor.set_extra_path(extract_directory) # Запуск декомпиляции проекта с помощью модуля extractor try: extractor.main() # Получениие списка возможних файлов main_files = extractor.get_main_files() for f in main_files: rename(join(extract_directory, f), join(extract_directory, f + '.pyc')) # Декомпиляция файлов в скрипт cache_decompiler(main_files, extract_directory, scripts_directory) # Спрашивает нужно ли компилоровать все .pyc файлы while True and auto_lib_decompiling is None: answer = input( '[?] Decompile all pycache files? (y/n): ').lower() if answer == 'y': # Декомпиляция файлов в скрипт cache_decompiler(None, cache_directory, modules_directory) break if answer == 'n': break except: try: print(Fore.YELLOW + '[>] Beginning extraction with py2exe!') unpy2exe.unpy2exe(sys.argv[1], '%s.%s' % sys.version_info[0:2], extract_directory) print(Fore.GREEN + '[>] decoding completed successfully!') # Декомпиляция файлов в скрипт cache_decompiler(None, extract_directory, scripts_directory) except Exception as e: #Обычно возникает когда файл не той же версии что и питон! print(Fore.RED + '[!] %s' % e) print(Fore.RED + '[!] The program can not decompile the file!') open_directory(extract_directory) # Если установлен флаг 'pyc' начнется распаковка файлов кэша if flag == '.pyc': # Создание папки для сохранения основных скриптов программы create_directory(current_directory) # Получение файла для декеширования file = [sys.argv[1]] # Декомпиляция файлов в скрипты cache_decompiler(file, current_directory, current_directory)
def main(file_name, dest_path): with open(file_name, 'r') as f: vids = f.readlines() vids = [v.strip() for v in vids] extractor.main(vids, base_path_to_chk_pts='./data/checkpoints', dest_path=dest_path)
import scorer import gflags import logger FLAGS = gflags.FLAGS if __name__ == '__main__': try: argv = FLAGS(sys.argv) # parse flags except gflags.FlagsError as e: print('%s\nUsage: %s ARGS\n%s' % (e, sys.argv[0], FLAGS)) sys.exit(1) import __main__ mydir = os.path.dirname(__main__.__file__) if os.path.exists(FLAGS.rule_dump): logger.writeln('unfiltered rules exists: %s' % FLAGS.rule_dump) else: extractor.main() FLAGS.filter_file = FLAGS.input scorer.main() glue_grammar = os.path.join(mydir, 'test-extractor/monotonic_glue.gr') if FLAGS.persent is None: FLAGS.grammars = [FLAGS.filtered, glue_grammar] else: FLAGS.grammars = [FLAGS.persent, glue_grammar] decoder.main()
def load_from_url(url, uploading=False): #The function with the metadata mapping, xmlstring = urlopen(url).read() xmldoc = minidom.parseString(xmlstring) itemlist = xmldoc.getElementsByTagName('channel') for s in itemlist: filelist = s.getElementsByTagName("item") for file in filelist: articletext = '== {{int:filedesc}} ==\n{{Photograph\n |photographer = ' collection = file.getElementsByTagName("dc:isPartOf") creator = file.getElementsByTagName( "dc:creator")[0].firstChild.data if creator == '[onbekend]' or creator == 'Onbekend' or creator == 'Fotograaf Onbekend': articletext += '{{unknown}}' hasPhotographerInDict = False elif creator == 'Fotograaf Onbekend / Anefo': articletext += '{{unknown}} (Anefo)' hasPhotographerInDict = False elif creator == 'Fotograaf Onbekend / DLC': articletext += '{{unknown}} (Fotocollectie Dienst voor Legercontacten Indonesië)' hasPhotographerInDict = False else: hasPhotographerInDict, photographerName, isAnefo = photographers_dict( creator) if hasPhotographerInDict: articletext += photographerName else: articletext += creator if isAnefo: articletext += ' (Anefo)' articletext += '\n |title = {{nl|' if file.getElementsByTagName("title")[0].firstChild: title = file.getElementsByTagName("title")[0].firstChild.data else: title = 'zonder titel' articletext += title articletext += '}}\n |description = {{nl|' if file.getElementsByTagName("description")[0].firstChild: description = file.getElementsByTagName( "description")[0].firstChild.data else: description = title articletext += description + '}}\n |depicted people = ' subjects = file.getElementsByTagName("dc:subject") for sub in subjects: if sub.getAttribute( 'rdf:about' ) == 'http://www.gahetna.nl/dc/subject/Persoons_instellingsnaam': articletext += sub.firstChild.data + ' ' articletext += '\n |depicted place =\n |date = ' date = file.getElementsByTagName("dc:date")[0].firstChild.data articletext += date + '\n |medium = {{nl|' type = file.getElementsByTagName("dc:type") for ty in type: medium = ty.firstChild.data collectionname = collection[1].firstChild.data reportagename = collection[2].firstChild.data articletext += medium articletext += '}}\n |dimensions =\n |institution = Nationaal Archief\n |department = ' + collection[ 1].firstChild.data if reportagename != '[ onbekend ]': articletext += ', ' + reportagename articletext += '\n |references =\n |object history =\n |exhibition history =\n |credit line = ' articletext += '' #add creditline + articletext += '\n |inscriptions =\n |notes =\n |accession number = ' identifiers = file.getElementsByTagName("dc:identifier") for id in identifiers: identifier = id.firstChild.data for partof in collection: a = re.match('([0-9\.]+)', partof.firstChild.data) if a != None: archiefinventaris = a.group(0) articletext += archiefinventaris + ' (archive inventory number), ' + identifier + ' (file number)\n |source = ' link = file.getElementsByTagName("link")[0].firstChild.data UUID = re.search('([\d\w\-]*)$', link).group(0) articletext += 'Nationaal Archief, ' + collectionname + ', {{Nationaal Archief-source|UUID=' + UUID + '|file_share_id=' + identifier + '}}\n |permission = ' r = file.getElementsByTagName("right") for r2 in r: if r2.getAttribute('name') == 'Public Domain': if r2.firstChild.data == 'TRUE': permission = 'Public Domain' license = '{{PD-old}}' elif r2.getAttribute('name') == 'CC BY': if r2.firstChild.data == 'TRUE': permission = 'CC BY 4.0' license = '{{cc-by-4.0}}' elif r2.getAttribute('name') == 'CC BY SA': if r2.firstChild.data == 'TRUE': permission = 'CC BY SA 4.0' license = '{{cc-by-sa-4.0}}' articletext += permission + '\n |other_versions =\n }}\n\n== {{int:license-header}} ==\n{{Nationaal Archief}}\n' + license + '\n\n' if hasPhotographerInDict: articletext += '[[Category:Photographs by ' + photographerName + ']]\n' if title == description: categories = main(title) else: categories += main(title) categories = main(description) categories += main(collectionname) for category in categories: articletext += '[[Category:' + category + ']]\n' print category images = file.getElementsByTagName("ese:isShownBy") gotimage = False for image in images: if '10000x10000' in image.firstChild.data and not gotimage: print(image.firstChild.data) gotimage = True image_url = image.firstChild.data if len(title) > 85: #cut off the description if it's longer than 85 tokens at a space around 85. filetitle = title[:90] cutposition = filetitle.rfind(' ') if (cutposition > 20): filetitle = re.sub('[:/#\[\]\{\}<>\|_]', '', unidecode(filetitle[:cutposition])) else: filetitle = re.sub('[:/#\[\]\{\}<>\|_;\?]', '', unidecode(title)) articletitle = filetitle + ' - Nationaal Archief - ' + identifier + '.jpg' print(articletitle.encode('utf-8')) print(articletext.encode('utf-8')) print(image_url.encode('utf-8')) if uploading: upload_file(image_url, articletext, articletitle)
#!/usr/bin/python import extractor #Importing extractor Class from sys import argv #Importing argv support (script, argument) = argv extractor.main(argument)