Справочник Программиста
6.29K subscribers
1.35K photos
386 videos
64 files
1.7K links
По рекламе - @it_start_programmer
Мои курсы - @courses_from_it_start_bot
Сайт - https://it-start.online/
YouTube - https://www.youtube.com/@it_start
Реклама на бирже - https://telega.in/c/programmersGuide_1

Предложить идею: @it_start_suggestion_bot
Download Telegram
#ГолосовойПомощникНаPython
Код из видео:

import pyttsx3
import speech_recognition as sr


def listen_command():
r = sr.Recognizer()
with sr.Microphone() as source:
print('Скажите команду: ')
r.pause_threshold = 1
r.adjust_for_ambient_noise(source, duration=1)
audio = r.listen(source)

try:
our_speech = r.recognize_google(audio, language='ru-RU')
print('Вы сказали: ' + our_speech)
return our_speech
except sr.UnknownValueError:
return 'Ошибка'
except sr.RequestError:
return 'Ошибка'


def do_this_message(message):
message = message.lower()
if 'привет' in message:
say_message('Привет!')
elif 'как дела' in message:
say_message('Хорошо')
elif 'пока' in message:
say_message('Пока')
exit()
else:
say_message('Команда не распознана!')


def say_message(message):
engine.say(message)
engine.runAndWait()
print(message)


engine = pyttsx3.init()
engine.setProperty('rate', 150)
engine.setProperty('volume', 1)

while True:
command = listen_command()
do_this_message(command)
👍6
#АнимацияБулевыхОперацийНаPython
Код из видео:

from manim import *


class Example(Scene):
def construct(self):
ellipse1 = Ellipse(width=4, height=5, fill_opacity=0.5, color=BLUE, stroke_width=10).move_to(LEFT)
ellipse2 = ellipse1.copy().set_color(color=RED).move_to(RIGHT)
bool_ops_text = MarkupText('<u>Example</u>').next_to(ellipse1, UP * 3)
ellipse_group = Group(bool_ops_text, ellipse1, ellipse2).move_to(LEFT * 3)
self.play(FadeIn(ellipse_group))

i = Intersection(ellipse1, ellipse2, color=GREEN, fill_opacity=0.5)
self.play(i.animate.scale(0.25).move_to(RIGHT * 5 + UP * 2.5))
intersaction_text = Text('Intersection', font_size=23).next_to(i, UP)
self.play(FadeIn(intersaction_text))

u = Union(ellipse1, ellipse2, color=ORANGE, fill_opacity=0.5)
union_text = Text('Union', font_size=23)
self.play(u.animate.scale(0.3).next_to(i, DOWN, buff=union_text.height * 3))
union_text.next_to(u, UP)
self.play(FadeIn(union_text))

e = Exclusion(ellipse1, ellipse2, color=YELLOW, fill_opacity=0.5)
exclusion_text = Text('Exclusion', font_size=23)
self.play(e.animate.scale(0.3).next_to(u, DOWN, buff=exclusion_text.height * 3.5))
exclusion_text.next_to(e, UP)
self.play(FadeIn(exclusion_text))

d = Difference(ellipse1, ellipse2, color=PINK, fill_opacity=0.5)
difference_text = Text('Difference', font_size=23)
self.play(d.animate.scale(0.3).next_to(u, LEFT, buff=difference_text.height * 3.5))
difference_text.next_to(d, UP)
self.play(FadeIn(difference_text))
#ПрячемФайлыВJpegИзображениеСПомощьюPython
Код из видео:

Прячем файл в изображение:
with open('photo.jpg', 'ab') as f, open('start.zip', 'rb') as s:
f.write(s.read())

Достаём канал:
with open('photo.jpg', 'rb') as f:
content = f.read()
offset = content.index(bytes.fromhex('FFD9'))

f.seek(offset + 2)
with open('newfile.zip', 'wb') as s:
s.write(f.read())
🎉2
#СъёмкаВидеоНаВебкамеруСПомощьюPython
Код из видео:

import cv2

cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_FPS, 24)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)

codec = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('output.avi', codec, 25.0, (1280, 720))

while True:
ret, frame = cap.read()
cv2.imshow('Web-camera', frame)
out.write(frame)

if cv2.waitKey(1) & 0xFF == ord('q'):
break

out.release()
cap.release()
cv2.destroyAllWindows()
👍2
#ДелаемКартинкуКнопкойВTkinterPython
Код из видео:

from tkinter import *
from PIL import ImageTk

root = Tk()
root.geometry('300x100')
root.resizable(False, False)
imgWatch = ImageTk.PhotoImage(file="watch.png")
btnWatch = Button(root, height=70, image=imgWatch, font='Arial 15 bold', compound=RIGHT, text='Часы')
btnWatch.pack()

root.mainloop()
👍8
#ПростаяВизуализацияДанныхНаКартеПоКоординатамСПомощьюPython
Код из видео:

import folium

m = folium.Map(location=[58.001645, 102.694781], zoom_start=12)

tooltip = ''
tooltip_2 = ''

folium.Marker([], popup='Усть-Илимск_', tooltip=tooltip).add_to(m)
folium.Marker([], popup='Братск_', tooltip=tooltip_2).add_to(m)
m.save('name.html')
👍3
#СозданиеАнимацииГрафиковPython
Код из видео:

import numpy as np
from manim import *


class Example(Scene):
def construct(self):
axes = Axes(
x_range=[-10, 10.3, 1],
y_range=[-1.5, 1.5, 1],
x_length=10,
axis_config={'color': GREEN},
x_axis_config={
'numbers_to_include': np.arange(-10, 10.01, 2),
'numbers_with_elongated_ticks': np.arange(-10, 10.01, 2)
},
tips=False
)
axes_labels = axes.get_axis_labels()
sin_graph = axes.plot(lambda x: np.sin(x), color=BLUE)
cos_graph = axes.plot(lambda x: np.cos(x), color=RED)

sin_label = axes.get_graph_label(sin_graph, '\\sin(x)', x_val=-10, direction=UP / 2)
cos_label = axes.get_graph_label(cos_graph, '\\cos(x)')

vert_line = axes.get_vertical_line(axes.i2gp(TAU, cos_graph), color=YELLOW, line_func=Line)
line_label = axes.get_graph_label(cos_graph, 'x=2\pi', x_val=TAU, direction=UR, color=WHITE)
plot = VGroup(axes, sin_graph, cos_graph, vert_line)
labels = VGroup(axes_labels, sin_label, cos_label, line_label)
self.play(Create(plot), run_time=6)
self.play(Create(labels), run_time=6)
👍9
#ОпределениеРасстоянияМеждуДвумяТочкамиНаЗемле
Код из видео:

from geopy.distance import geodesic

Moscow = (55.747592, 37.619908)

Peter = (59.925173, 30.330548)

distance_km = geodesic(Moscow, Peter).kilometers

print(f'Расстояние от Москвы до Питера составляет: {distance_km:.2f} км')
👍3
#ДелаемФотоНаВеб-камеруСПомощьюPython
Код из видео:

import cv2

cap = cv2.VideoCapture(0)

cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)

ret, frame = cap.read()
cv2.imwrite('photo.png', frame)

cap.release()