Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2nd version #157

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@

settings.py

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
19 changes: 14 additions & 5 deletions 1_if1.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,21 @@

"""


def main():
"""
Эта функция вызывается автоматически при запуске скрипта в консоли
В ней надо заменить pass на ваш код
"""
pass
"""Главная функция"""
age = int(input("Введите свой возраст: "))
if age < 6:
print("Вас ждет детский садик")
elif age <= 18 and age >= 6:
print("Вас ждет школа")
elif age > 18 and age < 23:
print("Вас ждет университет")
else:
print("Идите работать")




if __name__ == "__main__":
main()
30 changes: 22 additions & 8 deletions 2_if2.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,26 @@

"""

def main():
"""
Эта функция вызывается автоматически при запуске скрипта в консоли
В ней надо заменить pass на ваш код
"""
pass


def main(first_line, second_line):
if not isinstance(first_line, str) or not isinstance(second_line, str):
return 0
elif first_line == second_line:
return 1
elif len(first_line) > len(second_line):
if "learn" == second_line:
return 3
else:
return 2
elif "learn" == second_line:
return 3
return "такой комбинации не существует"


if __name__ == "__main__":
main()
print(main("привет", "мир"))
print(main("привет", "привет"))
print(main("привет", "солнышкоооо"))
print(main(1, "ghbdtn"))
print(main("hfhfhрррр", "learn"))
print(main("hfbh", 5.32))
36 changes: 24 additions & 12 deletions 8_ephem_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,19 @@
бота отвечать, в каком созвездии сегодня находится планета.

"""

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',
level=logging.INFO,
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)
Expand All @@ -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()

Expand Down
Empty file added mars.py
Empty file.