Skip to content

Instantly share code, notes, and snippets.

View pointofpresence's full-sized avatar
🏠
Working from home

ReSampled pointofpresence

🏠
Working from home
View GitHub Profile
@pointofpresence
pointofpresence / path_join.py
Last active April 7, 2022 07:27
Python using path join
os.path.join('/home', 'User/Desktop', 'file.txt')
# '/home/User/Desktop/file.txt'
@pointofpresence
pointofpresence / isfile_isdir.py
Last active March 31, 2024 20:14
Python: Определить, является ли путь файлом или директорией
os.path.isfile("bob.txt") # Does bob.txt exist? Is it a file, or a directory?
os.path.isdir("bob")
@pointofpresence
pointofpresence / yandex_disk_download.py
Last active April 8, 2022 11:25
Python Yandex Disk Download
import requests
from urllib.parse import urlencode
base_url = 'https://cloud-api.yandex.net/v1/disk/public/resources/download?'
public_key = 'https://yadi.sk/d/UJ8VMK2Y6bJH7A' # Сюда вписываете вашу ссылку
# Получаем загрузочную ссылку
final_url = base_url + urlencode(dict(public_key=public_key))
response = requests.get(final_url)
download_url = response.json()['href']
@pointofpresence
pointofpresence / video_frames_extractor.py
Created April 8, 2022 11:32
Python video frames extractor
import sys, glob, getopt, os
import cv2
VIDEO_FILE_EXT = ['*.mp4', '*.mov', '*.avi']
def findAllVideoFiles(directory, recursiveSearch):
videoFiles = []
for ext in VIDEO_FILE_EXT:
pattern = os.path.join(
directory,
@pointofpresence
pointofpresence / print_to_file.py
Created April 8, 2022 11:36
Python print to file
with open('out.txt', 'w') as f:
print('Filename:', filename, file=f) # Python 3.x
print >> f, 'Filename:', filename # Python 2.x
@pointofpresence
pointofpresence / multiple_exceptions.py
Last active April 8, 2022 11:39
Python Catch multiple exceptions in one line
except (IDontLikeYouException, YouAreBeingMeanException) as e:
pass
@pointofpresence
pointofpresence / audioextract.py
Last active March 31, 2024 19:01
Python extract audio from video
import moviepy.editor as mp
def extract_audio(video, audio):
my_clip = mp.VideoFileClip(video)
my_clip.audio.write_audiofile(audio)
@pointofpresence
pointofpresence / python enum.py
Last active March 31, 2024 20:11
Python: Использование Enum
from enum import Enum, auto
class Color(Enum):
RED = auto()
BLUE = auto()
GREEN = auto()
list(Color) # [<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]
@pointofpresence
pointofpresence / set_current_working_dir.py
Created April 9, 2022 12:08
Python set current working dir
import os
import sys
os.chdir(os.path.dirname(os.path.abspath(sys.argv[0])))
@pointofpresence
pointofpresence / ran_random_module.py
Created April 9, 2022 12:09
Python run random module
def run_random_module(modules):
module_name = random.choice(modules)
__import__(module_name)