Skip to content

PEP8 changes. #100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CountMillionCharacter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
1 change: 1 addition & 0 deletions CountMillionCharacters-2.0.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ def main():
value = pprint.pformat(count)
print(value)


if __name__ == "__main__":
main()
11 changes: 6 additions & 5 deletions backup_automater_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,21 @@

# 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
dropbox = os.getenv("dropbox") # Set the variable by getting the value from the OS setting
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
Expand Down
14 changes: 7 additions & 7 deletions batch_file_rename.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
once you pass the current and new extensions
'''

__author__ = 'Craig Richards'
__author__ = 'Craig Richards'
__version__ = '1.0'

import os
Expand All @@ -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)
)


Expand All @@ -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()

16 changes: 8 additions & 8 deletions check_file.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# 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

# Prints usage if not appropriate length of arguments are provided
def usage():
print('[-] Usage: python check_file.py <filename1> [filename2] ... [filenameN]')
exit(0)


# Readfile Functions which open the file that is passed to the script
def readfile(filename):
Expand All @@ -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()
6 changes: 3 additions & 3 deletions check_internet_con.py
Original file line number Diff line number Diff line change
@@ -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")
8 changes: 4 additions & 4 deletions create_dir_if_not_there.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 5 additions & 5 deletions daily_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@ 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

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():
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions dir_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
57 changes: 31 additions & 26 deletions fileinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)"""
)
24 changes: 13 additions & 11 deletions folder_size.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
20 changes: 8 additions & 12 deletions get_info_remoute_srv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


2 changes: 1 addition & 1 deletion get_youtube_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Loading