def get_apod_data_with_request_in_thread(self, data): """ Metoda wykonywana jest w przypadku potrzeby zaktualizowania danych aplikacji. Tworzy połączenie z API NASA oraz wysyła żądanie HTTP w celu otrzymania aktualnych informacji i aktualizuje te dane. Jeżeli uzyskanie informacji się nie powiedzie, zostają one ustawione jako None. :param data: Dane dotyczące wybranej daty. """ try: nasa_access = nasa.Nasa(key=ApiData.NASA_API_KEY) pic_data_dict = nasa_access.picture_of_the_day(data, hd=True) self.__model_data = ApodData(pic_data_dict['hdurl'], pic_data_dict['explanation'], pic_data_dict['title'], pic_data_dict['date']) except Exception: self.__model_data = ApodData()
def get_asteroid_data_with_request_in_thread(self, asteroids_date): """ Metoda wykonywana jest w przypadku potrzeby zaktualizowania danych aplikacji. Tworzy połączenie z API NASA oraz wysyła żądanie HTTP w celu otrzymania aktualnych informacji i aktualizuje te dane. Jeżeli uzyskanie informacji się nie powiedzie, zostają one ustawione jako None lub pustą listę w przypadku listy asteroid. :param asteroids_date: Dane dotyczące wybranej daty. """ try: nasa_access = nasa.Nasa(key=ApiData.NASA_API_KEY) asteroids_data = nasa_access.asteroid_feed( start_date=asteroids_date, end_date=asteroids_date) self.__asteroids_fetched_data = asteroids_data asteroids_dict = asteroids_data[ "near_earth_objects"] # tu jest słownik z datami asteroids_in_date = asteroids_dict[ asteroids_date] # słownik z asteroidami self.__model_data.add_data_date(asteroids_date) self.__model_data.clear_asteroids() for asteroid in asteroids_in_date: name = asteroid["name"] url = asteroid["nasa_jpl_url"] hazardous = asteroid["is_potentially_hazardous_asteroid"] date = asteroid["close_approach_data"][0][ "close_approach_date_full"] date_datetime = datetime.datetime.strptime( date, '%Y-%b-%d %H:%M') date_datetime_str = date_datetime.strftime('%Y-%b-%d %H:%M') velocity = asteroid["close_approach_data"][0][ "relative_velocity"]["kilometers_per_second"] miss_au = asteroid["close_approach_data"][0]["miss_distance"][ "astronomical"] miss_km = asteroid["close_approach_data"][0]["miss_distance"][ "kilometers"] diameter = asteroid["estimated_diameter"]["kilometers"][ "estimated_diameter_max"] self.__model_data.add_asteroid(name, url, hazardous, date_datetime_str, velocity, miss_km, miss_au, diameter) except Exception: self.__model_data = AsteroidsData()
async def potdCommand(self, ctx): nasa = nasapy.Nasa(key=NASA_KEY) d = datetime.today().strftime('%Y-%m-%d') apod = nasa.picture_of_the_day(date=d, hd=True) try: embed = discord.Embed(title=f'{apod["title"]}', description=f'{apod["explanation"]}') embed.set_image(url=f'{apod["hdurl"]}') embed.set_footer( text= f'NASA Picture of the Day : {datetime.today().strftime("%m-%d-%Y")}' ) await ctx.send(embed=embed) except: #FIXME: In case the description exceeds Discord's limits, it will simply send the embed without it. Be sure to clean up # this error checking in case it causes other problems. embed = discord.Embed(title=f'{apod["title"]}') embed.set_image(url=f'{apod["hdurl"]}') embed.set_footer( text= f'NASA Picture of the Day : {datetime.today().strftime("%m-%d-%Y")}' ) await ctx.send(embed=embed)
def __init__(self, key: str): self.key = key self.nasa = nasapy.Nasa(key)
import RPi.GPIO as GPIO import discord import sys from discord.ext import commands GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) BestFish = "media/poisson.jpg" Photo = "media/image.jpeg" ImgNasa = "media/imgNasa.png" PoissonCoupe = "media/poissoncoupe.png" ImgSuperposes = "imgSuperposes.png" load_dotenv(dotenv_path="config") key = os.environ.get(os.getenv("NASATOKEN")) nasa = nasapy.Nasa(key=key) class Bot(commands.Bot, discord.Client): def __init__(self): super(Bot, self).__init__(command_prefix="!") self.add_command(commands.Command(self.bestFish, name="bestFish")) self.add_command(commands.Command(self.fish, name="fish")) self.add_command(commands.Command(self.nasa, name="nasa")) self.add_command(commands.Command(self.spaceFish, name="spaceFish")) async def on_ready(self): print(f"{self.user.display_name} est connecté") async def bestFish(self, msg): try:
import nasapy import random import urllib.request from dotenv import load_dotenv from RPH import RemotePhotoHandler from Led import Led from PIL import Image from time import sleep from discord.ext import commands load_dotenv(dotenv_path="../configCle") imgNasa = "../image/imgNasa.png" imgPoisson = "../image/neuneilEspace.png" imgSuperposes = "../image/imgSuperposes.png" nasa = nasapy.Nasa(key=os.getenv("CLE")) picture = nasa.picture_of_the_day() rph = RemotePhotoHandler() class Bot(commands.Bot, discord.Client): def __init__(self): super().__init__(command_prefix="!") self.add_command(commands.Command(self.fish, name="fish")) self.add_command(commands.Command(self.nasapy, name="nasapy")) self.add_command(commands.Command(self.spacefish, name="spacefish")) async def on_ready(self): print(f"{self.user.display_name} est connecté au serveur.")
import telebot, nasapy, os, functions, database absolute_path = os.path.abspath(__file__) absolute_path = absolute_path[:absolute_path.rfind("/") + 1] token = os.environ.get('telebot_token') bot = telebot.TeleBot(token) api_key = os.environ.get('nasapy_token') api = nasapy.Nasa(key=api_key) def main(): info_list = { 'Шестнадцатеричниые цифры': f'{absolute_path}/16.png', 'Степени двойки': f'{absolute_path}/Step2.png', 'Веса информации': f'{absolute_path}/BBKMT.png', 'Максимальное число': f'{absolute_path}/max.png' } physics_list = () funcs = functions.functions_class(bot, api, api_key, telebot.types, database.database(), info_list, physics_list) @bot.message_handler(content_types=['text']) def handler(message): function_name = message.text[1:] if (message.from_user.id in funcs.get_user_ids()): try: if (funcs.get_user_level(message.from_user.id) <= funcs._dict_of_funcs[function_name][2]):