def test_get_image_main_color(): soup = ImageSoup() images = soup.search('blue site:en.wikipedia.org') im = images[0] main_color = im.main_color(reduce_size=True) assert len(main_color) == 1 assert main_color[0][0] == 'blue'
def test_imageresult_resize(): soup = ImageSoup() images = soup.search('python logo PNG') im = images[0] new_size = (400, 400) new_image = im.resize(new_size) assert new_image.size == new_size
def test_get_image_main_color(): soup = ImageSoup() images = soup.search('python logo PNG') im = images[0] main_color = im.main_color(reduce_size=True) assert len(main_color) == 1 assert main_color[0][0] == 'white'
def test_imageresult_show_image(): soup = ImageSoup() images = soup.search('python logo png') try: images[0].show() except: pytest.fail('Cant show image')
class Hunter(): IMAGES_WANTED = 5 def __init__(self): self.soup = ImageSoup() def hunt(self, word): images = self.soup.search(word, n_images=self.IMAGES_WANTED) return images
def image_download(): soup = ImageSoup() image_name = raw_input('Enter image name: ') images = soup.search(image_name, image_size='medium', aspect_ratio='square') im = images[0] im.URL im.size im.show() im.main_color(n=2) im.to_file(image_name + '.jpg')
def test_imageresult_tofile(): soup = ImageSoup() images = soup.search('pyhon site:python.org') im = images[0] im.to_file() STANDARD_NAME = 'image' assert os.path.isfile(STANDARD_NAME + '.png') is True os.remove(STANDARD_NAME + '.png') USER_INPUT_NAME = 'pythonlogo.png' im.to_file(USER_INPUT_NAME) assert os.path.isfile(USER_INPUT_NAME) is True os.remove(USER_INPUT_NAME)
def collectImagesGoogle(): soup = ImageSoup() for key in keywords: print("collecting images for keyword " + key) imagedir = directory + '/' + key if not os.path.exists(imagedir): os.makedirs(imagedir) images = soup.search(key, image_size='medium', n_images=1000) for i in range(0, len(images)): image = images[i] url = image.URL url = url.split('/') name = url[len(url) - 1] name = key + str(i) name = name + '.jpg' try: image.to_file(imagedir + '/' + name) except: print("some error occured") if i % 100 == 0: print("collected so far " + str(i))
def imagenes_google(marca,modelo,ano): # BUSQUEDA DE IMAGENES DEL MODELO DEL AURO EN GOOGLE busqueda = marca+modelo+ano if len(busqueda) == 1: print("\nError consiguiendo datos de SOAP") elif len(sys.argv) >= 3: try: auto = ImageSoup() images = auto.search(busqueda, n_images=5) firstimage = images[0] secondimage = images[1] thirdimage = images[2] firstimage.show() secondimage.show() thirdimage.show() except: print("Error en busqueda de imagen de vehiculo") else: pass
from imagesoup import ImageSoup import SaveImage soup = ImageSoup() # query = raw_input("Enter the query: ") # number_of_urls = int(input("Enter the number of urls to fetch: ")) number_of_urls = 500 queries = ["digital_meter"] for query in queries: saveObj = SaveImage.SaveImage("./gImages/meters2/" + query + "/" + query) images = soup.search(query, n_images=number_of_urls) for i in range(0, len(images)): img_url = images[i].URL print(i, img_url) saveObj.save(img_url)
li = [] for i in t1: if (i != '.' and i != '?' and i != '!'): str_ += i else: li.append(str_) str_ = "" l = len(li) print(li) print(l) ########################iniatialize IMageSOUP########################### imgsrch = ImageSoup() for i in range(0, l): print(li[i]) response = natural_language_understanding.analyze( text=li[i], features=Features(keywords=KeywordsOptions())).get_result() data = response #print(response) doc_sentence.update({str(i + 1): li[i]}) #absolute_image_paths = response_1.download(arguments) for p in data['keywords']: print('TEXT: ' + p['text']) doc_keywords.update({str(i + 1): p['text']}) images = imgsrch.search(p['text'], n_images=1) url = images[0].URL doc_image.update({str(i + 1): url})
def test_search_n_images_set_by_user(): N_IMAGES = 20 soup = ImageSoup() images = soup.search('python', n_images=N_IMAGES) assert len(images) == N_IMAGES
from imagesoup import ImageSoup soup = ImageSoup() images = soup.search('"mechanical room"', n_images=100) count = 0 for i in images: try: i.to_file("%s.jpg" % count) count += 1 except: pass
def test_search_image_returns_fewer_results_than_n_images(capsys): soup = ImageSoup() images = soup.search('python', n_images=2000) out, err = capsys.readouterr() assert out.startswith('Search query "python" returned only')
def test_imageresult_url(): soup = ImageSoup() images = soup.search('python site:python.org') im = images[0] assert im.URL.startswith('http')
def test_search_image_aspect_ratio(): soup = ImageSoup() images = soup.search('python site:python.org', aspect_ratio='tall') im = images[0] assert im.height > im.width
def test_search_image_exact_size(): soup = ImageSoup() size = (400, 400) images = soup.search('python', image_size=size) im = images[0] assert im.size == size
def test_search_with_image_size_parameter(): soup = ImageSoup() images = soup.search('python site:python.org', image_size='large') im = images[0] width, height = im.size assert width > 500 and height > 500
async def on_message(message): print(str(message.author.id) + ' ' + str(message.author)) # print(nameAndEmoteFilter(message.content,client)) print(message.channel.id, message.channel) # print(userFilter(str(message.content))) user = message.author read = open("list.txt", "r", encoding="utf-8") text = read.read() # print(text) if str(user.id) not in text: output = open("list.txt", "a+", encoding="utf-8") output.write(str(user.id) + ": " + user.name + '\n') output.close() read.close() if message.author == client.user: return read = open("blacklist.txt", "r", encoding="utf-8") text = read.read() read.close() # if one knows how to apology, delete the one's id from blacklist with open("blacklist.txt", "r", encoding="utf-8") as f: lines = f.readlines() if (message.content != None): if (message.content.lower() == "xin lỗi senko" and str(user.id) in text): os.remove("blacklist.txt") rewrite = open("blacklist.txt", "w+", encoding="utf-8") for line in lines: if str(user.id) not in line: rewrite.write(line) rewrite.close() message.content = "OK..." await message.channel.send("OK...") # Check if the one who just spoke in the blacklist or not, if yes: angry and mock him read = open("blacklist.txt", "r", encoding="utf-8") text = read.read() read.close() if str(user.id) in text: # self.reactToMessage(message_object.uid,MessageReaction.ANGRY) # message.content = quack(message.content) mocking(quack(nameAndEmoteFilter(message.content, client))) # await message.channel.send(quack(message.content)) emoji = '<:pikak:595999028240711691>' await message.add_reaction(emoji) await message.channel.send(file=discord.File('output.jpg')) await message.channel.send(user.mention) await message.channel.send(user.mention) await message.channel.send(user.mention) # self.send(message_object, thread_id=thread_id, thread_type=thread_type) else: # You mess with the wrong bot, m**********r if (message.content.lower().find("địt") >= 0 and message.content.lower().find("bot") >= 0) \ or (message.content.lower().find("đm") >= 0 and message.content.lower().find("bot") >= 0) \ or (message.content.lower().find("đ ") >= 0 and message.content.lower().find("bot") >= 0) \ or (message.content.lower().find("ngu") >= 0 and message.content.lower().find("bot") >= 0) \ or (message.content.lower().find("chó") >= 0 and message.content.lower().find("bot") >= 0) \ or (message.content.lower().find("lồn") >= 0 and message.content.lower().find("bot") >= 0) \ or (message.content.lower().find("phò") >= 0 and message.content.lower().find("bot") >= 0) \ or (message.content.lower().find("buồi") >= 0 and message.content.lower().find("bot") >= 0) \ or (message.content.lower().find("cax") >= 0 and message.content.lower().find("bot") >= 0) \ or (message.content.lower().find("dm") >= 0 and message.content.lower().find("bot") >= 0) \ or (message.content.lower().find("dkm") >= 0 and message.content.lower().find("bot") >= 0) \ or (message.content.lower().find("đkm") >= 0 and message.content.lower().find("bot") >= 0) \ or (message.content.lower().find("địt") >= 0 and message.content.lower().find("senko") >= 0) \ or (message.content.lower().find("đm") >= 0 and message.content.lower().find("senko") >= 0) \ or (message.content.lower().find("đ ") >= 0 and message.content.lower().find("senko") >= 0) \ or (message.content.lower().find("ngu") >= 0 and message.content.lower().find("senko") >= 0) \ or (message.content.lower().find("chó") >= 0 and message.content.lower().find("senko") >= 0) \ or (message.content.lower().find("lồn") >= 0 and message.content.lower().find("senko") >= 0) \ or (message.content.lower().find("phò") >= 0 and message.content.lower().find("senko") >= 0) \ or (message.content.lower().find("buồi") >= 0 and message.content.lower().find("senko") >= 0) \ or (message.content.lower().find("cax") >= 0 and message.content.lower().find("senko") >= 0) \ or (message.content.lower().find("dm") >= 0 and message.content.lower().find("senko") >= 0) \ or (message.content.lower().find("dkm") >= 0 and message.content.lower().find("senko") >= 0) \ or (message.content.lower().find("đkm") >= 0 and message.content.lower().find("senko") >= 0): emoji = '<:REEEEE:656417641883500545>' await message.add_reaction(emoji) if message.author.dm_channel == None: await message.author.create_dm() await message.author.dm_channel.send('Xong đời mày rồi, con chó ạ!' ) blacklist = open("blacklist.txt", "a+", encoding="utf-8") blacklist.write(str(user.id) + '\n') blacklist.close() if (message.content.lower().find(" sad") >= 0 or message.content.lower().find("alexa") >= 0 or message.content.lower().find("buồn") == 0): # message.content = "https://www.youtube.com/watch?v=kJQP7kiw5Fk" await message.channel.send( "https://www.youtube.com/watch?v=kJQP7kiw5Fk") if message.content != '' and message.content[-1] == '?': # message.content = "🤔" if random.randint(1, 4) == 2: await message.channel.send("<:senking:595632302495760439>") if message.content.lower().find("chọn ") == 0: choices = message.content[5:].split(',') if len(choices) > 1: message.content = random.choice(choices) await message.channel.send(message.content) elif message.content.lower( ).find("vả ") == 0 and message.content.lower( ).find("quạt") < 0 and message.content.lower().find( "ranh") < 0 and message.content.lower().find( "quat") < 0 and message.content.lower().find("rảnh") < 0: if message.content.lower().find("<@!") >= 0: slap( client.get_user(int(userFilterNick( message.content)[0])).name) elif message.content.lower().find("<@") >= 0: slap( client.get_user(int(userFilterOrig( message.content)[0])).name) else: slap(message.content[3:]) await message.channel.send(file=discord.File('slapout.jpg')) elif message.content.lower().find("pat ") == 0: if message.content.lower().find("<@!") >= 0: pat( client.get_user(int(userFilterNick( message.content)[0])).name) elif message.content.lower().find("<@") >= 0: pat( client.get_user(int(userFilterOrig( message.content)[0])).name) else: pat(message.content[4:]) await message.channel.send(file=discord.File('patout.jpg')) if message.content.lower().find(".gg ") == 0 and len( message.content) > 3: try: from googlesearch import search except ImportError: print("No module named 'google' found") # to search query = message.content[3:] message.content = "5 kết quả về " + message.content[3:] + ": \n" result = "" for j in search(query, tld="com", num=5, stop=5, pause=2): result = result + j + "\n" print(j) print(result) message.content = message.content + result await message.channel.send(message.content) if message.content.lower() == 'nanoja': embed = discord.Embed( title='Tiểu sử', description= 'Ta vốn là một chatbot trên facebook được Rảnh tạo ra vào một ngày đẹp trời tháng 5 năm 2019. Nhưng từ khi thanh niên Zucc nhúng tay vào thì ta được Rảnh cho chuyển sinh qua đây và hóa thành Senko vào 18/08/2019. \n今は童は仙狐じゃ!', colour=discord.Colour.orange()) # embed.set_image(url='https://tenor.com/6NXd.gif') embed.set_thumbnail( url= 'https://danbooru.donmai.us/data/__senko_sewayaki_kitsune_no_senko_san_drawn_by_araki495__c732565f9449561200981f705c540a78.png' ) embed.set_author( name='Senko của Rảnh nanoja!', icon_url= 'https://cdn.discordapp.com/emojis/595472994730770435.png') embed.add_field( name='Actions', value='vả, pat, chọn, .gg, .weather, .img, cưới, ly dị', inline=True) embed.add_field( name='Đừng buồn', value='Vì ta sẽ luôn ở bên để bật Despacito cho Người nghe', inline=True) embed.add_field( name='Đừng chửi ta', value= 'Vì Người cũng không muốn bị chửi, phải không nào... Nếu đã lỡ mồm thì phải xin lỗi nghe chưa?', inline=True) embed.add_field( name='Hãy góp ý', value= 'Vì ta không biết nhiều về thế giới hiện đại này lắm, nên là Người hãy chỉ cho ta biết là cần phải học thêm gì nhé. Ta sẽ cân nhắc nanoja.', inline=True) embed.set_footer(text='なのじゃ!') await message.channel.send(embed=embed) # Action Marry global marry global marryPartner global marryProposer if message.content.lower().find('cưới ') == 0 and len( message.content) > 5: if client.get_user(int(userIdFilter(message.content))) == None: await message.channel.send('Tag lại đối tượng của mình đi, ' + message.author.mention) elif userIdFilter( message.content ) == '589315866282164229' and message.author.id != 462170598399803394: await message.channel.send( 'Cảm ơn tấm lòng của Người, nhưng tấm thân này đã thuộc về Rảnh mất rồi... Hãy tìm ai đó tốt hơn ta đi nanoja.' ) elif userIdFilter( message.content ) == '589315866282164229' and message.author.id == 462170598399803394: await message.channel.send( 'N-Người nói gì vậy? Chúng ta đã thuộc về nhau rồi cơ mà, ' + message.author.mention) else: marry = 1 marryPartner = userIdFilter(message.content) marryProposer = str(message.author.id) read = open("couples.txt", "r", encoding="utf-8") text = read.read() read.close() # print(text) if marryPartner + ' ' + marryProposer in text or marryProposer + ' ' + marryPartner in text: await message.channel.send( 'Ủa, hai người đã cưới nhau rồi mà? Đùa hoài nanoja!') else: await message.channel.send( message.author.mention + ' đã cầu hôn ' + client.get_user( int(userIdFilter(message.content))).mention + '! Câu trả lời sẽ là gì đây? Ấn \'y\' để đồng ý hoặc ấn \'n\' để từ chối!' ) if message.content.lower( ) == 'y' and marry == 1 and marryPartner == str(message.author.id): marry = 0 output = open("couples.txt", "a+", encoding="utf-8") output.write(marryProposer + " " + marryPartner + '\n') output.close() await message.channel.send( '🎉🎉🎉 Xin chúc mừng ' + client.get_user(int(marryProposer)).mention + ' và ' + message.author.mention + ' đã đến được bên nhau nanoja!🎊🎊🎊 Chúc hai người hạnh phúc nanoja!🎉🎉🎉' ) marryPartner = '' marryProposer = '' if message.content.lower( ) == 'n' and marry == 1 and marryPartner == str(message.author.id): await message.channel.send( 'Ôi tiếc quá, ' + client.get_user(int(marryProposer)).mention + ' đã bị ' + message.author.mention + ' từ chối! Hãy kiên nhẫn chờ đúng người, đúng thời điểm nhé nanoja!' ) marry = 0 marryPartner = '' marryProposer = '' #Action Divorce global divorce, divorcePartner, divorceProposer if message.content.lower().find('ly dị ') == 0 and len( message.content) > 6: read = open("couples.txt", "r", encoding="utf-8") text = read.read() read.close() # print(text) # if marryPartner+' '+marryProposer in text or marryProposer+' '+marryPartner in text: if client.get_user(int(userIdFilter(message.content))) == None: await message.channel.send('Tag lại đối tượng của mình đi, ' + message.author.mention) elif userIdFilter(message.content) + ' ' + str( message.author.id) not in text and str( message.author.id) + ' ' + userIdFilter( message.content) not in text: await message.channel.send( 'Ủa, hai người có cưới nhau đâu mà đòi ly dị nanoja?') else: divorce = 1 divorcePartner = userIdFilter(message.content) divorceProposer = str(message.author.id) await message.channel.send( 'Ôi không, ' + message.author.mention + ' muốn ly dị ' + client.get_user( int(userIdFilter(message.content))).mention + '! Liệu đối phương có muốn ly dị không? Ấn \'y\' để đồng ý hoặc ấn \'n\' để từ chối!' ) if message.content.lower( ) == 'y' and divorce == 1 and divorcePartner == str(message.author.id): divorce = 0 with open("couples.txt", "r") as f: lines = f.readlines() with open("couples.txt", "w") as f: for line in lines: if line.find(divorcePartner + ' ' + divorceProposer ) < 0 and line.find(divorceProposer + ' ' + divorcePartner) < 0: f.write(line) await message.channel.send( client.get_user(int(divorceProposer)).mention + ' đã ly dị ' + message.author.mention + '! <:Aqua_cry:595633225637036043> <:Aqua_cry:595633225637036043> <:Aqua_cry:595633225637036043>' ) divorcePartner = '' divorceProposer = '' if message.content.lower( ) == 'n' and divorce == 1 and divorcePartner == str(message.author.id): await message.channel.send( message.author.mention + ' vẫn còn muốn níu kéo ' + client.get_user(int(divorceProposer)).mention + ' ! Hai người nên đóng cửa bảo nhau nhé!') divorce = 0 divorcePartner = '' divorceProposer = '' #Pixiv's url if message.content.lower().find('//www.pixiv.net/') >= 0: if message.content.lower().find( 'member_illust.php?illust_id=') > 0: id = message.content.split('illust_id=')[1].split('&')[0] elif message.content.lower().find('/artworks/') >= 0: id = message.content.split('/artworks/')[1] api = AppPixivAPI() api.login("*****@*****.**", "0918273645") # await message.channel.send('debuging...') # api = AppPixivAPI() # api.login("*****@*****.**","Chicothe123") # await message.channel.send('debuging...') json_result = api.illust_detail(id) # await message.channel.send(id+"") print(json_result) illust = json_result.illust if (illust.page_count == 1): url = illust.meta_single_page['original_image_url'] else: await message.channel.send("Album gồm " + str(illust.page_count) + " ảnh nanoja!") url = illust.meta_pages[0].image_urls['original'] pixiv_image_rsp = requests.get( url, headers={'Referer': 'https://app-api.pixiv.net/'}, stream=True) pixiv_image_rsp_fp = io.BytesIO(pixiv_image_rsp.content) # Add file name to stream # print(illust) if pixiv_image_rsp_fp.getbuffer().nbytes >= 8388608: await message.channel.send( "Ảnh lớn hơn 8mb nên ta sẽ post ảnh resize nanoja!") if (illust.page_count == 1): url = illust.image_urls['large'] else: url = illust.meta_pages[0].image_urls['large'] pixiv_image_rsp = requests.get( url, headers={'Referer': 'https://app-api.pixiv.net/'}, stream=True) pixiv_image_rsp_fp = io.BytesIO(pixiv_image_rsp.content) pixiv_image_rsp_fp.name = url.rsplit('/', 1)[-1] await message.channel.send( file=discord.File(pixiv_image_rsp_fp)) else: pixiv_image_rsp_fp.name = url.rsplit('/', 1)[-1] # print(illust) # await message.channel.send(illust.user) await message.channel.send( file=discord.File(pixiv_image_rsp_fp)) # Twitter's url twitter_switch = 0 if twitter_switch == 1 and message.content.lower().find( '//twitter.com/') >= 0: status_id = message.content.split('status/')[1].split('?s')[0] mess = '' # await message.channel.send(status_id) status = twitterapi.get_status(status_id, tweet_mode='extended') # await message.channel.send(twitterapi.get_status(status_id)) if hasattr(status, 'extended_entities'): if 'media' in status.extended_entities: count = 0 for pic in status.extended_entities['media']: if 'video' not in pic['media_url'] and count != 0: mess = mess + pic['media_url'] + '\n' count = count + 1 else: if 'media' in status.entities: count = 0 for pic in status.entities['media']: if 'video' not in pic['media_url'] and count != 0: mess = mess + pic['media_url'] + '\n' count = count + 1 await message.channel.send(mess) #Weather forecast if message.content.lower().find(".weather ") == 0: w_api = "e0c439c2a3fb825f966d3abdc9a6c19d" city = message.content.split(".weather ")[1] base_url = "http://api.openweathermap.org/data/2.5/weather?" complete_url = base_url + "appid=" + w_api + "&q=" + city response = requests.get(complete_url) info = response.json() # await message.channel.send(info) soup = ImageSoup() images = soup.search(city, n_images=1) print(images, images == []) if images == [] or images == None: city_img = "" city_img_url = "" else: city_img = images[0] city_img_url = city_img.URL arguments = {"keywords": "" + city, "limit": 1, "print_urls": True} if info["cod"] != "404": main = info["main"] weather = info["weather"] embed = discord.Embed(title="Today's weather in " + city + "", colour=discord.Colour.orange()) temp = str(round(float(main["temp"]) - 273, 2)) embed.add_field(name='Description', value=str(weather[0]['description']), inline=True) embed.add_field(name='Temprature', value=temp + "°C", inline=True) embed.add_field(name='Humidity', value=str(main["humidity"]) + "%", inline=True) embed.set_thumbnail(url=city_img_url) await message.channel.send(embed=embed) else: await message.channel.send( "Không tìm thấy thành phố đó nanoja...") #Search for image if message.content.lower().find(".img ") == 0: searchimg = message.content.split(".img ")[1] soup = ImageSoup() images = soup.search(searchimg, n_images=5) mess = "" for i in images: mess = mess + i.URL + '\n' await message.channel.send(mess) # Jankenpon game janken = ["Bao", "Búa", "Kéo"] if message.content.lower().find(".ott ") == 0: if message.content.lower().split( " ")[1] == "bao" or message.content.lower().split( " ")[1] == "búa" or message.content.lower().split( " ")[1] == "kéo": player_janken = message.content.lower().split(" ")[1] senko_janken = random.choice(janken) # await message.channel.send(senko_janken) result = jankenResult(senko_janken.lower(), player_janken) read = open("jankenpon.txt", "r", encoding="utf-8") text = read.read() read.close() if str(message.author.id) not in text: output = open("jankenpon.txt", "a+", encoding="utf-8") output.write(str(message.author.id) + " 0 0 0 0\n") output.close() with open("jankenpon.txt", "r") as f: lines = f.readlines() for line in lines: if str(message.author.id) in line: playerId = line.split(" ")[0] win = int(line.split(" ")[1]) tie = int(line.split(" ")[2]) lose = int(line.split(" ")[3]) score = int(line.split(" ")[4]) lineOld = playerId + " " + str(win) + " " + str( tie) + " " + str(lose) + " " + str( score) + "\n" if result == -1: lose = lose + 1 score = score - 10 if result == 0: tie = tie + 1 if result == 1: win = win + 1 score = score + 10 lineNew = playerId + " " + str(win) + " " + str( tie) + " " + str(lose) + " " + str( score) + "\n" # await message.channel.send(lines) lines[lines.index(lineOld)] = lineNew if score >= 1000: await message.author.add_roles( message.author.guild.get_role(658325379538354187)) elif score >= 500: await message.author.add_roles( message.author.guild.get_role(658325189834178572)) elif score >= 200: await message.author.add_roles( message.author.guild.get_role(658325047282499614)) elif score >= 100: await message.author.add_roles( message.author.guild.get_role(658324756864565278)) with open("jankenpon.txt", "w") as f: f.writelines(lines) if result == 0: await message.channel.send(senko_janken + " - Chúng ta hòa rồi!") elif result == -1: await message.channel.send(senko_janken + " - Hoan hô, ta thắng rồi!") elif result == 1: await message.channel.send( senko_janken + " - Hic, ta thua rồi <:Aqua_cry:595633225637036043>") else: await message.channel.send("Mời Người chọn bao, búa hoặc kéo.") if message.content.lower().find(".ottstatus") == 0: embed = discord.Embed(title="Thành tích oẳn tù tì của " + message.author.name, colour=discord.Colour.orange()) with open("jankenpon.txt", "r") as f: lines = f.readlines() for line in lines: if str(message.author.id) in line: playerId = line.split(" ")[0] win = line.split(" ")[1] tie = line.split(" ")[2] lose = line.split(" ")[3] score = line.split(" ")[4] embed.add_field(name='Thắng', value=win + " ván", inline=True) embed.add_field(name='Hòa', value=tie + " ván", inline=True) embed.add_field(name='Thua', value=lose + " ván", inline=True) embed.add_field(name='Điểm', value=score, inline=True) embed.set_thumbnail(url=message.author.avatar_url) await message.channel.send(embed=embed) # Mazii if message.content.lower().find(".mazii ") == 0: word = message.content.lower().split(" ")[1] API_ENDPOINT = "https://mazii.net/api/search" data = { "dict": "javi", "type": "word", "query": word, "limit": "20", "page": "1" } # sending post request and saving response as response object r = requests.post(url=API_ENDPOINT, data=data) # extracting response text jsondata = json.loads(r.text) result = "" for i in jsondata["data"][0]["means"]: result = result + i["mean"] + "\n" await message.channel.send(result)
def test_imageresult_verify_valid_file(): soup = ImageSoup() images = soup.search('python site:python.org') im = images[0] assert im.verify() is True
- TACO ============================================================================================================== I pick : Keras/Tensorflow, Keras/Pytorch VGG, Resnet https://www.pyimagesearch.com/2017/12/04/how-to-create-a-deep-learning-dataset-using-google-images/ from imagesoup import ImageSoup soup = ImageSoup() images_wanted = 1000 query = 'cheetah' images = soup.search(query, n_images=images_wanted) f = open('img-all/cheetah-url','w') urls='' for x in range(0,1000): index=x-n print(str(x) + " - " + str(index)) urls=urls+str(images[x])+"\n" f.write(urls) f.close() =============================================== var script = document.createElement('script'); script.src = "https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js";
def test_imageresult_url(): soup = ImageSoup() images = soup.search('python site:python.org') im = images[0] assert im.URL == 'https://www.python.org/static/opengraph-icon-200x200.png'
def datos_persona_auto(patente): try: url = "https://soap.uanbai.com/bci/soap/2018/ajax/loadPPU.jsp?PPU=%s&SES=DDB9674E703F9BB04C4F3BB2D96D8291.worker1" % patente peticion = requests.get(url) datos = json.loads(peticion.content) except: print("\nNo se pudo obtener la información (SOAP)") # try: # Datos del dueño datos_persona_auto.nombredueno = (datos['propietario']['nombre'] + " " + datos['propietario']['ap_paterno'] + " " + datos['propietario']['ap_materno']) datos_persona_auto.rut = (datos['propietario']['rut'] + "-" + datos['propietario']['dv']) print(datos_persona_auto.rut) # OBTENER DATOS DE DOMICIO ELECTORAL RUTIFY try: url = "https://api.rutify.cl/rut/%s" % datos_persona_auto.rut peticion = requests.get(url) datosruti = json.loads(peticion.content) datos_persona_auto.datosrutii = str(datosruti) # print(datos_persona_auto.datosrutii) datos_persona_auto.nombre = datosruti["nombre"] datos_persona_auto.rut = datosruti["rut"] if datosruti["sexo"] == 1: datos_persona_auto.sexo = "Masculino" else: datos_persona_auto.sexo = "Femenino" datos_persona_auto.comuna = datosruti["servel"]["comuna"] datos_persona_auto.domicilio = datosruti["servel"][ "domicilio electoral"] datos_persona_auto.pais = datosruti["servel"]["pais"] # CHECKBOX INDEX DIRECCION EN GOOGLE if basic_example.request.form.get('googlemap'): print("CHECKBOX - Mostrando mapa") direccionlala = datos_persona_auto.domicilio print(direccionlala) direccionlala = direccionlala.split() print(direccionlala) if len(direccionlala) > 2: print(" ".join(direccionlala[:3])) direccionlala = (" ".join(direccionlala[:3])) print("3" + direccionlala) print('https://www.google.com/maps/place/' + str(direccionlala) + " " + str(datos_persona_auto.comuna)) try: webbrowser.open('https://www.google.com/maps/place/' + str(direccionlala) + " " + str(datos_persona_auto.comuna)) except: print("Error mostrando mapa if") else: print('https://www.google.com/maps/place/' + datos_persona_auto.domicilio + " " + datos_persona_auto.comuna) try: webbrowser.open('https://www.google.com/maps/place/' + datos_persona_auto.domicilio + " " + datos_persona_auto.comuna) except: print("Error mostrando mapa else") else: print("NO CHECKBOX - No mostrando mapa") except: datos_persona_auto.errorruti = datosruti["error"] print("Error sacando info de rutify") # Datos del vehiculo try: datos_persona_auto.tipovehi = (tipoVehiculo(datos['id_tipo'])) print(datos_persona_auto.tipovehi) datos_persona_auto.marcavehi = (datos['marca']) datos_persona_auto.modelovehi = (datos['modelo']) datos_persona_auto.anoauto = (str(datos['ano'])) datos_persona_auto.nmotor = (str(datos['vin'])) datos_persona_auto.dvpatente = (str(datos['dvpatente'])) # Busqueda de imagenes en google del modelo del auto # Problema con mostrar imagenes de webs sin https busqueda = (datos_persona_auto.marcavehi, datos_persona_auto.modelovehi, datos_persona_auto.anoauto) auto = ImageSoup() images = auto.search(busqueda, n_images=4) datos_persona_auto.firstimage = images[0].URL datos_persona_auto.secondimage = images[1].URL datos_persona_auto.thirdimage = images[2].URL except: print("datos auto error") # except: # print("Error dato info de Persona")
def test_search_query_only_returns_100_images(): soup = ImageSoup() images = soup.search('python') assert len(images) == 100