Skip to content

Instantly share code, notes, and snippets.

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

Yogesh Singh yogeshsinghgit

🏠
Working from home
View GitHub Profile
@yogeshsinghgit
yogeshsinghgit / writeCSV.py
Created October 2, 2022 14:43
writing content in a csv file using python csv module
# importing library
import csv
def writeCSV(filename, columns_header, data):
with open(filename, mode='w') as csvfile: # opening file in write mode
writerObj = csv.writer(csvfile) # creating csv.writer object
writerObj.writerow(columns_header) # add columns value in csv
writerObj.writerows(data) # adding rows
@yogeshsinghgit
yogeshsinghgit / read and format.py
Created October 2, 2022 14:36
Reading and Formatting csv file contents in a table using python csv and prettytable library
# importing libraries
import csv
from prettytable import PrettyTable
def readAndFormat(filename):
with open(filename) as csvfile: # opeaning csv file in read mode
file_contents = csv.reader(csvfile) # reading file content using csv reader function
table = PrettyTable() # creating prettytable object
file_data = list(file_contents) # creating file object into a list
@yogeshsinghgit
yogeshsinghgit / readCSV.py
Created October 2, 2022 14:23
Reading CSV file
# importing library
import csv
def readCSV(filename):
with open(filename, mode = 'r') as csvfile: # opeaning a file in read mode
file_contents = csv.reader(csvfile) # read data from csv file using csv.reader function
for data in file_contents: # print the data using a for loop
print(data)
@yogeshsinghgit
yogeshsinghgit / main.py
Last active September 1, 2022 06:23
Web Scraping using Python BeautifulSoup Libraray
import requests
from bs4 import BeautifulSoup
url = "https://quotes.toscrape.com/"
page = requests.get(url)
if page.status_code == 200:
soup = BeautifulSoup(page.content, "html.parser")
@yogeshsinghgit
yogeshsinghgit / download_as_video.py
Last active June 2, 2024 13:30
Download YouTube Videos in Mp4 Format using Python Pytube module
from pytube import YouTube
def download_Video(yt):
# filter mp4 streams from object
my_streams = yt.streams.filter(file_extension='mp4',only_video=True)
for streams in my_streams:
# print itag, resolution and codec format of Mp4 streams
print(f"Video itag : {streams.itag} Resolution : {streams.resolution} VCodec : {streams.codecs[0]}")
@yogeshsinghgit
yogeshsinghgit / video_info.py
Created August 25, 2021 17:49
Get YouTube Video Information/Metadata using Python Pytube Module
# importing the module
from pytube import YouTube
# Function Takes YouTube Object as Argument.
def video_Info(yt):
print("Title : ",yt.title)
print("Total Length : ",yt.length," Seconds")
print("Total Views : ",yt.views)
print("Is Age Restricted : ",yt.age_restricted)
print("Video Rating ",round(yt.rating))