55 lines
1.7 KiB
Python
Executable File
55 lines
1.7 KiB
Python
Executable File
#!/usr/bin/python3
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import config
|
|
from datetime import datetime
|
|
import requests
|
|
|
|
TOKEN = config.token
|
|
|
|
from telegram.ext import Updater
|
|
from telegram.ext import CommandHandler
|
|
|
|
updater = Updater(token=TOKEN, use_context=True)
|
|
|
|
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()
|
|
message = f'https://www.irf.se/alis/allsky/krn/latest.jpeg?{num}'
|
|
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):
|
|
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}'
|
|
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()
|
|
message = f'https://www.spaceweather.se/content/irf-kp.png?{num}'
|
|
ctx.bot.send_message(chat_id=update.effective_chat.id, text=message)
|
|
sw_handler = CommandHandler('sw', sw)
|
|
dispatcher.add_handler(sw_handler)
|
|
|
|
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)
|
|
|
|
updater.start_polling() |