Skip to content

Instantly share code, notes, and snippets.

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

Harendra Kumar Kanojiya harendra21

🏠
Working from home
View GitHub Profile
from tqdm import tqdm
from PIL import Image
import os
from time import sleep
def Resize_image(size, image):
if os.path.isfile(image):
try:
im = Image.open(image)
# Get Ipaddress and Hostname of Website
# importing socket library
import socket
def get_hostname_IP():
hostname = input("Please enter website address(URL):")
try:
print (f'Hostname: {hostname}')
print (f'IP: {socket.gethostbyname(hostname)}')
except socket.gaierror as error:
from selenium import webdriver
import requests as rq
import os
from bs4 import BeautifulSoup
import time
# path= E:\web scraping\chromedriver_win32\chromedriver.exe
path = input("Enter Path : ")
url = input("Enter URL : ")
# pip install psutil
import psutil
battery = psutil.sensors_battery()
plugged = battery.power_plugged
percent = battery.percent
if percent <= 30 and plugged!=True:
# pip install py-notifier
# -*- coding: utf-8 -*-
import time
from calendar import isleap
# judge the leap year
def judge_leap_year(year):
if isleap(year):
return True
else:
return False
import os
import shutil
os.chdir("E:\downloads")
#print(os.getcwd())
#check number of files in directory
files = os.listdir()
#list of extension (You can add more if you want)
extentions = {
import csv
from email.message import EmailMessage
import smtplib
def get_credentials(filepath):
with open("credentials.txt", "r") as f:
email_address = f.readline()
email_pass = f.readline()
return (email_address, email_pass)

How to convert PDF to Audio using Python

import pyttsx3
import PyPDF2
pdfreader = PyPDF2.PdfFileReader(open('story.pdf','rb'))
speaker = pyttsx3.init()
for page_num in range(pdfreader.numPages):   
    text = pdfreader.getPage(page_num).extractText()  ## extracting text from the PDF
    cleaned_text = text.strip().replace('\n',' ')  ## Removes unnecessary spaces and break lines
 print(cleaned_text) ## Print the text from PDF
# Python script to PDF to Audio
import pyttsx3
import PyPDF2
pdfreader = PyPDF2.PdfFileReader(open('story.pdf','rb'))
speaker = pyttsx3.init()
for page_num in range(pdfreader.numPages):
text = pdfreader.getPage(page_num).extractText() ## extracting text from the PDF
cleaned_text = text.strip().replace('\n',' ') ## Removes unnecessary spaces and break lines
print(cleaned_text) ## Print the text from PDF
#speaker.say(cleaned_text) ## Let The Speaker Speak The Text
import email
import python-imap
EMAIL = 'mymail@mail.com'
PASSWORD = 'password'
SERVER = 'imap.gmail.com'
# connect to the server and go to its inbox
mail = imaplib.IMAP4_SSL(SERVER)
mail.login(EMAIL, PASSWORD)