def convert_to_txt(self): converter = Converter(self.file_name+".pdf",self.target_name,self.path) converter.convert() reader = Reader(self.target_name,self.pg_count,self.path) extracted_text = reader.get_text() extracted_text = os.linesep.join([s for s in extracted_text.splitlines() if s]) writer = Writer((self.target_name+".txt"),extracted_text,self.path) writer.write()
def run(self): total_num = len(self.model_ls) for idx, (model, cfg) in enumerate(zip(self.model_ls, self.cfg_ls)): print( "-------------------[{}/{}]: Begin Converting {}--------------" .format(idx + 1, total_num, model)) converter = Converter(model, cfg, self.get_onnx_path(model), self.get_libtorch_path(model), self.get_onnx_sim_path(model)) converter.convert()
def video_upload(update, context): user = update.message.from_user chat_id = update.message.chat.id video_file = update.message.video.get_file() video_file.download(f'{chat_id}_video.mp4') logger.info("Video upload successful %s", user.first_name) logger.info( f"chat_id:{chat_id} │ Got video from {user.first_name} {chat_id}_video.jpg" ) # api.set_data('/set') api.set_video(video_file.download_as_bytearray(), chat_id) logger.info("Video of %s: %s", user.first_name, f'{chat_id}_video.mp4') update.message.reply_text( 'Perfect! Now, wait, we are processing your request. Please wait, processing can last longer than 30 seconds' ) res = api.set_data('/inference', chat_id) bot = update.message.bot c = Converter(base64.b64encode(video_file.download_as_bytearray()), res['video'], result=f"{chat_id}_final.mp4") c.convert() with open(f"{chat_id}_final.gif", "wb") as fh: fh.write(base64.b64decode(res['video'])) bot.send_video(chat_id, video=open(f'{chat_id}_final.mp4', 'rb'), caption="Here's what I have for you.") logger.info( f"chat_id:{chat_id} │ Got video from {user.first_name}: {chat_id}_video.mp4" ) logger.info(f"chat_id:{chat_id} │ Send final result {user.first_name}") update.message.reply_text( 'Hope you enjoyed the result.\n\nTo start over message me with /start.', reply_markup=ReplyKeyboardRemove()) logger.info( f"chat_id:{update.message.chat.id} │ User {user.first_name} ended the conversation" ) return ConversationHandler.END
class UnitsWorkflow(Workflow): def __init__(self): super(UnitsWorkflow, self).__init__() self.currencies_file = os.path.join(self.cache_dir, 'currencies.txt') self.load_currencies() self.separator = self.config.get('separator') or '>' self.precision = self.config.get('precision') or None self.config['separator'] = self.separator self.config['precision'] = self.precision self.converter = Converter(self.currencies_file, separator=self.separator, precision=self.precision) def load_currencies(self): import datetime lines = [] last_refresh = None today = datetime.date.today() if os.path.exists(self.currencies_file): with open(self.currencies_file, 'rt') as cf: lines = cf.readlines() if len(lines) > 0 and lines[0].startswith('# date:'): last_refresh = lines[0].split(':')[1].strip() last_refresh = datetime.datetime.strptime(last_refresh, '%Y-%m-%d').date() if not last_refresh or last_refresh != today: import yfinance rates = yfinance.get_rates(CURRENCIES) with open(self.currencies_file, 'wt') as cf: cf.write('# date: ' + today.strftime('%Y-%m-%d') + '\n') cf.write('USD = [currency] = usd\n') for k, v in rates.items(): cf.write('{0} = USD / {1} = {2}\n'.format(k, v, k.lower())) def _convert(self, query): query = query.strip() try: value, text = self.converter.convert(query) except Exception, e: LOG.exception('Error converting') if e.message.startswith('Parse error in query'): return [Item('Waiting for input...')] else: try: int(e.message) return [Item('Waiting for input...')] except: pass raise e return [Item(text, arg=str(value), valid=True, subtitle='Action this item to copy %s to the ' 'clipboard' % value)]
"1) If you use an on premise installation, use bw config to set the url: bw config server <url>" ) print( "2) execute bw login once, as this script uses bw unlock only: bw login <user>" ) print(" ") while confirm != "y" and confirm != "n": confirm = input( "Confirm that you have set up bw cli [y/n]: ").lower() if confirm == "n": print("exiting...") sys.exit(2) # stdin password kp_pw = _read_password(args.kp_pw, "Please enter your KeePass 2.x db password: "******"Please enter your Bitwarden password: "******" ") print("All done.")
class TestConfigConverter(unittest.TestCase): data = {} def setUp(self): super().setUp() self.converter = Converter('old-test.txt', 'new-test.txt') self.converter.convert() self.data['test_key_convert'] = { "/Scripts/Key Bindings/GUI/Key": 52, "/GUI/Key": 52, "/Key Bindings/Script Bindings/GUI/Key": 52, "/.FAIO/7. dodgeIT/3. Dangerous enemy skills/Table 1/chaos_knight_chaos_bolt {{dodger}}": 1, "/Scripts/Script Options/.FAIO/7. dodgeIT/3. Dangerous enemy skills/Table 1/chaos_knight_chaos_bolt {{dodger}}": 1, "/Scripts/Script Options/.FAIO/2. Item Usage/1. Offensive items/1. Combo usage/Items/Use Item Shivas Guard": 1, "/.FAIO/2. Item Usage/1. Offensive items/1. Combo usage/Items/Use Item Shivas Guard": 1, "/.FAIO/6. Last hitter/7. Push key {{lasthit}}": 36, "/Key Bindings/Script Bindings/.FAIO/6. Last hitter/7. Push key {{lasthit}}": 36, "/Scripts/Key Bindings/.FAIO/6. Last hitter/7. Push key {{lasthit}}": 36, "/Scripts/Script Options/.FAIO/3. Hero Scripts/3. Intelligence heroes/Tinker/3. Push mode/1. Tinker push mode": 1, "/.FAIO/3. Hero Scripts/3. Intelligence heroes/Tinker/3. Push mode/1. Tinker push mode": 1, "/.FAIO/3. Hero Scripts/3. Intelligence heroes/Tinker/3. Push mode/2. Tinker push key {{tinker}}": 58, "/Key Bindings/Script Bindings/.FAIO/3. Hero Scripts/3. Intelligence heroes/Tinker/3. Push mode/2. Tinker push key {{tinker}}": 58, "/Scripts/Key Bindings/.FAIO/3. Hero Scripts/3. Intelligence heroes/Tinker/3. Push mode/2. Tinker push key {{tinker}}": 58, "/Utility/Translate/My Text To": 5, "/Utility/Translate/Their Text To": 2, "/Awareness/ESP/Illusion ESP": 1, "/Awareness/ESP/Illusion ESP/Illusion ESP": 1, "/Awareness/ESP/Illusion ESP/Illusion ESP: Hero Floats": 1, "/Awareness/ESP/Illusion ESP/Illusion ESP: Show on MiniMap": 1, "/Awareness/ESP/Illusion ESP/Illusion ESP: Unselectable": 0, "/Hero Specific/Shadow Fiend/Shadowraze Key": 36, "/Key Bindings/Shadowraze Key": 36, "/.FAIO/3. Hero Scripts/3. Intelligence heroes/Invoker/5. Fast skills/Chaos meteor/2. Activation key {{invoker Chaos meteor}}": 4, "/Key Bindings/Script Bindings/.FAIO/3. Hero Scripts/3. Intelligence heroes/Invoker/5. Fast skills/Chaos meteor/2. Activation key {{invoker Chaos meteor}}": 4, "/Scripts/Key Bindings/.FAIO/3. Hero Scripts/3. Intelligence heroes/Invoker/5. Fast skills/Chaos meteor/2. Activation key {{invoker Chaos meteor}}": 4, "/Scripts/Script Options/Awareness/Show Hidden Spells Plus/Invoker - EMP": 1 } def test_key_convert(self): self.assertEqual(self.data['test_key_convert'], self.converter.new_config) def test_config_parser_exceptions(self): with self.assertRaises(ConfigParserException): Converter('fakename.txt', 'fakename2.txt')
class UnitsWorkflow(Workflow): def __init__(self): super(UnitsWorkflow, self).__init__() self.currencies_file = os.path.join(self.cache_dir, 'currencies.txt') self.load_currencies() self.separator = self.config.get('separator') or '>' self.precision = self.config.get('precision') or None self.config['separator'] = self.separator self.config['precision'] = self.precision self.converter = Converter(self.currencies_file, separator=self.separator, precision=self.precision) def load_currencies(self): import datetime lines = [] last_refresh = None today = datetime.date.today() if os.path.exists(self.currencies_file): with open(self.currencies_file, 'rt') as cf: lines = cf.readlines() if len(lines) > 0 and lines[0].startswith('# date:'): last_refresh = lines[0].split(':')[1].strip() last_refresh = datetime.datetime.strptime(last_refresh, '%Y-%m-%d').date() if not last_refresh or last_refresh != today: import yfinance rates = yfinance.get_rates(CURRENCIES) with open(self.currencies_file, 'wt') as cf: cf.write('# date: ' + today.strftime('%Y-%m-%d') + '\n') cf.write('USD = [currency] = usd\n') for k, v in rates.items(): cf.write('{0} = USD / {1} = {2}\n'.format(k, v, k.lower())) def _convert(self, query): query = query.strip() try: value, text = self.converter.convert(query) except Exception, e: LOG.exception('Error converting') if e.message.startswith('Parse error in query'): return [Item('Waiting for input...')] else: try: int(e.message) return [Item('Waiting for input...')] except: pass raise e return [ Item(text, arg=str(value), valid=True, subtitle='Action this item to copy %s to the ' 'clipboard' % value) ]