🖥 ؛Litetar یک فریمورک قدرتمند و انعطاف پذیر ASGI است که بر ایجاد API متمرکز شده است
—
Litestar offers data validation, dependency injection, ORM integration, authorization primitives, and much more that you need to get your applications up and running.
A simple example of using Litestar:
from litestar import Litestar, get
🖥 GitHub
👉 Docks
#Python_tricks
#python
🆔 @Python4all_pro
—
pip install litestar
Litestar offers data validation, dependency injection, ORM integration, authorization primitives, and much more that you need to get your applications up and running.
A simple example of using Litestar:
from litestar import Litestar, get
@get("/")
async def hello_world() -> str:
return "Hello, world!"
app = Litestar([hello_world])
🖥 GitHub
👉 Docks
#Python_tricks
#python
🆔 @Python4all_pro
👍2
این سایت با انیمیشن و به صورت بصری به شما الگوریتم هارو یاد میده و میتونید ازش برای یادگیری الگوریتم استفاده کنید.
http://www.algoanim.ide.sk/
🆔 @Python4all_pro
http://www.algoanim.ide.sk/
🆔 @Python4all_pro
algoanim.ide.sk
Algorithm Animations and Visualizations
Algoanim.ide.sk - collection of computer science algorithm animations and visualizations for teaching and learning programming.
Tornado: a web framework for asynchronous network operations
Tornado is a web framework and Python library designed to handle network operations asynchronously.
Features of Tornado:
* Non-blocking I/O processing that scales to tens of thousands of active connections.
* Independence from the WSGI standard, which makes it different from most Python web frameworks.
* Integration with the asyncio module from the Python standard library, providing the same event loop.
* Support for long polling and web sockets.
Link: https://www.tornadoweb.org/en/stable/
#library
#python
🆔 @Python4all_pro
Tornado is a web framework and Python library designed to handle network operations asynchronously.
Features of Tornado:
* Non-blocking I/O processing that scales to tens of thousands of active connections.
* Independence from the WSGI standard, which makes it different from most Python web frameworks.
* Integration with the asyncio module from the Python standard library, providing the same event loop.
* Support for long polling and web sockets.
Link: https://www.tornadoweb.org/en/stable/
#library
#python
🆔 @Python4all_pro
❤1❤🔥1😍1
Forwarded from تهران دیتا-دانشگاه تهران
شروع دوره:
جامعترین دوره پروژه محور علم داده کل کشور
15 سرفصل کاربردی با 12 نرم افزار و ابزار تخصصی
Please open Telegram to view this post
VIEW IN TELEGRAM
👍2🤷♂1
Extract MP3 from MP4 Video with FFmpeg in #Python 🎵
First, install the necessary module:
Then, use this script:
With
#code
🆔 @Python4all_pro
Easily extract audio from a video file using FFmpeg with Python!
First, install the necessary module:
pip install ffmpeg-python
Then, use this script:
import ffmpeg
# https://t.me/LearnPython3
input_file = 'input.mp4'
output_file = 'output.mp3'
# Extract audio from the video
ffmpeg.input(input_file).output(output_file, format='mp3').run()
print('Audio extracted successfully!')
With
ffmpeg-python
, you can extract high-quality audio from your video files effortlessly.#code
🆔 @Python4all_pro
👍4😍2
Run #Javascript code using #python subprocess #Library
#code
🆔 @Python4all_pro
import subprocess
js_code = """
console.log("Hello, World!");
"""
with open("script.js", "w") as file:
file.write(js_code)
result = subprocess.run(["node", "script.js"], capture_output=True, text=True)
print(result.stdout)
#code
🆔 @Python4all_pro
😍7👍1
Find system name , version processor using #python.
#code
🆔 @Python4all_pro
import platform
system_name = platform.system()
system_version = platform.version()
architecture = platform.architecture()[0]
processor = platform.processor()
print("OS:", system_name)
print("OS Version:", system_version)
print("32 or 64:", architecture)
print("Processor :", processor)
#code
🆔 @Python4all_pro
👍6
Downloading a Audio file from YouTube Video
Free Code: https://www.clcoding.com/2024/06/downloading-audio-file-from-youtube.html
#code
🆔 @Python4all_pro
Free Code: https://www.clcoding.com/2024/06/downloading-audio-file-from-youtube.html
#code
🆔 @Python4all_pro
❤3🤷♀3
Convert Image to text
#code
🆔 @Python4all_pro
import pytesseract as t
from PIL import Image
img = Image.open("photo.jpg")
text = t.image_to_string(img)
print(text)
#code
🆔 @Python4all_pro
👍5
-Location of Mobile Number Code -
#code
🆔 @Python4all_pro
import phonenumbers
from phonenumbers import (timezone,geocoder,carrier)
number = input("Enter the phone number with country code : ")
# Parsing String to the Phone number
phoneNumber = phonenumbers.parse(number)
# printing the timezone using the timezone module
timeZone = timezone.time_zones_for_number(phoneNumber)
print(f"timezone : {timeZone}")
# printing the geolocation of the given number using the geocoder module
geolocation = geocoder.description_for_number(phoneNumber,"en")
print(f"location : {geolocation}")
# printing the service provider name using the carrier module
service = carrier.name_for_number(phoneNumber,"en")
print(f"service provider : {service}")
#code
🆔 @Python4all_pro
👍11
Python Logo Source Code
#code
🆔 @Python4all_pro
import turtle
t = turtle.Turtle()
s = turtle.Screen()
s.bgcolor("black")
t.speed(10)
t.pensize(2)
t.pencolor("white")
def s_curve():
for i in range(90):
t.left(1)
t.forward(1)
def r_curve():
for i in range(90):
t.right(1)
t.forward(1)
def l_curve():
s_curve()
t.forward(80)
s_curve()
def l_curve1():
s_curve()
t.forward(90)
s_curve()
def half():
t.forward(50)
s_curve()
t.forward(90)
l_curve()
t.forward(40)
t.left(90)
t.forward(80)
t.right(90)
t.forward(10)
t.right(90)
t.forward(120) #on test
l_curve1()
t.forward(30)
t.left(90)
t.forward(50)
r_curve()
t.forward(40)
t.end_fill()
def get_pos():
t.penup()
t.forward(20)
t.right(90)
t.forward(10)
t.right(90)
t.pendown()
def eye():
t.penup()
t.right(90)
t.forward(160)
t.left(90)
t.forward(70)
t.pencolor("black")
t.dot(35)
def sec_dot():
t.left(90)
t.penup()
t.forward(310)
t.left(90)
t.forward(120)
t.pendown()
t.dot(35)
t.fillcolor("#306998")
t.begin_fill()
half()
t.end_fill()
get_pos()
t.fillcolor("#FFD43B")
t.begin_fill()
half()
t.end_fill()
eye()
sec_dot()
def pause():
t.speed(2)
for i in range(100):
t.left(90)
pause()
#code
🆔 @Python4all_pro
👍6❤4🆒1
🖥 ؛SearXNG — یک موتور فراجستجوی رایگان است که در پایتون پیاده سازی شده است
؛SearXNG — نتایج جستجو و پایگاه داده های مختلف را ترکیب می کند و داده های حساس کاربر را جمع آوری یا ردیابی نمی کند
شروع سریع با Docker :
🖥 GitHub
🟡 Docks
#library
#python
🆔 @Python4all_pro
git clone https://github.com/searxng/searxng.git searxng
cd searxng
sudo -H ./utils/searxng.sh install all
؛SearXNG — نتایج جستجو و پایگاه داده های مختلف را ترکیب می کند و داده های حساس کاربر را جمع آوری یا ردیابی نمی کند
شروع سریع با Docker :
docker run --rm \
-d -p 8080:8080 \
-v "${PWD}/searxng:/etc/searxng" \
-e "BASE_URL=http://localhost:8080/" \
-e "INSTANCE_NAME=my-instance" \
searxng/searxng
🖥 GitHub
🟡 Docks
#library
#python
🆔 @Python4all_pro
👍5❤1
Convert Animated Gif to video
#code
🆔 @Python4all_pro
from os import remove,popen
import subprocess
def sprocess(a, b="utf-8"):
p = subprocess.Popen(a,shell=True,stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
return str(p[0].decode(b)+p[1].decode(b))
vid = await message.reply_to_message.download()
print(sprocess("ffmpeg -y -i '" + vid + "' -map_metadata -1 s.mp4"))
durasi = popen("ffprobe -i '" + vid + "' -show_entries format=duration -v quiet -of csv='p=0'").read()
await message.reply_video(video="s.mp4")
remove("s.mp4")
remove(vid)
#code
🆔 @Python4all_pro
👍4
حل سوالات استخدامی سایت leetcode.com
Task: No. 16. 3Sum Closest #medium
Condition:
Given an integer array nums of length n and an integer target, find the three integers in nums whose sum is closest to the target. Returns the sum of three integers. You can assume that each input will have exactly one solution.
Solution:
Explanation:
Sort an array:
First we sort the num array. This will allow us to use two pointers to find the closest sum.
Initializing the result:
We initialize the result variable with the sum of the first three elements of the sorted array. This will be our starting closest amount.
Traversing the array:
We use a for loop to iterate through the array. For each element we use two pointers j and k:
j starts immediately after the current element i.
k starts from the end of the array.
Two pointers:
Inside the while loop, while j is less than k, we calculate the sum of the elements num[i], num[j] and num[k].
If sum equals target, then we return sum since we found an exact match.
Result update:
If the current sum sum is closer to target than the previous closest sum result, update result.
Pointer shift:
If sum is less than target, move pointer j to the right to increase the sum.
If sum is greater than target, shift pointer k to the left to decrease the sum.
Return result:
After completing all iterations, we return result, which will contain the sum of three numbers closest to target.
Time and space complexity:
Time complexity: O(n^2), where n is the length of the array. Sorting takes O(n log n) and the basic algorithm with two pointers runs in O(n^2).
Space complexity: O(1) since we only use a few additional variables, and do not use additional memory depending on the size of the input data.
#interview #LeetCode
🆔 @Python4all_pro
Task: No. 16. 3Sum Closest #medium
Condition:
Given an integer array nums of length n and an integer target, find the three integers in nums whose sum is closest to the target. Returns the sum of three integers. You can assume that each input will have exactly one solution.
Solution:
def threeSumClosest(self, num, target):
num.sort()
result = num[0] + num[1] + num[2]
for i in range(len(num) - 2):
j, k = i+1, len(num) - 1
while j < k:
sum = num[i] + num[j] + num[k]
if sum == target:
return sum
if abs(sum - target) < abs(result - target):
result = sum
if sum < target:
j += 1
elif sum > target:
k -= 1
else:
return result
return result
Explanation:
Sort an array:
First we sort the num array. This will allow us to use two pointers to find the closest sum.
Initializing the result:
We initialize the result variable with the sum of the first three elements of the sorted array. This will be our starting closest amount.
Traversing the array:
We use a for loop to iterate through the array. For each element we use two pointers j and k:
j starts immediately after the current element i.
k starts from the end of the array.
Two pointers:
Inside the while loop, while j is less than k, we calculate the sum of the elements num[i], num[j] and num[k].
If sum equals target, then we return sum since we found an exact match.
Result update:
If the current sum sum is closer to target than the previous closest sum result, update result.
Pointer shift:
If sum is less than target, move pointer j to the right to increase the sum.
If sum is greater than target, shift pointer k to the left to decrease the sum.
Return result:
After completing all iterations, we return result, which will contain the sum of three numbers closest to target.
Time and space complexity:
Time complexity: O(n^2), where n is the length of the array. Sorting takes O(n log n) and the basic algorithm with two pointers runs in O(n^2).
Space complexity: O(1) since we only use a few additional variables, and do not use additional memory depending on the size of the input data.
#interview #LeetCode
🆔 @Python4all_pro
👍3❤1