반응형
1. PDF to Audio
import pyttsx3,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
speaker.save_to_file(cleaned_text,'story.mp3') ## Saving Text In a audio file 'story.mp3'
speaker.runAndWait()
speaker.stop()
2. Eamil (첨부파일 포함) 발송
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
body = '''
Hello, Admin
I am attaching The Sales Files With This Email.
This Year We Got a Wooping 200% Profit One Our Sales.
Regards,
Team Sales
xyz.com
'''
#Sender Email addresses and password
senders_email = 'deltadelta371@gmail.com'
sender_password = 'delta@371'
reveiver_email = 'parasharabhay13@gmail.com'
#MIME Setup
message = MIMEMultipart()
message['From'] = senders_email
message['To'] = reveiver_email
message['Subject'] = 'Sales Report 2021-- Team Sales'
message.attach(MIMEText(body, 'plain'))
## File
attach_file_name = 'car-sales.csv'
attach_file = open(attach_file_name, 'rb')
payload = MIMEBase('application', 'octate-stream')
payload.set_payload((attach_file).read())
encoders.encode_base64(payload)
payload.add_header('Content-Decomposition', 'attachment', filename=attach_file_name)
message.attach(payload)
#SMTP Connection For Sending Email
session = smtplib.SMTP('smtp.gmail.com', 587) #use gmail with port
session.starttls() #enable security
session.login(senders_email, sender_password) #login with mail_id and password
text = message.as_string()
session.sendmail(senders_email, reveiver_email, text)
session.quit()
print('Mail Sent')
3. 유튜브 다운로드
from pytube import YouTube
import pytube
try:
video_url = 'https://www.youtube.com/watch?v=lTTajzrSkCw'
youtube = pytube.YouTube(video_url)
video = youtube.streams.first()
video.download('C:/Users/abhay/Desktop/')
print("Download Successfull !!")
except:
print("Something Went Wrong !!")
반응형
'개발이야기' 카테고리의 다른 글
JPA batchSize 설정 해도 N+1 쿼리가 발생 해요 (0) | 2023.02.05 |
---|---|
파이썬 코드 샘플 - 대량메일 발송 하기 (0) | 2021.11.29 |
정규식은 항상 헷갈림 (0) | 2021.02.15 |
테스트 컨테이너 ~ 굿 ! (0) | 2021.01.20 |
MockMvc Test 대신 실제 Url 호출 테스트 (서블릿 필터 테스트) (0) | 2020.09.23 |