Mobil ilovalarni ishlab chiqish
Avvaldan kiritilgan tug‘ilgan kunlar va alohida hodisalarni eslatib turuvchi
Download 53.06 Kb. Pdf ko'rish
|
Mobil ilovalarni ishlab chiqish
Quyidagi kodlar, Python dasturi sifatida avvaldan kiritilgan tug'ilgan kunlarni va alohida hodisalarni eslatib turuvchi budilnikni yaratish uchun yozilgan: import datetime import time # Tug'ilgan kunlarni ro'yxatdan o'tkazish birthdays = {"Ali": "2000-10-15", "Vali": "1998-05-10", "Sara": "1995-12-30"} # Hodisalar ro'yxatidan foydalanish events = {"Meeting": "2023-04-20 10:00:00", "Birthday Party": "2023-05-10 19:00:00", "Deadline": "2023-05-15 23:59:59"} # Budilnik funksiyasi def alarm_clock(datetime_obj, event_name): now = datetime.datetime.now() diff = datetime_obj - now time.sleep(diff.total_seconds()) print(f"Reminder: {event_name} at {datetime_obj.strftime('%Y-%m-%d %H:%M:%S')}") # Tug'ilgan kunlar uchun budilniklar for name, birthday in birthdays.items(): birthday_date = datetime.datetime.strptime(birthday, "%Y-%m-%d") current_year_birthday = datetime.datetime(now.year, birthday_date.month, birthday_date.day) if current_year_birthday < now: current_year_birthday = datetime.datetime(now.year + 1, birthday_date.month, birthday_date.day) alarm_clock(current_year_birthday, f"{name}'s Birthday") # Hodisalar uchun budilniklar for event_name, event_datetime in events.items(): event_date = datetime.datetime.strptime(event_datetime, "%Y-%m-%d %H:%M:%S") alarm_clock(event_date, event_name) Dastur foydalanuvchi tomonidan avvaldan kiritilgan tug'ilgan kunlarni (birthdays) va hodisalar ro'yxatini (events) o'z ichiga oladi. alarm_clock() funksiyasi, datetime_obj argumenti sifatida qabul qilingan vaqtga (datetime objekti) qadar kutingan holda (time.sleep()) eslatma chiqaradi. Eslatmada, event_name argumenti sifatida hodisa nomi va datetime_obj argumenti sifatida esa eslatma vaqti ko'rsatiladi. Dastur tug'ilgan kunlarni eslatib turish uchun birthdays ro'yxatini o'z ichiga oladi. Ro'yxatdagi har bir tug'ilgan kuni uchun budilnikni chaqirish uchun for tsikli yordamida har bir tug'ilgan kuni kiritilgan sanaga aylantirib (datetime.datetime(now.year, birthday_date.month, birthday_date.day)), o'zingizning tug'ilgan kuningizdan oldinmi, yoki keyinmi ekanligini tekshirib (if current_year_birthday < now) so'ng, alarm_clock() funksiyasini chaqiradi. Hodisalar uchun esa, events ro'yxati o'z ichiga olindi va har bir hodisa uchun `alarm Download 53.06 Kb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling