def main(draw_faces=False): try: simg = get_image(get_random_searchtag()) except ConnectionError: logging.warning("Retried since couldn't get source...") return main() if id_is_blacklisted(simg.id): logging.info("Retried, already posted image...") return main() if check_pixiv_404(fix_source_url(simg.source)): logging.warning("Skipping since pixiv linked 404'd") return main() append_blacklisted(simg.id) with DownloadedImage(simg.imurl) as impath: img = cv2.imread(impath) cascade = cascade = cv2.CascadeClassifier( os.path.join("lbpcascade_animeface", "lbpcascade_animeface.xml")) gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) gray = cv2.equalizeHist(gray) faces = cascade.detectMultiScale( gray, # detector options scaleFactor=1.1, minNeighbors=5, minSize=(24, 24)) if draw_faces: for (x, y, w, h) in faces: cv2.rectangle(img, (x, y), (x + w, y + h), (0, 0, 255), 2) logging.info("Found image %i faces, id: %i" % (len(faces), simg.id)) pilimg = Image.fromarray(cv2.cvtColor(img, cv2.COLOR_BGR2RGB)) text = utils.get_quote(CONFIG["texts"]) logging.info(text) font = utils.set_font(pilimg, text) draw = ImageDraw.Draw(pilimg) lines = utils.messages_multiline(text, font, pilimg) colours = utils.get_colors(impath) (x, y, faces) = utils.randomize_location(pilimg, lines, font, faces) for line in lines: height = font.getsize(line[1])[1] utils.draw_with_border(x, y, line, colours[0], colours[1], font, draw) y = y + height pilimg.save("img.png") return "img.png", fix_source_url(simg.source), text
async def on_reminder(task, description, time_due): embed = discord.Embed(title=task, description=f"Due at: {time_due}", color=EMBED_COLOR) embed.set_author(name="Sir SoInstant", url=NAME_URL, icon_url=ICON_URL) for n, subtask in enumerate(description): embed.add_field(name=f"Subtask {n + 1}", value=subtask, inline=False) embed.set_footer(text=utils.get_quote()) await bot.get_channel(REMINDERS_CHANNEL_ID).send( content=f"<@{OWNER_ID}> The task {task} is due at {time_due}!", embed=embed)
async def list_reminders(self, ctx): reminders = utils.get_reminders() if reminders == []: await ctx.channel.send( content="You have no current tasks to complete! :tada:") else: embed = discord.Embed(title="__Here are your pending tasks:__", color=EMBED_COLOR) embed.set_author( name="Sir SoInstant", url=NAME_URL, icon_url=ICON_URL, ) for i, document in enumerate(reminders): embed.add_field( name= f"{i+1}. **{document['task']}** (Due on {utils.unix_to_timestamp(document['time_due'])})", value="- " + "\n- ".join(document["description"]), inline=False, ) embed.set_footer(text=utils.get_quote()) await ctx.channel.send(embed=embed)
async def on_message(message): if message.author == client.user: return msg = message.content if msg.startswith('$inspire'): quote = get_quote() await message.channel.send(quote) if msg.startswith('$add'): value = msg.split('add ', 1)[1] if value in add_words: add_value(value) await message.channel.send('Added') else: await message.channel.send( f'Look at your value. Must be as here: {add_words}') if msg.startswith('$del'): value = msg.split('del ', 1)[1] if value in add_words: string = delete_value(value) await message.channel.send(string) else: await message.channel.send( f'Look at your value. Must be as here: {add_words}') if msg == '$clear': clean_stat() await message.channel.send('Your stats for today have been cleaned') if msg.startswith('$stat'): string = '' if len(msg) > len('$stat'): value = msg.split('stat ', 1)[1] string = get_stat(value) else: string = get_stat('') await message.channel.send(string)
def post(): with open("files.csv") as f: reader = csv.reader(f) chosen_row = random.choice(list(reader)) source = chosen_row[1] file_extension = chosen_row[2].split(".")[1] filename = "pics/" + chosen_row[2] text = get_quote("texts/quotes.txt") image = Image.open(filename) font = set_font(image, text) # get font size based on image size draw = ImageDraw.Draw(image) lines = messages_multiline(text, font, image) # split up lines for text wrapping colors = get_colors(image.filename) # get colors (x, y, faces) = randomize_location( image, lines, font ) # where to start drawing text for line in lines: height = font.getsize(line[1])[1] draw_with_border(x, y, line, colors[0], colors[1], font, draw) y = y + height image.save(f"to_tweet.{file_extension}") photo = open(f"to_tweet.{file_extension}", "rb") response = twitter.upload_media(media=photo) message = f"{text} ({source})" print(filename, message) twitter.update_status(status=message, media_ids=[response["media_id"]]) photo.close() os.remove(photo.name) with open("log", "a") as f: f.write( f"{datetime.now().strftime('%d-%m-%Y %H:%M:%S')}\t{filename}\t({image.size[0]} {image.size[1]})\t{font.size} ({max((font.size // 25), 2)})\t{text}\n" )
def quote(): sym = request.args.get('s') return jsonify(sym=sym, price=utils.get_quote(sym))