Notes![what is notes.io? What is notes.io?](/theme/images/whatisnotesio.png)
![]() ![]() Notes - notes.io |
import time
from telegram.update import Update
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, CallbackContext
def get_price(api_key, symbol):
api_url = 'https://rest.coinapi.io/v1/exchangerate/'
headers = {
'9DA4CB60-C350-47EF-A87B-03060F8E8C3C': api_key
}
url = f'{api_url}{symbol}/USD'
response = requests.get(url, headers=headers)
if response.status_code == 200:
data = response.json()
price = round(data['rate'], 2)
return price
return None
def update_price(update: Update, context: CallbackContext):
api_key = '9DA4CB60-C350-47EF-A87B-03060F8E8C3C'
chat_id = update.message.chat_id
message = update.message.text
if not message.isupper(): # if message is not in all caps
context.bot.send_message(chat_id=chat_id, text="Lütfen büyük harf kullanın.")
return
try:
price = get_price(api_key, message)
if price is None:
raise Exception('Price could not be fetched')
# Update the message text with the new price
context.bot.edit_message_text(chat_id=chat_id, message_id=update.message.message_id, text=f"{message} fiyatı: {price:.2f}")
# Check if any targets have been set and update them with a checkmark emoji if they have been reached
targets = context.chat_data.get("targets", {})
for target, value in targets.items():
if value and price >= value:
targets[target] = None
context.bot.edit_message_text(chat_id=chat_id, message_id=target, text=f"{target}n✅")
context.chat_data["targets"] = targets
except IndexError:
context.bot.send_message(chat_id=chat_id, text="Geçersiz simge.")
return
except Exception as e:
print(e)
context.bot.send_message(chat_id=chat_id, text="Bir hata oluştu, lütfen tekrar deneyin.")
return
def main():
api_key = '9DA4CB60-C350-47EF-A87B-03060F8E8C3C'
symbol = 'BTC/USD'
updater = Updater(token='5914092544:AAGGiL3crIpwAq9NM1O4pLm6xFAmCxOzlYQ', use_context=True)
dp = updater.dispatcher
dp.add_handler(CommandHandler('start', start))
# add message handler
dp.add_handler(MessageHandler(Filters.text & (~Filters.command), update_price, pass_job_queue=True, pass_chat_data=True))
updater.start_polling()
updater.idle()
def start(update, context):
chat_id = update.effective_chat.id
context.bot.send_message(chat_id=chat_id, text='Bot başlatıldı!')
if __name__ == '__main__':
main()
![]() |
Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 12 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team