AuroraDiscordBot/auroraBot.py

55 lines
1.7 KiB
Python
Raw Normal View History

2023-03-20 18:54:38 +00:00
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import config
2023-03-23 22:45:22 +00:00
from datetime import datetime
2023-03-20 19:43:40 +00:00
import requests
2023-03-20 18:54:38 +00:00
TOKEN = config.token
2023-03-23 22:45:22 +00:00
from telegram.ext import Updater
from telegram.ext import CommandHandler
2023-03-20 18:54:38 +00:00
2023-03-23 22:45:22 +00:00
updater = Updater(token=TOKEN, use_context=True)
2023-03-20 18:54:38 +00:00
2023-03-23 22:45:22 +00:00
dispatcher = updater.dispatcher
def start(update, context):
context.bot.send_message(chat_id=update.effective_chat.id, text="Sóc un bot, prova a dir-me /aurora")
start_handler = CommandHandler('start', start)
dispatcher.add_handler(start_handler)
def asc(update, ctx):
num = datetime.now().timestamp()
2023-03-20 19:27:40 +00:00
message = f'https://www.irf.se/alis/allsky/krn/latest.jpeg?{num}'
2023-03-23 22:45:22 +00:00
ctx.bot.send_message(chat_id=update.effective_chat.id, text=message)
asc_handler = CommandHandler('aurora', asc)
dispatcher.add_handler(asc_handler)
def kp(update, ctx):
2023-03-20 19:43:40 +00:00
response = requests.get('https://services.swpc.noaa.gov/products/noaa-planetary-k-index.json')
data = response.json()
kp = data[-1][1]
message = f'The current Kp index is {kp}'
2023-03-23 22:45:22 +00:00
ctx.bot.send_message(chat_id=update.effective_chat.id, text=message)
kp_handler = CommandHandler('kp', kp)
dispatcher.add_handler(kp_handler)
def sw(update, ctx):
num = datetime.now().timestamp()
2023-03-20 22:07:37 +00:00
message = f'https://www.spaceweather.se/content/irf-kp.png?{num}'
2023-03-23 22:45:22 +00:00
ctx.bot.send_message(chat_id=update.effective_chat.id, text=message)
sw_handler = CommandHandler('sw', sw)
dispatcher.add_handler(sw_handler)
2023-03-24 17:13:49 +00:00
def vid(update, ctx):
num = datetime.now().timestamp()
message = f'https://www.irf.se/alis/allsky/krn/latest_movie.mp4?{num}'
ctx.bot.send_message(chat_id=update.effective_chat.id, text=message)
vid_handler = CommandHandler('video', vid)
dispatcher.add_handler(vid_handler)
2023-03-23 22:45:22 +00:00
updater.start_polling()