def where_planet(bot, update): # text = 'Напечатайте планету на английском или вопрос о полнолунии' # update.message.reply_text(text) planet_text = update.message.text.replace('/planet', '').strip() if planet_text == 'Mercury': planet = ephem.Mercury() elif planet_text == 'Venus': planet = ephem.Venus() elif planet_text == 'Mars': planet = ephem.Mars() elif planet_text == 'Jupiter': planet = ephem.Jupiter() elif planet_text == 'Saturn': planet = ephem.Saturn() elif planet_text == 'Uranus': planet = ephem.Uranus() elif planet_text == 'Neptune': planet = ephem.Neptune() elif planet_text == 'Pluto': planet = ephem.Pluto() elif planet_text == 'Sun': planet = ephem.Sun() elif planet_text == 'Moon': planet = ephem.Moon() else: update.message.reply_text('Я не знаю такой планеты') return planet.compute() update.message.reply_text(ephem.constellation(planet))
def planet(bot, update): date = datetime.date.today() text_at = update.message.text.split(' ')[1].capitalize() if text_at == 'Sun': const = ephem.constellation(ephem.Sun(date)) elif text_at == 'Mercury': const = ephem.constellation(ephem.Mercury(date)) elif text_at == 'Venus': const = ephem.constellation(ephem.Venus(date)) elif text_at == 'Earth': const = 'Неизвестная планета' elif text_at == 'Moon': const = ephem.constellation(ephem.Mars(date)) elif text_at == 'Mars': const = ephem.constellation(ephem.Mars(date)) elif text_at == 'Jupiter': const = ephem.constellation(ephem.Jupiter(date)) elif text_at == 'Saturn': const = ephem.constellation(ephem.Saturn(date)) elif text_at == 'Uranus': const = ephem.constellation(ephem.Uranus(date)) elif text_at == 'Neptune': const = ephem.constellation(ephem.Neptune(date)) elif text_at == 'Pluto': const = ephem.constellation(ephem.Pluto(date)) else: const = 'Данные не доступны' update.message.reply_text(const)
def get_planet(bot, update): planet_obj = None planet_cmd = update.message.text planet = planet_cmd.split()[1] if planet == "Mercury": planet_obj = ephem.Mercury(datetime.date.today()) elif planet == "Venus": planet_obj = ephem.Venus(datetime.date.today()) elif planet == "Earth": update.message.reply_text("Ты же на Земле!") return elif planet == "Mars": planet_obj = ephem.Mars(datetime.date.today()) elif planet == "Jupiter": planet_obj = ephem.Jupiter(datetime.date.today()) elif planet == "Saturn": planet_obj = ephem.Saturn(datetime.date.today()) elif planet == "Uranus": planet_obj = ephem.Uranus(datetime.date.today()) elif planet == "Neptune": planet_obj = ephem.Neptune(datetime.date.today()) elif planet == "Pluto": planet_obj = ephem.Pluto(datetime.date.today()) else: update.message.reply_text("Введена неверная планета") return update.message.reply_text(ephem.constellation(planet_obj)[1])
def planet_constellation(bot, update): try: current_date = update.message.date planet = update.message.text.split()[1].lower().capitalize() if planet == "Sun": planet_object = ephem.Sun(current_date) elif planet == "Moon": planet_object = ephem.Moon(current_date) elif planet == "Mercury": planet_object = ephem.Mercury(current_date) elif planet == "Venus": planet_object = ephem.Venus(current_date) elif planet == "Mars": planet_object = ephem.Mars(current_date) elif planet == "Jupiter": planet_object = ephem.Jupiter(current_date) elif planet == "Saturn": planet_object = ephem.Saturn(current_date) elif planet == "Uranus": planet_object = ephem.Uranus(current_date) elif planet == "Neptune": planet_object = ephem.Neptune(current_date) elif planet == "Pluto": planet_object = ephem.Pluto(current_date) else: update.message.reply_text("Нет такой планеты!") const = ephem.constellation(planet_object) text = f'Планета "{planet}" находится сейчас в созвездии {const}.' update.message.reply_text(text) except IndexError: update.message.reply_text("Напиши название планеты после /planet!")
def planet(bot, update, args): print('Command /planet was called') current_time = datetime.datetime.now() #input_planet = str(update.message.text.strip().split()[-1]) input_planet = args[0].strip().title() all_planets = { 'Pluto': ephem.Pluto(), 'Mercury': ephem.Mercury(), 'Venus': ephem.Venus(), 'Mars': ephem.Mars(), 'Jupiter': ephem.Jupiter(), 'Saturn': ephem.Saturn(), 'Uranus': ephem.Uranus(), 'Neptune': ephem.Neptune() } answer = '' def constel_answer(planet): planet.compute(current_time) return ('Planet\'s info: %s %s %s' % (planet.ra, planet.dec, planet.mag), 'The current constellation is: {}'.format( ephem.constellation(planet)[1])) if input_planet in all_planets: answer = constel_answer(all_planets[input_planet]) elif input_planet == 'Earth': answer = 'Earth is our planet!' else: answer = 'Please enter a planet of the Solar system next to the command /planet.' update.message.reply_text(answer)
def show_constellation(update, context): text = update.message.text.lower().split() if len(text) != 2: update.message.reply_text('Неверно задана планета. Попробуйте ещё раз.') return currentDate = dt.date.today().strftime('%Y/%m/%d') planet = ephem.Planet if text[1] == 'mercury': planet = ephem.Mercury(currentDate) elif text[1] == 'venus': planet = ephem.Venus(currentDate) elif text[1] == 'mars': planet = ephem.Mars(currentDate) elif text[1] == 'jupiter': planet = ephem.Jupiter(currentDate) elif text[1] == 'saturn': planet = ephem.Saturn(currentDate) elif text[1] == 'uranus': planet = ephem.Uranus(currentDate) elif text[1] == 'neptune': planet = ephem.Neptune(currentDate) elif text[1] == 'pluto': planet = ephem.Pluto(currentDate) else: response = f'Планета введена неверно. Повторите ввод.\n Список планет: {pll.planets}' print(response) update.message.reply_text(response) return constellation = ephem.constellation(planet) print(constellation) response = f'{pll.planets_rus.get(planet.name, planet.name)} сегодня находится в созвездии {constellation[1]}.' update.message.reply_text(response)
def planet1(bot, update): text = 'Введите название планеты ' print(text) update.message.reply_text(text) #bot.send_message(text) text = message.text planet_choose = update.message.text print ('Бля,...', planet_choose) #planet_choose = update.message.text dt1 = dt.today() #planet_choose = input('Выберите планету: ') if planet_choose.lower() == 'mercury': planet = ep.constellation(ep.Mercury(dt1)) elif planet_choose.lower() =='venus': planet =ep.constellation(ep.Venus(dt1)) elif planet_choose.lower() =='earth': planet = ep.constellation(ep.Earth(dt1)) elif planet_choose.lower() =='mars': planet =ep.constellation(ep.Mars(dt1)) #print(planet) elif planet_choose.lower() =='jupiter': planet =ep.constellation(ep.Jupiter(dt1)) elif planet_choose.lower() =='saturn': planet =ep.constellation(ep.Saturn(dt1)) elif planet_choose.lower() =='uranus': planet = ep.constellation(ep.Uranus(dt1)) elif planet_choose.lower() =='neptune': planet = ep.constellation(ep.Neptune(dt1)) elif planet_choose.lower() =='pluto': planet = ep.constellation(ep.Pluto(dt1)) else: print (planet_choose) planet = 'Нет таких планет' print(planet) update.message.reply_text(planet)
def where_planet(bot, update): planet_text = update.message.text print(planet_text) if planet_text == 'Mercury': planet = ephem.Mercury() elif planet_text == 'Venus': planet = ephem.Venus() elif planet_text == 'Mars': planet = ephem.Mars() elif planet_text == 'Jupiter': planet = ephem.Jupiter() elif planet_text == 'Saturn': planet = ephem.Saturn() elif planet_text == 'Uranus': planet = ephem.Uranus() elif planet_text == 'Neptune': planet = ephem.Neptune() elif planet_text == 'Pluto': planet = ephem.Pluto() elif planet_text == 'Sun': planet = ephem.Sun() elif planet_text == 'Moon': planet = ephem.Moon() else: update.message.reply_text('Я не знаю такой планеты') return planet.compute() update.message.reply_text(ephem.constellation(planet))
def planet(bot, update): if update == None or update.message == None: return #Периоди́чески возникает такая хрень edata = f"{datetime.datetime.today():%Y/%m/%d}" #посмотри “datetime tostring” #Думаю так будет лучше ephem_dic = { 'mars': ephem.Mars(edata), 'moon': ephem.Moon(edata), 'mercury': ephem.Mercury(edata), 'venus': ephem.Venus(edata), 'jupiter': ephem.Jupiter(edata), 'saturn': ephem.Saturn(edata), 'uranus': ephem.Uranus(edata), 'neptune': ephem.Neptune(edata), 'pluto': ephem.Pluto(edata), } text = update.message.text.split(' ') try: text = text[1].lower() #Получили название планеты ephem_one = ephem_dic[text] const = ephem.constellation(ephem_one) update.message.reply_text( f'Планета {text.upper()} сегодня находится в созвездии "{const[1].upper()}"' ) except: # у тебя по смыслу тут ловится только ошибка «отсутствие в словаре» давай тогда только эту операцию транс и обернём, будет правильней update.message.reply_text( 'Я вас не понял. Вы должны набрать /planet планета') update.message.reply_text( 'Сейчас я знаю такие планеты: ' + str([x.capitalize() for x in list(ephem_dic) ])[1:-1]) #давай с большой буквы выведем планеты
def major_planetary_signs(birth): bodies = (('sun', ephem.Sun()), ('moon', ephem.Moon()), ('mercury', ephem.Mercury()), ('venus', ephem.Venus()), ('mars', ephem.Mars()), ('jupiter', ephem.Jupiter()), ('saturn', ephem.Saturn()), ('uranus', ephem.Uranus()), ('neptune', ephem.Neptune()), ('pluto', ephem.Pluto())) return planetary_signs(birth, bodies)
def planet(bot, update): user_text = update.message.text if user_text.split()[1] == 'Mercury': update.message.reply_text( ephem.constellation(ephem.Mercury(date.today()))) elif user_text.split()[1] == 'Venus': update.message.reply_text( ephem.constellation(ephem.Venus(date.today()))) elif user_text.split()[1] == 'Mars': update.message.reply_text(ephem.constellation(ephem.Mars( date.today()))) elif user_text.split()[1] == 'Jupiter': update.message.reply_text( ephem.constellation(ephem.Jupiter(date.today()))) elif user_text.split()[1] == 'Saturn': update.message.reply_text( ephem.constellation(ephem.Saturn(date.today()))) elif user_text.split()[1] == 'Uranus': update.message.reply_text( ephem.constellation(ephem.Uranus(date.today()))) elif user_text.split()[1] == 'Neptune': update.message.reply_text( ephem.constellation(ephem.Neptune(date.today()))) elif user_text.split()[1] == 'Pluto': update.message.reply_text( ephem.constellation(ephem.Pluto(date.today()))) else: update.message.reply_text('Не знаю такую планету')
def ask_planet( update, context ): # функция которая должна отвечать пользователю если он ввел название планеты user_text = update.message.text # получаем от пользователя сообщение user_text = user_text.split(' ') # делаем список из сообщения пользователя if user_text[0] == "\planet": #Перебираем планеты date = datetime.datetime(now) # обозначили что нужна сегодняшняя дата if user_text == 'Mars': # если тест от пользователя приравнен к слову Mars mars = ephem.Mars( date ) # то в переменную mars кладется расположение планеты сегодня update.message.reply_text(ephem.constellation( mars)) # выводится сообщение пользователю о созвездии if user_text == 'Venus': venus = ephem.Venus(date) update.message.reply_text(ephem.constellation(venus)) if user_text == 'Mercury': mercury = ephem.Mercury(date) update.message.reply_text(ephem.constellation(mercury)) if user_text == 'Jupiter': jupiter = ephem.Jupiter(date) update.message.reply_text(ephem.constellation(jupiter)) if user_text == 'Saturn': saturn = ephem.Saturn(date) update.message.reply_text(ephem.constellation(saturn)) if user_text == 'Uranus': uranus = ephem.Uranus(date) update.message.reply_text(ephem.constellation(uranus)) if user_text == 'Neptune': neptune = ephem.Neptune(date) update.message.reply_text(ephem.constellation(neptune)) if user_text == 'Pluto': pluto = ephem.Pluto(date) update.message.reply_text(ephem.constellation(pluto))
def constellation_of_planet (bot,update): user_text = update.message.text.replace('/planet ','').capitalize() today_date = datetime.datetime.today().strftime('%Y/%m/%d') if user_text=='Mars': today_location_of_planet=ephem.Mars(datetime.date.today()) update.message.reply_text(ephem.constellation(today_location_of_planet)) elif user_text=='Mercury': today_location_of_planet=ephem.Mercury(datetime.date.today()) update.message.reply_text(ephem.constellation(today_location_of_planet)) elif user_text=='Venus': today_location_of_planet=ephem.Venus(datetime.date.today()) update.message.reply_text(ephem.constellation(today_location_of_planet)) elif user_text=='Jupiter': today_location_of_planet=ephem.Jupiter(datetime.date.today()) update.message.reply_text(ephem.constellation(today_location_of_planet)) elif user_text=='Saturn': today_location_of_planet=ephem.Saturn(datetime.date.today()) update.message.reply_text(ephem.constellation(today_location_of_planet)) elif user_text=='Uranus': today_location_of_planet=ephem.Uranus(datetime.date.today()) update.message.reply_text(ephem.constellation(today_location_of_planet)) elif user_text=='Neptune': today_location_of_planet=ephem.Neptune(datetime.date.today()) update.message.reply_text(ephem.constellation(today_location_of_planet)) elif user_text=='Pluto': today_location_of_planet=ephem.Pluto(datetime.date.today()) update.message.reply_text(ephem.constellation(today_location_of_planet)) else: update.message.reply_text('Ошибка! Введите название планеты на английском.')
def planets_chat(bot, update): name_planet = update.message.text logging.info(name_planet) if name_planet == 'Mars': sky = ephem.Mars() elif name_planet == 'Mercury': sky = ephem.Mercury() elif name_planet == 'Venus': sky = ephem.Venus() elif name_planet == 'Earth': sky = ephem.Earth() elif name_planet == 'Jupiter': sky = ephem.Jupiter() elif name_planet == 'Saturn': sky = ephem.Saturn() elif name_planet == 'Uranus': sky = ephem.Uranus() elif name_planet == 'Neptune': sky = ephem.Neptune() elif name_planet == 'Pluto': sky = ephem.Pluto() else: update.message.reply_text('Wrong name planet') sky.compute(datetime.date.today()) update.message.reply_text(ephem.constellation(sky))
def get_constellation(update, context): print('Вызвана планета/start') planet_name = update.message.text.split( )[-1] #сплит разделит текст от user по пробелу на отдельный словарь и добавили последний элемент из списка planets = { 'Mercury': ephem.Mercury('2020/12/05'), 'Venus': ephem.Venus('2020/12/05'), 'Mars': ephem.Mars('2020/12/05'), 'Jupiter': ephem.Jupiter('2020/12/05'), 'Saturn': ephem.Saturn('2020/12/05'), 'Uranus': ephem.Uranus('2020/12/05'), 'Neptune': ephem.Neptune('2020/12/05'), 'Pluto': ephem.Pluto('2020/12/05') } # Создан словарь планет с указанной датой - ключем if planet_name in planets: planet = planets[planet_name] constellation = ephem.constellation(planet) update.message.reply_text( constellation ) # мы скопировали из функции talk to me ответ полученный в консоли и перенаправляем в ответ на телеграмм else: update.message.reply_text( 'Wrong: This planet not definde' ) #дополнительный ответ в случае неправильного ввода
def plot_planets_plus_Pluto(ax, date=parameters.NEWMOONS[parameters.DISCOVERY_NEW_MOON]): for planet in [ephem.Saturn(), ephem.Uranus(), ephem.Neptune(), ephem.Pluto()]: planet.compute(ephem.date(date)) fc = plot_fanciness.ALMOST_BLACK if planet.name == 'Pluto': alpha = 0.35 size = 10 fs = 5 else: alpha = 0.7 size = 20 fs = 10 ax.scatter(planet.ra, planet.sun_distance, marker='o', s=size, facecolor=fc, edgecolor=fc, alpha=alpha) if planet.name == 'Saturn': ax.annotate(planet.name, (planet.ra + (math.radians(3)), planet.sun_distance - 2), size=fs) elif planet.name == 'Uranus': ax.annotate(planet.name, (planet.ra - (math.radians(12)), planet.sun_distance + 1), size=fs) else: ax.annotate(planet.name, (planet.ra - (math.radians(0.5)), planet.sun_distance + 2), size=fs) # Neptune's orbit has e = 0.01, so can get away with a circle if planet.name == 'Neptune': orb = np.arange(0, 2 * np.pi, (2 * np.pi) / 360) ax.plot(orb, np.repeat(planet.sun_distance, len(orb)), color='b', linestyle=':', linewidth=0.4, alpha=0.7) return
def __init__(self, config): super(self.__class__, self).__init__(config) self.body = ephem.Pluto() self.id = "pluto" self.name = "Pluto" self.category = "planet"
def planet(bot, update, args): date_today = d.datetime.today() planet_name = ' '.join(args) planet_name = planet_name.lower() try: if planet_name == 'mars': planet_name = ephem.Mars(date_today) update.message.reply_text(ephem.constellation(planet_name)[1]) elif planet_name == 'neptune': planet_name = ephem.Neptune(date_today) update.message.reply_text(ephem.constellation(planet_name)[1]) elif planet_name == 'pluto': planet_name = ephem.Pluto(date_today) update.message.reply_text(ephem.constellation(planet_name)[1]) elif planet_name == 'saturn': planet_name = ephem.Saturn(date_today) update.message.reply_text(ephem.constellation(planet_name)[1]) elif planet_name == 'uranus': planet_name = ephem.Uranus(date_today) update.message.reply_text(ephem.constellation(planet_name)[1]) elif planet_name == 'venus': planet_name = ephem.Venus(date_today) update.message.reply_text(ephem.constellation(planet_name)[1]) elif planet_name == 'jupiter': planet_name = ephem.Jupiter(date_today) update.message.reply_text(ephem.constellation(planet_name)[1]) else: update.message.reply_text('No data') except IndexError: update.message.reply_text( 'Enter planet name please! For example, /planet Mars', reply_markup=get_keyboard()) logging.info('User did not enter a planet')
def print_new_planet(bot, update): user_text = update.message.text planet_name = user_text.split(' ')[1] print(planet_name) year = "2019" list_planets = give_me_planets() if planet_name in list_planets: if planet_name == "Mars": m = ephem.Mars(year) elif planet_name == "Mercury": m = ephem.Mercury(year) elif planet_name == "Venus": m = ephem.Venus(year) elif planet_name == "Jupiter": m = ephem.Jupiter(year) elif planet_name == "Saturn": m = ephem.Saturn(year) elif planet_name == "Uranus": m = ephem.Uranus(year) elif planet_name == "Neptune": m = ephem.Neptune(year) elif planet_name == "Pluto": m = ephem.Pluto(year) elif planet_name == "Sun": m = ephem.Sun(year) elif planet_name == "Moon": m = ephem.Moon(year) constell_name = ephem.constellation(m) print(constell_name) update.message.reply_text(constell_name) else: update.message.reply_text('Not a planet!')
def planet_ephem(bot, update, args): date = datetime.datetime.now().strftime('%Y/%m/%d') if args[0] == 'Jupiter': planet_constellation = ephem.constellation(ephem.Jupiter(date)) #/planet Jupiter elif args[0] == 'Mars': planet_constellation = ephem.constellation(ephem.Mars(date)) #/planet Mars elif args[0] == 'Mercury': planet_constellation = ephem.constellation(ephem.Mercury(date)) #/planet Mercury elif args[0] == 'Moon': planet_constellation = ephem.constellation(ephem.Moon(date)) #/planet Moon elif args[0] == 'Neptune': planet_constellation = ephem.constellation(ephem.Neptune(date)) #/planet Neptune elif args[0] == 'Pluto': planet_constellation = ephem.constellation(ephem.Pluto(date)) #/planet Pluto elif args[0] == 'Saturn': planet_constellation = ephem.constellation(ephem.Saturn(date)) #/planet Saturn elif args[0] == 'Sun': planet_constellation = ephem.constellation(ephem.Sun(date)) #/planet Sun elif args[0] == 'Uranus': planet_constellation = ephem.constellation(ephem.Uranus(date)) #/planet Uranus elif args[0] == 'Venus': planet_constellation = ephem.constellation(ephem.Venus(date)) #/planet Venus text = planet_constellation update.message.reply_text(" Планета {0} находится в созвездии {1} на дату {2}".format(args[0], text[1], date ))
def get_planet( update, context ): #функция показывает в каком созвездии планета с командой /planet date_user = '******' #input('Введите дату в формате год/месяц/день: ') if context.args[0] == 'mars': planetname = ephem.Mars(date_user) elif context.args[0] == 'venus': planetname = ephem.Venus(date_user) elif context.args[0] == 'jupiter': planetname = ephem.Jupiter(date_user) elif context.args[0] == 'earth': planetname = ephem.Earth(date_user) elif context.args[0] == 'moon': planetname = ephem.Moon(date_user) elif context.args[0] == 'sun': planetname = ephem.Sun(date_user) elif context.args[0] == 'uranus': planetname = ephem.Uranus(date_user) elif context.args[0] == 'pluto': planetname = ephem.Pluto(date_user) else: update.message.reply_text('ошибочка вышла') return constel_planet = ephem.constellation(planetname) update.message.reply_text( f'{date_user} Планета {context.args[0].upper()} в созвездии {constel_planet[-1]}' )
def planet(bot, update): edata = datetime.date.today() edata = str(edata.year)+'/'+str(edata.month)+'/'+str(edata.day) ephem_dic = {'mars':ephem.Mars(edata), 'moon':ephem.Moon(edata), 'mercury':ephem.Mercury(edata), 'venus':ephem.Venus(edata), 'jupiter':ephem.Jupiter(edata), 'saturn':ephem.Saturn(edata), 'uranus':ephem.Uranus(edata), 'neptune':ephem.Neptune(edata), 'pluto':ephem.Pluto(edata), } try: if update == None or update.message == None: return #Периоди́чески возникает такая хрень text = update.message.text.split(' ') if len(text)<2: raise ValueError('Ошибка. Вы не ввели название планеты') text = text[1].lower() #Получили название планеты ephem_one = ephem_dic.get(text) if ephem_one==None: raise ValueError('Ошибка. Я не знаю такой планеты') const = ephem.constellation(ephem_one) if len(const) != 2: #На всякий случай raise ValueError('Ошибка. Я не знаю такой планеты') update.message.reply_text(f'Планета {text.upper()} сегодня находится в созвездии "{const[1].upper()}"') except ValueError as e: update.message.reply_text(str(e)) update.message.reply_text('Вы должны набрать /planet планета') update.message.reply_text('Сейчас я знаю такие планеты: '+str(list(ephem_dic))[1:-1])
def planet_user(bot, update): text = 'Для ввода названия планеты используйте "/planet [название планеты на англ]"' #planet = update.message.text.rsplit() planets = [ 'Sun', 'Moon', 'Mercury', 'Venus', 'Mars', 'Jupiter', 'Saturn', 'Uranus', 'Neptune', 'Pluto' ] user_input_planet = update.message.text[8:].capitalize() if user_input_planet in planets: d = datetime.datetime.now().strftime('%Y') if user_input_planet == 'Sun': planet_answer = ephem.constellation( ephem.Sun(datetime.datetime.now().strftime('%Y'))) bot.sendMessage(update.message.chat_id, planet_answer) elif user_input_planet == 'Moon': planet_answer = ephem.constellation( ephem.Moon(datetime.datetime.now().strftime('%Y'))) bot.sendMessage(update.message.chat_id, planet_answer) elif user_input_planet == 'Mercury': planet_answer = ephem.constellation( ephem.Mercury(datetime.datetime.now().strftime('%Y'))) bot.sendMessage(update.message.chat_id, planet_answer) elif user_input_planet == 'Venus': planet_answer = ephem.constellation( ephem.Venus(datetime.datetime.now().strftime('%Y'))) bot.sendMessage(update.message.chat_id, planet_answer) elif user_input_planet == 'Mars': planet_answer = ephem.constellation( ephem.Mars(datetime.datetime.now().strftime('%Y'))) bot.sendMessage(update.message.chat_id, planet_answer) elif user_input_planet == 'Jupiter': planet_answer = ephem.constellation( ephem.Jupiter(datetime.datetime.now().strftime('%Y'))) bot.sendMessage(update.message.chat_id, planet_answer) elif user_input_planet == 'Saturn': planet_answer = ephem.constellation( ephem.Saturn(datetime.datetime.now().strftime('%Y'))) bot.sendMessage(update.message.chat_id, planet_answer) elif user_input_planet == 'Uranus': planet_answer = ephem.constellation( ephem.Uranus(datetime.datetime.now().strftime('%Y'))) bot.sendMessage(update.message.chat_id, planet_answer) elif user_input_planet == 'Neptune': planet_answer = ephem.constellation( ephem.Neptune(datetime.datetime.now().strftime('%Y'))) bot.sendMessage(update.message.chat_id, planet_answer) elif user_input_planet == 'Pluto': planet_answer = ephem.constellation( ephem.Pluto(datetime.datetime.now().strftime('%Y'))) bot.sendMessage(update.message.chat_id, planet_answer) else: planet_answer = "Неправильно введено название планеты" bot.sendMessage(update.message.chat_id, planet_answer) #print(ephem.constellation(m)) #constellation = ephem.constellation(planet) logging.info(text)
def get_events(date=datetime.now().strftime('%Y-%m-%d'), lat='0', lon='0'): """Calculates all astronomical events on a given day at a given location. The returned events containin information about: - the Sun; - the Moon; - visible planets for the night; - any oppositions, conjunctions and elongations; - any current meteor showers; and - if the given day is a solstice or equinox. Keyword arguments: date -- a YYYY-MM-DD string. lat -- a floating-point latitude string. (positive/negative = North/South) lon -- a floating-point longitude string. (positive/negative = East/West) """ # Determine the hemisphere based on the latitude. if float(lat) > 0: hemisphere = 'north' else: hemisphere = 'south' # Create a location and all body objects. location = helpers.define_location(date, lat, lon) # Create all of the PyEphem objects that will be used. sun = ephem.Sun(location) moon = ephem.Moon(location) mercury = ephem.Mercury(location) venus = ephem.Venus(location) mars = ephem.Mars(location) jupiter = ephem.Jupiter(location) saturn = ephem.Saturn(location) uranus = ephem.Uranus(location) neptune = ephem.Neptune(location) pluto = ephem.Pluto(location) # Create lists for referencing in later loops. planets = [mercury, venus, mars, jupiter, saturn, uranus, neptune, pluto] bodies = [moon] + planets # Define a list to store all events that occur on the given day. events = { 'sun': get_sun_data(sun, date, lat, lon), 'moon': get_moon_data(moon, date, lat, lon), 'planets': get_planet_data(planets, date, lat, lon), 'events': [] } events['events'] += get_planetary_events(planets, date, lat, lon) events['events'] += get_separation_events(bodies, date) events['events'] += get_celestial_events(date) return events
def talk_planet(bot, update): # Получаем от юзера сообщение user_text = update.message.text # складываем в список полученное сообщение, разделяя пробелом user_text = user_text.split(' ') # Проверяем полученое сообщение if user_text[0] == '/planet': # Определяем календарную дату date = datetime.datetime.now() # Определяем название планеты и выводим в сообщение в каком созвездии сегодня находится планета. if user_text[1] == 'Sun': sun = ephem.Sun(date) update.message.reply_text(ephem.constellation(sun)) elif user_text[1] == 'Mars': mars = ephem.Mars(date) update.message.reply_text(ephem.constellation(mars)) elif user_text[1] == 'Mercury': mercury = ephem.Mercury(date) update.message.reply_text(ephem.constellation(mercury)) elif user_text[1] == 'Venus': venus = ephem.Venus(date) update.message.reply_text(ephem.constellation(venus)) elif user_text[1] == 'Jupiter': jupiter = ephem.Jupiter(date) update.message.reply_text(ephem.constellation(jupiter)) elif user_text[1] == 'Saturn': saturn = ephem.Saturn(date) update.message.reply_text(ephem.constellation(saturn)) elif user_text[1] == 'Uranus': uranus = ephem.Uranus(date) update.message.reply_text(ephem.constellation(uranus)) elif user_text[1] == 'Neptune': neptune = ephem.Neptune(date) update.message.reply_text(ephem.constellation(neptune)) elif user_text[1] == 'Pluto': pluto = ephem.Pluto(date) update.message.reply_text(ephem.constellation(pluto)) else: update.message.reply_text("""Вы ввели не верное название планеты. Введите любую планету из этого списка: - Sun - Mars - Mercury - Venus - Jupiter - Saturn - Uranus - Neptune - Pluto """)
def closest_point_to_pluto(): pluto = ephem.Pluto() obs = ephem.Observer() now = ephem.now() # http://stackoverflow.com/a/477610/724176 def drange(start, stop, step): """Decimal range""" r = start while r < stop: yield r r += step def calc_best(min_lat=-90, max_lat=90, min_lon=-180, max_lon=180, step=10): """Check a bunch of lat/lon points and find the one where Pluto's observed altitude is closest to 90 degrees""" best_alt = 0 best_az = None best_lat = None best_lon = None for lat in drange(min_lat, max_lat + 1, step): for lon in drange(min_lon, max_lon + 1, step): obs.lon = str(lon) obs.lat = str(lat) obs.date = now pluto.compute(obs) if abs(pluto.alt - NINETY) < abs(best_alt - NINETY): best_alt = pluto.alt best_az = pluto.az best_lat = lat best_lon = lon # print(lat, lon, pluto.alt, pluto.az) print("Best:") print(best_lat, best_lon, best_alt, best_az) return best_lat, best_lon best_lat, best_lon = calc_best() last_step = 10 for step in [1, 0.1, 0.01]: best_lat, best_lon = calc_best( best_lat - last_step, best_lat + last_step, best_lon - last_step, best_lon + last_step, step, ) last_step = step return best_lat, best_lon
def planet_constellation(bot, update, args): #определяем текущую дату и время date = datetime.datetime.now().strftime('%Y/%m/%d') #input_text = ' '.join(args) #Меркурий if str(args[0]) == 'Mercury': p = ephem.Mercury(date) bot.sendMessage(update.message.chat_id, text=str(args[0]) + ' в созвездии ' + ephem.constellation(p)[1]) #Венера if str(args[0]) == 'Venus': p = ephem.Venus(date) bot.sendMessage(update.message.chat_id, text=str(args[0]) + ' в созвездии ' + ephem.constellation(p)[1]) #Марс if str(args[0]) == 'Mars': p = ephem.Mars(date) bot.sendMessage(update.message.chat_id, text=str(args[0]) + ' в созвездии ' + ephem.constellation(p)[1]) #Юпитер if str(args[0]) == 'Jupiter': p = ephem.Jupiter(date) bot.sendMessage(update.message.chat_id, text=str(args[0]) + ' в созвездии ' + ephem.constellation(p)[1]) #Сатурн if str(args[0]) == 'Saturn': p = ephem.Saturn(date) bot.sendMessage(update.message.chat_id, text=str(args[0]) + ' в созвездии ' + ephem.constellation(p)[1]) #Уран if str(args[0]) == 'Uranus': p = ephem.Uranus(date) bot.sendMessage(update.message.chat_id, text=str(args[0]) + ' в созвездии ' + ephem.constellation(p)[1]) #Нептун if str(args[0]) == 'Neptune': p = ephem.Neptune(date) bot.sendMessage(update.message.chat_id, text=str(args[0]) + ' в созвездии ' + ephem.constellation(p)[1]) #Плутон if str(args[0]) == 'Pluto': p = ephem.Pluto(date) bot.sendMessage(update.message.chat_id, text=str(args[0]) + ' в созвездии ' + ephem.constellation(p)[1])
def space(bot, update): date = datetime.datetime.now() #logging.info(user_text) #update.message.reply_text('Введите планету ') planeta = update.message.text print(planeta) print(len(planeta)) print(planeta[9:]) planeta = planeta[9:] print('Итог ', planeta) #update.message.reply_text('Введите дату согласно формату ГГГГ/ММ/ДД ') #date=update.message.text #planeta=input('Введите планету ') #date=input('Введите дату согласно формату ГГГГ/ММ/ДД ') #reply_to_user= update.message.text if planeta == 'Mars': mars = ephem.Mars(date) reply_to_user = ephem.constellation(mars) elif planeta == 'Mercury': mercury = ephem.Mercury(date) reply_to_user = ephem.constellation(mercury) elif planeta == 'Venus': venus = ephem.Venus(date) reply_to_user = ephem.constellation(venus) elif planeta == 'Jupiter': jupiter = ephem.Jupiter(date) reply_to_user = ephem.constellation(jupiter) elif planeta == 'Saturn': saturn = ephem.Saturn(date) reply_to_user = ephem.constellation(saturn) elif planeta == 'Uranus': uranus = ephem.Mars(date) reply_to_user = ephem.constellation(uranus) elif planeta == 'Neptune': neptune = ephem.Neptune(date) reply_to_user = ephem.constellation(neptune) elif planeta == 'Pluto': pluto = ephem.Pluto(date) reply_to_user = ephem.constellation(pluto) #update.message.reply_text(user_text) update.message.reply_text(reply_to_user)
def get_planet_name(bot, update): planet_list = [ 'Mars', 'Mercury', 'Saturn', 'Venus', 'Uranus', 'Jupiter', 'Sun', 'Neptune', 'Pluto', 'Moon' ] t = update.message.text logging.info(f'вызван get_planet_name + {update.message.text}') tlist = t.split() planet = list(set(planet_list) & set(tlist)) today = date.today().strftime('%Y/%m/%d') if len(planet) == 1: if 'Mars' in planet: planet_today = ephem.Mars(today) const = ephem.constellation(planet_today) elif 'Mercury' in planet: planet_today = ephem.Mercury(today) const = ephem.constellation(planet_today) elif 'Saturn' in planet: planet_today = ephem.Saturn(today) const = ephem.constellation(planet_today) elif "Venus" in planet: planet_today = ephem.Venus(today) const = ephem.constellation(planet_today) elif 'Uranus' in planet: planet_today = ephem.Uranus(today) const = ephem.constellation(planet_today) elif 'Jupiter' in planet: planet_today = ephem.Jupiter(today) const = ephem.constellation(planet_today) elif 'Sun' in planet: planet_today = ephem.Sun(today) const = ephem.constellation(planet_today) elif 'Neptune' in planet: planet_today = ephem.Neptune(today) const = ephem.constellation(planet_today) elif 'Pluto' in planet: planet_today = ephem.Pluto(today) const = ephem.constellation(planet_today) elif 'Moon' in planet: planet_today = ephem.Moon(today) const = ephem.constellation(planet_today) elif len(planet) > 1: const = 'Введите не больше 1 планеты' else: const = 'Вы не ввели название планеты, либо я не знаю таких планет' text = const update.message.reply_text(text) logging.info(f'определено созвездие: {text}')
def convert(date, lat, lon, elevation): """ degistirme isini yapar """ gatech = ephem.Observer() gatech.lon = lat gatech.lat = lon gatech.elevation = elevation gatech.date = date catalog_stars = [] for edb_file in os.listdir(PATH): if edb_file.endswith(EXT): catalog_stars.extend(get_lines(PATH + edb_file)) new_catalog = "" for catalog_star in catalog_stars: if catalog_star.startswith("#") or catalog_star.strip() == "": continue try: star = ephem.readdb(catalog_star) star.compute(gatech) ra = angle_to_right_ascension(star.az) dec = math.degrees(star.alt) new_catalog += f"{ra},{dec},{star.mag},{star.name}\n" except Exception as ex: print(catalog_star) logging.exception(ex) planets = [ ephem.Jupiter(), ephem.Mars(), ephem.Mercury(), ephem.Moon(), ephem.Neptune(), ephem.Pluto(), ephem.Saturn(), ephem.Sun(), ephem.Uranus(), ephem.Venus(), ] for planet in planets: planet.compute(gatech) ra = angle_to_right_ascension(planet.az) dec = math.degrees(planet.alt) new_catalog += f"{ra},{dec},{planet.mag},{planet.name}\n" return new_catalog