def _ensure_clip_support(clipboard): if not pyperclip.is_available(): pyperclip.set_clipboard(clipboard) if not pyperclip.is_available(): print("Copy functionality unavailable!") print( '''On Linux, install xclip or xsel or klipper via package manager. For example, in Debian: sudo apt-get install xclip sudo apt-get install xsel ''') exit(1)
def user_config(config_complete_path, auth): config = ConfigParser() config.read(config_complete_path) username = input('Type in your Twitter username: '******'Failed to get request token.') msg_auth_link = 'Access this link to authorize usage of your Twitter account: ' + bold(lightpurple(auth_url)) if(pyperclip.is_available()): msg_auth_link += ' (URL automatically copied to clipboard)' pyperclip.copy(auth_url) print(msg_auth_link) verifier = input('Type in the verifier code available on the authorization link: ') try: access_token, access_secret = auth.get_access_token(verifier) except tweepy.TweepError: error(config_complete_path, 'Failed to get access token.') config[username] = {'AccessToken':access_token, 'AccessSecret':access_secret} with open(config_complete_path, 'w') as configfile: config.write(configfile) return access_token, access_secret
def copyToClipperFeatures(self): if not pyperclip.is_available(): # print >> sys.stderr, '[e] no pyperclip functionality available' print '[w] no pyperclip functionality available' try: print '[i] features copied to clipboard' sf = self.features_text() pyperclip.copy('\n'.join(sf)) except: print '[e] pyperclip.copy failed.'
def export_tab_urls(self, path_outputFolder, copy_to_clipboard=False): # Create url-list text file from iCloud_device_tab_urls dictionary output = '' for device, url_list in self.get_tab_urls().items(): output += '----- ' + device + ' -----' + '\n' output += '\n'.join(url_list) + '\n\n' path_output = os.path.join(path_outputFolder, C_File_Tab_Urls) utils_io.write_file(path_output, output, mode='json', indent=2) if copy_to_clipboard: if pyperclip.is_available(): pyperclip.copy(output) else: print("Clipboard Copy functionality unavailable!")
def copyToClipboard(self): copied = self.content.Copy() # print "[i] logfile text copied to clipboard", copied if not pyperclip.is_available(): # print >> sys.stderr, '[e] no pyperclip functionality available' print '[w] no pyperclip functionality available' try: cl = [] with open(self.logfilename, 'r') as f: cl = f.readlines() pyperclip.copy(''.join(cl)) except: print '[e] pyperclip.copy failed.' # print >> sys.stderr, self.content.getClipText() self.draw()
def new_totp(keyname, keyfile): """Generate a new key based totp for a service""" totp = TOTP(keyfile) if not keyname: print("No key selected, select a key from the list:") keyname = totp.choose_one_key() totp_now = totp.get_new_totp(keyname) remaining_time = 30 - (datetime.now().second % 30) try: pyperclip.copy(totp_now) if pyperclip.is_available(): pyperclip.copy(totp_now) print("\n{} otp: {}\nValid for: {} seconds\n" "It is available on your clipboard.".format( keyname, totp_now, remaining_time)) except pyperclip.PyperclipException: print("\n{} otp: {}\nValid for: {} seconds\n".format( keyname, totp_now, remaining_time)) print("Consider installing xclip/xsel to export" " your totp to clipboard")
break except: get_mft_credentials() pass password = generate_mnemonic_password() link = mft.create_file_share( share_type=Client.ShareType.send, files=mft_files, password=password, subject=f'MFT Context Menu Share {timestamp}') output_file = open( os.path.join( os.path.split(input_files[0])[0], f'MFT Context Menu Share {timestamp}.txt'), 'w') output_file.write(f"Link: {link}\n") output_file.write(f"Password: {password}\n\n") output_file.write(f"Files:\n") for file in mft_files: output_file.write(f"{file}\n") output_file.close() if pyperclip.is_available(): pyperclip.copy(f"{link}\nPassword: {password}") toaster.show_toast( title="MFT Link Generated", msg="The link and password have been copied to your clipboard." ) else: toaster.show_toast(title="MFT Link Generated", msg="Details in the txt file.")
def paste(self): if pyperclip.is_available() == True: pyperclip.paste()
# mapIt.py - Launches a map in the browser using an address from the command line or clipboard import webbrowser import sys import pyperclip if not pyperclip.is_available(): print("Copy functionality unavailable, please install the pyperclip package") exit if(len(sys.argv) > 1): #Get the address from the command line address = ' '.join(sys.argv[1:]) else: address = pyperclip.paste() webbrowser.open('https://www.google.com/maps/place/' + address)
def main(self, dir_path, client_secrets_file_path, chrome_driver_path, username, password, query_string, sender_email, receiver_email, email_password): full_path = dir_path + '/sourav' mod_path = full_path.split('/') mod_path = "\\".join(mod_path) + "\\\\" # check whether directory is already present, then no need to fire API if not os.path.isdir(full_path): # the following code describes the firing of YOUTUBE Data V3 API # using Google Oauth authorization flow # The authorization is automated through web using selenium scopes = ["https://www.googleapis.com/auth/youtube.force-ssl"] os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1" api_service_name = "youtube" api_version = "v3" # this file is very important in determing tokens for authorization # set it's path correctly client_secrets_file = client_secrets_file_path # Get credentials and create an API client flow = google_auth_oauthlib.flow.InstalledAppFlow.from_client_secrets_file( client_secrets_file, scopes) driver = webdriver.Chrome(chrome_driver_path) # going to authorization url # everything below is automated process driver.get( "https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=744704855386-ov8kf1j3eagfcthepkliprjb4ok4nho4.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fyoutube.force-ssl&state=AySChscgPs1jYjuald3bRiOiMU1kgC&prompt=consent&access_type=offline" ) try: driver.implicitly_wait(random.randint(10, 20)) driver.find_element_by_name("identifier").send_keys(username) driver.implicitly_wait(random.randint(10, 20)) driver.find_element_by_xpath( '//*[@id="identifierNext"]/span/span').click() driver.implicitly_wait(random.randint(10, 20)) driver.find_element_by_name("password").send_keys(password) driver.implicitly_wait(random.randint(10, 20)) driver.find_element_by_xpath( '//*[@id="passwordNext"]/span/span').click() driver.implicitly_wait(random.randint(10, 20)) driver.find_element_by_xpath( '//*[@id="yDmH0d"]/div[1]/div[1]/a').click() driver.implicitly_wait(random.randint(10, 20)) driver.find_element_by_xpath( '//*[@id="yDmH0d"]/div[1]/div[2]/p[2]/a').click() driver.implicitly_wait(random.randint(10, 20)) driver.find_element_by_xpath( '//*[@id="oauthScopeDialog"]/div[3]/div[1]/span/span' ).click() driver.implicitly_wait(random.randint(10, 20)) driver.find_element_by_xpath( '//*[@id="submit_approve_access"]/span/span').click() driver.implicitly_wait(random.randint(10, 20)) token = driver.find_element_by_class_name( 'qBHUIf').get_attribute('value') pyperclip.copy(token) except Exception as e: print("AUTHORIZATION ERROR !") driver.close() # Now here only, we need to press one time CTRL + V to put the authorization token which is already been copied to clipboard if pyperclip.is_available(): credentials = flow.run_console( authorization_prompt_message="", authorization_code_message= "Press CTRL+V to paste the token and then Press Enter : ") # stdout.write(token) youtube = googleapiclient.discovery.build( api_service_name, api_version, credentials=credentials) # firing API and fetching the results request = youtube.search().list(part="snippet", maxResults=50, type='video', videoDuration='short', q=query_string) response = request.execute() # scraping the results and construcing the list of video id's video_links = [] for i in range(0, 50): try: video_id = response['items'][i]['id']['videoId'] video_links.append(video_id) except Exception as e: print(f"failed to retrieve video_links{i}") os.mkdir(full_path) # call download function for downloading these created video id's self.Download_videos(mod_path, chrome_driver_path, video_links) else: print( "Could not retrive the links ! Program Exits without Accesing API." ) else: print( "Directory already exists !, Skipping Youtube Data API Search..." ) # all other functions self.rename_files(full_path) self.trim_audio(dir_path) zipped_paths = self.zip_files(dir_path) if len(zipped_paths) == 0: print("No Zipped files found ! Unable to send mail.") else: subject = "An email with attachment of audio files from Python" body = f"This is an email with zipped attachment of 100 videos converted to audio downloaded according to given query : {query}" for batch, path in enumerate(zipped_paths): self.sent_mail(path, subject, body, sender_email, receiver_email, email_password, batch)