From 35b05a1707e573ab33a9edac88ca4826510ae8af Mon Sep 17 00:00:00 2001 From: Shirikova Aleksandra Date: Fri, 24 Nov 2023 00:21:01 +0300 Subject: [PATCH 1/6] 1st version --- 1_if1.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/1_if1.py b/1_if1.py index be736084..0ec81b2c 100644 --- a/1_if1.py +++ b/1_if1.py @@ -14,12 +14,22 @@ """ + def main(): - """ - Эта функция вызывается автоматически при запуске скрипта в консоли - В ней надо заменить pass на ваш код - """ - pass + """Главная функция""" + + +age = int(input("Введите свой возраст: ")) +if age < 6: + print("Вас ждет детский садик") +elif age >= 6 or age <= 18: + print("Вас ждет школа") +elif age > 18 or age < 23: + print("Вас ждет университет") +else: + print("Идите работать") + + if __name__ == "__main__": main() From 74afec08dbc5e5ae702c5b12d465ef5b6ca985a7 Mon Sep 17 00:00:00 2001 From: Shirikova Aleksandra Date: Fri, 24 Nov 2023 12:46:11 +0300 Subject: [PATCH 2/6] 2nd version --- 1_if1.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/1_if1.py b/1_if1.py index 0ec81b2c..c47f1046 100644 --- a/1_if1.py +++ b/1_if1.py @@ -22,14 +22,15 @@ def main(): age = int(input("Введите свой возраст: ")) if age < 6: print("Вас ждет детский садик") -elif age >= 6 or age <= 18: +elif age <= 18 and age >= 6: print("Вас ждет школа") -elif age > 18 or age < 23: +elif age > 18 and age < 23: print("Вас ждет университет") else: print("Идите работать") + if __name__ == "__main__": main() From d99f01ec0e9279869621acb1750139288cd428ed Mon Sep 17 00:00:00 2001 From: Shirikova Aleksandra Date: Fri, 24 Nov 2023 13:27:30 +0300 Subject: [PATCH 3/6] 3rs ver --- 1_if1.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/1_if1.py b/1_if1.py index c47f1046..0f94b9af 100644 --- a/1_if1.py +++ b/1_if1.py @@ -17,17 +17,15 @@ def main(): """Главная функция""" - - -age = int(input("Введите свой возраст: ")) -if age < 6: - print("Вас ждет детский садик") -elif age <= 18 and age >= 6: - print("Вас ждет школа") -elif age > 18 and age < 23: - print("Вас ждет университет") -else: - print("Идите работать") + age = int(input("Введите свой возраст: ")) + if age < 6: + print("Вас ждет детский садик") + elif age <= 18 and age >= 6: + print("Вас ждет школа") + elif age > 18 and age < 23: + print("Вас ждет университет") + else: + print("Идите работать") From 4118228273732f4afa1375d273f0f435e3f4633c Mon Sep 17 00:00:00 2001 From: Shirikova Aleksandra Date: Fri, 24 Nov 2023 23:00:44 +0300 Subject: [PATCH 4/6] 1st ver --- 2_if2.py | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/2_if2.py b/2_if2.py index 0f1644f3..422b41b0 100644 --- a/2_if2.py +++ b/2_if2.py @@ -15,12 +15,28 @@ """ -def main(): - """ - Эта функция вызывается автоматически при запуске скрипта в консоли - В ней надо заменить pass на ваш код - """ - pass + +def main(first_line, second_line): + if not isinstance(first_line, str) and isinstance(second_line, str): + return 0 + elif len(first_line) == len(second_line): + return 1 + elif len(first_line) > len(second_line): + if "learn" in second_line: + return 3 + else: + return 2 + elif len(first_line) < len(second_line): + if "learn" in second_line: + return 3 + else: + return ("такой комбинации не описано") + + if __name__ == "__main__": - main() + print(main("привет", "мир")) + print(main("привет", "прощай")) + print(main("привет", "солнышкоооо")) + print(main(1, "ghbdtn")) + print(main("hfhfhрррр", "learn")) From c89bb6e1f4ce612ad560a9b6ee2205b54aff3fd7 Mon Sep 17 00:00:00 2001 From: Shirikova Aleksandra Date: Sat, 25 Nov 2023 14:45:18 +0300 Subject: [PATCH 5/6] 2nd ver --- 2_if2.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/2_if2.py b/2_if2.py index 422b41b0..eb43b3a2 100644 --- a/2_if2.py +++ b/2_if2.py @@ -17,26 +17,24 @@ def main(first_line, second_line): - if not isinstance(first_line, str) and isinstance(second_line, str): + if not isinstance(first_line, str) or not isinstance(second_line, str): return 0 - elif len(first_line) == len(second_line): + elif first_line == second_line: return 1 elif len(first_line) > len(second_line): - if "learn" in second_line: + if "learn" == second_line: return 3 else: return 2 - elif len(first_line) < len(second_line): - if "learn" in second_line: - return 3 - else: - return ("такой комбинации не описано") - + elif "learn" == second_line: + return 3 + return "такой комбинации не существует" - + if __name__ == "__main__": print(main("привет", "мир")) - print(main("привет", "прощай")) + print(main("привет", "привет")) print(main("привет", "солнышкоооо")) print(main(1, "ghbdtn")) print(main("hfhfhрррр", "learn")) + print(main("hfbh", 5.32)) From 1987a240e23cb319d1f748d6a9d2319831f5e8b7 Mon Sep 17 00:00:00 2001 From: Shirikova Aleksandra Date: Sat, 25 Nov 2023 19:40:00 +0300 Subject: [PATCH 6/6] Mars_now --- .gitignore | 3 +++ 8_ephem_bot.py | 36 ++++++++++++++++++++++++------------ mars.py | 0 3 files changed, 27 insertions(+), 12 deletions(-) create mode 100644 mars.py diff --git a/.gitignore b/.gitignore index af6d5026..9150b00e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ + +settings.py + # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] diff --git a/8_ephem_bot.py b/8_ephem_bot.py index 1cf9ea19..62923a2c 100644 --- a/8_ephem_bot.py +++ b/8_ephem_bot.py @@ -12,8 +12,12 @@ бота отвечать, в каком созвездии сегодня находится планета. """ + +import ephem import logging +import settings +from datetime import datetime from telegram.ext import Updater, CommandHandler, MessageHandler, Filters logging.basicConfig(format='%(name)s - %(levelname)s - %(message)s', @@ -21,15 +25,6 @@ filename='bot.log') -PROXY = { - 'proxy_url': 'socks5://t1.learn.python.ru:1080', - 'urllib3_proxy_kwargs': { - 'username': 'learn', - 'password': 'python' - } -} - - def greet_user(update, context): text = 'Вызван /start' print(text) @@ -39,16 +34,33 @@ def greet_user(update, context): def talk_to_me(update, context): user_text = update.message.text print(user_text) - update.message.reply_text(text) + update.message.reply_text(user_text) + + +def show_planet(planet_name, context): + user_text = planet_name.message.text + user_text_split = user_text.split() + print(user_text_split) + if 'Mars' in user_text_split: + time_0 = datetime.now() + now = (time_0.strftime('%Y-%m-%d')) + mars = ephem.Mars(now) + const = ephem.constellation(mars) + print(const) + planet_name.message.reply_text(const) + else: + planet_name.message.reply_text(user_text) def main(): - mybot = Updater("КЛЮЧ, КОТОРЫЙ НАМ ВЫДАЛ BotFather", request_kwargs=PROXY, use_context=True) + mybot = Updater(settings.API_KEY, use_context=True) dp = mybot.dispatcher dp.add_handler(CommandHandler("start", greet_user)) + dp.add_handler(CommandHandler("planet", show_planet)) dp.add_handler(MessageHandler(Filters.text, talk_to_me)) - + dp.add_handler(MessageHandler(Filters.text, show_planet)) + logging.info("Бот стартовал") mybot.start_polling() mybot.idle() diff --git a/mars.py b/mars.py new file mode 100644 index 00000000..e69de29b