async def polish(self, interaction, word: str = None): await interaction.defer() me = interaction.author if not word: return await interaction.send( f"**Please {me.mention}, inform a word to search!**", hidden=True) root = 'http://online-polish-dictionary.com/word' async with self.session.get(f"{root}/{word}") as response: if response.status == 200: data = await response.text() start = 'https://e-polish.eu/dictionary/en/' end = '.pdf' s = data.find(start) e = data.find(end) url = data[s:e + 4] else: return await interaction.send( "**For some reason I couldn't process it!**", hidden=True) async with self.session.get(url) as response: #response = requests.get(url) if response.status == 200: try: with open(f'files/{me.id}.pdf', 'wb') as f: f.write(await response.read()) except Exception: return await interaction.send( "**I couldn't find anything for that word!**", hidden=True) else: # print(error) return await interaction.reply( "**For some reason I couldn't process it!**", hidden=True) convertapi.api_secret = self.pdf_token convertapi.convert('png', { 'File': f'./files/{me.id}.pdf', }, from_format='pdf').save_files('./files') # Opens a image in RGB mode im = Image.open(rf"files/{me.id}.png") # Size of the image in pixels (size of orginal image) # (This is not mandatory) # Setting the points for cropped image left = 155 top = 300 right = 1550 bottom = 1550 # Cropped image of above dimension # (It will not change orginal image) im1 = im.crop((left, top, right, bottom)) # Shows the image in image viewer im1.save(f'files/{me.id}.png') file = discord.File(f'files/{me.id}.png', filename='polish.png') await interaction.send(file=file) os.remove(f"files/{me.id}.pdf") os.remove(f"files/{me.id}.png")
def convertapi_to_pdf(from_file, to_file): convertapi.api_secret = daconfig.get('convertapi secret') result = convertapi.convert('pdf', { 'File': from_file }) result.file.save(to_file)
import convertapi import os import tempfile convertapi.api_secret = os.environ['CONVERT_API_SECRET'] # your api secret # Example of extracting first and last pages from PDF and then merging them back to new PDF. # https://www.convertapi.com/pdf-to-split # https://www.convertapi.com/pdf-to-merge split_result = convertapi.convert('split', {'File': 'files/test.pdf'}) first_page = split_result.files[0] last_page = split_result.files[-1] files = [first_page, last_page] merge_result = convertapi.convert('merge', {'Files': files}) saved_files = merge_result.save_files(tempfile.gettempdir()) print("The PDF saved to %s" % saved_files)
def convertapi_to_pdf(from_file, to_file): convertapi.api_secret = daconfig.get('convertapi secret') result = convertapi.convert('pdf', {'File': from_file}) result.file.save(to_file)
import convertapi path_txt = r'TEMP.txt' path_pdf = input('Input the path of pdf file:') convertapi.api_secret = 'JvAUsZV9gfILDwQ7' result = convertapi.convert('txt', {'File': path_pdf}, from_format='pdf') result.save_files(path_txt)
import convertapi convertapi.api_secret = '9JqSIe7fJPGuMHsh' convertapi.convert('txt', { 'File': 'Transcript.pdf' }, from_format='pdf').save_files('Transcript.txt') ''' def getinfo(key1,key2,key3): dic = {} linenum , res = 0 , 0 lst = simplify('Demo Transcript1.txt') ls = len(lst) for ele in lst: if key1 in ele: break linenum += 1 for i in range(linenum,ls): if key2 in lst[i]: dic[lst[i]] = float(lst[i+1]) #res = sorted(dic.items(),key = lambda item : item[1],reverse = True) #return res[:key3] for key in dic: res += dic[key] res /= len(dic) return round(res,3) def simplify(file): lst = [] #f = open('Demo Transcript1.txt') with open(file,'r') as files: #content = f.readline()
def doc_to_pdf_converter(infile): result = convertapi.convert('pdf', {'File': infile}) result.file.save(outfile) print("File created")