def view_command(ticker=""): """Displays image from Finviz [Finviz]""" # Debug if cfg.DEBUG: logger.debug("ta view %s", ticker) # Check for argument if ticker == "": raise Exception("Stock ticker is required") image_data = finviz_model.get_finviz_image(ticker) dataBytesIO = io.BytesIO(image_data) im = Image.open(dataBytesIO) im = im.resize((800, 340), Image.ANTIALIAS) imagefile = "ta_view.png" im.save(dataBytesIO, "PNG", quality=100) dataBytesIO.seek(0) imagefile = image_border(imagefile, base64=dataBytesIO) im.close() return { "title": f"Stocks: [Finviz] Trendlines & Data {ticker.upper()}", "imagefile": imagefile, }
def view(ticker: str, external_axes: Optional[List[plt.Axes]] = None): """View finviz image for ticker Parameters ---------- ticker : str Stock ticker external_axes : Optional[List[plt.Axes]], optional External axes (1 axis is expected in the list), by default None """ image_data = finviz_model.get_finviz_image(ticker) dataBytesIO = io.BytesIO(image_data) im = Image.open(dataBytesIO) # This plot has 1 axis if not external_axes: fig, ax = plt.subplots(figsize=plot_autoscale(), dpi=PLOT_DPI) else: if len(external_axes) != 1: logger.error("Expected list of one axis item.") console.print("[red]Expected list of one axis item./n[/red]") return (ax, ) = external_axes ax.set_axis_off() fig.subplots_adjust(left=0, right=1, top=1, bottom=0) ax.imshow(im) # added for the watermark if not external_axes: theme.visualize_output()
async def view_command(ctx, ticker=""): """Displays image from Finviz [Finviz]""" try: # Debug if cfg.DEBUG: print(f"!stocks.ta.view {ticker}") # Check for argument if ticker == "": raise Exception("Stock ticker is required") image_data = finviz_model.get_finviz_image(ticker) dataBytesIO = io.BytesIO(image_data) im = Image.open(dataBytesIO) fig, ax = plt.subplots(figsize=plot_autoscale(), dpi=PLOT_DPI) ax.set_axis_off() fig.subplots_adjust(left=0, right=1, top=1, bottom=0) plt.imshow(im) plt.savefig("ta_view.png") uploaded_image = gst_imgur.upload_image("ta_view.png", title="something") image_link = uploaded_image.link if cfg.DEBUG: print(f"Image URL: {image_link}") title = "Stocks: [Finviz] Trendlines & Data " + ticker embed = discord.Embed(title=title, colour=cfg.COLOR) embed.set_author( name=cfg.AUTHOR_NAME, icon_url=cfg.AUTHOR_ICON_URL, ) embed.set_image(url=image_link) os.remove("ta_view.png") await ctx.send(embed=embed) except Exception as e: embed = discord.Embed( title="ERROR Stocks: [Finviz] Trendlines & Data", colour=cfg.COLOR, description=e, ) embed.set_author( name=cfg.AUTHOR_NAME, icon_url=cfg.AUTHOR_ICON_URL, ) await ctx.send(embed=embed)
def view(ticker: str): """View finviz image for ticker Parameters ---------- ticker : str Stock ticker """ image_data = finviz_model.get_finviz_image(ticker) dataBytesIO = io.BytesIO(image_data) im = Image.open(dataBytesIO) fig, ax = plt.subplots(figsize=plot_autoscale(), dpi=PLOT_DPI) ax.set_axis_off() fig.subplots_adjust(left=0, right=1, top=1, bottom=0) if gtff.USE_ION: plt.ion() plt.imshow(im) plt.show() console.print("")
def test_get_finviz_image(): result = finviz_model.get_finviz_image(ticker="PM") assert isinstance(result, bytes)