I will give a modified answer of Austin Marino, here a solution that just worked for me in a 2000 word list (would work in bigger list too).
first you need to install NordVPN and add it to the system path check this link :
https://support.nordvpn.com/Connectivity/Windows/1350897482/Connect-to-NordVPN-app-on-Windows-using-the-Command-Prompt.htm
The goal is so you can connect/disconnect and chose servers with CMD (you can do the same thing in linux) so you can cantrole theses NordVPN CMD commands through Python code.
Here is the function (please import the libraries) :
import random
listofservers = ["South Africa", "Egypt" , "Australia", "New Zealand", "South Korea", "Singapore", "Taiwan", "Vietnam", "Hong Kong", "Indonesia", "Thailand", "Japan", "Malaysia", "United Kingdom", "Netherlands", "Germany", "France", "Belgium", "Switzerland", "Sweden","Spain","Denmark", "Italy", "Norway", "Austria", "Romania", "Czech Republic", "Luxembourg", "Poland", "Finland", "Hungary", "Latvia", "Russia", "Iceland", "Bulgaria", "Croatia", "Moldova", "Portugal", "Albania", "Ireland", "Slovakia","Ukraine", "Cyprus", "Estonia", "Georgia", "Greece", "Serbia", "Slovenia", "Azerbaijan", "Bosnia and Herzegovina", "Macedonia","India", 'Turkey', 'Israel', 'United Arab Emirates', 'United States', 'Canada','Mexico'
,"Brazil", "Costa Rica", "Argentina", "Chile"]
def SelectServer(l):
return random.choice(l)
def translate_text(text, dest_language="en"):
# Used to translate using the googletrans library
translator = googletrans.Translator()
try:
translation = translator.translate(text=text, dest=dest_language)
except json.decoder.JSONDecodeError:
# api call restriction
print("exception !! déconection du VPN ")
process = subprocess.Popen(["nordvpn", "-d"], shell = True ,stdout=subprocess.PIPE, stderr=subprocess.PIPE)
process.wait()
time.sleep(5)
srv = SelectServer(listofservers)
print("sélection du serveur : "+ srv + " et connexion")
process = subprocess.Popen(["nordvpn", "-c", "-g", srv ], shell = True ,stdout=subprocess.PIPE, stderr=subprocess.PIPE)
process.wait()
time.sleep(60)
return translate_text(text=text, dest_language=dest_language)
return translation.text
#translate to EN and remove EN stopwords
ListCapTranslated = []
for row in ListCaptionsCleanFiltred:
# REINITIALIZE THE API
newrow = translate_text(row, dest_language="en")
ListCapTranslated.append(newrow)
ListCapTranslated
Before running the code, please add NordVPN to System path and test connecting/disconnecting on servers through CMD so you make sure everything works.
Cheers.