def printCredentials(self): """ Print a list of the credentials""" credentials = readJsonFile(self.credentailsPath) if credentials: for name, credential in credentials.items(): print(name, ': ', credential) else: print("No credentials yet")
def requestCredentials(self): """ Request the credentials with the credentials configuration file""" credentials = {} print("\nPlase, capture your information") # Get configuration for each credential configCredentials = readJsonFile(self.configCredentialsPath) # Request to user each credential for configCredential in configCredentials: while True: # Extract config info name = configCredential['name'] description = configCredential['description'] validation = configCredential['validation'] # Request credential and add to the dictionary credential = input(name + ' (%s): ' % description) # Validate credential try: validation = int(validation) if len(credential) >= validation: break else: print( 'Incorrect lenght. The credential needs at least %s characters' % int(validation)) except: # Convert validation items to list if validation: # Convert validation info to python data if ',' in validation: validation = json.loads(validation) if type(validation) != list: validation = [validation] # Count correct validations validationCounter = 0 for validationItem in validation: if validationItem in credential: validationCounter += 1 else: print('The credential needs to have "%s"' % validationItem) # Check number of validations if validationCounter == len(validation): break else: break credentials[configCredential['name']] = credential # Save credentials writeJsonFile(self.credentailsPath, credentials)
def printConfigCredentials(self): """ Print a list of the config of credentials""" credentialConfigCounter = 0 configCredentials = readJsonFile(self.configCredentialsPath) if configCredentials: for configCredentail in configCredentials: credentialConfigCounter += 1 print(credentialConfigCounter) for name, value in configCredentail.items(): print(name, ': ', value) else: print("No config of credentials yet")
def send_message(friends, message): """ Read information and send message""" # Files path = os.path.dirname(__file__) json_file = os.path.join(path, 'search_bar.json') alarm_sound = os.path.join(path, 'sound.mp3') # Open page webbrowser.open("https://web.whatsapp.com/") # Cordenates data = readJsonFile(json_file) if not data: getSearchBarInfo(json_file, alarm_sound) seaarchBar = data['xy'] seaarchBarColor = data['rgb'] # Wait web page print('Whait for the whatsapp web window...') while not pyautogui.pixelMatchesColor(seaarchBar[0], seaarchBar[1], seaarchBarColor): time.sleep(0.5) # Send menssage for friend in friends: print('Sending menssage to %s' % (friend)) pyautogui.click(seaarchBar) time.sleep(1) pyautogui.typewrite(friend) time.sleep(1) pyautogui.typewrite(['enter']) time.sleep(1) pyautogui.typewrite(message) time.sleep(1) pyautogui.typewrite(['enter']) time.sleep(1)
def getCredentials(self): credentials = readJsonFile(self.credentailsPath) return (credentials)
def __init__(self, pathCredentialsFile, pathConfigCredentialsFile): """ Run the inefaz""" """Run the complite interfaz""" # Initical vars self.credentailsPath = pathCredentialsFile self.configCredentialsPath = pathConfigCredentialsFile # Menssages helpMenssage = "\n write '-l --cred' to see all credentials. \ \n write '-l --keys' to see all instrucction keys. \ \n write '-l --keys KEYNAME' to see all instrucctions from specific key. \ \n write '-e --cred' to edit all credentials. \ \n write '-e --keys --add' to add new keys and instrucctions. \ \n write '-d --keys KEYNAME' to delete a specific key." errorMenssage = "Incorrect input. Write --help for more information" # Run interfaz if len(sys.argv) == 2: if sys.argv[1] == '--help': # Print help menssage print(helpMenssage) else: print(errorMenssage) sys.exit() elif len(sys.argv) > 2: if sys.argv[1] == '-l': # List json and csv files info if sys.argv[2] == '--keys': # Return list of keys or instrucctions if len(sys.argv) == 4: # print instrucctions from a file printCommands(sys.argv[3]) else: # print list of keys printFiles() elif sys.argv[2] == '--cred': # Return list of info self.printCredentials() else: print(errorMenssage) elif sys.argv[1] == '-e': # Edit json files if sys.argv[2] == '--keys' and len(sys.argv) == 4: if sys.argv[3] == '--add': # add keys addCommand() else: print(errorMenssage) elif sys.argv[2] == '--cred': # Requet credentials self.requestCredentials() else: print(errorMenssage) elif sys.argv[1] == '-d' and sys.argv[2] == '--keys' and len( sys.argv) == 4: # Delete epecific key deleteCommands(sys.argv[3]) else: print(errorMenssage) sys.exit() # Read files. configCredentials = readJsonFile(pathConfigCredentialsFile) credentials = readJsonFile(pathCredentialsFile) # if files are empty, requet it if not configCredentials: self.requestConfigCredentials() if not credentials: self.requestCredentials()
#! python3 from rwJson import readJsonFile import os, csv path = os.path.dirname(__file__) file_json = os.path.join(path, "data.json") file_csv = os.path.join(path, "data.csv") data_json = readJsonFile(file_json) header = ['name', 'date', 'size', 'url', 'video', 'all', 'best'] writer_csv = csv.writer(open(file_csv, 'w')) writer_csv.writerow(header) for line_data in data_json: row = [] row.append(line_data['name']) year = line_data['date'][:4] month = line_data['date'][4:6] day = line_data['date'][6:] date = year + ' - ' + month + ' - ' + day row.append(date) row.append(line_data['size']) row.append(line_data['url']) row.append(line_data['video'])
def __init__(self, pathCredentialsFile, pathConfigCredentialsFile): """ Run the inefaz""" """Run the complite interfaz""" # Initical vars self.credentailsPath = pathCredentialsFile self.configCredentialsPath = pathConfigCredentialsFile # Menssages helpMenssage = "Run the interfaz.py to request credentials or configuration of credentials. \ \n interfaz.py return the current credentials.\ \n write '-l --cred' to see all credentials \ \n write '-l --config' to see all credentials configuration options. \ \n write '-e --config' to edit all credentials configuration options. \ \n write '-e --cred' to edit all credentials" errorMenssage = "Incorrect input. Write --help for more information" # Run interfaz if len(sys.argv) == 2: if sys.argv[1] == '--help': # Print help menssage print(helpMenssage) sys.exit() else: print(errorMenssage) sys.exit() elif len(sys.argv) == 3: if sys.argv[1] == '-l': # List json files info if sys.argv[2] == '--config': # Return list of info self.printConfigCredentials() elif sys.argv[2] == '--cred': # Return list of info self.printCredentials() else: print(errorMenssage) sys.exit() elif sys.argv[1] == '-e': # Edit json files if sys.argv[2] == '--config': # Return list of info self.requestConfigCredentials() elif sys.argv[2] == '--cred': # Return list of info self.requestCredentials() else: print(errorMenssage) sys.exit() else: print(errorMenssage) # Read files. configCredentials = readJsonFile(pathConfigCredentialsFile) credentials = readJsonFile(pathCredentialsFile) # if files are empty, requet it if not configCredentials: self.requestConfigCredentials() if not credentials: self.requestCredentials()