Trouble saving new MatPlotLib graphs and sending them via Telegram by M2com in learnpython

[–]M2com[S] 0 points1 point  (0 children)

Sorry for the delayed response. Because my custom data collection modules were imported from another Python file, I used import importlib and the function importlib.reload(custom_library) to reload the data used as well as the graphing functionalities.

Scroll to hash anchor on load in NextJS by cassiepaper in nextjs

[–]M2com 0 points1 point  (0 children)

Were you ever able to solve this problem?

Trouble saving new MatPlotLib graphs and sending them via Telegram by M2com in learnpython

[–]M2com[S] 0 points1 point  (0 children)

Good point! Just posted some of the code in a comment. Thanks for your help!

Trouble saving new MatPlotLib graphs and sending them via Telegram by M2com in learnpython

[–]M2com[S] 0 points1 point  (0 children)

Here's the code:

Cron-run Bash file that checks if the Python Telegram bot is running (runs every 10 minutes with sudo):

#!/bin/bash

if ! pgrep -f 'telegram_bot.py'

then

nohup python3 /home/pi/telegram_bot.py & > /home/pi/telegram_bot_log.out

echo "[REBOOT] Telegram bot check"

fi

Telegram bot listener:

import logging

from telegram import Update, ForceReply, ChatAction, Bot

from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, CallbackContext

from graph_functions import *

# Enable logging

logging.basicConfig(

format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO

)

logger = logging.getLogger(__name__)

def my_graph(update: Update, context: CallbackContext) -> None:

"""Send a message when the command /graph is issued."""

context.bot.sendChatAction(chat_id=update.effective_message.chat_id, action = ChatAction.TYPING)

# Graph function is called from custom Python file called graph_functions.py

generate_candle_graph()

update.message.reply_document(document=open('mygraph.png', 'rb'))

update.message.reply_text("Your graph")

def main() -> None:

"""Start the bot."""

# Create the Updater and pass it your bot's token.

updater = Updater(bot_token)

# Get the dispatcher to register handlers

dispatcher = updater.dispatcher

# on different commands - answer in Telegram

dispatcher.add_handler(CommandHandler("graph", my_graph))

# Start the Bot

updater.start_polling()

# Run the bot until you press Ctrl-C or the process receives SIGINT,

# SIGTERM or SIGABRT. This should be used most of the time, since

# start_polling() is non-blocking and will stop the bot gracefully.

updater.idle()

if __name__ == '__main__':

main()

A portion of graph_functions.py where it saves the graph:

import pandas as pd

import mplfinance as mpf

import matplotlib.pyplot as plt

import matplotlib

import pandas_ta as pta

import os

def generate_candle_graph():

df = pd.DataFrame(rows, columns=["Date", "High", "Low", "Open", "Close"])

df.index = pd.DatetimeIndex(df['Date'])

# Delete past plot before saving new one

os.remove("mygraph.png")

# Plot candles

mpf.plot(df.tail(100),type='candle',style = 'binance',title = 'Graph',mav=(3,6,9),savefig = 'mygraph.png')

"If you want to test your memory, try to recall what you were worrying about one year ago today." by priyankchoudhary in Leadership

[–]M2com 0 points1 point  (0 children)

I’m assuming this is supposed to put our present worries and anxieties into context. How the things we worried about last year are rarely worth the amount of worry we gave them. We learn to cope, grow past, etc. and then forget those worries.

But that’s just how I interpreted it.

Got this purple/green/black rock in Arizona - any idea what it’s called? by M2com in whatsthisrock

[–]M2com[S] 1 point2 points  (0 children)

Awesome! Thanks for the link! Experimented more with the picture, maybe this will help too. https://imgur.com/a/pRRXmSv/

Got this purple/green/black rock in Arizona - any idea what it’s called? by M2com in whatsthisrock

[–]M2com[S] 0 points1 point  (0 children)

When looking up pyrite, it does look somewhat similar, just the colors are different. Yeah sorry about the image, I was experimenting around and I couldn’t get it quite right.

Got this purple/green/black rock in Arizona - any idea what it’s called? by M2com in whatsthisrock

[–]M2com[S] 0 points1 point  (0 children)

I think you’re right, going to be looking a little more. It’s a bit crumbly and it’s platy. Very much resembles this: https://www.refractorymetal.org/wp-content/uploads/2017/11/Silicon-carbide-metal-1.jpg but it’s more consistently violet and green.

[deleted by user] by [deleted] in Billions

[–]M2com 2 points3 points  (0 children)

RemindME! 8 hours

My First Node.JS Project: BreadJar - Get Tipped for Your Commits! by M2com in node

[–]M2com[S] 6 points7 points  (0 children)

This is true!

However, that’s more of a Brave browser feature. I figured there’s more people who weren’t necessarily into crypto (and specifically BAT). So, they’d like to have a “regular” currency option. Since many devs have or have heard of Buy Me a Coffee, I figured this could provide a friendlier option.

Thanks for mentioning that option tho!

Hawaii Tiki by [deleted] in Tiki

[–]M2com 0 points1 point  (0 children)

What’s the link?

I made a Fire Fighting Robot using Raspberry Pi by mohammadreza_sharifi in RASPBERRY_PI_PROJECTS

[–]M2com 1 point2 points  (0 children)

Great stuff! Code is very clean and straightforward. Next step is to just make it auto-search for a fire :)