Skip to content

Commit

Permalink
Merge pull request geekcomputers#363 from StupidTAO/master
Browse files Browse the repository at this point in the history
Format code by PEP8
  • Loading branch information
geekcomputers authored Sep 24, 2018
2 parents 41fb608 + afbaae8 commit 062dcb9
Show file tree
Hide file tree
Showing 18 changed files with 207 additions and 194 deletions.
15 changes: 8 additions & 7 deletions CountMillionCharacter.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
'''Simple million word count program.
main idea is Python pairs words
with the number of times
that number appears in the triple quoted string.
Credit to William J. Turkel and Adam Crymble for the word
frequency code used below. I just merged the two ideas.
'''
"""
Simple million word count program.
main idea is Python pairs words
with the number of times
that number appears in the triple quoted string.
Credit to William J. Turkel and Adam Crymble for the word
frequency code used below. I just merged the two ideas.
"""

wordstring = '''SCENE I. Yorkshire. Gaultree Forest.
Enter the ARCHBISHOP OF YORK, MOWBRAY, LORD HASTINGS, and others
Expand Down
44 changes: 16 additions & 28 deletions Credit_Card_Validator.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#luhn algorithm
# luhn algorithm


class CreditCard:
def __init__(self,card_no):
self.card_no = card_no


@property
def company(self):
comp =None
comp = None
if str(self.card_no).startswith('4'):
comp = 'Visa Card'
comp = 'Visa Card'
elif str(self.card_no).startswith(('50', '67', '58','63',)):
comp = 'Maestro Card'
elif str(self.card_no).startswith('5'):
Expand All @@ -27,69 +27,57 @@ def company(self):

return 'Company : '+comp



def first_check(self):
if 13<=len(self.card_no)<=19:
if 13 <= len(self.card_no) <= 19:
message = "First check : Valid in terms of length."

else:
message = "First chek : Check Card number once again it must be of 13 or 16 digit long."
return message




def validate(self):
#double every second digit from right to left
sum_=0
# double every second digit from right to left
sum_ = 0
crd_no = self.card_no[::-1]
for i in range(len(crd_no)):
if i%2==1:
if i % 2 == 1:
double_it = int(crd_no[i])*2

if len(str(double_it))==2:
if len(str(double_it)) == 2:
sum_ += sum([eval(i) for i in str(double_it)])

else:
sum_+=double_it
sum_ += double_it

else:
sum_+=int(crd_no[i])
sum_ += int(crd_no[i])



if sum_%10==0:
if sum_ % 10 == 0:
response = "Valid Card"
else:
response = 'Invalid Card'

return response



@property
def checksum(self):
return '#CHECKSUM# : '+self.card_no[-1]


@classmethod
def set_card(cls,card_to_check):
return cls(card_to_check)



card_number = input()
card_number = input()
card = CreditCard.set_card(card_number)
print(card.company)
print('Card : ',card.card_no)
print('Card : ', card.card_no)
print(card.first_check())
print(card.checksum)
print(card.validate())



# 79927398713
#4388576018402626
#379354508162306
# 4388576018402626
# 379354508162306

14 changes: 7 additions & 7 deletions Cricket_score.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
url = "http://www.cricbuzz.com/cricket-match/live-scores"

sauce = request.urlopen(url).read()
soup = bs.BeautifulSoup(sauce,"lxml")
#print(soup)
soup = bs.BeautifulSoup(sauce, "lxml")
# print(soup)
score = []
results = []
#for live_matches in soup.find_all('div',attrs={"class":"cb-mtch-lst cb-col cb-col-100 cb-tms-itm"}):
# for live_matches in soup.find_all('div',attrs={"class":"cb-mtch-lst cb-col cb-col-100 cb-tms-itm"}):
for div_tags in soup.find_all('div', attrs={"class": "cb-lv-scrs-col text-black"}):
score.append(div_tags.text)
score.append(div_tags.text)
for result in soup.find_all('div', attrs={"class": "cb-lv-scrs-col cb-text-complete"}):
results.append(result.text)
results.append(result.text)


print(score[0],results[0])
toaster.show_toast(title=score[0],msg=results[0])
print(score[0], results[0])
toaster.show_toast(title=score[0], msg=results[0])

30 changes: 15 additions & 15 deletions backup_automater_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@
import os # Load the library module
import shutil # 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
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
# Combine several settings to create
destdir = os.path.join(dropbox, "My_backups" + "/" + "Automater_services" + todaystr + "/")

# 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
if fname: # For the lines that are not blank
sourcefile = os.path.join(sourcedir, fname) # Get the name of the source files to backup
destfile = os.path.join(destdir, fname) # Get the name of the destination file names
shutil.copytree(sourcefile, destfile) # Copy the directories
# 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
if fname: # For the lines that are not blank
sourcefile = os.path.join(sourcedir, fname) # Get the name of the source files to backup
destfile = os.path.join(destdir, fname) # Get the name of the destination file names
shutil.copytree(sourcefile, destfile) # Copy the directories
19 changes: 12 additions & 7 deletions batch_file_rename.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
# batch_file_rename.py
# Created: 6th August 2012

'''
"""
This will batch rename a group of files in a given directory,
once you pass the current and new extensions
'''
#just checking
"""


# just checking
__author__ = 'Craig Richards'
__version__ = '1.0'

import os
import argparse


def batch_rename(work_dir, old_ext, new_ext):
'''
"""
This will batch rename a group of files in a given directory,
once you pass the current and new extensions
'''
"""
# files = os.listdir(work_dir)
for filename in os.listdir(work_dir):
# Get the file extension
Expand All @@ -33,17 +36,19 @@ def batch_rename(work_dir, old_ext, new_ext):
os.path.join(work_dir, newfile)
)


def get_parser():
parser = argparse.ArgumentParser(description='change extension of files in a working directory')
parser.add_argument('work_dir', metavar='WORK_DIR', type=str, nargs=1, help='the directory where to change extension')
parser.add_argument('old_ext', metavar='OLD_EXT', type=str, nargs=1, help='old extension')
parser.add_argument('new_ext', metavar='NEW_EXT', type=str, nargs=1, help='new extension')
return parser


def main():
'''
"""
This will be called if the script is directly invoked.
'''
"""
# adding command line argument
parser = get_parser()
args = vars(parser.parse_args())
Expand Down
8 changes: 4 additions & 4 deletions calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ def calc(term):
# This part is for reading and converting function expressions.
term = term.lower()

for function in functions:
if function in term:
withmath = 'math.' + function
term = term.replace(function, withmath)
for func in functions:
if func in term:
withmath = 'math.' + func
term = term.replace(func, withmath)

try:

Expand Down
2 changes: 2 additions & 0 deletions chaos.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# A simple program illustrating chaotic behaviour


def main():
print ("This program illustrates a chaotic function")

Expand All @@ -17,5 +18,6 @@ def main():
x = 3.9 * x * (1-x)
print (x)


if __name__ == '__main__':
main()
11 changes: 6 additions & 5 deletions check_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,24 @@ def usage():
# Readfile Functions which open the file that is passed to the script
def readfile(filename):
with open(filename, 'r') as f: # Ensure file is correctly closed under
file = f.read() # all circumstances
print(file)
read_file = f.read() # all circumstances
print(read_file)
print()
print('#'*80)
print()


def main():
# Check the arguments passed to the script
if len(sys.argv) >= 2:
filenames = sys.argv[1:]
filteredfilenames_1 = list(filenames) #To counter changing in the same list which you are iterating
filteredfilenames_1 = list(filenames) # To counter changing in the same list which you are iterating
filteredfilenames_2 = list(filenames)
# Iterate for each filename passed in command line argument
for filename in filteredfilenames_1:
if not os.path.isfile(filename): # Check the File exists
print('[-] ' + filename + ' does not exist.')
filteredfilenames_2.remove(filename) #remove non existing files from fileNames list
filteredfilenames_2.remove(filename) # remove non existing files from fileNames list
continue

# Check you can read the file
Expand All @@ -55,7 +56,7 @@ def main():
readfile(filename)

else:
usage() # Print usage if not all parameters passed/Checked
usage() # Print usage if not all parameters passed/Checked


if __name__ == '__main__':
Expand Down
22 changes: 12 additions & 10 deletions check_for_sqlite_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from __future__ import print_function
import os


def isSQLite3(filename):
from os.path import isfile, getsize

Expand All @@ -28,13 +29,14 @@ def isSQLite3(filename):
else:
return False

log=open('sqlite_audit.txt','w')
for r,d,f in os.walk(r'.'):
for files in f:
if isSQLite3(files):
print(files)
print("[+] '%s' **** is a SQLITE database file **** " % os.path.join(r,files))
log.write("[+] '%s' **** is a SQLITE database file **** " % files+'\n')
else:
log.write("[-] '%s' is NOT a sqlite database file" % os.path.join(r,files)+'\n')
log.write("[-] '%s' is NOT a sqlite database file" % files+'\n')

log = open('sqlite_audit.txt','w')
for r, d, f in os.walk(r'.'):
for files in f:
if isSQLite3(files):
print(files)
print("[+] '%s' **** is a SQLITE database file **** " % os.path.join(r, files))
log.write("[+] '%s' **** is a SQLITE database file **** " % files+'\n')
else:
log.write("[-] '%s' is NOT a sqlite database file" % os.path.join(r, files)+'\n')
log.write("[-] '%s' is NOT a sqlite database file" % files+'\n')
16 changes: 8 additions & 8 deletions check_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ def get_user_input(start,end):
while input invalid asks user again
"""

loop = True # controls while-loop
loop = True # controls while-loop

while (loop):
while loop:

try:

# reads and converts the input from the console.
userInput = int(input("Enter Your choice: "))
user_input = int(input("Enter Your choice: "))

# checks whether input is in the given bounds.
if userInput > end or userInput < start:
if user_input > end or user_input < start:

# error case
print("Please try again. Not in valid bounds.")
Expand All @@ -36,11 +36,11 @@ def get_user_input(start,end):
# error case
print("Please try again. Only numbers")

return userInput
return user_input


x = get_user_input(1,6)
print(x)
###Asks user to enter something, ie. a number option from a menu.
###While type != interger, and not in the given range,
###Program gives error message and asks for new input.
# Asks user to enter something, ie. a number option from a menu.
# While type != interger, and not in the given range,
# Program gives error message and asks for new input.
Loading

0 comments on commit 062dcb9

Please sign in to comment.