Skip to content

Commit f2367d5

Browse files
committed
added files
1 parent 940c1ea commit f2367d5

24 files changed

+822
-893
lines changed

README.md

+37-37
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
1-
Here is some more detailed information about the scripts I have written. I do not consider myself a programmer, I create these little programs as experiments to have a play with the language, or to solve a problem for myself. I would gladly accept pointers from others to improve the code and make it more efficient, or simplify the code. If you would like to make any comments then please feel free to email me at [email protected].
2-
3-
In the scripts the comments etc are lined up correctly when they are viewed in [Notepad++](https://notepad-plus-plus.org/). This is what I use to code Python scripts.
4-
5-
- `batch_file_rename.py` - This will batch rename a group of files in a given directory, once you pass the current and new extensions.
6-
7-
- `create_dir_if_not_there.py` - Checks to see if a directory exists in the users home directory, if not then create it.
8-
9-
- `dir_test.py` - Tests to see if the directory `testdir` exists, if not it will create the directory for you.
10-
11-
- `env_check.py` - This script will check to see if all of the environment variables I require are set.
12-
13-
- `fileinfo.py` - Show file information for a given file.
14-
15-
- `folder_size.py` - This will scan the current directory and all subdirectories and display the size.
16-
17-
- `logs.py` - This script will search for all `*.log` files in the given directory, zip them using the program you specify and then date stamp them.
18-
19-
- `move_files_over_x_days.py` - This will move all the files from the src directory that are over 240 days old to the destination directory.
20-
21-
- `nslookup_check.py` - This very simple script opens the file `server_list.txt` and the does an nslookup for each one to check the DNS entry/
22-
23-
- `osinfo.py` - Displays some information about the OS you are running this script on.
24-
25-
- `ping_servers.py` - This script will, depending on the arguments supplied will ping the servers associated with that application group.
26-
27-
- `ping_subnet.py` - After supplying the first 3 octets it will scan the final range for available addresses.
28-
29-
- `powerdown_startup.py` - This goes through the server list and pings the machine, if it's up it will load the putty session, if its not it will notify you.
30-
31-
- `puttylogs.py` - Zip up all the logs in the given directory.
32-
33-
- `script_count.py` - This scans my scripts directory and gives a count of the different types of scripts.
34-
35-
- `script_listing.py` - This will list all the files in the given directory, it will also go through all the subdirectories as well.
36-
37-
- `testlines.py` - This very simple script open a file and prints out 100 lines of whatever is set for the line variable.
1+
Here is some more detailed information about the scripts I have written. I do not consider myself a programmer, I create these little programs as experiments to have a play with the language, or to solve a problem for myself. I would gladly accept pointers from others to improve the code and make it more efficient, or simplify the code. If you would like to make any comments then please feel free to email me at [email protected].
2+
3+
In the scripts the comments etc are lined up correctly when they are viewed in [Notepad++](https://notepad-plus-plus.org/). This is what I use to code Python scripts.
4+
5+
- `batch_file_rename.py` - This will batch rename a group of files in a given directory, once you pass the current and new extensions.
6+
7+
- `create_dir_if_not_there.py` - Checks to see if a directory exists in the users home directory, if not then create it.
8+
9+
- `dir_test.py` - Tests to see if the directory `testdir` exists, if not it will create the directory for you.
10+
11+
- `env_check.py` - This script will check to see if all of the environment variables I require are set.
12+
13+
- `fileinfo.py` - Show file information for a given file.
14+
15+
- `folder_size.py` - This will scan the current directory and all subdirectories and display the size.
16+
17+
- `logs.py` - This script will search for all `*.log` files in the given directory, zip them using the program you specify and then date stamp them.
18+
19+
- `move_files_over_x_days.py` - This will move all the files from the src directory that are over 240 days old to the destination directory.
20+
21+
- `nslookup_check.py` - This very simple script opens the file `server_list.txt` and the does an nslookup for each one to check the DNS entry/
22+
23+
- `osinfo.py` - Displays some information about the OS you are running this script on.
24+
25+
- `ping_servers.py` - This script will, depending on the arguments supplied will ping the servers associated with that application group.
26+
27+
- `ping_subnet.py` - After supplying the first 3 octets it will scan the final range for available addresses.
28+
29+
- `powerdown_startup.py` - This goes through the server list and pings the machine, if it's up it will load the putty session, if its not it will notify you.
30+
31+
- `puttylogs.py` - Zip up all the logs in the given directory.
32+
33+
- `script_count.py` - This scans my scripts directory and gives a count of the different types of scripts.
34+
35+
- `script_listing.py` - This will list all the files in the given directory, it will also go through all the subdirectories as well.
36+
37+
- `testlines.py` - This very simple script open a file and prints out 100 lines of whatever is set for the line variable.

backup_automater_services.py

+30-30
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
# Script Name : backup_automater_services.py
2-
# Author : Craig Richards
3-
# Created : 24th October 2012
4-
# Last Modified :
5-
# Version : 1.0
6-
7-
# Modifications :
8-
9-
# Description : This will go through and backup all my automator services workflows
10-
11-
import shutil # Load the library module
12-
import datetime # Load the library module
13-
import os # Load the library module
14-
15-
today=datetime.date.today() # Get Today's date
16-
todaystr=today.isoformat() # Format it so we can use the format to create the directory
17-
18-
confdir=os.getenv("my_config") # Set the variable by getting the value from the OS setting
19-
dropbox=os.getenv("dropbox") # Set the variable by getting the value from the OS setting
20-
conffile = ('services.conf') # Set the variable as the name of the configuration file
21-
conffilename=os.path.join(confdir, conffile) # Set the variable by combining the path and the file name
22-
sourcedir=os.path.expanduser('~/Library/Services/') # Source directory of where the scripts are located
23-
destdir=os.path.join(dropbox, "My_backups"+"/"+"Automater_services"+todaystr+"/") # Combine several settings to create the destination backup directory
24-
25-
for file_name in open(conffilename): # Walk through the configuration file
26-
fname = file_name.strip() # Strip out the blank lines from the configuration file
27-
if fname: # For the lines that are not blank
28-
sourcefile=os.path.join(sourcedir, file_name.strip()) # Get the name of the source files to backup
29-
destfile=os.path.join(destdir, file_name.strip()) # Get the name of the destination file names
30-
shutil.copytree(sourcefile, destfile) # Copy the directories
1+
# Script Name : backup_automater_services.py
2+
# Author : Craig Richards
3+
# Created : 24th October 2012
4+
# Last Modified :
5+
# Version : 1.0
6+
7+
# Modifications :
8+
9+
# Description : This will go through and backup all my automator services workflows
10+
11+
import shutil # Load the library module
12+
import datetime # Load the library module
13+
import os # Load the library module
14+
15+
today=datetime.date.today() # Get Today's date
16+
todaystr=today.isoformat() # Format it so we can use the format to create the directory
17+
18+
confdir=os.getenv("my_config") # Set the variable by getting the value from the OS setting
19+
dropbox=os.getenv("dropbox") # Set the variable by getting the value from the OS setting
20+
conffile = ('services.conf') # Set the variable as the name of the configuration file
21+
conffilename=os.path.join(confdir, conffile) # Set the variable by combining the path and the file name
22+
sourcedir=os.path.expanduser('~/Library/Services/') # Source directory of where the scripts are located
23+
destdir=os.path.join(dropbox, "My_backups"+"/"+"Automater_services"+todaystr+"/") # Combine several settings to create the destination backup directory
24+
25+
for file_name in open(conffilename): # Walk through the configuration file
26+
fname = file_name.strip() # Strip out the blank lines from the configuration file
27+
if fname: # For the lines that are not blank
28+
sourcefile=os.path.join(sourcedir, file_name.strip()) # Get the name of the source files to backup
29+
destfile=os.path.join(destdir, file_name.strip()) # Get the name of the destination file names
30+
shutil.copytree(sourcefile, destfile) # Copy the directories

blog-reading-time.py

-96
This file was deleted.

bookmark.py

+45-37
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,45 @@
1-
# Author : Pranjal Dubey
2-
# Created : 31 Dec 2015
3-
# Last Modified :
4-
# Version : 1.0
5-
# Modifications :
6-
# Description : Script to keep a sync between your soft copy and hard copy file
7-
# Known Bugs :
8-
9-
10-
import PyPDF2, re
11-
12-
pdfFileObject = open("pdfs/the_girl_who_played_with_fire.pdf", "rb")
13-
pdfReader = PyPDF2.PdfFileReader(pdfFileObject)
14-
15-
pdfFileData = ''
16-
17-
for i in range(pdfReader.numPages):
18-
pageObject = pdfReader.getPage(i)
19-
pdfFileData += pageObject.extractText()
20-
21-
actualBookPages = 568
22-
23-
avgCharCountPerPage = len(pdfFileData) / actualBookPages
24-
25-
print(avgCharCountPerPage)
26-
27-
bookmarkPageWords = input('Enter few words of page to bookmark: ')
28-
29-
matchCase = r'' + bookmarkPageWords
30-
31-
regex = re.compile(matchCase, re.IGNORECASE | re.DOTALL)
32-
33-
print(re.search(regex, pdfFileData).start())
34-
35-
pageNumber = re.search(regex, pdfFileData).start() / avgCharCountPerPage
36-
37-
print(pageNumber)
1+
# Author : Pranjal Dubey
2+
# Created : 31 Dec 2015
3+
# Last Modified :
4+
# Version : 1.0
5+
# Modifications :
6+
# Description : Script to keep a sync between your soft copy and hard copy file
7+
# Known Bugs :
8+
9+
10+
import PyPDF2, re
11+
12+
filename = input('\nFilename : ')
13+
actualBookPages = input('\nTotal number of pages in your hard copy : ')
14+
bookmarkPageWords = input('\nFew words of page to bookmark : ')
15+
16+
pdfFileObject = open(filename, "rb")
17+
pdfReader = PyPDF2.PdfFileReader(pdfFileObject)
18+
19+
pdfFileData = ''
20+
21+
print('\nReading file...')
22+
23+
for i in range(pdfReader.numPages):
24+
pageObject = pdfReader.getPage(i)
25+
pdfFileData += pageObject.extractText()
26+
27+
avgCharCountPerPage = len(pdfFileData) / int(actualBookPages)
28+
29+
matchCase = r'' + bookmarkPageWords
30+
31+
regex = re.compile(matchCase, re.IGNORECASE | re.DOTALL)
32+
33+
matchResults = re.finditer(regex, pdfFileData)
34+
possiblePages = [match.start(0) for match in matchResults]
35+
36+
if len(possiblePages) == 1:
37+
print('\nPossible hit in your hard copy:-\n')
38+
elif len(possiblePages) > 1:
39+
print('\nPossible hits in your hard copy:-\n')
40+
else:
41+
print('\nNo matches found!')
42+
exit
43+
44+
for page in possiblePages:
45+
print(int(page / avgCharCountPerPage))

create_dir_if_not_there.py

+17-17
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
# Script Name : create_dir_if_not_there.py
2-
# Author : Craig Richards
3-
# Created : 09th January 2012
4-
# Last Modified : 22nd October 2015
5-
# Version : 1.0
6-
# Modifications : Added exceptions
7-
8-
# Description : Checks to see if a directory exists in the users home directory, if not then create it
9-
10-
import os # Import the OS module
11-
try:
12-
home=os.path.expanduser("~") # Set the variable home by expanding the users set home directory
13-
print home # Print the location
14-
if not os.path.exists(home+'/testdir'):
15-
os.makedirs(home+'/testdir') # If not create the directory, inside their home directory
16-
except Exceptions as e:
17-
print e
1+
# Script Name : create_dir_if_not_there.py
2+
# Author : Craig Richards
3+
# Created : 09th January 2012
4+
# Last Modified : 22nd October 2015
5+
# Version : 1.0
6+
# Modifications : Added exceptions
7+
8+
# Description : Checks to see if a directory exists in the users home directory, if not then create it
9+
10+
import os # Import the OS module
11+
try:
12+
home=os.path.expanduser("~") # Set the variable home by expanding the users set home directory
13+
print home # Print the location
14+
if not os.path.exists(home+'/testdir'):
15+
os.makedirs(home+'/testdir') # If not create the directory, inside their home directory
16+
except Exceptions as e:
17+
print e

dir_test.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# Script Name : dir_test.py
2-
# Author : Craig Richards
3-
# Created : 29th November 2011
4-
# Last Modified :
5-
# Version : 1.0
6-
# Modifications :
7-
8-
# Description : Tests to see if the directory testdir exists, if not it will create the directory for you
9-
10-
import os # Import the OS module
11-
if not os.path.exists('testdir'): # Check to see if it exists
12-
os.makedirs('testdir') # Create the directory
1+
# Script Name : dir_test.py
2+
# Author : Craig Richards
3+
# Created : 29th November 2011
4+
# Last Modified :
5+
# Version : 1.0
6+
# Modifications :
7+
8+
# Description : Tests to see if the directory testdir exists, if not it will create the directory for you
9+
10+
import os # Import the OS module
11+
if not os.path.exists('testdir'): # Check to see if it exists
12+
os.makedirs('testdir') # Create the directory

0 commit comments

Comments
 (0)