diff --git a/CountMillionCharacter.py b/CountMillionCharacter.py index cf6696cbae8..5de7d14d0d4 100644 --- a/CountMillionCharacter.py +++ b/CountMillionCharacter.py @@ -287,9 +287,9 @@ ARCHBISHOP OF YORK Before, and greet his grace: my lord, we come. Exeunt''' -count = { } +count = {} for character in info.upper(): - count[character]=count.get(character,0)+1 + count[character] = count.get(character, 0) + 1 value = pprint.pformat(count) print(value) diff --git a/CountMillionCharacters-2.0.py b/CountMillionCharacters-2.0.py index ec1e3e54b4d..47482ba6858 100644 --- a/CountMillionCharacters-2.0.py +++ b/CountMillionCharacters-2.0.py @@ -20,5 +20,6 @@ def main(): value = pprint.pformat(count) print(value) + if __name__ == "__main__": main() diff --git a/backup_automater_services.py b/backup_automater_services.py index 79cdee479e9..916aea771fc 100644 --- a/backup_automater_services.py +++ b/backup_automater_services.py @@ -8,11 +8,11 @@ # Description : This will go through and backup all my automator services workflows +import datetime # Load the library module +import os # Load the library module import shutil # Load the library module -import datetime # Load the library module -import os # Load the library module -today = datetime.date.today() # Get Today's date +today = datetime.date.today() # Get Today's date todaystr = today.isoformat() # Format it so we can use the format to create the directory confdir = os.getenv("my_config") # Set the variable by getting the value from the OS setting @@ -20,8 +20,9 @@ conffile = ('services.conf') # Set the variable as the name of the configuration file conffilename = os.path.join(confdir, conffile) # Set the variable by combining the path and the file name sourcedir = os.path.expanduser('~/Library/Services/') # Source directory of where the scripts are located -destdir = os.path.join(dropbox, "My_backups"+"/"+"Automater_services"+todaystr+"/") # Combine several settings to create - +destdir = os.path.join(dropbox, "My_backups" + "/" + + "Automater_services" + todaystr + "/") # Combine several settings to create + # the destination backup directory for file_name in open(conffilename): # Walk through the configuration file fname = file_name.strip() # Strip out the blank lines from the configuration file diff --git a/batch_file_rename.py b/batch_file_rename.py index e8c01d4c778..14d230d7bb2 100644 --- a/batch_file_rename.py +++ b/batch_file_rename.py @@ -6,7 +6,7 @@ once you pass the current and new extensions ''' -__author__ = 'Craig Richards' +__author__ = 'Craig Richards' __version__ = '1.0' import os @@ -28,8 +28,8 @@ def batch_rename(work_dir, old_ext, new_ext): newfile = filename.replace(old_ext, new_ext) # Write the files os.rename( - os.path.join(work_dir, filename), - os.path.join(work_dir, newfile) + os.path.join(work_dir, filename), + os.path.join(work_dir, newfile) ) @@ -40,12 +40,12 @@ def main(): # Set the variable work_dir with the first argument passed work_dir = sys.argv[1] # Set the variable old_ext with the second argument passed - old_ext = sys.argv[2] + old_ext = sys.argv[2] # Set the variable new_ext with the third argument passed - new_ext = sys.argv[3] - + new_ext = sys.argv[3] + batch_rename(work_dir, old_ext, new_ext) + if __name__ == '__main__': main() - diff --git a/check_file.py b/check_file.py index 1e4b1ba527e..36fd3f23c0a 100644 --- a/check_file.py +++ b/check_file.py @@ -1,14 +1,14 @@ # Script Name : check_file.py # Author : Craig Richards -# Created : 20 May 2013 -# Last Modified : +# Created : 20 May 2013 +# Last Modified : # Version : 1.0 # Modifications : with statement added to ensure correct file closure # Description : Check a file exists and that we can read the file -from __future__ import print_function +from __future__ import print_function import sys # Import the Modules import os # Import the Modules @@ -16,7 +16,7 @@ def usage(): print('[-] Usage: python check_file.py [filename2] ... [filenameN]') exit(0) - + # Readfile Functions which open the file that is passed to the script def readfile(filename): @@ -29,21 +29,21 @@ def main(): filenames = sys.argv[1:] for filename in filenames: # Iterate for each filename passed in command line argument if not os.path.isfile(filename): # Check the File exists - print ('[-] ' + filename + ' does not exist.') + print ('[-] ' + filename + ' does not exist.') filenames.remove(filename) #remove non existing files from filenames list continue - + if not os.access(filename, os.R_OK): # Check you can read the file print ('[-] ' + filename + ' access denied') filenames.remove(filename) # remove non readable filenames continue else: usage() # Print usage if not all parameters passed/Checked - + # Read the content of each file for filename in filenames: print ('[+] Reading from : ' + filename) # Display Message and read the file contents readfile(filename) - + if __name__ == '__main__': main() diff --git a/check_internet_con.py b/check_internet_con.py index 13c89bf706c..2823c92267b 100644 --- a/check_internet_con.py +++ b/check_internet_con.py @@ -1,8 +1,8 @@ import urllib2 try: - urllib2.urlopen("http://google.com/", timeout=2) - print ("working connection") + urllib2.urlopen("http://google.com/", timeout=2) + print ("working connection") except urllib2.URLError: - print ("No internet connection") + print ("No internet connection") diff --git a/create_dir_if_not_there.py b/create_dir_if_not_there.py index 3c7468a4abb..2c72ad48085 100644 --- a/create_dir_if_not_there.py +++ b/create_dir_if_not_there.py @@ -12,8 +12,8 @@ try: home = os.path.expanduser("~") # Set the variable home by expanding the users set home directory print home # Print the location - - if not os.path.exists(home+'/testdir'): - os.makedirs(home+'/testdir') # If not create the directory, inside their home directory -except Exceptions as e: + + if not os.path.exists(home + '/testdir'): + os.makedirs(home + '/testdir') # If not create the directory, inside their home directory +except Exception, e: print e diff --git a/daily_checks.py b/daily_checks.py index 31d8ae45cd0..5aae0ad3f0f 100644 --- a/daily_checks.py +++ b/daily_checks.py @@ -28,8 +28,8 @@ def clear_screen(): # Function to clear the screen def print_docs(): # Function to print the daily checks automatically print ("Printing Daily Check Sheets:") # The command below passes the command line string to open word, open the document, print it then close word down - subprocess.Popen(["C:\\Program Files (x86)\Microsoft Office\Office14\winword.exe", "P:\\\\Documentation\\Daily Docs\\Back office Daily Checks.doc", "/mFilePrintDefault", "/mFileExit"]).communicate() - + subprocess.Popen(["C:\\Program Files (x86)\Microsoft Office\Office14\winword.exe", "P:\\\\Documentation\\Daily Docs\\Back office Daily Checks.doc", "/mFilePrintDefault", "/mFileExit"]).communicate() + def putty_sessions(): # Function to load the putty sessions I need for server in open(conffilename): # Open the file server_list.txt, loop through reading each line - 1.1 -Changed - 1.3 Changed name to use variable conffilename subprocess.Popen(('putty -load '+server)) # Open the PuTTY sessions - 1.1 @@ -37,12 +37,12 @@ def putty_sessions(): # Function to load the putty sessions I need def rdp_sessions(): print ("Loading RDP Sessions:") subprocess.Popen("mstsc eclr.rdp") # Open up a terminal session connection and load the euroclear session - + def euroclear_docs(): # The command below opens IE and loads the Euroclear password document subprocess.Popen('"C:\\Program Files\\Internet Explorer\\iexplore.exe"' '"file://fs1\pub_b\Pub_Admin\Documentation\Settlements_Files\PWD\Eclr.doc"') -# End of the functions +# End of the functions # Start of the Main Program def main(): @@ -53,7 +53,7 @@ def main(): clear_screen() # Call the clear screen function # The command below prints a little welcome message, as well as the script name, the date and time and where it was run from. - print ("Good Morning " + os.getenv('USERNAME') + ", "+ + print ("Good Morning " + os.getenv('USERNAME') + ", "+ filename, "ran at", strftime("%Y-%m-%d %H:%M:%S"), "on",platform.node(), "run from",os.getcwd()) print_docs() # Call the print_docs function diff --git a/dir_test.py b/dir_test.py index 8d701055c0c..2bebee7faee 100644 --- a/dir_test.py +++ b/dir_test.py @@ -3,11 +3,11 @@ # Created : 29th November 2011 # Last Modified : # Version : 1.0 -# Modifications : +# Modifications : # Description : Tests to see if the directory testdir exists, if not it will create the directory for you -import os # Import the OS module +import os # Import the OS module if not os.path.exists('testdir'): # Check to see if it exists os.makedirs('testdir') # Create the directory diff --git a/fileinfo.py b/fileinfo.py index 93301383e24..78f4d5741d5 100644 --- a/fileinfo.py +++ b/fileinfo.py @@ -13,49 +13,54 @@ from __future__ import print_function import os import sys -import stat # index constants for os.stat() +import stat # index constants for os.stat() import time try_count = 16 while try_count: - file_name = raw_input("Enter a file name: ") # pick a file you have ... + file_name = raw_input("Enter a file name: ") # pick a file you have try_count >>= 1 - try : + try: file_stats = os.stat(file_name) break except OSError: - print ("\nNameError : [%s] No such file or directory\n" %file_name) + print ("\nNameError : [%s] No such file or directory\n", file_name) if try_count == 0: print ("Trial limit exceded \nExiting program") sys.exit() # create a dictionary to hold file info file_info = { - 'fname': file_name, - 'fsize': file_stats [stat.ST_SIZE], - 'f_lm': time.strftime("%d/%m/%Y %I:%M:%S %p",time.localtime(file_stats[stat.ST_MTIME])), - 'f_la': time.strftime("%d/%m/%Y %I:%M:%S %p",time.localtime(file_stats[stat.ST_ATIME])), - 'f_ct': time.strftime("%d/%m/%Y %I:%M:%S %p",time.localtime(file_stats[stat.ST_CTIME])) + 'fname': file_name, + 'fsize': file_stats[stat.ST_SIZE], + 'f_lm': time.strftime("%d/%m/%Y %I:%M:%S %p", + time.localtime(file_stats[stat.ST_MTIME])), + 'f_la': time.strftime("%d/%m/%Y %I:%M:%S %p", + time.localtime(file_stats[stat.ST_ATIME])), + 'f_ct': time.strftime("%d/%m/%Y %I:%M:%S %p", + time.localtime(file_stats[stat.ST_CTIME])) } + print -print ("file name = %(fname)s" % file_info) -print ("file size = %(fsize)s bytes" % file_info) -print ("last modified = %(f_lm)s" % file_info) -print ("last accessed = %(f_la)s" % file_info) -print ("creation time = %(f_ct)s" % file_info) +print ("file name = %(fname)s", file_info) +print ("file size = %(fsize)s bytes", file_info) +print ("last modified = %(f_lm)s", file_info) +print ("last accessed = %(f_la)s", file_info) +print ("creation time = %(f_ct)s", file_info) print if stat.S_ISDIR(file_stats[stat.ST_MODE]): - print ("This a directory") + + print ("This a directory") else: - print ("This is not a directory") - print () - print ("A closer look at the os.stat(%s) tuple:" % file_name) - print (file_stats) - print () - print ("The above tuple has the following sequence:") - print ("""st_mode (protection bits), st_ino (inode number), - st_dev (device), st_nlink (number of hard links), - st_uid (user ID of owner), st_gid (group ID of owner), - st_size (file size, bytes), st_atime (last access time, seconds since epoch), - st_mtime (last modification time), st_ctime (time of creation, Windows)""" + print ("This is not a directory") + print () + print ("A closer look at the os.stat(%s) tuple:" % file_name) + print (file_stats) + print () + print ("The above tuple has the following sequence:") + print ("""st_mode (protection bits), st_ino (inode number), + st_dev (device), st_nlink (number of hard links), + st_uid (user ID of owner), st_gid (group ID of owner), + st_size (file size, bytes), st_atime (last access time, seconds since epoch), + st_mtime (last modification time), st_ctime (time of creation, Windows)""" ) diff --git a/folder_size.py b/folder_size.py index d89f2232e28..d92ed82de85 100755 --- a/folder_size.py +++ b/folder_size.py @@ -8,25 +8,27 @@ # Description : This will scan the current directory and all subdirectories and display the size. -import os, sys # Load the library module and the sys module for the argument vector +import os +import sys ''' Load the library module and the sys module for the argument vector''' try: - directory = sys.argv[1] # Set the variable directory to be the argument supplied by user. + directory = sys.argv[1] # Set the variable directory to be the argument supplied by user. except IndexError: sys.exit("Must provide an argument.") -dir_size = 0 # Set the size to 0 -fsizedicr = {'Bytes': 1, 'Kilobytes': float(1)/1024, 'Megabytes': float(1)/(1024*1024), 'Gigabytes': float(1)/(1024*1024 - * - 1024)} - +dir_size = 0 # Set the size to 0 +fsizedicr = {'Bytes': 1, + 'Kilobytes': float(1) / 1024, + 'Megabytes': float(1) / (1024 * 1024), + 'Gigabytes': float(1) / (1024 * 1024 + * 1024)} for (path, dirs, files) in os.walk(directory): # Walk through all the directories. For each iteration, os.walk returns the folders, subfolders and files in the dir. for file in files: # Get all the files - filename = os.path.join(path, file) + filename = os.path.join(path, file) dir_size += os.path.getsize(filename) # Add the size of each file in the root dir to get the total size. - -fsizeList = [str(round(fsizedicr[key]*dir_size, 2)) + " " + key for key in fsizedicr] # List of units -if dir_size == 0: print ("File Empty") # Sanity check to eliminate corner-case of empty file. +fsizeList = [str(round(fsizedicr[key] * dir_size, 2)) + " " + key for key in fsizedicr] # List of units + +if dir_size == 0: print ("File Empty") # Sanity check to eliminate corner-case of empty file. else: for units in sorted(fsizeList)[::-1]: # Reverse sort list of units so smallest magnitude units print first. print ("Folder Size: " + units) diff --git a/get_info_remoute_srv.py b/get_info_remoute_srv.py index 6b6a917c346..245587fcd6d 100644 --- a/get_info_remoute_srv.py +++ b/get_info_remoute_srv.py @@ -4,32 +4,28 @@ # Last Modified : - # Version : 1.0.0 -# Modifications : +# Modifications : # Description : this will get info about remoute server on linux through ssh connection. Connect these servers must be through keys import subprocess -import sys +HOSTS = ('proxy1', 'proxy') -HOSTS = ['proxy1', 'proxy'] - -COMMANDS = ['uname -a', 'uptime'] +COMMANDS = ('uname -a', 'uptime') for host in HOSTS: result = [] for command in COMMANDS: - ssh = subprocess.Popen(["ssh", "%s" % host, command], - shell=False, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE) + ssh = subprocess.Popen(["ssh", "%s" % host, command], + shell=False, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) result.append(ssh.stdout.readlines()) - print('--------------- '+host+' --------------- ') + print('--------------- ' + host + ' --------------- ') for res in result: if not res: print(ssh.stderr.readlines()) break else: print(res) - - diff --git a/get_youtube_view.py b/get_youtube_view.py index aca443b2ca4..ca3d6218c4f 100644 --- a/get_youtube_view.py +++ b/get_youtube_view.py @@ -4,7 +4,7 @@ #how much views you want #This only works when video has less than 300 views, it won't work when there are more than 300 views... #due to youtube's policy. -print("Enjoy your Time\n" +time.ctime()) +print("Enjoy your Time\n" + time.ctime()) for count in range(30): time.sleep(5) webbrowser.open("https://www.youtube.com/watch?v=o6A7nf3IeeA") diff --git a/jee_result.py b/jee_result.py index a616b5bbb20..367c5613391 100644 --- a/jee_result.py +++ b/jee_result.py @@ -1,5 +1,6 @@ +from bs4 import BeautifulSoup +import datetime import mechanize -from bs4 import BeautifulSoup import urllib2 # Create a Browser b = mechanize.Browser() @@ -19,28 +20,27 @@ # Fill it out b['regno'] = '37000304' -import datetime currentdate = datetime.date(1997,3,10) enddate = datetime.date(1998,4,1) while currentdate <= enddate: ct=0 #print currentdate - yyyymmdd=currentdate.strftime("%Y/%m/%d") - ddmmyyyy=yyyymmdd[8:]+"/"+yyyymmdd[5:7]+"/"+yyyymmdd[:4] + yyyymmdd = currentdate.strftime("%Y/%m/%d") + ddmmyyyy = yyyymmdd[8:] + "/" + yyyymmdd[5:7] + "/" +yyyymmdd[:4] print(ddmmyyyy) b.open('http://cbseresults.nic.in/jee/jee_2015.htm') b.select_form(nr=0) b['regno'] = '37000304' - b['dob']=ddmmyyyy - + b['dob'] = ddmmyyyy + fd = b.submit() #print(fd.read()) soup = BeautifulSoup(fd.read(),'html.parser') for writ in soup.find_all('table'): - ct=ct+1; + ct = ct + 1; #print (ct) - if ct==6: + if ct == 6: print("---fail---") else: print("--true--")