├── 1-dars. Tanishuv
├── README.md
└── algoritmlsh
│ └── README.md
├── 10-dars. Exceptions and Handling
└── README.md
├── 11-dars. Module final
├── README.md
├── __pycache__
│ └── formula.cpython-310.pyc
├── formula.py
└── main.py
├── 12-dars. Classlar va Obyektlar
└── README.md
├── 13-dars. Dunder methodlar
└── README.md
├── 14-dars. OOP
└── README.md
├── 15-dars. Fayllar
├── README.md
├── main.py
└── royhat.txt
├── 4-dars. Matematika va Sonlar
└── README.md
├── 5-dars. Shartli operatorlar
└── README.md
├── 6-dars. List va Tuple
└── README.md
├── 7-dars. Dictionary va Set
└── README.md
├── 8-dars. Funksiyalar
└── README.md
├── 9-dars. Takrorlanuvchi operatorlar
└── README.md
├── Kirish
└── README.md
├── O'zgaruvchilar
└── README.md
├── README.md
├── background.jpg
├── cat.jpg
├── dars.txt
├── pishak.png
├── pupil.db
├── sqlite.db
├── string
└── README.md
├── telegram-bot
├── 1-dars
│ ├── 1-dars.py
│ ├── __pycache__
│ │ └── bir.cpython-310.pyc
│ ├── bir.py
│ ├── cat.py
│ └── ikki.py
├── 10-dars
│ ├── __pycache__
│ │ └── inlinebutton.cpython-310.pyc
│ ├── bot.py
│ └── inlinebutton.py
├── 11-dars
│ ├── __pycache__
│ │ ├── inlinebutton.cpython-310.pyc
│ │ └── keyboard_button.cpython-310.pyc
│ ├── bot.py
│ ├── inlinebutton.py
│ └── keyboard_button.py
├── 12-dars
│ ├── __pycache__
│ │ ├── my_insta.cpython-310.pyc
│ │ └── my_yutube.cpython-310.pyc
│ ├── bot.py
│ ├── my_insta.py
│ └── my_yutube.py
├── 13-dars
│ ├── __pycache__
│ │ └── insta.cpython-310.pyc
│ ├── bot.py
│ ├── insta.py
│ └── tik_tok.py
├── 14-dars
│ ├── __pycache__
│ │ ├── insta.cpython-310.pyc
│ │ └── tik_tok.cpython-310.pyc
│ ├── bot.py
│ └── tik_tok.py
├── 15-dars
│ ├── add_data.py
│ ├── create.py
│ ├── delete.py
│ ├── read.py
│ └── update.py
├── 16-dars
│ ├── __pycache__
│ │ └── states.cpython-310.pyc
│ ├── bot.py
│ ├── create.py
│ └── states.py
├── 17-dars
│ ├── __pycache__
│ │ └── states.cpython-310.pyc
│ ├── bot.py
│ ├── create.py
│ └── states.py
├── 18-dars
│ ├── .env
│ ├── bot.py
│ ├── data
│ │ ├── __pycache__
│ │ │ └── config.cpython-310.pyc
│ │ └── config.py
│ └── filters
│ │ ├── __pycache__
│ │ └── admin.cpython-310.pyc
│ │ └── admin.py
├── 19-dars
│ └── main.txt
├── 2-dars
│ ├── 2-dars.py
│ ├── __pycache__
│ │ ├── cat.cpython-310.pyc
│ │ └── design.cpython-310.pyc
│ ├── cat.py
│ ├── design.py
│ └── main.py
├── 20-dars
│ ├── .env
│ ├── bot.py
│ ├── data
│ │ ├── __pycache__
│ │ │ ├── config.cpython-310.pyc
│ │ │ ├── config.cpython-311.pyc
│ │ │ └── config.cpython-312.pyc
│ │ └── config.py
│ └── filters
│ │ ├── __pycache__
│ │ ├── admin.cpython-310.pyc
│ │ ├── admin.cpython-311.pyc
│ │ ├── admin.cpython-312.pyc
│ │ ├── check_sub_channel.cpython-310.pyc
│ │ ├── check_sub_channel.cpython-311.pyc
│ │ └── check_sub_channel.cpython-312.pyc
│ │ ├── admin.py
│ │ └── check_sub_channel.py
├── 3-dars
│ ├── 3-dars.py
│ └── cat.py
├── 4-dars vazifa
│ ├── __pycache__
│ │ └── wiki.cpython-310.pyc
│ ├── bot.py
│ └── wiki.py
├── 4-dars
│ ├── bot.py
│ └── ism_manosi.py
├── 5-dars
│ ├── __pycache__
│ │ └── remove_bg.cpython-310.pyc
│ ├── background.jpg
│ ├── bot.py
│ ├── ferrari.jpg
│ └── remove_bg.py
├── 6-dars
│ └── README.md
├── 7-dars
│ ├── __pycache__
│ │ ├── states.cpython-310.pyc
│ │ └── states.cpython-312.pyc
│ ├── bot.py
│ ├── bots.py
│ ├── reja.txt
│ └── states.py
├── 8-9-dars
│ ├── 9-dars
│ │ ├── __pycache__
│ │ │ └── mybuttons.cpython-310.pyc
│ │ ├── bot.py
│ │ └── mybuttons.py
│ ├── __pycache__
│ │ ├── ism_manosi.cpython-310.pyc
│ │ └── my_keyboards.cpython-310.pyc
│ ├── bot.py
│ ├── ism_manosi.py
│ ├── maktab.jpg
│ ├── my_keyboards.py
│ ├── reja.txt
│ └── state.py
├── Ansor.pptx
├── README.md
├── lesson-20.zip
└── other.py
├── text.txt
├── video
└── video.mp4
/1-dars. Tanishuv/README.md:
--------------------------------------------------------------------------------
1 | 00. Tanishuv
2 | Reja:
3 |
4 | 0.1 Kompyuter qurilmalari va dastrulash tillari turlari
5 |
6 | 0.2 Dasturlash asoslari va muhitlari
7 |
8 | 0.3 Pythonni o'rnatish
9 |
10 | 0.4 Pycharm
11 |
12 | 0.5 Thonny
13 |
14 | 0.6 replit.com
15 |
16 | 0.7 Darslar haqida
17 |
18 |
19 |
20 | 0.1 Kompyuter qurilmalari va dastrulash tillari turlari
21 |
22 |
23 | 
24 |
25 |
26 | 
27 | 
28 | 
29 |
30 |
--------------------------------------------------------------------------------
/1-dars. Tanishuv/algoritmlsh/README.md:
--------------------------------------------------------------------------------
1 | 
2 | 
3 | 
4 | 
5 | 
6 | 
7 | 
8 | 
9 | 
10 | 
11 | 
12 | 
13 | 
14 | 
15 | 
16 | 
17 | 
18 | 
19 | 
20 | 
21 | 
22 | 
23 | 
24 | 
25 | 
26 | 
27 | 
28 | 
29 | 
30 | 
31 | 
32 | 
33 | 
34 | 
35 | 
36 | 
37 | 
38 | 
39 | 
40 | 
41 | 
42 | 
43 | 
44 | 
45 | 
46 | 
47 | 
48 | 
49 | ![Uploading image.png…]()
50 | ![Uploading image.png…]()
51 |
--------------------------------------------------------------------------------
/10-dars. Exceptions and Handling/README.md:
--------------------------------------------------------------------------------
1 | 1-topshiriq
2 | #oson
3 | IndexError va KeyError hosil qiladigan kod yozing
4 |
5 | 2-topshiriq
6 | #oson
7 | TypeError hosil qiladigan kod yozing
8 |
9 | 3-topshiriq
10 | #qiyin
11 | 1- va 2- topshiriqda yozgan kodingizni try/except ichida yozib, ekranga errorni chiqaradigan kod yozing
12 |
13 |
14 | 4-topshiriq
15 | #juda_qiyin
16 | Har 2 soniyada ekranga vaqtni ko'rsatadigan kod yozing.
17 | Ctrl + C bosilganda (kod to'xtatilganda) ekranga "stopped" deb yozib, loopni to'xtating.
18 |
19 | Ayni vaqtni o'lish uchun "datetime" kutubxonasidan foydalaning. https://docs.python.org/3/library/datetime.html
20 | https://strftime.org/
21 |
22 | Example:
23 | from datetime import datetime
24 | now = datetime.now()
25 | print(now.strftime("%X"))
26 |
--------------------------------------------------------------------------------
/11-dars. Module final/README.md:
--------------------------------------------------------------------------------
1 | Python 1-modul uchun loyiha.
2 |
3 | TicTacToe o`yinini yarating:
4 | O`yin sxemasi 3*3 sxemada bo`lishi kerak
5 | O`yin boshlanganda barcha kataklar '-' belgisi bilan to`ldirilgan holatda bo`ladi.
6 | Foydalanuvchilardan birinchisi o, ikkinchisi x belgisi bilan katakni to`ldirishi kerak.
7 | O`yin yutish yoki teng kelish shartlari sizga ma`lum. Vazifangiz kataklar holatiga qarab o`yin davm etishi va natijasini chiqarish olgoritmini tuzish bo`ladi.
8 |
9 | O`yinchilar ismi o`yin boshlanishida so`raladi va saqlanadi, bu o`yin hisobini olib borish uchun ishlatilinadi.
10 | O`yinchilar bir necha round ketma ket o`ynashlari mumkin va har gal o`yin tugaganida o`yin qayta o`ynalishi yoki yuqligi dastur tomonidan so`ralishi kerak.
11 |
12 | O`yin oxirida hisob chiqarilishi kerak:
13 | Ism : score
14 | Ism : score
15 | === winner : Ism === kurinishida.
16 |
--------------------------------------------------------------------------------
/11-dars. Module final/__pycache__/formula.cpython-310.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/muslimbek77/Python-course/21297c27636f3adabffb2199769e223c936ccae6/11-dars. Module final/__pycache__/formula.cpython-310.pyc
--------------------------------------------------------------------------------
/11-dars. Module final/formula.py:
--------------------------------------------------------------------------------
1 | import math
2 |
3 | def ekuk(a,b):
4 | ekub = math.gcd(a,b)
5 | natija = a*b/ekub
6 | return natija
--------------------------------------------------------------------------------
/11-dars. Module final/main.py:
--------------------------------------------------------------------------------
1 | # import formula
2 |
3 | # a = 6
4 | # b = 10
5 |
6 | # natija = formula.ekuk(a,b)
7 |
8 | # print(natija)
9 |
10 | # import math
11 |
12 | # print(math.ceil(2.1))
13 |
14 | # import random as r
15 |
16 | # random_son = r.randint(1,10)
17 | # print(random_son)
18 |
19 | # royhat = ["Boborahim","Diyorbek","Fayozbek"]
20 |
21 | # navbatchi = r.choice(royhat)
22 | # result = r.choices(royhat, weights=[10,1,1],k=3)
23 | # print(result)
24 | # print(f"Bugungi navbatchi: {navbatchi}")
25 | # r.shuffle(royhat)
26 | # print(royhat)
27 |
28 | # uz_eng_words = {"mashina":"car","muhim":"essential","eshik":"door","qiziqarli":"interesting","qon":"blood","devor":"wall","daftar":"notebook"}
29 |
30 | # chance = 3
31 | # score = 0
32 | # print("So'zlarni inglizcha tarjimasini toping!\n")
33 | # questions = list(uz_eng_words.keys())
34 | # r.shuffle(questions)
35 | # questions_count = len(questions)
36 | # index = 0
37 | # while True:
38 |
39 | # if chance==0 or (index == questions_count):
40 | # if round(score*100/questions_count,2) >= 60:
41 | # print(f"Tabriklaymiz siz {round(score*100/questions_count,2)}% natija bilan {score}ta so'zni topdingiz.🎉")
42 | # else:
43 | # print(f"Afsuski siz {round(score*100/questions_count,2)}% natija bilan {score}ta so'zni topdingiz.😔")
44 | # break
45 | # else:
46 | # answer = input(f"{uz_eng_words[questions[index]]}: ").lower()
47 | # if uz_eng_words.get(answer) == uz_eng_words[questions[index]]:
48 | # print(f"To'g'ri ✅ {chance}ta imkoniyatingiz qoldi.")
49 | # score = score + 1
50 | # else:
51 | # chance = chance - 1
52 | # print(f"Noto'g'ri ❌ {chance}ta imkoniyatingiz qoldi.")
53 | # index = index + 1
54 |
55 | # natija = r.randrange(10,100,12)
56 | # print(list(range(10,100,12)))
57 | # print(natija)
58 |
59 | # def addAB(a,b):
60 | # return a+b
61 |
62 | # a= int(input("a="))
63 | # b= int(input("b="))
64 | # print(f"natija{addAB(a,b)}")
65 |
--------------------------------------------------------------------------------
/12-dars. Classlar va Obyektlar/README.md:
--------------------------------------------------------------------------------
1 | 1-topshiriq
2 |
3 | Student nomli class yarating.
4 | __init__ metodi orqali studentning ismi, yoshi va h,k larni qabul qilsin.
5 | about nomli metod ham qo'shing.
6 |
7 |
8 | 2-topshiriq
9 |
10 | Queue ma'lumot turini yarating.
11 | 3 ta metodni implement qilsin:
12 | 1. enque - element kiritish.
13 | 2. deque - elementni olish.
14 | 3. size - queue dagi elementlar sonini qaytarsin.
15 |
16 |
17 | 3-topshiriq
18 |
19 | 2-topshiriqda yozgan Queue class uchun "assert" dan foydalanib testlar yozing.
20 |
--------------------------------------------------------------------------------
/13-dars. Dunder methodlar/README.md:
--------------------------------------------------------------------------------
1 | 1-topshiriq
2 |
3 | Student nomli class yarating.
4 | __init__ metodi orqali studentning ismi, yoshi va h,k larni qabul qilsin.
5 | about nomli metod ham qo'shing.
6 |
7 |
8 | 2-topshiriq
9 |
10 | Dars davomida yaratilgan Vector class ga ayirish imkoniyatini qo'shing.
11 |
12 | Misol:
13 | v1 = Vector(3, 4)
14 | v2 = Vector(2, 4)
15 |
16 | v3 = v1 - v2
17 | # v3 - Vector(1, 0) bo'lishi kerak.
18 | # Vectorlar haqida qo'shimcha o'rganish uchun resurs - https://www.mathsisfun.com/algebra/vectors.html
19 |
20 |
21 | 3-topshiriq
22 |
23 | Student class yarating, name va age attributlari bo'lsin.
24 | Student class obyektlariga yosh bo'yicha taqqoslash imkoniyatini qo'shing.
25 |
26 | Misol:
27 | john = Student(name="John", age=21)
28 | bob = Student(name="Bob", age=32)
29 | alice = Student(name="Alice", age=21)
30 |
31 |
32 | print(john > bob) # False
33 | print(john < bob) # True
34 | print(john == alice) # True chiqishi kerak
35 |
--------------------------------------------------------------------------------
/14-dars. OOP/README.md:
--------------------------------------------------------------------------------
1 | 1-topshiriq
2 |
3 | O'tgan dars vazifa sifatida yaratilgan Student classni o'zgartiring.
4 | Student class'dan yaratilgan obyektni print qiliganda studentni ismi ekranga chiqarilsin.
5 |
6 | Misol:
7 | student = Student(name="John")
8 | print(student)
9 | # John
10 |
11 |
12 | 2-topshiriq
13 |
14 | Calculator nomli class yarating.
15 | add, subtract, multiply, divide nomi static metodlar qo'shing.
16 |
17 | Misol:
18 | print(Calculator.add(1, 2)) # 3
19 | print(Calculator.subtract(1, 2)) # -1
20 | print(Calculator.multiply(1, 2)) # 2
21 | print(Calculator.divide(1, 2)) # 0.5
22 |
23 |
24 | 3-topshiriq
25 |
26 | Yangi Teacher classini hosil qiling va u dars mobaynida yaratilgan User classidan voris olsin. Dars mobaynida yaratilgan Mentor classi User class dan emas Teacher classdan voris olsin. Teacher classiga subclass bo'lgan yangi Assistant classini ham yarating.
27 |
--------------------------------------------------------------------------------
/15-dars. Fayllar/README.md:
--------------------------------------------------------------------------------
1 | 1-topshiriq
2 |
3 | Quyidagi ishlarni bajaradigan dastur tuzing:
4 | file.txt nomli text fayl yaratib,
5 | ichiga "Hello Files" deb yozsin.
6 |
7 |
8 | 2-topshiriq
9 |
10 | Quyidagi faylni yuklab oling. Va faylni o'qib, ekranga chiqaradigan dastur tuzing.
11 | hospitals.csv
12 |
13 | https://online.pdp.uz/api/file/get/34bb6bbd-9493-4aa1-a7b8-3cd6a4337526
14 |
15 | 3-topshiriq
16 |
17 | 2-topshiridagi CSV faylni o'qib, 2012-2017-yillarda oralig'ida jami eng ko'p kasalxonalar qurilgan 3ta viloyatni ekranga chiqaradigan dastur tuzing.
18 |
--------------------------------------------------------------------------------
/15-dars. Fayllar/main.py:
--------------------------------------------------------------------------------
1 | #faylni ochish uchun
2 | # file = open(file="15-dars. Fayllar/royhat.txt",mode="r")
3 | # malumot = file.readline()
4 | # print(malumot)
5 | # malumot = file.readline()
6 | # print(malumot)
7 | # malumot = file.readline()
8 | # print(malumot)
9 | # malumot = file.readline()
10 | # print(malumot)
11 | # while True:
12 | # malumot = file.readline()
13 | # print("line ",malumot,end="")
14 | # if not malumot:
15 | # break
16 | # malumot = file.readlines()
17 | # print(malumot)
18 | # file.close() #faylni yopadi
19 | # print(file.closed)
20 | # print(malumot)
21 |
22 | # file = open("dars.txt","w")
23 | # file.write("Salom\nBugun juma!")
24 | # file.close()
25 |
26 | # for i in range(1000000):
27 | # file = open(f"dars/dars-{i+1}.txt","w")
28 | # file.write("salom")
29 |
30 | # with open("dars.txt","a") as file:
31 | # file.write("\nBugun Juma")
32 |
33 | #mode
34 | #r - read(o'qish uchun)
35 | #w - write(yozish uchun)
36 | #a - append(davomidan qo'shish uchun)
37 | #x - file do not exsist(fayl yaratilmagan bo'lsa)
38 | #r+, w+ ,a+, binar - rb, wb, ab
39 |
40 | # import requests
41 |
42 | # response = requests.get("https://cataas.com/cat")
43 | # content = response.content
44 |
45 | # with open(file="cat.jpg",mode="wb") as file:
46 | # file.write(content)
47 |
48 | # cat = open("cat.jpg","rb").read()
49 |
50 | # with open(file="cat-copy.jpg",mode="wb") as file:
51 | # file.write(cat)
52 |
--------------------------------------------------------------------------------
/15-dars. Fayllar/royhat.txt:
--------------------------------------------------------------------------------
1 | Boborahim
2 | Diyorbek
3 | Fayozbek
4 | Samandar
5 | Zarifbek
--------------------------------------------------------------------------------
/4-dars. Matematika va Sonlar/README.md:
--------------------------------------------------------------------------------
1 | 1-topshiriq
2 | #oson
3 | Butun sonlardan foydalanib beshta misol yozing
4 | - masalan: hozirgi_yil=2020
5 |
6 | 2-topshiriq
7 | #oson
8 | Haqiyqiy sonlardan foydalanib 5 ta misol yozing
9 | masalan: tana_harorati=36.6
10 |
11 | 3-topshiriq
12 | #oson
13 | 2 ni 42 – darajasini hisoblaydigan dastur tuzing
14 |
15 | 4-topshiriq
16 | #qiyin
17 | Foydalanuvchilardan ikkita butun son so’rab ularni EKUBini topadigan dastur tuzing
18 | masalan: 12 20 —> 4
19 |
20 | 5-topshiriq
21 | #juda_qiyin
22 | Foydalanuvchidan haqiqiy son so’rab uni ilmiy ko’rinishga o’tkazib chiqaradigan dastur tuzing.
23 | Masalan: 120000—>1.2*10^5
24 |
--------------------------------------------------------------------------------
/5-dars. Shartli operatorlar/README.md:
--------------------------------------------------------------------------------
1 | 1-topshiriq
2 | #oson
3 | Standart input orqali olingan son toq yoki juft ekanligini ekranga chiqaring.
4 | Misollar:
5 | Input: 3
6 | Natija: 3 - toq son
7 |
8 | Input: 18
9 | Natija: 18 - juft son
10 |
11 | 2-topshiriq
12 | #oson
13 | Standar input orqali son qabul qiling, agar bu son 3ga qoldiqsiz bo'linsa ekranga "Fiz", 5ga qoldiqsiz bo'linsa "Biz", ham 5ga ham 3ga qoldiqsiz bo'linsa "FizBiz" ni ekranga chiqaring.
14 | Agar son hech qaysi shartni bajarmasa sonni o'zini ekranga chiqaring.
15 |
16 | Misollar:
17 | Input: 3
18 | Natija: Fiz
19 |
20 | Input: 10
21 | Natija: Biz
22 |
23 | Input: 15
24 | Natija: FizBiz
25 |
26 | Input: 17
27 | Natija: 17
28 |
29 | 3-topshiriq
30 | #qiyin
31 | ax^2 + bx + c = 0 kvadrat tenglama nechta yechimga ega ekanligini hisoblaydigan dastur yozing.
32 | a, b va c o'zgaruvchilarini standart input orqali qabul qiling.
33 |
34 | Misollar
35 | Input: a = 1, b = 4, c = 4
36 | Natija: "Tenglama 1ta yechimga ega"
37 |
38 | Input: a = 2, b = 2, c = 4
39 | Natija: "Tenglama 0ta yechimga ega"
40 |
41 | Input: a = 1, b = 6, c = 8
42 | Natija: "Tenglama 2ta yechimga ega"
43 |
--------------------------------------------------------------------------------
/6-dars. List va Tuple/README.md:
--------------------------------------------------------------------------------
1 | 1-topshiriq
2 | #oson
3 | Standart input orqali olingan son toq yoki juft ekanligini ekranga chiqaring.
4 | Misollar:
5 | Input: 3
6 | Natija: 3 - toq son
7 |
8 | Input: 18
9 | Natija: 18 - juft son
10 |
11 | 2-topshiriq
12 | #qiyin
13 | Standart kiruvchi ma'lumotdagi vergul bilan ajratilgan so'zlar ketma-ketligini teskari tartibda chiqaradigan dastur tuzing
14 | Masalan: Ismlar: john, alice, bob
15 | Natija: bob, alice, john
16 |
17 | words = input("Vergul bilan ajratib so'zlar kiriting: ").split(sep=",")
18 | # davomini o'zingiz yozing!
19 |
20 |
21 | 3-topshiriq
22 | #qiyin
23 | Standart kiruvchi ma'lumotdagi vergul bilan ajratilgan so'zlar ketma-ketligini alifbo tartibida chiqaradigan dastur tuzing
24 | Masalan: Ismlar: john, alice, bob
25 | Natija: alice, bob, john
26 |
27 | words = input("Vergul bilan ajratib so'zlar kiriting: ").split(sep=",")
28 | # davomini o'zingiz yozing!
29 |
30 |
31 | 4-topshiriq
32 | #qiyin
33 | Standart kiruvchi ma'lumotdagi vergullar bilan ajratilgan so'zlar ketma-ketligi orasida maqsad qilingan so'z aynan qaysi indeksda turganligini aniqlovchi dastur tuzing
34 | Masalan: - Ismlar: john, alice, bob
35 | Maqsad: bob
36 | Natija: 2
37 |
38 | words = input("Vergul bilan ajratib so'zlar kiriting: ").split(sep=",")
39 | # davomini o'zingiz yozing!
40 |
41 | 5-topshiriq
42 | #juda_qiyin
43 | Standart kiruvchi ma'lumotdagi vergul bilan ajratilgan so'zlar ketma-ketligida maqsad qilingan so'z necha marta takrorlanganligini aniqlovchi dastur tuzing
44 | Masalan: - Ismlar: alice, john, bob, alice, bob, john, alice
45 | - Maqsad: alice
46 | - Natija: 3
47 |
48 | words = input("Vergul bilan ajratib so'zlar kiriting: ").split(sep=",")
49 | # davomini o'zingiz yozing!
50 |
51 |
52 |
--------------------------------------------------------------------------------
/7-dars. Dictionary va Set/README.md:
--------------------------------------------------------------------------------
1 | 1-topshiriq
2 | #oson
3 | Standart input orqali vergul bilan ajratilgan sonlarni o'qing va u yerda nechta son qatnashganini ekranga chiqaring (takrorlanishlar inobatga olinmasin).
4 |
5 | Misollar:
6 | Input: 2,3,3,4
7 | Natija: 3
8 |
9 | Input: 1,1,1,1,1
10 | Natija: 1
11 |
12 | Input: 1,2,3
13 | Natija: 3
14 |
15 | 2-topshiriq
16 | #qiyin
17 | Standart kiruvchi ma'lumot sifatida ikkita so'zni o'qib olib, ularning anagram (bitta so'zni ikkinchisidan ajratib olish mumkin) ekanligini tekshiruvchi dastur tuzing. Havola: https://leetcode.com/problems/valid-anagram/
18 | Masalan:
19 | Kiruvchi ma'lumot: anagram gramana
20 | Natija: True
21 | Kiruvchi ma'lumot: rat cat
22 | Natija: False
23 |
--------------------------------------------------------------------------------
/8-dars. Funksiyalar/README.md:
--------------------------------------------------------------------------------
1 | 1-topshiriq
2 | #oson
3 | Salom deydigan greeting nomli funksiya tuzing va unga docstring yozing.
4 |
5 |
6 | 2-topshiriq
7 | #oson
8 | Argument sifatida ismni o’qib olib, natija sifatida o’sha ismga salom deydigan funktsiya tuzing.
9 |
10 | 3-topshiriq
11 | #oson
12 | Standart kirituvchi ma’lumot sifatida ismlarni o’qib olib, ularning ichidan eng uzunini chiqaruvchi dastur tuzing
13 |
14 | 4-topshiriq
15 | #qiyin
16 | Standart kirituvchi ma’lumot sifatida ismlarni o’qib olib, ularning ichidan eng kaltasini chiqaruvchi dastur tuzing
17 |
18 | 5-topshiriq
19 | #qiyin
20 | Parametr sifatida ismni o’qib olib, uni teskari tartibda chiqarib beradigan funksiya tuzing.
21 |
22 | 6-topshiriq
23 | #juda_qiyin
24 | Standart kiruvchi ma’lumot sifatida ismni o’qib olib, uni rekursiv funksiya yordamida teskari tartibda qaytaruvchi dastur tuzing
25 |
--------------------------------------------------------------------------------
/9-dars. Takrorlanuvchi operatorlar/README.md:
--------------------------------------------------------------------------------
1 | 1-topshiriq
2 | #oson
3 | 1 - 100 oraliqdagi natural sonlardan 7 ga karrali sonlarning kvadratlarini ekranga chiqaring.
4 |
5 | 2-topshiriq
6 | #qiyin
7 | 2 dan 9 gacha bo’lgan sonlarning karra jadvalini ekranga chiqaruvchi dastur tuzing
8 |
9 | 3-topshiriq
10 | #qiyin
11 | Quyidagi havoladagi Fizz Buzz misolini ishlang: https://leetcode.com/problems/fizz-buzz/
12 |
13 | 4-topshiriq
14 | #qiyin
15 | Standart kiruvchi ma’lumotdan sonlarni o’qib olib, ushbu sonlarning raqamlarini teskari tartibda chiqaruvchi dastur tuzing. Masalan:
16 | Sonlar: 102 346 5897
17 | Natija: 201 643 7985
18 |
--------------------------------------------------------------------------------
/Kirish/README.md:
--------------------------------------------------------------------------------
1 | Task 1
2 |
3 | Python dasturlash muhitini ko'chirib oling hamda o'rnating.
4 |
5 |
6 | Task 2
7 |
8 | Hello World ! dasturini tuzing
9 |
10 | Task 3
11 |
12 | VSCode o'rnating
13 |
14 | Task 4
15 |
16 | VSCode da Hello world ! dasturini tuzing
17 |
--------------------------------------------------------------------------------
/O'zgaruvchilar/README.md:
--------------------------------------------------------------------------------
1 | 1-topshiriq
2 | #oson
3 | a va b nomli o'zgaruvchisini e'lon qiling (istalgan integer qiymati bilan). Ularning yig'indisini ekranga chiqaring.
4 |
5 | 2-topshiriq
6 | #oson
7 | a, b va c nomli o'zgaruvchisini e'lon qiling (istalgan integer qiymati bilan). Ularning o'rta arifmetigini ekranga chiqaring va o'rta arifmetik qanday hisoblangaligi haqida komment yozing.
8 |
9 | 3-topshiriq
10 | #qiyin
11 | birth_year nomli o'zgaruvchi e'lon qiling va uning qiymatiga tug'ilgan yilingizni kiriting, current_year nomli o'zgaruvchi e'lon qiling va uning qiymatiga hozirgi yilni kiriting. Yoshingiz nechidaligini hisoblab, natijani ekranga chiqaring.
12 |
13 | 4-topshiriq
14 | #juda_qiyin
15 | a va b nomli o'zgaruvchisini e'lon qiling (istalgan integer qiymati bilan). a ning qiymatini b ga, b ning qiymanitni a ga o'zgartiradigan kod yozing. (qo'shimcha o'zgaruvchi ishlatish mumkin emas)
16 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Python-course
--------------------------------------------------------------------------------
/background.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/muslimbek77/Python-course/21297c27636f3adabffb2199769e223c936ccae6/background.jpg
--------------------------------------------------------------------------------
/cat.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/muslimbek77/Python-course/21297c27636f3adabffb2199769e223c936ccae6/cat.jpg
--------------------------------------------------------------------------------
/dars.txt:
--------------------------------------------------------------------------------
1 | Ertaga Shanba
2 | Bugun Juma
--------------------------------------------------------------------------------
/pishak.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/muslimbek77/Python-course/21297c27636f3adabffb2199769e223c936ccae6/pishak.png
--------------------------------------------------------------------------------
/pupil.db:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/muslimbek77/Python-course/21297c27636f3adabffb2199769e223c936ccae6/pupil.db
--------------------------------------------------------------------------------
/sqlite.db:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/muslimbek77/Python-course/21297c27636f3adabffb2199769e223c936ccae6/sqlite.db
--------------------------------------------------------------------------------
/string/README.md:
--------------------------------------------------------------------------------
1 | 1-topshiriq
2 | #oson
3 | Standart kiritish ma’lumoti sifatida ismingizni so’rab, siz bilan salomlashadigan dastur tuzing;
4 | -Satrlarni birlashtirishdan foydalaning
5 | - Satr formatlaridan foydalaning
6 |
7 | 2-topshiriq
8 | #qiyin
9 | Dasturingizni yangilang: kiritilgan ma'lumotni birinchi belgisini katta harf ko'rinishida qolganlarini kichik harf ko'rinishida qoladigan bo'lsin va dasturingiz familyangiz bilan ham ishlay oladimi?
10 |
--------------------------------------------------------------------------------
/telegram-bot/1-dars/1-dars.py:
--------------------------------------------------------------------------------
1 | import asyncio
2 | import logging
3 | import sys
4 | from aiogram import Bot, Dispatcher
5 | from aiogram.enums import ParseMode
6 | from aiogram.filters import CommandStart
7 | from aiogram.types import Message
8 | from aiogram import F
9 |
10 | TOKEN = "6841416417:AAEGzxAPm0JHbr48dwYKy_Vw9C28coSeXYk"
11 | dp = Dispatcher()
12 |
13 | @dp.message(F.text)
14 | async def start_handler(message: Message):
15 | user = message.from_user.full_name
16 | await message.answer(text=f"{user} siz tekst yubordingiz")
17 |
18 | @dp.message(F.dice)
19 | async def send_dice(message:Message):
20 | user = message.from_user.full_name
21 | dice = message.dice.emoji
22 | await message.answer(text=f"{user} siz {dice} emoji yubordingiz")
23 |
24 | #vazifa(video,photo,contact,game,poll,location,sticker,animation,document,mp3)
25 |
26 | async def main() -> None:
27 | bot = Bot(TOKEN, parse_mode=ParseMode.HTML)
28 | await dp.start_polling(bot)
29 |
30 |
31 | if __name__ == "__main__":
32 | logging.basicConfig(level=logging.INFO, stream=sys.stdout)
33 | asyncio.run(main())
34 |
35 |
36 |
37 | # import requests
38 |
39 | # response = requests.get("https://api.telegram.org/bot6841416417:AAEGzxAPm0JHbr48dwYKy_Vw9C28coSeXYk/getMe")
40 |
41 | # if response.status_code==200:
42 | # print(response.content.decode())
43 |
44 | # message = input("xabar kiriting: ")
45 |
46 | # url = f"https://api.telegram.org/bot6841416417:AAEGzxAPm0JHbr48dwYKy_Vw9C28coSeXYk/sendMessage?chat_id=-1002022943392&text={message}"
47 |
48 |
49 | # requests.get(url)
50 |
51 | # #rasm yuborish
52 | # # API_KEY = "------"
53 | # # chat_id = 999588837
54 | # # photo = "https://www.linearity.io/blog/content/images/2023/06/how-to-create-a-car-NewBlogCover.png"
55 | # # url = f"https://api.telegram.org/bot{API_KEY}/sendPhoto?chat_id={chat_id}&photo={photo}"
56 | # # requests.get(url)
57 |
58 |
--------------------------------------------------------------------------------
/telegram-bot/1-dars/__pycache__/bir.cpython-310.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/muslimbek77/Python-course/21297c27636f3adabffb2199769e223c936ccae6/telegram-bot/1-dars/__pycache__/bir.cpython-310.pyc
--------------------------------------------------------------------------------
/telegram-bot/1-dars/bir.py:
--------------------------------------------------------------------------------
1 |
2 |
3 | # def hello():
4 | # print("hello")
5 |
6 | # print(__name__)
7 |
8 | # if __name__== "__main__":
9 | # print(5)
10 | # print("salom")
11 | # hello()
--------------------------------------------------------------------------------
/telegram-bot/1-dars/cat.py:
--------------------------------------------------------------------------------
1 | import requests
2 | url = "https://cataas.com/cat"
3 |
4 |
5 | def get_cat_image():
6 | return url
--------------------------------------------------------------------------------
/telegram-bot/1-dars/ikki.py:
--------------------------------------------------------------------------------
1 | # import bir
2 |
3 |
4 | # bir.hello()
--------------------------------------------------------------------------------
/telegram-bot/10-dars/__pycache__/inlinebutton.cpython-310.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/muslimbek77/Python-course/21297c27636f3adabffb2199769e223c936ccae6/telegram-bot/10-dars/__pycache__/inlinebutton.cpython-310.pyc
--------------------------------------------------------------------------------
/telegram-bot/10-dars/bot.py:
--------------------------------------------------------------------------------
1 | import asyncio
2 | import logging
3 | import sys
4 | from aiogram import Bot, Dispatcher
5 | from aiogram.enums import ParseMode
6 | from aiogram.filters import CommandStart,Command
7 | from aiogram import F
8 | from aiogram.types import Message,CallbackQuery
9 | from aiogram.fsm.context import FSMContext
10 | from inlinebutton import inline_menu,course_button #new
11 | from aiogram.types import ReplyKeyboardRemove
12 |
13 | ADMIN = 999588837 # Bu yerga id kiriting
14 |
15 | TOKEN = "6962596717:AAH6EuGxYtxyAidzaVqS1WGezffgktFfvQg" #Token kiriting
16 | dp = Dispatcher()
17 | bot = Bot(TOKEN, parse_mode=ParseMode.HTML)
18 |
19 | #new
20 | @dp.message(F.text=="/menu")
21 | async def my_menu(message:Message):
22 | photo = "https://i.pinimg.com/736x/e5/94/02/e594028fbe30b388e76a49d4d19523a5.jpg"
23 | # await message.answer(text="Asosiy menu",reply_markup=inline_menu)
24 | await message.answer_photo(photo=photo,caption="Sifat o'quv markazi",reply_markup=inline_menu)
25 |
26 | @dp.message(F.text=="Frontend")
27 | async def frontend_course(message:Message):
28 | await message.answer("Frontend kurslarimiz,.....",reply_markup=inline_menu)
29 |
30 | # @dp.message(F.location)
31 | # async def my_location(message:Message):
32 | # latitude = message.location.latitude
33 | # longitude = message.location.longitude
34 | # text = f"latitude={latitude},longitude={longitude}"
35 | # await message.answer(text)
36 |
37 | @dp.callback_query(F.data=="address")
38 | async def my_address(callback:CallbackQuery):
39 | await callback.answer("Sifat Manzil")
40 | latitude=40.102467
41 | longitude=65.373444
42 | await callback.message.answer("Sifat o'quv markazi manzili")
43 | await callback.message.answer_location(latitude=latitude,longitude=longitude)
44 |
45 | @dp.callback_query(F.data=="course")
46 | async def me_course(callback:CallbackQuery):
47 |
48 | await callback.message.answer(text = "Sifat o'quv kurslari, Kurslardan birini tanlang",reply_markup=course_button)
49 |
50 |
51 | async def main() -> None:
52 | bot = Bot(TOKEN, parse_mode=ParseMode.HTML)
53 | await dp.start_polling(bot)
54 |
55 |
56 | if __name__ == "__main__":
57 | logging.basicConfig(level=logging.INFO, stream=sys.stdout)
58 | asyncio.run(main())
--------------------------------------------------------------------------------
/telegram-bot/10-dars/inlinebutton.py:
--------------------------------------------------------------------------------
1 | from aiogram.types import InlineKeyboardMarkup,InlineKeyboardButton,KeyboardButton,ReplyKeyboardMarkup,ReplyKeyboardRemove
2 |
3 |
4 | #1-usul
5 | inline_menu = InlineKeyboardMarkup(
6 | inline_keyboard=[
7 | [InlineKeyboardButton(text="Sifat o'quv kurslari",callback_data='course')],
8 |
9 | [InlineKeyboardButton(text="Bizning manzil",callback_data='address'),
10 | InlineKeyboardButton(text="Biz haqimizda",callback_data='about')
11 | ],
12 | [
13 | InlineKeyboardButton(text="Admin bilan bog'lanish",callback_data="admin")
14 | ]
15 | ]
16 | )
17 |
18 | course_button = ReplyKeyboardMarkup(
19 | keyboard=[
20 | [
21 | KeyboardButton(text="Frontend"),
22 | KeyboardButton(text="Backend"),
23 |
24 | ],
25 |
26 | ],
27 | resize_keyboard=True,
28 | input_field_placeholder="Tugmalardan birini tanlang"
29 | )
30 |
31 |
--------------------------------------------------------------------------------
/telegram-bot/11-dars/__pycache__/inlinebutton.cpython-310.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/muslimbek77/Python-course/21297c27636f3adabffb2199769e223c936ccae6/telegram-bot/11-dars/__pycache__/inlinebutton.cpython-310.pyc
--------------------------------------------------------------------------------
/telegram-bot/11-dars/__pycache__/keyboard_button.cpython-310.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/muslimbek77/Python-course/21297c27636f3adabffb2199769e223c936ccae6/telegram-bot/11-dars/__pycache__/keyboard_button.cpython-310.pyc
--------------------------------------------------------------------------------
/telegram-bot/11-dars/bot.py:
--------------------------------------------------------------------------------
1 | import asyncio
2 | import logging
3 | import sys
4 | from aiogram import Bot, Dispatcher
5 | from aiogram.enums import ParseMode
6 | from aiogram.filters import CommandStart,Command
7 | from aiogram import F
8 | from aiogram.types import Message,CallbackQuery
9 | from aiogram.fsm.context import FSMContext
10 | from inlinebutton import inline_menu,course_button,ortga_button #new
11 | from aiogram.types import ReplyKeyboardRemove,input_file
12 | from keyboard_button import main_menu_button #new
13 | from aiogram.types import FSInputFile
14 | ADMIN = 999588837 # Bu yerga id kiriting
15 |
16 | TOKEN = "6962596717:AAH6EuGxYtxyAidzaVqS1WGezffgktFfvQg" #Token kiriting
17 | dp = Dispatcher()
18 | bot = Bot(TOKEN, parse_mode=ParseMode.HTML)
19 |
20 | @dp.message(CommandStart())
21 | async def start_bot(message:Message):
22 | # await message.answer_video(video = FSInputFile("video.mp4"))
23 | await message.answer("Bizning botimizga hush kelibsiz!",reply_markup=main_menu_button)
24 |
25 | #new
26 | @dp.message(F.text=="Menu")
27 | async def my_menu(message:Message):
28 | photo = "https://i.pinimg.com/736x/e5/94/02/e594028fbe30b388e76a49d4d19523a5.jpg"
29 | # await message.answer(text="Asosiy menu",reply_markup=inline_menu)
30 | await message.answer_photo(photo=photo,caption="Sifat o'quv markazi",reply_markup=inline_menu)
31 |
32 | #ortga qaytarish
33 | @dp.callback_query(F.data=="back")
34 | async def ortga_funksiyasi(callback:CallbackQuery):
35 | photo = "https://i.pinimg.com/736x/e5/94/02/e594028fbe30b388e76a49d4d19523a5.jpg"
36 |
37 | await callback.message.answer_photo(photo=photo,caption="Sifat o'quv markazi",reply_markup=inline_menu)
38 | await callback.message.delete()
39 |
40 |
41 |
42 | @dp.callback_query(F.data=="address")
43 | async def my_address(callback:CallbackQuery):
44 | await callback.answer("Sifat Manzil")
45 | latitude=40.102467
46 | longitude=65.373444
47 | await callback.message.answer("Sifat o'quv markazi manzili")
48 | await callback.message.answer_location(latitude=latitude,longitude=longitude)
49 |
50 | @dp.callback_query(F.data=="course")
51 | async def me_course(callback:CallbackQuery):
52 |
53 | await callback.message.edit_caption(caption = "Sifat o'quv kurslari, Kurslardan birini tanlang",reply_markup=course_button.as_markup())
54 |
55 | @dp.callback_query(F.data=="frontend")
56 | async def frontend_course(callback:CallbackQuery):
57 | frontend_photo = "https://s.dou.ua/storage-files/how-to-front-end.jpg"
58 | await callback.message.answer_photo(photo=frontend_photo,caption="Frontend haqida ma'lumot",reply_markup=ortga_button.as_markup())
59 | await callback.message.delete()
60 |
61 |
62 |
63 |
64 | async def main() -> None:
65 | bot = Bot(TOKEN, parse_mode=ParseMode.HTML)
66 | await dp.start_polling(bot)
67 |
68 |
69 | if __name__ == "__main__":
70 | logging.basicConfig(level=logging.INFO, stream=sys.stdout)
71 | asyncio.run(main())
--------------------------------------------------------------------------------
/telegram-bot/11-dars/inlinebutton.py:
--------------------------------------------------------------------------------
1 | from aiogram.types import InlineKeyboardMarkup,InlineKeyboardButton
2 | from aiogram.utils.keyboard import InlineKeyboardBuilder
3 |
4 | #1-usul
5 | inline_menu = InlineKeyboardMarkup(
6 | inline_keyboard=[
7 | [InlineKeyboardButton(text="Sifat o'quv kurslari",callback_data='course')],
8 |
9 | [InlineKeyboardButton(text="Bizning manzil",callback_data='address'),
10 | InlineKeyboardButton(text="Biz haqimizda",callback_data='about')
11 | ],
12 | [
13 | InlineKeyboardButton(text="Admin bilan bog'lanish",callback_data="admin")
14 | ]
15 | ]
16 | )
17 |
18 | # 2-usul
19 |
20 | course_button = InlineKeyboardBuilder()
21 | course_button.add(InlineKeyboardButton(text="🖼 Frontend",callback_data="frontend"))
22 | course_button.add(InlineKeyboardButton(text="💻 Backend",callback_data="backend"))
23 | course_button.add(InlineKeyboardButton(text="Online kurslarimiz",url="https://www.youtube.com/watch?v=kqtD5dpn9C8"))
24 | course_button.add(InlineKeyboardButton(text="🔙 ortga",callback_data="back"))
25 | course_button.adjust(2)
26 |
27 | #3-usul
28 | ortga_button = InlineKeyboardBuilder()
29 | ortga_button.row(InlineKeyboardButton(text="🔙 ortga",callback_data="course"))
30 |
--------------------------------------------------------------------------------
/telegram-bot/11-dars/keyboard_button.py:
--------------------------------------------------------------------------------
1 | from aiogram.types import ReplyKeyboardMarkup, KeyboardButton
2 |
3 | main_menu_button = ReplyKeyboardMarkup(
4 | keyboard=[
5 | [KeyboardButton(text="Menu")],
6 | ],
7 | resize_keyboard=True,
8 | input_field_placeholder="Asosiy menu"
9 | )
10 |
--------------------------------------------------------------------------------
/telegram-bot/12-dars/__pycache__/my_insta.cpython-310.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/muslimbek77/Python-course/21297c27636f3adabffb2199769e223c936ccae6/telegram-bot/12-dars/__pycache__/my_insta.cpython-310.pyc
--------------------------------------------------------------------------------
/telegram-bot/12-dars/__pycache__/my_yutube.cpython-310.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/muslimbek77/Python-course/21297c27636f3adabffb2199769e223c936ccae6/telegram-bot/12-dars/__pycache__/my_yutube.cpython-310.pyc
--------------------------------------------------------------------------------
/telegram-bot/12-dars/bot.py:
--------------------------------------------------------------------------------
1 | import asyncio
2 | import logging
3 | import sys
4 | from aiogram import Bot, Dispatcher
5 | from aiogram.enums import ParseMode
6 | from aiogram.filters import CommandStart,Command
7 | from aiogram.types import Message,FSInputFile
8 | from aiogram import F
9 | from my_yutube import yutube_save
10 | from my_insta import insta_save
11 |
12 |
13 | TOKEN = "6962596717:AAH6EuGxYtxyAidzaVqS1WGezffgktFfvQg"
14 | dp = Dispatcher()
15 |
16 | @dp.message(CommandStart())
17 | async def command_start_handler(message: Message) -> None:
18 | await message.answer(f"Salom, Botimiz sizga youtubdan video olib beradi.\nBotdan foydalanish uchun link yuboring")
19 |
20 |
21 | @dp.message(F.text.contains("www.youtube.com"))
22 | async def yutube_download(message:Message):
23 | result = yutube_save(message.text)
24 | video = FSInputFile(result)
25 | await message.answer_video(video=video,caption="@uz12345_bot")
26 | # await message.answer("siz yutube link yubordingiz")
27 |
28 | @dp.message(F.text.contains("instagram"))
29 | async def instagram_download(message:Message):
30 | result = insta_save(message.text)
31 | # photo = FSInputFile(result)
32 | await message.answer_photo(photo=result,caption="@uz12345_bot")
33 | # await message.answer("siz yutube link yubordingiz")
34 |
35 | @dp.message()
36 | async def other_thins(message:Message):
37 | await message.answer("Youtube link yuboring")
38 |
39 | async def main() -> None:
40 |
41 | bot = Bot(TOKEN, parse_mode=ParseMode.HTML)
42 | await dp.start_polling(bot)
43 |
44 |
45 | if __name__ == "__main__":
46 | logging.basicConfig(level=logging.INFO, stream=sys.stdout)
47 | asyncio.run(main())
--------------------------------------------------------------------------------
/telegram-bot/12-dars/my_insta.py:
--------------------------------------------------------------------------------
1 | import requests
2 |
3 | def insta_save(link):
4 | url = "https://instagram-post-and-reels-downloader.p.rapidapi.com/insta/"
5 |
6 | querystring = {"url":link}
7 |
8 | headers = {
9 | "X-RapidAPI-Key": "90de015fedmsh6cb4b8ec8899b66p10b5c6jsn95e5205d74bc",
10 | "X-RapidAPI-Host": "instagram-post-and-reels-downloader.p.rapidapi.com"
11 | }
12 |
13 | response = requests.get(url, headers=headers, params=querystring)
14 |
15 | return response.json()["detail"]["data"]["items"][0]["pictureUrl"]
16 |
17 | # print(insta_save("https://www.instagram.com/p/CxTG997oaH1/"))
--------------------------------------------------------------------------------
/telegram-bot/12-dars/my_yutube.py:
--------------------------------------------------------------------------------
1 | import pytube
2 |
3 | def yutube_save(link):
4 | yt = pytube.YouTube(link)
5 | print(yt.streams)
6 | stream = yt.streams.first()
7 | stream.download(filename="video.mp4")
8 | return stream.get_file_path(filename="video.mp4")
9 |
--------------------------------------------------------------------------------
/telegram-bot/13-dars/__pycache__/insta.cpython-310.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/muslimbek77/Python-course/21297c27636f3adabffb2199769e223c936ccae6/telegram-bot/13-dars/__pycache__/insta.cpython-310.pyc
--------------------------------------------------------------------------------
/telegram-bot/13-dars/bot.py:
--------------------------------------------------------------------------------
1 | import asyncio
2 | import logging
3 | import sys
4 | from aiogram import Bot, Dispatcher
5 | from aiogram.enums import ParseMode
6 | from aiogram.filters import CommandStart,Command
7 | from aiogram.types import Message,FSInputFile
8 | from aiogram import F
9 | from insta import insta_save
10 |
11 |
12 | TOKEN = "6962596717:AAH6EuGxYtxyAidzaVqS1WGezffgktFfvQg"
13 | dp = Dispatcher()
14 |
15 | @dp.message(CommandStart())
16 | async def command_start_handler(message: Message) -> None:
17 | await message.answer(f"Salom, Botimiz sizga instagramdan video olib beradi.\nBotdan foydalanish uchun link yuboring")
18 |
19 |
20 |
21 | @dp.message(F.text.contains("instagram"))
22 | async def instagram_download(message:Message):
23 | link = message.text
24 | result = insta_save(link)
25 | if result[0]=="video":
26 | await message.answer_video(video=result[1])
27 | elif result[0]=="rasm":
28 | await message.answer_photo(photo=result[1])
29 | else:
30 | await message.answer("Notog'ri link yubordingiz")
31 |
32 | async def main() -> None:
33 |
34 | bot = Bot(TOKEN, parse_mode=ParseMode.HTML)
35 | await dp.start_polling(bot)
36 |
37 |
38 | if __name__ == "__main__":
39 | logging.basicConfig(level=logging.INFO, stream=sys.stdout)
40 | asyncio.run(main())
--------------------------------------------------------------------------------
/telegram-bot/13-dars/insta.py:
--------------------------------------------------------------------------------
1 | import requests
2 | from pprint import pprint
3 | url = "https://instagram-media-downloader.p.rapidapi.com/rapid/post_v2.php"
4 |
5 | def insta_save(link):
6 |
7 | querystring = {"url":link}
8 |
9 | headers = {
10 | "X-RapidAPI-Key": "90de015fedmsh6cb4b8ec8899b66p10b5c6jsn95e5205d74bc",
11 | "X-RapidAPI-Host": "instagram-media-downloader.p.rapidapi.com"
12 | }
13 |
14 | response = requests.get(url, headers=headers, params=querystring)
15 |
16 | try:
17 | result = ("video",response.json()["items"][0]["video_versions"][0]["url"])
18 | except:
19 | result = ("rasm",response.json()["items"][0]["image_versions2"]["candidates"][0]["url"])
20 |
21 | return result
22 |
23 |
24 | # insta_save("https://www.instagram.com/p/CboPHrYIFti/?utm_source=ig_web_copy_link&igsh=MzRlODBiNWFlZA==")
--------------------------------------------------------------------------------
/telegram-bot/13-dars/tik_tok.py:
--------------------------------------------------------------------------------
1 | import requests
2 |
3 | url = "https://tiktok-download-video1.p.rapidapi.com/getVideo"
4 |
5 | querystring = {"url":"https://www.tiktok.com/@tiktok/video/7106658991907802411","hd":"1"}
6 |
7 | headers = {
8 | "X-RapidAPI-Key": "90de015fedmsh6cb4b8ec8899b66p10b5c6jsn95e5205d74bc",
9 | "X-RapidAPI-Host": "tiktok-download-video1.p.rapidapi.com"
10 | }
11 |
12 | response = requests.get(url, headers=headers, params=querystring)
13 |
14 | print(response.json())
--------------------------------------------------------------------------------
/telegram-bot/14-dars/__pycache__/insta.cpython-310.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/muslimbek77/Python-course/21297c27636f3adabffb2199769e223c936ccae6/telegram-bot/14-dars/__pycache__/insta.cpython-310.pyc
--------------------------------------------------------------------------------
/telegram-bot/14-dars/__pycache__/tik_tok.cpython-310.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/muslimbek77/Python-course/21297c27636f3adabffb2199769e223c936ccae6/telegram-bot/14-dars/__pycache__/tik_tok.cpython-310.pyc
--------------------------------------------------------------------------------
/telegram-bot/14-dars/bot.py:
--------------------------------------------------------------------------------
1 | import asyncio
2 | import logging
3 | import sys
4 | from aiogram import Bot, Dispatcher
5 | from aiogram.enums import ParseMode
6 | from aiogram.filters import CommandStart,Command
7 | from aiogram.types import Message,FSInputFile,InputMediaPhoto
8 | from aiogram import F
9 | from tik_tok import tiktok_save
10 |
11 |
12 | TOKEN = "6962596717:AAH6EuGxYtxyAidzaVqS1WGezffgktFfvQg"
13 | dp = Dispatcher()
14 |
15 | @dp.message(CommandStart())
16 | async def command_start_handler(message: Message) -> None:
17 | await message.answer(f"Salom, Botimiz sizga youtubdan video olib beradi.\nBotdan foydalanish uchun link yuboring")
18 |
19 |
20 |
21 | @dp.message(F.text.contains("tiktok"))
22 | async def tiktok_download(message:Message):
23 | link = message.text
24 | tiktok = tiktok_save(link)
25 | video = tiktok.get("video")
26 | music = tiktok.get("music")
27 | rasmlar = tiktok.get("images")
28 |
29 | if rasmlar:
30 | #1-usul
31 | # for i,rasm in enumerate(rasmlar):
32 | # await message.answer_photo(photo=rasm,caption=f"{i+1}-rasm")
33 |
34 | #2-usul
35 | rasm = []
36 | for i,r in enumerate(rasmlar):
37 | rasm.append(InputMediaPhoto(media=r))
38 | if (i+1)%10==0:
39 | await message.answer_media_group(rasm)
40 | rasm=[]
41 | if rasm:
42 | await message.answer_media_group(rasm)
43 | elif video:
44 | await message.answer_video(video=video,caption="Bizning bot")
45 | if music:
46 | await message.answer_audio(audio=music)
47 |
48 |
49 |
50 |
51 |
52 |
53 | async def main() -> None:
54 |
55 | bot = Bot(TOKEN, parse_mode=ParseMode.HTML)
56 | await dp.start_polling(bot)
57 |
58 |
59 | if __name__ == "__main__":
60 | logging.basicConfig(level=logging.INFO, stream=sys.stdout)
61 | asyncio.run(main())
--------------------------------------------------------------------------------
/telegram-bot/14-dars/tik_tok.py:
--------------------------------------------------------------------------------
1 | import requests
2 | from pprint import pprint
3 | url = "https://tiktok-download-video1.p.rapidapi.com/getVideo"
4 |
5 | def tiktok_save(link):
6 | querystring = {"url":link,"hd":"1"}
7 |
8 | headers = {
9 | "X-RapidAPI-Key": "90de015fedmsh6cb4b8ec8899b66p10b5c6jsn95e5205d74bc",
10 | "X-RapidAPI-Host": "tiktok-download-video1.p.rapidapi.com"
11 | }
12 |
13 | response = requests.get(url, headers=headers, params=querystring)
14 | data = {}
15 | try:
16 | data["music"] = response.json()["data"]["music"]
17 | except:
18 | pass
19 | try:
20 | data["video"] = response.json()["data"]["hdplay"]
21 | except:
22 | pass
23 | try:
24 | data["images"] = response.json()["data"]["images"]
25 | except:
26 | pass
27 |
28 | return data
29 |
30 |
--------------------------------------------------------------------------------
/telegram-bot/15-dars/add_data.py:
--------------------------------------------------------------------------------
1 | import sqlite3
2 |
3 | connection = sqlite3.connect("pupil.db")
4 |
5 | command = """
6 | INSERT INTO pupils('first_name','last_name','email','class','age')
7 | VALUES('Maqsud', 'Quvondiqov','maqsud@mail.ru', '7-class', '13'),('Shuxrat',"Hamidov",'shuhrathamidov007@gmail.com','10-sinf',16);
8 |
9 | """
10 |
11 | cursor = connection.cursor()
12 |
13 | cursor.execute(command)
14 |
15 | connection.commit()
--------------------------------------------------------------------------------
/telegram-bot/15-dars/create.py:
--------------------------------------------------------------------------------
1 | import sqlite3
2 |
3 | connection = sqlite3.connect("pupil.db")
4 |
5 | command = """
6 | CREATE TABLE IF NOT EXISTS pupils (
7 | first_name TEXT,
8 | last_name TEXT,
9 | email TEXT unique,
10 | class TEXT,
11 | age NUMBER
12 | );
13 | """
14 | cursor = connection.cursor()
15 |
16 | cursor.execute(command)
17 |
18 | connection.commit()
--------------------------------------------------------------------------------
/telegram-bot/15-dars/delete.py:
--------------------------------------------------------------------------------
1 | import sqlite3
2 |
3 | connection = sqlite3.connect("pupil.db")
4 |
5 | command = """
6 | DELETE FROM pupils WHERE first_name = 'Sardor';
7 | """
8 |
9 | cursor = connection.cursor()
10 |
11 | cursor.execute(command)
12 |
13 | connection.commit()
--------------------------------------------------------------------------------
/telegram-bot/15-dars/read.py:
--------------------------------------------------------------------------------
1 | import sqlite3
2 |
3 | connection = sqlite3.connect("pupil.db")
4 |
5 | command = """
6 | SELECT * from pupils ORDER BY age;
7 | """
8 |
9 | cursor = connection.cursor()
10 |
11 | cursor.execute(command)
12 |
13 | pupils = cursor.fetchall()
14 |
15 | # print(pupils)
16 |
17 | command = """
18 | SELECT DISTINCT class from pupils ;
19 | """
20 | cursor.execute(command)
21 |
22 | sinflar = cursor.fetchall()
23 |
24 | # print(f"Bizda o'yiyotkan o'quvchilar sinflari:{sinflar}")
25 |
26 | #eng yosh o'quvchilar
27 |
28 | command = """
29 | SELECT *, MIN(age) from pupils;
30 | """
31 | cursor.execute(command)
32 | eng_yosh_oquvchi = cursor.fetchall()
33 | print(eng_yosh_oquvchi)
34 |
35 |
36 |
--------------------------------------------------------------------------------
/telegram-bot/15-dars/update.py:
--------------------------------------------------------------------------------
1 | import sqlite3
2 |
3 | connection = sqlite3.connect("pupil.db")
4 |
5 | command = """
6 | UPDATE pupils SET first_name = 'Sardor', last_name = 'Tuxtapulatov',age='14' WHERE last_name='Turobov';
7 | """
8 |
9 | cursor = connection.cursor()
10 |
11 | cursor.execute(command)
12 |
13 | connection.commit()
--------------------------------------------------------------------------------
/telegram-bot/16-dars/__pycache__/states.cpython-310.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/muslimbek77/Python-course/21297c27636f3adabffb2199769e223c936ccae6/telegram-bot/16-dars/__pycache__/states.cpython-310.pyc
--------------------------------------------------------------------------------
/telegram-bot/16-dars/bot.py:
--------------------------------------------------------------------------------
1 | import asyncio
2 | import logging
3 | import sys
4 | from aiogram import Bot, Dispatcher,types
5 | from aiogram.enums import ParseMode
6 | from aiogram.filters import CommandStart,Command
7 | from aiogram import F
8 | from aiogram.types import Message
9 | from aiogram.fsm.context import FSMContext
10 | from states import Form
11 | import sqlite3
12 |
13 | #regular expression uchun
14 | import re # yangi qo'shildi e'tibor bering
15 |
16 |
17 | ADMIN = 999588837 # Bu yerga id kiriting
18 | TOKEN = "6841416417:AAEGzxAPm0JHbr48dwYKy_Vw9C28coSeXYk" #Token kiriting
19 | dp = Dispatcher()
20 | bot = Bot(TOKEN, parse_mode=ParseMode.HTML)
21 |
22 | @dp.message(CommandStart())
23 | async def command_start_handler(message: Message,state:FSMContext) -> None:
24 | await state.set_state(Form.first_name)
25 | full_name = message.from_user.full_name
26 | text = f"Assalomu alaykum,{full_name} Sifat botiga hush kelibsiz\nRo'yhatdan o'tish uchun ismingizni kiriting!"
27 | await message.reply(text=text)
28 |
29 | @dp.message(Form.first_name,F.text)
30 | async def get_first_name(message:Message,state:FSMContext):
31 |
32 | first_name = message.text
33 | await state.update_data(first_name=first_name)
34 |
35 | await state.set_state(Form.last_name)
36 | text = f"Familyangizni kiriting!"
37 | await message.reply(text=text)
38 |
39 | @dp.message(Form.last_name, F.text)
40 | async def get_last_name(message:Message,state:FSMContext):
41 |
42 | last_name = message.text
43 | await state.update_data(last_name=last_name)
44 |
45 | await state.set_state(Form.photo)
46 | text = f"Rasmingizni yuboring!"
47 | await message.reply(text=text)
48 |
49 |
50 | #rasm uchun dispacher handler state
51 | @dp.message(Form.photo,F.photo)
52 | async def get_photo(message:Message,state:FSMContext):
53 |
54 | photo = message.photo[-1].file_id #rasmni file id sini saqlab olamiz
55 | await state.update_data(photo=photo)
56 | await state.set_state(Form.phone_number)
57 | text = f"Telefon nomeringizni kiriting!"
58 | await message.reply(text=text)
59 |
60 | #rasmdan boshqa narsa yuborilsa javob qaytaramiz
61 | @dp.message(Form.photo)
62 | async def not_get_photo(message:Message,state:FSMContext):
63 | text = f"Iltimos rasm yuboring!"
64 | await message.reply(text=text)
65 |
66 |
67 | #telefon nomer uchun
68 | @dp.message(Form.phone_number)
69 | async def get_phone_number(message:Message,state:FSMContext):
70 | pattern = "^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$"
71 | #shart beramiz
72 | #telefon nomer to'g'ri kiritilgan bo'lsa ishlaydi
73 | if re.match(pattern,message.text):
74 |
75 | phone_number = message.text
76 | await state.update_data(phone_number=phone_number)
77 |
78 | await state.set_state(Form.home_number)
79 | text = f"Uy raqamingizni kiriting!"
80 | await message.reply(text=text)
81 | #aks holda esa telefon nomerni to'g'ri kiritishini so'raymiz.
82 | else:
83 | await message.reply(text="telefon nomeringizni noto'g'ri kiritdingiz")
84 |
85 | #Vazifa [photo,kurs_nomi,email....... va hokazo] 15 tacha filterdan foydalanib ro'yhatdan o'tish uchun, kiritilishi kerak bo'lgan ma'lumotlarga state tuzib kelasilar.
86 | #photo va telefon raqam to'g'ri kiritilganligini tekshirib keyin o'tkazuvchi stateni qilib ko'rsataman.
87 |
88 | @dp.message(Form.home_number,F.text)
89 | async def home_number_get(message:Message,state:FSMContext):
90 | number = message.text
91 | if number.isdigit():
92 | await state.update_data(home_number=number)
93 |
94 | await state.set_state(Form.address)
95 | text = f"Manzilingizni kiriting!"
96 | await message.reply(text=text)
97 | else:
98 | await message.reply("Noto'g'ri")
99 |
100 | @dp.message(Form.home_number)
101 | async def not_hom_number(message:Message,state:FSMContext):
102 | await message.reply("Text ko'rinishida ma'lumot kiriting")
103 |
104 |
105 |
106 | @dp.message(Form.address)
107 | async def get_address(message:Message,state:FSMContext):
108 |
109 | address = message.text
110 | await state.update_data(address=address)
111 |
112 | data = await state.get_data()
113 |
114 | my_photo = data.get("photo") #rasmni qabul qilib olish
115 | first_name = data.get("first_name")
116 | last_name = data.get("last_name")
117 | phone_number = data.get("phone_number")
118 | address = data.get("address")
119 | telegram_id = message.from_user.id
120 | try:
121 | connection = sqlite3.connect("sqlite.db")
122 | cursor = connection.cursor()
123 | command = f"""
124 | INSERT INTO USERS('first_name','last_name','phone_number','telegram_id')
125 | VALUES('{first_name}','{last_name}','{phone_number}','{telegram_id}');
126 | """
127 | cursor.execute(command)
128 | connection.commit()
129 | except:
130 | pass
131 |
132 | text = f"Ariza\nIsmi: {first_name}\nFamilyasi: {last_name}\nTel: {phone_number}\nManzil: {address}"
133 |
134 | #adminga ariza ma'lumotlarini yuboramiz
135 |
136 | await bot.send_photo(ADMIN,photo=my_photo,caption=text)
137 | # print(first_name,last_name,phone_number,address)
138 |
139 | await state.clear()
140 | text = f"Siz muvaffaqiyatli tarzda ro'yhatdan o'tdingiz🎉"
141 | await message.reply(text=text)
142 |
143 |
144 | async def main() -> None:
145 | bot = Bot(TOKEN, parse_mode=ParseMode.HTML)
146 | await dp.start_polling(bot)
147 |
148 |
149 | if __name__ == "__main__":
150 | logging.basicConfig(level=logging.INFO, stream=sys.stdout)
151 | asyncio.run(main())
--------------------------------------------------------------------------------
/telegram-bot/16-dars/create.py:
--------------------------------------------------------------------------------
1 | import sqlite3
2 |
3 | connection = sqlite3.connect("sqlite.db")
4 |
5 | cursor = connection.cursor()
6 |
7 | #photo,address,username
8 | command = """
9 | CREATE TABLE IF NOT EXISTS USERS(
10 | first_name TEXT,
11 | last_name TEXT,
12 | phone_number TEXT,
13 | telegram_id NUMBER unique
14 | );
15 | """
16 |
17 | cursor.execute(command)
18 |
19 | connection.commit()
--------------------------------------------------------------------------------
/telegram-bot/16-dars/states.py:
--------------------------------------------------------------------------------
1 | from aiogram.fsm.state import State, StatesGroup
2 |
3 | class Form(StatesGroup):
4 | first_name = State()
5 | last_name = State()
6 | phone_number = State()
7 | address = State()
8 | photo = State() #yangi qo'shildi
9 | home_number = State()
10 |
--------------------------------------------------------------------------------
/telegram-bot/17-dars/__pycache__/states.cpython-310.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/muslimbek77/Python-course/21297c27636f3adabffb2199769e223c936ccae6/telegram-bot/17-dars/__pycache__/states.cpython-310.pyc
--------------------------------------------------------------------------------
/telegram-bot/17-dars/bot.py:
--------------------------------------------------------------------------------
1 | import asyncio
2 | import logging
3 | import sys
4 | from aiogram import Bot, Dispatcher,types
5 | from aiogram.enums import ParseMode
6 | from aiogram.filters import CommandStart,Command
7 | from aiogram import F
8 | from aiogram.types import Message
9 | from aiogram.fsm.context import FSMContext
10 | from states import Form
11 | import sqlite3
12 |
13 | #regular expression uchun
14 | import re # yangi qo'shildi e'tibor bering
15 |
16 |
17 | ADMIN = 999588837 # Bu yerga id kiriting
18 | TOKEN = "6841416417:AAEGzxAPm0JHbr48dwYKy_Vw9C28coSeXYk" #Token kiriting
19 | dp = Dispatcher()
20 | bot = Bot(TOKEN, parse_mode=ParseMode.HTML)
21 |
22 | @dp.message(CommandStart())
23 | async def command_start_handler(message: Message,state:FSMContext) -> None:
24 | full_name = message.from_user.full_name
25 | connection = sqlite3.connect("sqlite.db")
26 | cursor = connection.cursor()
27 | command = """SELECT telegram_id FROM USERS"""
28 | cursor.execute(command)
29 | users_id = cursor.fetchall()
30 | try:
31 | users_id = [i[0] for i in users_id]
32 | except:
33 | pass
34 | if message.from_user.id in users_id:
35 | await message.reply(text="Botimizdan foydalanishingiz mumkin")
36 | else:
37 | await state.set_state(Form.first_name)
38 |
39 | text = f"Assalomu alaykum,{full_name} Sifat botiga hush kelibsiz\nRo'yhatdan o'tish uchun ismingizni kiriting!"
40 | await message.reply(text=text)
41 |
42 |
43 | #/count /allusers
44 | @dp.message(F.text=="/count")
45 | async def count_users(message:Message):
46 | connection = sqlite3.connect("sqlite.db")
47 | cursor = connection.cursor()
48 | command = """SELECT count(*) FROM USERS"""
49 | cursor.execute(command)
50 | count = cursor.fetchone()[0]
51 |
52 | await message.answer(text=f"Bizning botimizda {count}ta foydalanuvchi bor!")
53 |
54 | @dp.message(F.text=="/allusers")
55 | async def all_users(message:Message):
56 | connection = sqlite3.connect("sqlite.db")
57 | cursor = connection.cursor()
58 | command = """SELECT first_name,last_name,phone_number FROM USERS"""
59 | cursor.execute(command)
60 | users = cursor.fetchall()
61 | text ="Bizning foydalanuvchilar:\n"
62 | for index,data in enumerate(users):
63 | text += f"{index+1}. Ismi:{data[0]}\n{index+1}. Familyasi:{data[1]}\n{index+1}. Tel:{data[2]}\n\n"
64 |
65 |
66 |
67 | await message.answer(text=text)
68 |
69 |
70 |
71 | @dp.message(Form.first_name,F.text)
72 | async def get_first_name(message:Message,state:FSMContext):
73 |
74 | first_name = message.text
75 | await state.update_data(first_name=first_name)
76 |
77 | await state.set_state(Form.last_name)
78 | text = f"Familyangizni kiriting!"
79 | await message.reply(text=text)
80 |
81 | @dp.message(Form.last_name, F.text)
82 | async def get_last_name(message:Message,state:FSMContext):
83 |
84 | last_name = message.text
85 | await state.update_data(last_name=last_name)
86 |
87 | await state.set_state(Form.photo)
88 | text = f"Rasmingizni yuboring!"
89 | await message.reply(text=text)
90 |
91 |
92 | #rasm uchun dispacher handler state
93 | @dp.message(Form.photo,F.photo)
94 | async def get_photo(message:Message,state:FSMContext):
95 |
96 | photo = message.photo[-1].file_id #rasmni file id sini saqlab olamiz
97 | await state.update_data(photo=photo)
98 | await state.set_state(Form.phone_number)
99 | text = f"Telefon nomeringizni kiriting!"
100 | await message.reply(text=text)
101 |
102 | #rasmdan boshqa narsa yuborilsa javob qaytaramiz
103 | @dp.message(Form.photo)
104 | async def not_get_photo(message:Message,state:FSMContext):
105 | text = f"Iltimos rasm yuboring!"
106 | await message.reply(text=text)
107 |
108 |
109 | #telefon nomer uchun
110 | @dp.message(Form.phone_number)
111 | async def get_phone_number(message:Message,state:FSMContext):
112 | pattern = "^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$"
113 | #shart beramiz
114 | #telefon nomer to'g'ri kiritilgan bo'lsa ishlaydi
115 | if re.match(pattern,message.text):
116 |
117 | phone_number = message.text
118 | await state.update_data(phone_number=phone_number)
119 |
120 | await state.set_state(Form.home_number)
121 | text = f"Uy raqamingizni kiriting!"
122 | await message.reply(text=text)
123 | #aks holda esa telefon nomerni to'g'ri kiritishini so'raymiz.
124 | else:
125 | await message.reply(text="telefon nomeringizni noto'g'ri kiritdingiz")
126 |
127 | #Vazifa [photo,kurs_nomi,email....... va hokazo] 15 tacha filterdan foydalanib ro'yhatdan o'tish uchun, kiritilishi kerak bo'lgan ma'lumotlarga state tuzib kelasilar.
128 | #photo va telefon raqam to'g'ri kiritilganligini tekshirib keyin o'tkazuvchi stateni qilib ko'rsataman.
129 |
130 | @dp.message(Form.home_number,F.text)
131 | async def home_number_get(message:Message,state:FSMContext):
132 | number = message.text
133 | if number.isdigit():
134 | await state.update_data(home_number=number)
135 |
136 | await state.set_state(Form.address)
137 | text = f"Manzilingizni kiriting!"
138 | await message.reply(text=text)
139 | else:
140 | await message.reply("Noto'g'ri")
141 |
142 | @dp.message(Form.home_number)
143 | async def not_hom_number(message:Message,state:FSMContext):
144 | await message.reply("Text ko'rinishida ma'lumot kiriting")
145 |
146 |
147 |
148 | @dp.message(Form.address)
149 | async def get_address(message:Message,state:FSMContext):
150 |
151 | address = message.text
152 | await state.update_data(address=address)
153 |
154 | data = await state.get_data()
155 |
156 | my_photo = data.get("photo") #rasmni qabul qilib olish
157 | first_name = data.get("first_name")
158 | last_name = data.get("last_name")
159 | phone_number = data.get("phone_number")
160 | address = data.get("address")
161 | telegram_id = message.from_user.id
162 | try:
163 | connection = sqlite3.connect("sqlite.db")
164 | cursor = connection.cursor()
165 | command = f"""
166 | INSERT INTO USERS('first_name','last_name','phone_number','telegram_id')
167 | VALUES('{first_name}','{last_name}','{phone_number}','{telegram_id}');
168 | """
169 | cursor.execute(command)
170 | connection.commit()
171 | except:
172 | pass
173 |
174 | text = f"Ariza\nIsmi: {first_name}\nFamilyasi: {last_name}\nTel: {phone_number}\nManzil: {address}"
175 |
176 | #adminga ariza ma'lumotlarini yuboramiz
177 |
178 | await bot.send_photo(ADMIN,photo=my_photo,caption=text)
179 | # print(first_name,last_name,phone_number,address)
180 |
181 | await state.clear()
182 | text = f"Siz muvaffaqiyatli tarzda ro'yhatdan o'tdingiz🎉"
183 | await message.reply(text=text)
184 |
185 |
186 | async def main() -> None:
187 | bot = Bot(TOKEN, parse_mode=ParseMode.HTML)
188 | await dp.start_polling(bot)
189 |
190 |
191 | if __name__ == "__main__":
192 | logging.basicConfig(level=logging.INFO, stream=sys.stdout)
193 | asyncio.run(main())
--------------------------------------------------------------------------------
/telegram-bot/17-dars/create.py:
--------------------------------------------------------------------------------
1 | import sqlite3
2 |
3 | connection = sqlite3.connect("sqlite.db")
4 |
5 | cursor = connection.cursor()
6 |
7 | #photo,address,username
8 | command = """
9 | CREATE TABLE IF NOT EXISTS USERS(
10 | first_name TEXT,
11 | last_name TEXT,
12 | phone_number TEXT,
13 | telegram_id NUMBER unique
14 | );
15 | """
16 |
17 | cursor.execute(command)
18 |
19 | connection.commit()
--------------------------------------------------------------------------------
/telegram-bot/17-dars/states.py:
--------------------------------------------------------------------------------
1 | from aiogram.fsm.state import State, StatesGroup
2 |
3 | class Form(StatesGroup):
4 | first_name = State()
5 | last_name = State()
6 | phone_number = State()
7 | address = State()
8 | photo = State() #yangi qo'shildi
9 | home_number = State()
10 |
--------------------------------------------------------------------------------
/telegram-bot/18-dars/.env:
--------------------------------------------------------------------------------
1 | BOT_TOKEN=6161514516:AAH6BjrgxVh2w-zx3pxQIOBxPuyUMmFckpQ
2 | ADMINS=999588837,5894759301
3 |
--------------------------------------------------------------------------------
/telegram-bot/18-dars/bot.py:
--------------------------------------------------------------------------------
1 | import asyncio
2 | import logging
3 | import sys
4 | from aiogram import Bot, Dispatcher,types
5 | from aiogram.enums import ParseMode
6 | from aiogram.filters import CommandStart,Command
7 | from aiogram import F
8 | from aiogram.types import Message
9 | from data import config
10 | from filters.admin import IsBotAdminFilter
11 |
12 |
13 | ADMINS = config.ADMINS
14 | TOKEN = config.BOT_TOKEN
15 |
16 | dp = Dispatcher()
17 |
18 |
19 |
20 |
21 | @dp.message(CommandStart())
22 | async def command_start_handler(message: Message) -> None:
23 | print(message.from_user.id)
24 | await message.answer(text="Assalomu alaykum")
25 |
26 | @dp.message(F.text,IsBotAdminFilter(ADMINS))
27 | async def user_funksiyasi(message:Message):
28 | await message.answer("Tabriklaymiz siz adminsiz⭐️")
29 |
30 | @dp.message(F.text)
31 | async def admin_funksiyasi(message:Message):
32 | await message.answer("Afsuski siz admin emassiz😔")
33 |
34 |
35 | #bot ishga tushganini xabarini yuborish
36 | async def on_startup_notify(bot: Bot):
37 | for admin in ADMINS:
38 | try:
39 | await bot.send_message(chat_id=int(admin),text="Bot ishga tushdi")
40 | except Exception as err:
41 | logging.exception(err)
42 |
43 | #bot ishga tushganini xabarini yuborish
44 | async def off_startup_notify(bot: Bot):
45 | for admin in ADMINS:
46 | try:
47 | await bot.send_message(chat_id=int(admin),text="Bot ishdan to'xtadi!")
48 | except Exception as err:
49 | logging.exception(err)
50 |
51 |
52 | async def main() -> None:
53 | bot = Bot(TOKEN, parse_mode=ParseMode.HTML)
54 | await on_startup_notify(bot)
55 | await dp.start_polling(bot)
56 | await off_startup_notify(bot)
57 |
58 |
59 |
60 |
61 | if __name__ == "__main__":
62 | logging.basicConfig(level=logging.INFO, stream=sys.stdout)
63 | asyncio.run(main())
--------------------------------------------------------------------------------
/telegram-bot/18-dars/data/__pycache__/config.cpython-310.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/muslimbek77/Python-course/21297c27636f3adabffb2199769e223c936ccae6/telegram-bot/18-dars/data/__pycache__/config.cpython-310.pyc
--------------------------------------------------------------------------------
/telegram-bot/18-dars/data/config.py:
--------------------------------------------------------------------------------
1 | from environs import Env
2 |
3 | # environs kutubxonasidan foydalanish
4 | env = Env()
5 | env.read_env()
6 |
7 | # .env fayl ichidan quyidagilarni o'qiymiz
8 | BOT_TOKEN = env.str("BOT_TOKEN") # Bot Token
9 | ADMINS = env.list("ADMINS") # adminlar ro'yxati
10 | print(f"Bottoken: {BOT_TOKEN}\nAdminlar: {ADMINS}")
11 |
--------------------------------------------------------------------------------
/telegram-bot/18-dars/filters/__pycache__/admin.cpython-310.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/muslimbek77/Python-course/21297c27636f3adabffb2199769e223c936ccae6/telegram-bot/18-dars/filters/__pycache__/admin.cpython-310.pyc
--------------------------------------------------------------------------------
/telegram-bot/18-dars/filters/admin.py:
--------------------------------------------------------------------------------
1 | from aiogram.filters import BaseFilter
2 | from aiogram.types import Message
3 |
4 |
5 | class IsBotAdminFilter(BaseFilter):
6 | def __init__(self, user_ids: list):
7 | self.user_ids = user_ids
8 |
9 | async def __call__(self, message: Message):
10 | admin_ids_int = map(int,self.user_ids)
11 | return int(message.from_user.id) in admin_ids_int
--------------------------------------------------------------------------------
/telegram-bot/19-dars/main.txt:
--------------------------------------------------------------------------------
1 | Ну я вообще вот так проблему решил:
2 |
3 |
4 | from aiogram.client.session.aiohttp import AiohttpSession
5 |
6 | session = AiohttpSession(proxy='http://proxy.server:3128')
7 |
8 | bot = Bot(token=..., session=session)
--------------------------------------------------------------------------------
/telegram-bot/2-dars/2-dars.py:
--------------------------------------------------------------------------------
1 | import asyncio
2 | import logging
3 | import sys
4 | from aiogram import Bot, Dispatcher,types
5 | from aiogram.enums import ParseMode
6 | from aiogram.filters import CommandStart,Command
7 | from aiogram import F
8 | from aiogram.types import Message
9 | from cat import get_cat
10 | from design import art_image
11 |
12 | TOKEN = "6841416417:AAEGzxAPm0JHbr48dwYKy_Vw9C28coSeXYk"
13 | dp = Dispatcher()
14 |
15 | @dp.message(CommandStart())
16 | async def command_start_handler(message: Message) -> None:
17 | first_name = message.from_user.first_name
18 | last_name = message.from_user.last_name
19 | full_name = message.from_user.full_name
20 | print(message.text)
21 | await message.reply(f"Hello.{full_name}")
22 |
23 |
24 | @dp.message(F.text.contains("/cat"))
25 | async def cat_image_send(message:Message):
26 | photo = get_cat(message.text[4:])
27 | await message.answer_document(document=types.input_file.BufferedInputFile(photo,filename="cat.png"))
28 |
29 |
30 | @dp.message(Command(commands="art"))
31 | async def art_design_photo(message:Message):
32 | data = art_image()
33 | image = data.get("image")
34 | culture = data.get("culture")
35 | museum = data.get("museum")
36 | text = f"Culture:{culture}\nMuseum:{museum}"
37 | text = f"{text}"
38 | #country,dimensions,geographyType,accessionYear
39 |
40 | if image:
41 | await message.answer_photo(photo=image,caption=text,has_spoiler=True)
42 | else:
43 | await message.answer(text=text)
44 |
45 |
46 |
47 |
48 | async def main() -> None:
49 |
50 | bot = Bot(TOKEN, parse_mode=ParseMode.HTML)
51 | await dp.start_polling(bot)
52 |
53 |
54 | if __name__ == "__main__":
55 | logging.basicConfig(level=logging.INFO, stream=sys.stdout)
56 | asyncio.run(main())
--------------------------------------------------------------------------------
/telegram-bot/2-dars/__pycache__/cat.cpython-310.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/muslimbek77/Python-course/21297c27636f3adabffb2199769e223c936ccae6/telegram-bot/2-dars/__pycache__/cat.cpython-310.pyc
--------------------------------------------------------------------------------
/telegram-bot/2-dars/__pycache__/design.cpython-310.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/muslimbek77/Python-course/21297c27636f3adabffb2199769e223c936ccae6/telegram-bot/2-dars/__pycache__/design.cpython-310.pyc
--------------------------------------------------------------------------------
/telegram-bot/2-dars/cat.py:
--------------------------------------------------------------------------------
1 | import requests
2 |
3 | def get_cat(text):
4 | url = f"https://cataas.com/cat/says/{text}"
5 |
6 | return requests.get(url).content
7 |
8 |
--------------------------------------------------------------------------------
/telegram-bot/2-dars/design.py:
--------------------------------------------------------------------------------
1 | import requests
2 | import random
3 |
4 | def art_image():
5 |
6 | object_id = random.randint(100,1000)
7 |
8 | url = f"https://collectionapi.metmuseum.org/public/collection/v1/objects/{object_id}"
9 |
10 | response = requests.get(url)
11 |
12 | if response.status_code == 200:
13 | image = response.json()["primaryImage"]
14 | culture = response.json()["culture"]
15 | museum = response.json()["repository"]
16 |
17 | data = {}
18 | data["image"] = image
19 | data["culture"] = culture
20 | data["museum"] = museum
21 |
22 | return data
23 |
24 |
--------------------------------------------------------------------------------
/telegram-bot/2-dars/main.py:
--------------------------------------------------------------------------------
1 | import requests
2 |
3 | response = requests.get("https://cataas.com/cat")
4 |
5 | file = response.content
6 |
7 | with open("pishak.png","wb") as pishak:
8 | pishak.write(file)
--------------------------------------------------------------------------------
/telegram-bot/20-dars/.env:
--------------------------------------------------------------------------------
1 | BOT_TOKEN=6161514516:AAF8uMMTsiHHQcG6ynfu5jC4Kf14S4Yjkgg
2 | ADMINS=999588837
3 | CHANNELS=-1001340930902
4 |
--------------------------------------------------------------------------------
/telegram-bot/20-dars/bot.py:
--------------------------------------------------------------------------------
1 | import asyncio
2 | import logging
3 | import sys
4 | from aiogram import Bot, Dispatcher,types
5 | from aiogram.enums import ParseMode
6 | from aiogram.filters import CommandStart,Command,and_f
7 | from aiogram import F
8 | from aiogram.types import Message, ChatPermissions
9 | from data import config
10 | from filters.admin import IsBotAdminFilter
11 | from filters.check_sub_channel import IsCheckSubChannels
12 | ADMINS = config.ADMINS
13 | TOKEN = config.BOT_TOKEN
14 |
15 | dp = Dispatcher()
16 |
17 | #forward qilingan xabarlar chat id sini oladi
18 | # @dp.message(F.forward_from_chat)
19 | # async def check_channel_id(message:Message):
20 | # await message.answer(f"CHannel id: {message.forward_from_chat.id}")
21 |
22 | # @dp.message(IsCheckSubChannels())
23 | # async def is_check_sub_channel(message:Message):
24 | # await message.answer(text="Botdan foydalanishingiz mumkin")
25 |
26 | # @dp.message(F.chat.func(lambda chat: chat.type == "supergroup"))
27 | # async def test(message:Message):
28 | # text = f"""
29 | # chat type: {message.chat.type}\n
30 | # chat id: {message.chat.id}\n
31 | # chat name: {message.chat.full_name}
32 | # """
33 | # await message.answer(text=text)
34 |
35 | @dp.message(F.new_chat_member)
36 | async def new_member(message:Message):
37 | user = message.new_chat_member.get("first_name")
38 | await message.answer(f"{user} Guruhga xush kelibsiz!")
39 | await message.delete()
40 |
41 | @dp.message(F.left_chat_member)
42 | async def new_member(message:Message):
43 | # print(message.new_chat_member)
44 | user = message.left_chat_member.full_name
45 | await message.answer(f"{user} Xayr!")
46 | await message.delete()
47 |
48 | @dp.message(and_f(F.reply_to_message,F.text=="/ban"))
49 | async def ban_user(message:Message):
50 | user_id = message.reply_to_message.from_user.id
51 | await message.chat.ban_sender_chat(user_id)
52 | await message.answer(f"{message.reply_to_message.from_user.first_name} guruhdan chiqarib yuborilasiz.")
53 |
54 | @dp.message(and_f(F.reply_to_message,F.text=="/unban"))
55 | async def unban_user(message:Message):
56 | user_id = message.reply_to_message.from_user.id
57 | await message.chat.unban_sender_chat(user_id)
58 | await message.answer(f"{message.reply_to_message.from_user.first_name} guruhga qaytishingiz mumkin.")
59 |
60 | from time import time
61 | @dp.message(and_f(F.reply_to_message,F.text=="/mute"))
62 | async def mute_user(message:Message):
63 | user_id = message.reply_to_message.from_user.id
64 | permission = ChatPermissions(can_send_messages=False)
65 |
66 | until_date = int(time()) + 60 # 1minut guruhga yoza olmaydi
67 | await message.chat.restrict(user_id=user_id,permissions=permission,until_date=until_date)
68 | await message.answer(f"{message.reply_to_message.from_user.first_name} 1 minutga blocklandingiz")
69 |
70 | @dp.message(and_f(F.reply_to_message,F.text=="/unmute"))
71 | async def unmute_user(message:Message):
72 | user_id = message.reply_to_message.from_user.id
73 | permission = ChatPermissions(can_send_messages=True)
74 | await message.chat.restrict(user_id=user_id,permissions=permission)
75 | await message.answer(f"{message.reply_to_message.from_user.first_name} guruhga yoza olasiz")
76 |
77 |
78 | from time import time
79 | xaqoratli_sozlar = {"tentak","jinni"}
80 | @dp.message(and_f(F.chat.func(lambda chat: chat.type == "supergroup"),F.text ))
81 | async def tozalash(message:Message):
82 | text = message.text
83 | print(text)
84 | for soz in xaqoratli_sozlar:
85 | print(soz,text.lower().find(soz))
86 | if text.lower().find(soz)!=-1 :
87 | user_id = message.from_user.id
88 | until_date = int(time()) + 60 # 1minut guruhga yoza olmaydi
89 | permission = ChatPermissions(can_send_messages=False)
90 | await message.chat.restrict(user_id=user_id,permissions=permission,until_date=until_date)
91 | await message.answer(text=f"{message.from_user.mention_html()} guruhda so'kinganingiz uchun 1 minutga blokga tushdingiz")
92 | await message.delete()
93 | break
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 | @dp.message(CommandStart())
102 | async def command_start_handler(message: Message) -> None:
103 | print(message.from_user.id)
104 | await message.answer(text="Assalomu alaykum")
105 |
106 | @dp.message(F.text,IsBotAdminFilter(ADMINS))
107 | async def user_funksiyasi(message:Message):
108 | await message.answer("Tabriklaymiz siz adminsiz⭐️")
109 |
110 | @dp.message(F.text)
111 | async def admin_funksiyasi(message:Message):
112 | await message.answer("Afsuski siz admin emassiz😔")
113 |
114 |
115 | #bot ishga tushganini xabarini yuborish
116 | @dp.startup()
117 | async def on_startup_notify(bot: Bot):
118 | for admin in ADMINS:
119 | try:
120 | await bot.send_message(chat_id=int(admin),text="Bot ishga tushdi")
121 | except Exception as err:
122 | logging.exception(err)
123 |
124 | #bot ishga tushganini xabarini yuborish
125 | @dp.shutdown()
126 | async def off_startup_notify(bot: Bot):
127 | for admin in ADMINS:
128 | try:
129 | await bot.send_message(chat_id=int(admin),text="Bot ishdan to'xtadi!")
130 | except Exception as err:
131 | logging.exception(err)
132 |
133 |
134 | async def main() -> None:
135 | bot = Bot(TOKEN, parse_mode=ParseMode.HTML)
136 | await dp.start_polling(bot)
137 |
138 |
139 |
140 |
141 | if __name__ == "__main__":
142 | logging.basicConfig(level=logging.INFO, stream=sys.stdout)
143 | asyncio.run(main())
--------------------------------------------------------------------------------
/telegram-bot/20-dars/data/__pycache__/config.cpython-310.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/muslimbek77/Python-course/21297c27636f3adabffb2199769e223c936ccae6/telegram-bot/20-dars/data/__pycache__/config.cpython-310.pyc
--------------------------------------------------------------------------------
/telegram-bot/20-dars/data/__pycache__/config.cpython-311.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/muslimbek77/Python-course/21297c27636f3adabffb2199769e223c936ccae6/telegram-bot/20-dars/data/__pycache__/config.cpython-311.pyc
--------------------------------------------------------------------------------
/telegram-bot/20-dars/data/__pycache__/config.cpython-312.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/muslimbek77/Python-course/21297c27636f3adabffb2199769e223c936ccae6/telegram-bot/20-dars/data/__pycache__/config.cpython-312.pyc
--------------------------------------------------------------------------------
/telegram-bot/20-dars/data/config.py:
--------------------------------------------------------------------------------
1 | from environs import Env
2 |
3 | # environs kutubxonasidan foydalanish
4 | env = Env()
5 | env.read_env()
6 |
7 | # .env fayl ichidan quyidagilarni o'qiymiz
8 | BOT_TOKEN = env.str("BOT_TOKEN") # Bot Token
9 | ADMINS = list(map(int,env.list("ADMINS"))) # adminlar ro'yxati
10 | CHANNELS = list(map(int,env.list("CHANNELS")))
11 | # print(f"Bottoken: {BOT_TOKEN}\nAdminlar: {ADMINS}")
12 | # print(f"CHANNELS: {CHANNELS}")
13 |
--------------------------------------------------------------------------------
/telegram-bot/20-dars/filters/__pycache__/admin.cpython-310.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/muslimbek77/Python-course/21297c27636f3adabffb2199769e223c936ccae6/telegram-bot/20-dars/filters/__pycache__/admin.cpython-310.pyc
--------------------------------------------------------------------------------
/telegram-bot/20-dars/filters/__pycache__/admin.cpython-311.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/muslimbek77/Python-course/21297c27636f3adabffb2199769e223c936ccae6/telegram-bot/20-dars/filters/__pycache__/admin.cpython-311.pyc
--------------------------------------------------------------------------------
/telegram-bot/20-dars/filters/__pycache__/admin.cpython-312.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/muslimbek77/Python-course/21297c27636f3adabffb2199769e223c936ccae6/telegram-bot/20-dars/filters/__pycache__/admin.cpython-312.pyc
--------------------------------------------------------------------------------
/telegram-bot/20-dars/filters/__pycache__/check_sub_channel.cpython-310.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/muslimbek77/Python-course/21297c27636f3adabffb2199769e223c936ccae6/telegram-bot/20-dars/filters/__pycache__/check_sub_channel.cpython-310.pyc
--------------------------------------------------------------------------------
/telegram-bot/20-dars/filters/__pycache__/check_sub_channel.cpython-311.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/muslimbek77/Python-course/21297c27636f3adabffb2199769e223c936ccae6/telegram-bot/20-dars/filters/__pycache__/check_sub_channel.cpython-311.pyc
--------------------------------------------------------------------------------
/telegram-bot/20-dars/filters/__pycache__/check_sub_channel.cpython-312.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/muslimbek77/Python-course/21297c27636f3adabffb2199769e223c936ccae6/telegram-bot/20-dars/filters/__pycache__/check_sub_channel.cpython-312.pyc
--------------------------------------------------------------------------------
/telegram-bot/20-dars/filters/admin.py:
--------------------------------------------------------------------------------
1 | from aiogram.filters import BaseFilter
2 | from aiogram.types import Message
3 |
4 |
5 | class IsBotAdminFilter(BaseFilter):
6 | def __init__(self, user_ids: list):
7 | self.user_ids = user_ids
8 |
9 | async def __call__(self, message: Message):
10 | admin_ids_int = map(int,self.user_ids)
11 | return int(message.from_user.id) in admin_ids_int
--------------------------------------------------------------------------------
/telegram-bot/20-dars/filters/check_sub_channel.py:
--------------------------------------------------------------------------------
1 | from data.config import CHANNELS
2 | from aiogram import filters,Bot
3 | from aiogram.types import Message
4 |
5 | class IsCheckSubChannels(filters.Filter):
6 | async def __call__(self,message:Message,bot:Bot):
7 | result = await bot.get_chat_member(CHANNELS[0],message.from_user.id)
8 | if result.status in ["member","adminstrator","creator"]:
9 | return True
10 | else:
11 | ChatInviteLink = await bot.create_chat_invite_link(CHANNELS[0])
12 | await message.answer(f"{ChatInviteLink.invite_link} kanaliga azo bo'ling")
13 | return False
--------------------------------------------------------------------------------
/telegram-bot/3-dars/3-dars.py:
--------------------------------------------------------------------------------
1 | import asyncio
2 | import logging
3 | import sys
4 | from aiogram import Bot, Dispatcher,types
5 | from aiogram.enums import ParseMode
6 | from aiogram.filters import CommandStart,Command
7 | from aiogram import F
8 | from aiogram.types import Message
9 | from cat import get_cat
10 | TOKEN = "6885421621:AAFGJ-bCA0w3uSLkNIiOPZpXdQp8CxS5XdY"
11 | dp = Dispatcher()
12 |
13 | @dp.message(CommandStart())
14 | async def command_start_handler(message: Message) -> None:
15 | first_name = message.from_user.first_name
16 | last_name = message.from_user.last_name
17 | full_name = message.from_user.full_name
18 | print(message.text)
19 | await message.reply(f"Hello,{full_name}")
20 |
21 |
22 | @dp.message(F.text.contains("/cat"))
23 | async def cat_image_send(message:Message):
24 | photo = get_cat(message.text[4:])
25 | await message.answer_photo(photo=types.input_file.BufferedInputFile(photo,filename="cat.png"))
26 |
27 | # @dp.message()
28 | # async def message_txt(message:Message):
29 | # text = message.text
30 | # await message.answer(text=text)
31 |
32 | @dp.message(Command(commands="help"))
33 | async def command_help_handler(message: Message) -> None:
34 |
35 | text = "bot kamandalari\n /start-botni ishga tushirish\n /cat-rasm chiqaradi"
36 | await message.reply(text)
37 |
38 | @dp.message(F.dice)
39 | async def message_dice(message:Message):
40 |
41 | await message.answer("BU BOTGA DICE EMOJI YUBORILDI(🎲)")
42 |
43 | @dp.message(F.video)
44 | async def message_video(message:Message):
45 |
46 | await message.answer("BU BOTGA VIDEO YUBORILDI(📹)")
47 |
48 | @dp.message(F.audio)
49 | async def message_audio(message:Message):
50 |
51 | await message.answer("BU BOTGA AUDIO YUBORILDI(🎵)")
52 |
53 | @dp.message(F.photo)
54 | async def message_photo(message:Message):
55 |
56 | await message.answer("BU BOTGA RASM YUBORILDI(🖻)")
57 |
58 |
59 | @dp.message(F.location)
60 | async def message_location(message:Message):
61 |
62 | await message.answer("BU BOTGA LOKATSIYA YUBORILDI(✆)")
63 |
64 | @dp.message(F.animation)
65 | async def message_animation(message:Message):
66 |
67 | await message.answer("BU BOTGA ANIMATSIYA YUBORILDI(🐿)")
68 |
69 | @dp.message(F.document)
70 | async def message_document(message:Message):
71 |
72 | await message.answer("BU BOTGA DOCUMENT YUBORILDI(🖺)")
73 |
74 | @dp.message(F.contact)
75 | async def message_contact(message:Message):
76 |
77 | await message.answer("BU BOTGA CONTACT YUBORILDI(📞)")
78 |
79 | @dp.message(F.game)
80 | async def message_game(message:Message):
81 |
82 | await message.answer("BU BOTGA O'YIN YUBORILDI(🎮)")
83 |
84 | @dp.message(F.poll)
85 | async def message_poll(message:Message):
86 |
87 | await message.answer("BU BOTGA POLL YUBORILDI(🈪)")
88 |
89 | @dp.message(F.sticker)
90 | async def message_sticker(message:Message):
91 |
92 | await message.answer("BU BOTGA STICKER YUBORILDI(😂)")
93 |
94 | async def main() -> None:
95 |
96 | bot = Bot(TOKEN, parse_mode=ParseMode.HTML)
97 | await dp.start_polling(bot)
98 |
99 |
100 | if __name__ == "__main__":
101 | logging.basicConfig(level=logging.INFO, stream=sys.stdout)
102 | asyncio.run(main())
--------------------------------------------------------------------------------
/telegram-bot/3-dars/cat.py:
--------------------------------------------------------------------------------
1 | import requests
2 |
3 | def get_cat(text):
4 | url = f"https://cataas.com/cat/says/{text}"
5 |
6 | return requests.get(url).content
--------------------------------------------------------------------------------
/telegram-bot/4-dars vazifa/__pycache__/wiki.cpython-310.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/muslimbek77/Python-course/21297c27636f3adabffb2199769e223c936ccae6/telegram-bot/4-dars vazifa/__pycache__/wiki.cpython-310.pyc
--------------------------------------------------------------------------------
/telegram-bot/4-dars vazifa/bot.py:
--------------------------------------------------------------------------------
1 | import asyncio
2 | import logging
3 | import sys
4 | from aiogram import Bot, Dispatcher,types
5 | from aiogram.enums import ParseMode
6 | from aiogram.filters import CommandStart,Command
7 | from aiogram import F
8 | from aiogram.types import Message
9 | from aiogram.client.session.aiohttp import AiohttpSession #new
10 | from wiki import wiki_malumot
11 |
12 | session = AiohttpSession(proxy='http://proxy.server:3128') #new
13 |
14 | TOKEN = "6962596717:AAH6EuGxYtxyAidzaVqS1WGezffgktFfvQg"
15 | dp = Dispatcher()
16 |
17 | @dp.message(CommandStart())
18 | async def command_start_handler(message: Message) -> None:
19 | full_name = message.from_user.full_name
20 | text = f"Assalomu alaykum,{full_name}\n Bu bot ismingizni ma'nosini topib beradi. Isminigizni kiriting !!!"
21 | await message.reply(text=text)
22 |
23 | @dp.message(F.text)
24 | async def name(message:Message):
25 | malumot = message.text
26 | natija = wiki_malumot(malumot=malumot)
27 |
28 | await message.answer(text=natija)
29 |
30 | async def main() -> None:
31 | bot = Bot(TOKEN, parse_mode=ParseMode.HTML,session=session) #new
32 | await dp.start_polling(bot)
33 |
34 |
35 | if __name__ == "__main__":
36 | logging.basicConfig(level=logging.INFO, stream=sys.stdout)
37 | asyncio.run(main())
--------------------------------------------------------------------------------
/telegram-bot/4-dars vazifa/wiki.py:
--------------------------------------------------------------------------------
1 | #pythondagi wikipedia moduli
2 | import wikipedia
3 |
4 |
5 |
6 | def wiki_malumot(malumot):
7 | # wikipedia tilini sozlash
8 | wikipedia.set_lang("uz")
9 |
10 | try:
11 | # Wikipediadan ma'lumotni olish
12 | result = wikipedia.summary(malumot)
13 | except:
14 | #malumot topilmagan holat uchun
15 | result = "Topilmadi!😔"
16 |
17 | #ma'lumotni chop e'tish
18 | return result
19 |
--------------------------------------------------------------------------------
/telegram-bot/4-dars/bot.py:
--------------------------------------------------------------------------------
1 | import asyncio
2 | import logging
3 | import sys
4 | from aiogram import Bot, Dispatcher,types
5 | from aiogram.enums import ParseMode
6 | from aiogram.filters import CommandStart,Command
7 | from aiogram import F
8 | from aiogram.types import Message
9 |
10 | from ism_manosi import ismlar_manosi
11 |
12 | TOKEN = "6962596717:AAGws9oAuKEpz9m4zwp3K_Y7CnAJbV4_L1c"
13 | dp = Dispatcher()
14 |
15 | @dp.message(CommandStart())
16 | async def command_start_handler(message: Message) -> None:
17 | full_name = message.from_user.full_name
18 | text = f"Assalomu alaykum,{full_name}\n Bu bot ismingizni ma'nosini topib beradi. Isminigizni kiriting !!!"
19 | await message.reply(text=text)
20 |
21 | @dp.message(F.text)
22 | async def name(message:Message):
23 | ism = message.text
24 | natija = ismlar_manosi(ism=ism)
25 |
26 | await message.answer(text=natija)
27 |
28 | async def main() -> None:
29 | bot = Bot(TOKEN, parse_mode=ParseMode.HTML)
30 | await dp.start_polling(bot)
31 |
32 |
33 | if __name__ == "__main__":
34 | logging.basicConfig(level=logging.INFO, stream=sys.stdout)
35 | asyncio.run(main())
--------------------------------------------------------------------------------
/telegram-bot/4-dars/ism_manosi.py:
--------------------------------------------------------------------------------
1 | from bs4 import BeautifulSoup
2 | import requests
3 |
4 |
5 | def ismlar_manosi(ism):
6 | link = f"https://ismlar.com/uz/name/{ism}"
7 | content = requests.get(link).content
8 | soup = BeautifulSoup(content,"html5lib")
9 | if "404 Афсуски, сиз қидирган саҳифа топилмади."==soup.find("h1").text.strip():
10 | return "topilmadi"
11 | else:
12 | try:
13 | soup = soup.find("div",class_ = "p-4 rounded-2xl mb-4 space-y-4 bg-cyan-100").find("p").text
14 | except:
15 | soup = soup.find("div",class_ = "p-4 rounded-2xl mb-4 space-y-4 bg-pink-100").find("p").text
16 |
17 | return soup.strip()
18 |
19 |
20 |
--------------------------------------------------------------------------------
/telegram-bot/5-dars/__pycache__/remove_bg.cpython-310.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/muslimbek77/Python-course/21297c27636f3adabffb2199769e223c936ccae6/telegram-bot/5-dars/__pycache__/remove_bg.cpython-310.pyc
--------------------------------------------------------------------------------
/telegram-bot/5-dars/background.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/muslimbek77/Python-course/21297c27636f3adabffb2199769e223c936ccae6/telegram-bot/5-dars/background.jpg
--------------------------------------------------------------------------------
/telegram-bot/5-dars/bot.py:
--------------------------------------------------------------------------------
1 | import asyncio
2 | import logging
3 | import sys
4 | from aiogram import Bot, Dispatcher,types
5 | from aiogram.enums import ParseMode
6 | from aiogram.filters import CommandStart,Command
7 | from aiogram import F
8 | from aiogram.types import Message
9 | import io
10 | from remove_bg import removebg
11 |
12 | TOKEN = "6962596717:AAGws9oAuKEpz9m4zwp3K_Y7CnAJbV4_L1c"
13 | dp = Dispatcher()
14 | bot = Bot(TOKEN, parse_mode=ParseMode.HTML)
15 | @dp.message(CommandStart())
16 | async def command_start_handler(message: Message) -> None:
17 | full_name = message.from_user.full_name
18 | text = f"Assalomu alaykum,{full_name}\nBu bot rasm orqa fonini o'chirib beradi. Botdan foydalanish uchun rasm yuboring!!!"
19 | await message.reply(text=text)
20 |
21 |
22 |
23 | @dp.message(F.photo)
24 | async def name(message:Message):
25 | file_id = message.photo[-1].file_id
26 | file = await bot.get_file(file_id)
27 | file_path = file.file_path
28 | photos_url = f"https://api.telegram.org/file/bot{TOKEN}/{file_path}"
29 | rasm = removebg(photos_url)
30 | if rasm:
31 | await message.answer_photo(photo=types.input_file.BufferedInputFile(rasm,filename="no-remove.png"))
32 | await message.answer_document(document=types.input_file.BufferedInputFile(rasm,filename="no-remove.png"))
33 |
34 | @dp.message()
35 | async def text_message(message:Message):
36 | message.answer("Iltimos, rasm yuboring!!!")
37 |
38 | async def main() -> None:
39 | bot = Bot(TOKEN, parse_mode=ParseMode.HTML)
40 | await dp.start_polling(bot)
41 |
42 |
43 | if __name__ == "__main__":
44 | logging.basicConfig(level=logging.INFO, stream=sys.stdout)
45 | asyncio.run(main())
--------------------------------------------------------------------------------
/telegram-bot/5-dars/ferrari.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/muslimbek77/Python-course/21297c27636f3adabffb2199769e223c936ccae6/telegram-bot/5-dars/ferrari.jpg
--------------------------------------------------------------------------------
/telegram-bot/5-dars/remove_bg.py:
--------------------------------------------------------------------------------
1 | import requests
2 |
3 |
4 | def removebg(FILE_NAME):
5 | rasm=''
6 | API_KEY ='RMXXt43mVCBYYf6x9QPYMzbW'
7 |
8 |
9 | response = requests.post(
10 | 'https://api.remove.bg/v1.0/removebg',
11 | data={
12 | 'image_url': FILE_NAME,
13 | 'size': 'auto',
14 | #'bg_image_url':'image/url'
15 | },
16 | files = {
17 | #'bg_image_file':open("background.jpg","rb"),
18 | },
19 | headers={'X-Api-Key': API_KEY},
20 | )
21 | if response.status_code == requests.codes.ok:
22 |
23 | rasm = response.content
24 | else:
25 | print("Error:", response.status_code, response.text)
26 | return rasm
27 |
28 |
--------------------------------------------------------------------------------
/telegram-bot/6-dars/README.md:
--------------------------------------------------------------------------------
1 | Bu yerda 6-dars bo'lishi kerak
2 |
--------------------------------------------------------------------------------
/telegram-bot/7-dars/__pycache__/states.cpython-310.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/muslimbek77/Python-course/21297c27636f3adabffb2199769e223c936ccae6/telegram-bot/7-dars/__pycache__/states.cpython-310.pyc
--------------------------------------------------------------------------------
/telegram-bot/7-dars/__pycache__/states.cpython-312.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/muslimbek77/Python-course/21297c27636f3adabffb2199769e223c936ccae6/telegram-bot/7-dars/__pycache__/states.cpython-312.pyc
--------------------------------------------------------------------------------
/telegram-bot/7-dars/bot.py:
--------------------------------------------------------------------------------
1 | import asyncio
2 | import logging
3 | import sys
4 | from aiogram import Bot, Dispatcher,types
5 | from aiogram.enums import ParseMode
6 | from aiogram.filters import CommandStart,Command
7 | from aiogram import F
8 | from aiogram.types import Message
9 | from aiogram.fsm.context import FSMContext #new
10 | from states import Form #new
11 |
12 | #regular expression uchun
13 | import re # yangi qo'shildi e'tibor bering
14 |
15 |
16 | ADMIN = 999588837 # Bu yerga id kiriting
17 | TOKEN = "6962596717:AAH8rK6QXNil4On5IeRbp5MfCSxIXf8cmbs" #Token kiriting
18 | dp = Dispatcher()
19 | bot = Bot(TOKEN, parse_mode=ParseMode.HTML)
20 |
21 | @dp.message(CommandStart())
22 | async def command_start_handler(message: Message,state:FSMContext) -> None:
23 | await state.set_state(Form.first_name)
24 | full_name = message.from_user.full_name
25 | text = f"Assalomu alaykum,{full_name} Sifat botiga hush kelibsiz\nRo'yhatdan o'tish uchun ismingizni kiriting!"
26 | await message.reply(text=text)
27 |
28 | @dp.message(Form.first_name,F.text)
29 | async def get_first_name(message:Message,state:FSMContext):
30 |
31 | first_name = message.text
32 | await state.update_data(first_name=first_name)
33 |
34 | await state.set_state(Form.last_name)
35 | text = f"Familyangizni kiriting!"
36 | await message.reply(text=text)
37 |
38 | @dp.message(Form.last_name, F.text)
39 | async def get_last_name(message:Message,state:FSMContext):
40 |
41 | last_name = message.text
42 | await state.update_data(last_name=last_name)
43 |
44 | await state.set_state(Form.photo)
45 | text = f"Rasmingizni yuboring!"
46 | await message.reply(text=text)
47 |
48 |
49 | #rasm uchun dispacher handler state
50 | @dp.message(Form.photo,F.photo)
51 | async def get_photo(message:Message,state:FSMContext):
52 |
53 | photo = message.photo[-1].file_id #rasmni file id sini saqlab olamiz
54 | await state.update_data(photo=photo)
55 | await state.set_state(Form.phone_number)
56 | text = f"Telefon nomeringizni kiriting!"
57 | await message.reply(text=text)
58 |
59 | #rasmdan boshqa narsa yuborilsa javob qaytaramiz
60 | @dp.message(Form.photo)
61 | async def not_get_photo(message:Message,state:FSMContext):
62 | text = f"Iltimos rasm yuboring!"
63 | await message.reply(text=text)
64 |
65 |
66 | #telefon nomer uchun
67 | @dp.message(Form.phone_number)
68 | async def get_phone_number(message:Message,state:FSMContext):
69 | pattern = "^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$"
70 | #shart beramiz
71 | #telefon nomer to'g'ri kiritilgan bo'lsa ishlaydi
72 | if re.match(pattern,message.text):
73 |
74 | phone_number = message.text
75 | await state.update_data(phone_number=phone_number)
76 |
77 | await state.set_state(Form.home_number)
78 | text = f"Uy raqamingizni kiriting!"
79 | await message.reply(text=text)
80 | #aks holda esa telefon nomerni to'g'ri kiritishini so'raymiz.
81 | else:
82 | await message.reply(text="telefon nomeringizni noto'g'ri kiritdingiz")
83 |
84 | #Vazifa [photo,kurs_nomi,email....... va hokazo] 15 tacha filterdan foydalanib ro'yhatdan o'tish uchun, kiritilishi kerak bo'lgan ma'lumotlarga state tuzib kelasilar.
85 | #photo va telefon raqam to'g'ri kiritilganligini tekshirib keyin o'tkazuvchi stateni qilib ko'rsataman.
86 |
87 | @dp.message(Form.home_number,F.text)
88 | async def home_number_get(message:Message,state:FSMContext):
89 | number = message.text
90 | if number.isdigit():
91 | await state.update_data(home_number=number)
92 |
93 | await state.set_state(Form.address)
94 | text = f"Manzilingizni kiriting!"
95 | await message.reply(text=text)
96 | else:
97 | await message.reply("Noto'g'ri")
98 |
99 | @dp.message(Form.home_number)
100 | async def not_hom_number(message:Message,state:FSMContext):
101 | await message.reply("Text ko'rinishida ma'lumot kiriting")
102 |
103 |
104 |
105 | @dp.message(Form.address)
106 | async def get_address(message:Message,state:FSMContext):
107 |
108 | address = message.text
109 | await state.update_data(address=address)
110 |
111 | data = await state.get_data()
112 |
113 | my_photo = data.get("photo") #rasmni qabul qilib olish
114 | first_name = data.get("first_name")
115 | last_name = data.get("last_name")
116 | phone_number = data.get("phone_number")
117 | address = data.get("address")
118 | telegram_id = message.from_user.id
119 |
120 | text = f"Ariza\nIsmi: {first_name}\nFamilyasi: {last_name}\nTel: {phone_number}\nManzil: {address}"
121 |
122 | #adminga ariza ma'lumotlarini yuboramiz
123 |
124 | await bot.send_photo(ADMIN,photo=my_photo,caption=text)
125 | # print(first_name,last_name,phone_number,address)
126 |
127 |
128 | await state.clear()
129 | text = f"Siz muvaffaqiyatli tarzda ro'yhatdan o'tdingiz🎉"
130 | await message.reply(text=text)
131 |
132 |
133 | async def main() -> None:
134 | bot = Bot(TOKEN, parse_mode=ParseMode.HTML)
135 | await dp.start_polling(bot)
136 |
137 |
138 | if __name__ == "__main__":
139 | logging.basicConfig(level=logging.INFO, stream=sys.stdout)
140 | asyncio.run(main())
--------------------------------------------------------------------------------
/telegram-bot/7-dars/bots.py:
--------------------------------------------------------------------------------
1 | import asyncio
2 | import logging
3 | import sys
4 | from aiogram import Bot, Dispatcher,types
5 | from aiogram.enums import ParseMode
6 | from aiogram.filters import CommandStart,Command
7 | from aiogram import F
8 | from aiogram.types import Message
9 | from aiogram.fsm.context import FSMContext #new
10 | from states import Form #new
11 | import re
12 |
13 |
14 | TOKEN = "6161514516:AAFDc54ZGIIj83aqgPkH1mvAWpD-H35vaI8" #Token kiriting
15 | ADMIN = 999588837
16 | dp = Dispatcher()
17 | bot = Bot(TOKEN, parse_mode=ParseMode.HTML)
18 |
19 | @dp.message(CommandStart())
20 | async def command_start_handler(message: Message,state:FSMContext):
21 |
22 | await state.set_state(Form.first_name)
23 | await message.answer(text="Assalomu alaykum, Ro'yhatdan o'tish uchun ismingizni kiriting")
24 |
25 | @dp.message(F.text,Form.first_name)
26 | async def first_name_register(message:Message,state:FSMContext):
27 | ism = message.text
28 | await state.update_data(first_name=ism)
29 | await state.set_state(Form.last_name)
30 |
31 | await message.answer(text="Familyangizni kiriting")
32 |
33 | @dp.message(F.text,Form.last_name)
34 | async def last_name_register(message:Message,state:FSMContext):
35 | familya = message.text
36 | await state.update_data(last_name = familya)
37 | await state.set_state(Form.phone_number)
38 |
39 | await message.answer(text="Tel nomeringizni kiriting")
40 |
41 | @dp.message(F.text,Form.phone_number)
42 | async def phone_number_register(message:Message,state:FSMContext):
43 | tel = message.text
44 | pattern = re.compile("^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$")
45 | if pattern.match(tel):
46 | await state.update_data(phone_number = tel)
47 | await state.set_state(Form.address)
48 | await message.answer(text="Manzilingizni kiriting")
49 | else:
50 | await message.answer(text="Tel nomeringiz noto'g'ri, Iltimos qayta kiriting")
51 |
52 |
53 |
54 |
55 | @dp.message(F.text,Form.address)
56 | async def address_register(message:Message,state:FSMContext):
57 | manzil = message.text
58 | await state.update_data(address = manzil)
59 | data = await state.get_data()
60 | first_name = data.get("first_name")
61 | last_name = data.get("last_name")
62 | phone_number = data.get("phone_number")
63 | address = data.get("address")
64 | await state.clear()
65 |
66 | text = f"Yangi foydalanuvchi ro'yhatdan o'tdi\n\nIsmi:{first_name}\nFamilyasi:{last_name}\nTel:{phone_number}\nManzil:{address}"
67 |
68 | await message.answer(text="Siz muvafaqiyatli ro'yhatdan o'tdingiz")
69 | await bot.send_message(chat_id=ADMIN,text=text)
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 | async def main() -> None:
79 | bot = Bot(TOKEN, parse_mode=ParseMode.HTML)
80 | await dp.start_polling(bot)
81 |
82 |
83 | if __name__ == "__main__":
84 | logging.basicConfig(level=logging.INFO, stream=sys.stdout)
85 | asyncio.run(main())
--------------------------------------------------------------------------------
/telegram-bot/7-dars/reja.txt:
--------------------------------------------------------------------------------
1 | 1)/start -> Sifat telegram botiga hush kelibsiz.
2 | 2)Ro'yhatdan o'tish uchun ismingizni kiriting.
3 | 3)Familyangizni kiriting.
4 | 4)Telefon nomeringizni kiriting.
5 | 5)Manzilingizni kiriting.
--------------------------------------------------------------------------------
/telegram-bot/7-dars/states.py:
--------------------------------------------------------------------------------
1 | from aiogram.fsm.state import State, StatesGroup
2 |
3 | class Form(StatesGroup):
4 | first_name = State()
5 | last_name = State()
6 | phone_number = State()
7 | address = State()
8 | # photo = State() #yangi qo'shildi
9 | # home_number = State()
10 |
--------------------------------------------------------------------------------
/telegram-bot/8-9-dars/9-dars/__pycache__/mybuttons.cpython-310.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/muslimbek77/Python-course/21297c27636f3adabffb2199769e223c936ccae6/telegram-bot/8-9-dars/9-dars/__pycache__/mybuttons.cpython-310.pyc
--------------------------------------------------------------------------------
/telegram-bot/8-9-dars/9-dars/bot.py:
--------------------------------------------------------------------------------
1 | import asyncio
2 | import logging
3 | import sys
4 | from aiogram import Bot, Dispatcher,types
5 | from aiogram.enums import ParseMode
6 | from aiogram.filters import CommandStart,Command
7 | from aiogram import F
8 | from aiogram.types import Message,CallbackQuery
9 | from mybuttons import inline_menu,courses_menu
10 |
11 |
12 |
13 | TOKEN = "6161514516:AAH6BjrgxVh2w-zx3pxQIOBxPuyUMmFckpQ" #Token kiriting
14 | dp = Dispatcher()
15 |
16 | @dp.message(CommandStart())
17 | async def command_start_handler(message: Message) -> None:
18 | await message.answer(text="Assalomu alaykum",reply_markup=inline_menu)
19 |
20 |
21 | @dp.callback_query(F.data=="courses")
22 | async def bizning_kurslar(callback:CallbackQuery):
23 |
24 |
25 | await callback.answer("Bizning kurslar")
26 |
27 | await callback.message.answer("Bizning kurslar: ",reply_markup=courses_menu)
28 | await callback.message.delete()
29 |
30 |
31 | async def main() -> None:
32 | bot = Bot(TOKEN, parse_mode=ParseMode.HTML)
33 | await dp.start_polling(bot)
34 |
35 |
36 | if __name__ == "__main__":
37 | logging.basicConfig(level=logging.INFO, stream=sys.stdout)
38 | asyncio.run(main())
39 |
--------------------------------------------------------------------------------
/telegram-bot/8-9-dars/9-dars/mybuttons.py:
--------------------------------------------------------------------------------
1 | # from aiogram.types import ReplyKeyboardMarkup, KeyboardButton,KeyboardButtonPollType
2 | # #yangi
3 | # from aiogram.utils.keyboard import ReplyKeyboardBuilder
4 |
5 | # #button yaratish 3-usul
6 |
7 | # builder3 = ReplyKeyboardBuilder()
8 | # # Qator usuli sizga aniq qator yaratish imkonini beradi
9 | # # bir yoki bir nechta tugmalardan. Masalan, birinchi qator
10 | # # ikkita tugmadan iborat bo'ladi ...
11 | # builder3.row(
12 | # KeyboardButton(text="Manzil yuborish", request_location=True),
13 | # KeyboardButton(text="Kontakt yuborish", request_contact=True)
14 | # )
15 | # # ... ikkinchisi ...
16 | # builder3.row(KeyboardButton(
17 | # text="Viktorina yaratish",
18 | # request_poll=KeyboardButtonPollType(type="quiz"))
19 | # )
20 | # button = builder3.as_markup(resize_keyboard=True)
21 |
22 |
23 | from aiogram.types import InlineKeyboardMarkup,InlineKeyboardButton
24 | from aiogram.utils.keyboard import InlineKeyboardBuilder
25 |
26 | inline_menu = InlineKeyboardMarkup(
27 | inline_keyboard= [
28 |
29 | [InlineKeyboardButton(text="Bizning kurslar",callback_data="courses"),
30 | InlineKeyboardButton(text="Bizning manzil",callback_data="location"),],
31 |
32 | [InlineKeyboardButton(text="Biz haqimizda",callback_data="about-us"),],
33 |
34 | [InlineKeyboardButton(text="Admin bilan bog'lanish",callback_data="contact-admin"),]
35 |
36 | ]
37 | )
38 |
39 | courses_menu = InlineKeyboardMarkup(
40 | inline_keyboard= [
41 |
42 | [InlineKeyboardButton(text="Frontend",callback_data="frontend"),
43 | InlineKeyboardButton(text="Backend",callback_data="backend"),],
44 |
45 | [InlineKeyboardButton(text="Online kurslar",url="https://www.youtube.com/watch?v=D9LwKc223t4"),],
46 |
47 | ]
48 | )
49 |
50 | #ikkinchi usul
51 | # numbers = InlineKeyboardBuilder()
52 |
53 | # for number in range(1,16):
54 | # numbers.add(InlineKeyboardButton(text=f"{number}",callback_data=f"{number}"))
55 |
56 | # numbers.adjust(2)
57 |
58 | # num_inline_menu = numbers.as_markup()
--------------------------------------------------------------------------------
/telegram-bot/8-9-dars/__pycache__/ism_manosi.cpython-310.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/muslimbek77/Python-course/21297c27636f3adabffb2199769e223c936ccae6/telegram-bot/8-9-dars/__pycache__/ism_manosi.cpython-310.pyc
--------------------------------------------------------------------------------
/telegram-bot/8-9-dars/__pycache__/my_keyboards.cpython-310.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/muslimbek77/Python-course/21297c27636f3adabffb2199769e223c936ccae6/telegram-bot/8-9-dars/__pycache__/my_keyboards.cpython-310.pyc
--------------------------------------------------------------------------------
/telegram-bot/8-9-dars/bot.py:
--------------------------------------------------------------------------------
1 | import asyncio
2 | import logging
3 | import sys
4 | from aiogram import Bot, Dispatcher,types
5 | from aiogram.enums import ParseMode
6 | from aiogram.filters import CommandStart,Command
7 | from aiogram import F
8 | from aiogram.types import Message
9 | from aiogram.fsm.context import FSMContext
10 | from aiogram.types import ReplyKeyboardRemove, ReplyKeyboardMarkup, KeyboardButton
11 | from my_keyboards import menu_button,auto_keyboard,builder3,eng_uz_colors
12 | from ism_manosi import ismlar_manosi
13 |
14 | ADMIN = 999588837 # Bu yerga id kiriting
15 |
16 | TOKEN = "6841416417:AAEGzxAPm0JHbr48dwYKy_Vw9C28coSeXYk" #Token kiriting
17 | dp = Dispatcher()
18 | bot = Bot(TOKEN, parse_mode=ParseMode.HTML)
19 |
20 | @dp.message(CommandStart())
21 | async def command_start_handler(message: Message) -> None:
22 | full_name = message.from_user.full_name
23 | text = f"Assalomu alaykum,{full_name} Sifat Maktablar botiga hush kelibsiz\nBu yerda maktablar haqida ma'lumot olishingiz mumkin!"
24 | await message.answer(text=text,reply_markup=menu_button)
25 |
26 |
27 | @dp.message(F.text)
28 | async def ism_funksiyasi(message:Message):
29 | ism = message.text
30 | natija = ismlar_manosi(ism)
31 |
32 | await message.answer(text=natija)
33 |
34 |
35 | #maktab tugmasi bosilganda yuboriladigon habar
36 | @dp.message(F.text=="Maktab 🎒")
37 | async def maktab_menu(message:Message):
38 | #maktabingiz haqida ma'lumot
39 | text = """Maktab 1978- yil Zomin tumanga qarashli 39-maktab ochilgan. Maktab moslashtirilgan binoda joylashgan. Unga 130 ta 15 ta o’qituvchi maktab direktorii Nurmatov I.
40 |
41 | 1979- yil 1- sentyabrdan Yangi qurilgan binoda 200 o’quvchi 20 nafar o’qiituvchi ko’p millatli maktab bo’lib asosiy o’quvchilarni rusiyzabon o’quvchilar tashkil etilgan.
42 |
43 | Maktab direktori: Baratov Bolbek Umarovich. 1980-yildan boshlab maktab 10-yillik bo’lib maktabda 400 o’quvchi 40 nafar o’qituvchi faoliyat ko’rsatgan.
44 |
45 | Maktab direktori: Eshboev Mamat
46 |
47 | 1981- yildan boshlab maktab direktori: Tovboev Bosim 360 nafar o’quvchi 45 nafar o’qituvchi faoliyat ko’rsatgan."""
48 | #maktab rasmini olish #telegram-bot/8-9-dars/maktab.jpg
49 | photo = types.FSInputFile("telegram-bot/8-9-dars/maktab.jpg",filename="Fayozbek.jpg")
50 |
51 | #maktab haqidagi ma'lumotni yuborish
52 | await message.answer_photo(photo=photo,caption=text)
53 |
54 |
55 | @dp.message(F.text=="/tugma3")
56 | async def tugma_menu3(message:Message,state:FSMContext):
57 | await message.answer(text="3-tugma",reply_markup=builder3.as_markup(resize_keyboard=True))
58 |
59 |
60 |
61 | @dp.message(Command(commands="colors"))
62 | async def tugma_menu2(message:Message,state:FSMContext):
63 |
64 | await message.answer(text="My colors",reply_markup=auto_keyboard().as_markup(resize_keyboard=True))
65 |
66 | @dp.message(F.text)
67 | async def my_color(message:Message):
68 | text = message.text
69 | if text in eng_uz_colors.keys():
70 | result = eng_uz_colors[text]
71 | await message.answer(text=result)
72 | else:
73 | await message.answer(text="not")
74 |
75 |
76 | @dp.message(F.text)
77 | async def name(message:Message):
78 | ism = message.text
79 | natija = ismlar_manosi(ism=ism)
80 |
81 | await message.answer(text=natija)
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 | async def main() -> None:
90 | bot = Bot(TOKEN, parse_mode=ParseMode.HTML)
91 | await dp.start_polling(bot)
92 |
93 |
94 | if __name__ == "__main__":
95 | logging.basicConfig(level=logging.INFO, stream=sys.stdout)
96 | asyncio.run(main())
97 |
--------------------------------------------------------------------------------
/telegram-bot/8-9-dars/ism_manosi.py:
--------------------------------------------------------------------------------
1 | from bs4 import BeautifulSoup
2 | import requests
3 |
4 | def ismlar_manosi(ism):
5 | link = f"https://ismlar.com/uz/name/{ism}"
6 | content = requests.get(link).content
7 | soup = BeautifulSoup(content,"html5lib")
8 | try:
9 | soup = soup.find("div",class_ = "p-4 rounded-2xl mb-4 space-y-4 bg-cyan-100").find("p").text
10 | except:
11 | try:
12 | soup = soup.find("div",class_ = "p-4 rounded-2xl mb-4 space-y-4 bg-pink-100").find("p").text
13 | except:
14 | return "topilmadi"
15 | return soup.strip()
16 |
17 | natija = ismlar_manosi("Sardor")
18 | print(natija)
19 |
--------------------------------------------------------------------------------
/telegram-bot/8-9-dars/maktab.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/muslimbek77/Python-course/21297c27636f3adabffb2199769e223c936ccae6/telegram-bot/8-9-dars/maktab.jpg
--------------------------------------------------------------------------------
/telegram-bot/8-9-dars/my_keyboards.py:
--------------------------------------------------------------------------------
1 | from aiogram.types import ReplyKeyboardMarkup, KeyboardButton,KeyboardButtonPollType
2 | #yangi
3 | from aiogram.utils.keyboard import ReplyKeyboardBuilder
4 |
5 |
6 |
7 | #button yaratish 1-usul
8 | # menu_button = ReplyKeyboardMarkup(
9 | # keyboard=[
10 | # [
11 | # KeyboardButton(text="Maktab"),
12 | # #5ta maktab qo'shishilar kerak misol:1-Maktab, 4-Maktab
13 | # ],
14 |
15 |
16 | # [ #Bu tugmani bosganda o'ziz xaqizda ma'lumot chiqsin
17 | # KeyboardButton(text="Biz haqimizda👨🏻💻"),
18 |
19 | # ],
20 | # ],
21 | # resize_keyboard=True,
22 | # input_field_placeholder="Menudan birini tanlang"
23 | # )
24 |
25 | menu_button = ReplyKeyboardMarkup(
26 | keyboard=[
27 | [KeyboardButton(text="Fayozbek"),KeyboardButton(text="1"),KeyboardButton(text="1")],
28 | [KeyboardButton(text="2"),KeyboardButton(text="2")],
29 |
30 | [KeyboardButton(text="3"),KeyboardButton(text="3")],
31 |
32 |
33 | ],
34 | resize_keyboard=True,
35 | input_field_placeholder="Menudan birini tanlang"
36 | )
37 |
38 |
39 |
40 |
41 | #button yaratish 2-usul
42 | names = [
43 | "Ozodbek",
44 | "Asliddin",
45 | "Qobil",
46 | "Asilbek",
47 | "Sardor",
48 | "Boburjon",
49 | "Otabek",
50 | "Shuhrat",
51 | "Gulhayo",
52 | "Sunnat",
53 | "Maqsud",
54 | "Nurbek",
55 | "Behruz",
56 | "Sitora"
57 | ]
58 |
59 | eng_uz_colors = {
60 | "red": "qizil",
61 | "blue": "ko'k",
62 | "green": "yashil",
63 | "yellow": "sariq",
64 | "orange": "orol",
65 | "purple": "binafsha",
66 | "pink": "pushti",
67 | "brown": "jigarrang",
68 | "gray": "kulrang",
69 | "black": "qora",
70 | "white": "oq"
71 | # Add more colors as needed
72 | }
73 |
74 | def auto_keyboard():
75 | builder2 = ReplyKeyboardBuilder()
76 |
77 | for color in eng_uz_colors.keys():
78 |
79 | builder2.add(KeyboardButton(text=color))
80 |
81 | builder2.adjust(2)
82 |
83 | return builder2
84 |
85 |
86 | #button yaratish 3-usul
87 |
88 | builder3 = ReplyKeyboardBuilder()
89 | # Qator usuli sizga aniq qator yaratish imkonini beradi
90 | # bir yoki bir nechta tugmalardan. Masalan, birinchi qator
91 | # ikkita tugmadan iborat bo'ladi ...
92 | builder3.row(
93 | KeyboardButton(text="Manzil yuborish", request_location=True),
94 | KeyboardButton(text="Kontakt yuborish", request_contact=True)
95 | )
96 | # ... ikkinchisi ...
97 | builder3.row(KeyboardButton(
98 | text="Viktorina yaratish",
99 | request_poll=KeyboardButtonPollType(type="quiz"))
100 | )
101 | button3 = builder3.as_markup(resize_keyboard=True)
--------------------------------------------------------------------------------
/telegram-bot/8-9-dars/reja.txt:
--------------------------------------------------------------------------------
1 | ["Biz haqimizda","Maktab"]
--------------------------------------------------------------------------------
/telegram-bot/8-9-dars/state.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/muslimbek77/Python-course/21297c27636f3adabffb2199769e223c936ccae6/telegram-bot/8-9-dars/state.py
--------------------------------------------------------------------------------
/telegram-bot/Ansor.pptx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/muslimbek77/Python-course/21297c27636f3adabffb2199769e223c936ccae6/telegram-bot/Ansor.pptx
--------------------------------------------------------------------------------
/telegram-bot/README.md:
--------------------------------------------------------------------------------
1 | Phase 1: Foundation (Days 1-7)
2 |
3 | Python Basics
4 | Telegram Bot API
5 | aiogram3 Introduction
6 | Phase 2: Deep Dive (Days 8-15)
7 |
8 | Asynchronous Programming
9 | Routers and Handlers
10 | Middlewares
11 | Phase 3: Advanced Topics (Days 16-23)
12 |
13 | Finite State Machines (FSM)
14 | Database Integration
15 | Deployment and Monitoring
16 | Phase 4: Practice and Projects (Days 24-30)
17 |
18 | Working on Small Projects
19 | Challenging Projects
20 | Engaging with the aiogram3 Community
21 |
22 | Filtrlar
23 | 1.1 Commands, ContentType, Hashtags, User ID
24 | 1.2 Text, RegEx, States va boshqalar
25 | 1.3 Dars davomida yozilgan handlerlar
26 |
27 | Holatlar
28 | 2.1 Yangi repozitoriy
29 | 2.2 Holatlar (states)
30 | 2.3 Tugmalar (keyboards)
31 | 2.4 Xabar osti tugmalari (inline keyboards).
32 | 2.5 Matnlarni formatlash
33 |
34 | Guruh uchun bot
35 | 3.1 Guruh va shaxsiydagi xabarlar uchun filtrlar
36 | 3.2 Guruh ma'lumotlarini o'zgartirish
37 | 3.3 Moderator bot
38 |
39 | Kanallar bilan ishlash
40 | 4.1 Kanalga obunani tekshirish
41 | 4.2 Middlware
42 | 4.3 Kanalga obunani tekshirish
43 | 4.4 Bot orqali kanalga post joylash
44 |
45 | Hujjatlar va media
46 | 5.1 Fayllarni serverga yuklab olish (Download)
47 | 5.2 Rasm fonini olib tashlaydigan bot. 1-qism. Tanishuv
48 | 5.3 Rasm fonini olib tashlaydigan bot. 2-qism. Telegraph xosting
49 | 5.4 Rasm fonini olib tashlaydigan bot. 3-qism. BackgroundRemover API
50 | 5.5 Rasm yuborishning 3-yo'li (ID, URL, File)
51 | 5.6 Albom yuborish
52 | 5.7 Lokatsiya bilan ishlash. Masofa hisoblash.
53 | 5.8 Kontakt qabul qilish
54 |
55 | Inline Mode
56 | 6.1 Inline mode nima
57 | 6.2 Matn, rasm, video, keyboard qaytaramiz
58 | 6.3 Resultsni siklda qaytarish
59 |
60 | BOT ORQALI TO'LOV
61 | 7.1 KIRISH
62 | 7.2 Telegram API. sendInvoice
63 | 7.3 Provider Token
64 | 7.4 Mahsulotlar.Yetkazib berish
65 | 7.5 Invoice
66 | 7.6 Invice photo
67 | 7.7 Adminga xarid haqida xabar berish
68 |
69 | MA'LUMOTLAR OMBORI. SQLITE
70 | 8.1 SQLite. Kirish
71 | 8.2 Foydalanuvchilarni Bazaga qo'shish
72 | 8.3 Admin komandalar. Reklama yuborish.
73 | 8.4 Bazani yangilash.Test
74 |
75 | MA'LUMOTLAR OMBORI. POSTGRESQL
76 | 9.1 PostgreSQL o'rnatamiz
77 | 9.2 postgresql.py
78 | 9.3 Handlers
79 | 9.4 PyCharm Professional
80 |
81 |
82 | Matnli qo'llanma: AIOgram frameworkida yozilgan telegram botni railway.app saytiga tekinga joylash (https://telegra.ph/AIOgram-frameworkida-yozilgan-telegram-botni-railwayapp-saytiga-tekinga-joylash-12-07)
83 |
84 |
85 |
86 | https://www.geeksforgeeks.org/implementing-web-scraping-python-beautiful-soup/
87 | 1. Wikipedia bot
88 | 2. background remover bot
89 | 3. Lotin-Krill bot
90 | 4. Youtube, instagram, tik-tok downloader bot
91 | 5. Ismlar ma'nosi bot
92 | 6. weather bot
93 | 7. Guruh bilan ishlaydigon bot
94 | 8. Kanal bilan ishlaydigon bot
95 | 9. Valyuta kursi bot
96 | 10. Translate bot
97 | 11. Kalkulyator bot
98 | 12. Nakrutka bot
99 | 13. Online shop bot
100 | 14. Registration bot
101 | 15. Ismlarga rasm bot
102 | 16. Niklar bot
103 | 17. Inline botlar (@pic, @ovozqanibot)
104 | 18. video to audio bot
105 | 19. music lyrics bot
106 | 20. ttsuz bot
107 | 21. dumaloq bot
108 |
109 | 
110 | 
111 | 
112 |
113 |
114 |
--------------------------------------------------------------------------------
/telegram-bot/lesson-20.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/muslimbek77/Python-course/21297c27636f3adabffb2199769e223c936ccae6/telegram-bot/lesson-20.zip
--------------------------------------------------------------------------------
/telegram-bot/other.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/muslimbek77/Python-course/21297c27636f3adabffb2199769e223c936ccae6/telegram-bot/other.py
--------------------------------------------------------------------------------
/text.txt:
--------------------------------------------------------------------------------
1 | salom
2 |
--------------------------------------------------------------------------------
/video:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/muslimbek77/Python-course/21297c27636f3adabffb2199769e223c936ccae6/video
--------------------------------------------------------------------------------
/video.mp4:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/muslimbek77/Python-course/21297c27636f3adabffb2199769e223c936ccae6/video.mp4
--------------------------------------------------------------------------------