from selenium import webdriver

from selenium.webdriver.common.keys import Keys
import pandas as pd
import os
import googletrans
from googletrans import Translator
from PIL import Image

def func():

try:

link = pd.read_csv('/Users/jitendersingh/Documents/test.csv', squeeze=True,usecols=["Link", "Name" , "Status", "Image 1", "Image 2"])
new = link.reset_index() # add index in new file / try to run this code when upload new file
url = link.loc[0, 'Link']
tabname = link.loc[0, 'Name']

driver = webdriver.Chrome('/Users/jitendersingh/Downloads/chromedriver')
driver.set_page_load_timeout(40)

driver.get(url)

#driver.implicitly_wait(20)
players = driver.find_element_by_class_name('DrugOverview__content___22ZBX').text
#driver.implicitly_wait(10)
#driver.find_element_by_css_selector('.styles__selector___3W00I').click()
#driver.implicitly_wait(10)
#driver.find_element_by_css_selector('.styles__lang-link___3ISYW span').click()
#driver.implicitly_wait(10)
#tabname = driver.find_element_by_class_name('DrugHeader__title-content___2ZaPo').text
#driver.implicitly_wait(10)


#tabnamee = tabname.replace("/"," ").replace(" /"," ").replace("/ "," ").replace(" / "," ")

translator = Translator(service_urls=['translate.googleapis.com'])
translate_channel = translator.translate(players, dest='hi')
final = translate_channel.text.replace(" हैं "," हैं,").replace(" या "," या, ").replace(" और "," और, ").replace(" जैसे "," जैसे, ").replace(" ("," , यानि की ( ").replace(" क्योकि क्योकि "," क्योकि ").replace(" हैं "," हैं, ").replace("-"," ")
file =open("/Users/jitendersingh/Desktop/filename.txt", "w")
file.write(final)
file.flush()
file.close
driver.quit()



import os
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = '/Users/jitendersingh/Documents/api.json'

def synthesize_ssml(ssml,
booktitle,
language_code,
voice_name,
speaking_rate
):

from google.cloud import texttospeech

client = texttospeech.TextToSpeechClient()

input_text = texttospeech.SynthesisInput(ssml=ssml)

# Note: the voice can also be specified by name.
# Names of voices can be retrieved with client.list_voices().
voice = texttospeech.VoiceSelectionParams(
language_code=language_code,
name=voice_name
)

audio_config = texttospeech.AudioConfig(
audio_encoding=texttospeech.AudioEncoding.LINEAR16,
speaking_rate = speaking_rate
)

response = client.synthesize_speech(
input=input_text, voice=voice, audio_config=audio_config
)

# The response's audio_content is binary.
with open("/Users/jitendersingh/Documents/jitenderaud/"+tabname+".wav", "wb") as out:
out.write(response.audio_content)



import json
folder_path = '/Users/jitendersingh/Desktop/'
booktitle = "filename"
filename = folder_path + booktitle + ".txt"
print(filename)
with open(filename, 'r') as f:
text = f.read()
f.close()
print(text)

Emily = synthesize_ssml(text,
booktitle,
language_code = "hi-IN",
voice_name = "hi-IN-Wavenet-A",
speaking_rate = 0
)


delete = link.drop(link.index[[0]],axis=0,inplace=True) #delete first row
save = link.to_csv('/Users/jitendersingh/Documents/test.csv') #save file but index also deletes
link2 = pd.read_csv('/Users/jitendersingh/Documents/test.csv', squeeze=True,usecols=["Link", "Name" , "Status", "Image 1", "Image 2"]) #again open file for correct index
new = link.reset_index() # correct index
save = link2.to_csv('/Users/jitendersingh/Documents/test.csv') #save file with correct index


#im = Image.open(r"/Users/jitendersingh/Documents/tik.png")
#im.show()
except:
#im = Image.open(r"/Users/jitendersingh/Documents/redtik.png")
#im.show()
link = pd.read_csv('/Users/jitendersingh/Documents/test.csv', squeeze=True,usecols=["Link", "Name" , "Status", "Image 1", "Image 2"])
new = link.reset_index() # add index in new file / try to run this code when upload new file
url = link.loc[0, 'Link']
tabname = link.loc[0, 'Name']

driver = webdriver.Chrome('/Users/jitendersingh/Downloads/chromedriver')
driver.set_page_load_timeout(40)

driver.get(url)

#driver.implicitly_wait(20)
players = driver.find_element_by_class_name('DrugOverview__content___22ZBX').text
#driver.implicitly_wait(10)
#driver.find_element_by_css_selector('.styles__selector___3W00I').click()
#driver.implicitly_wait(10)
#driver.find_element_by_css_selector('.styles__lang-link___3ISYW span').click()
#driver.implicitly_wait(10)
#tabname = driver.find_element_by_class_name('DrugHeader__title-content___2ZaPo').text
#driver.implicitly_wait(10)


#tabnamee = tabname.replace("/"," ").replace(" /"," ").replace("/ "," ").replace(" / "," ")

translator = Translator(service_urls=['translate.googleapis.com'])
translate_channel = translator.translate(players, dest='hi')
final = translate_channel.text.replace(" हैं "," हैं,").replace(" या "," या, ").replace(" और "," और, ").replace(" जैसे "," जैसे, ").replace(" ("," , यानि की ( ").replace(" क्योकि क्योकि "," क्योकि ").replace(" हैं "," हैं, ").replace("-"," ")
file =open("/Users/jitendersingh/Desktop/filename.txt", "w")
file.write(final)
file.flush()
file.close
driver.quit()



import os
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = '/Users/jitendersingh/Documents/api.json'

def synthesize_ssml(ssml,
booktitle,
language_code,
voice_name,
speaking_rate
):

from google.cloud import texttospeech

client = texttospeech.TextToSpeechClient()

input_text = texttospeech.SynthesisInput(ssml=ssml)

# Note: the voice can also be specified by name.
# Names of voices can be retrieved with client.list_voices().
voice = texttospeech.VoiceSelectionParams(
language_code=language_code,
name=voice_name
)

audio_config = texttospeech.AudioConfig(
audio_encoding=texttospeech.AudioEncoding.LINEAR16,
speaking_rate = speaking_rate
)

response = client.synthesize_speech(
input=input_text, voice=voice, audio_config=audio_config
)

# The response's audio_content is binary.
with open("/Users/jitendersingh/Documents/jitenderaud/"+tabname+".wav", "wb") as out:
out.write(response.audio_content)



import json
folder_path = '/Users/jitendersingh/Desktop/'
booktitle = "filename"
filename = folder_path + booktitle + ".txt"
print(filename)
with open(filename, 'r') as f:
text = f.read()
f.close()
print(text)

Emily = synthesize_ssml(text,
booktitle,
language_code = "hi-IN",
voice_name = "hi-IN-Wavenet-A",
speaking_rate = 0
)


delete = link.drop(link.index[[0]],axis=0,inplace=True) #delete first row
save = link.to_csv('/Users/jitendersingh/Documents/test.csv') #save file but index also deletes
link2 = pd.read_csv('/Users/jitendersingh/Documents/test.csv', squeeze=True,usecols=["Link", "Name" , "Status", "Image 1", "Image 2"]) #again open file for correct index
new = link.reset_index() # correct index
save = link2.to_csv('/Users/jitendersingh/Documents/test.csv') #save file with correct index

def func0():
try:
func()
except:
func()

def func1():
try:
func0()
except:
func0()

def func2():
try:
func1()
except:
func1()

def func10():
func2()
func2()
func2()
func2()
func2()
func2()
func2()
func2()
func2()
func2()

def func100():
func10()
func10()
func10()
func10()
func10()
func10()
func10()
func10()
func10()
func10()

# func100()
# func100()
# func100()
# func100()
# func10()
# func10()
# func10()
# func10()
# func10()
# func10()
func2()
func2()
func2()
func2()
func2()
func2()

0 comments:

Post a Comment

 
Top