Skip to content

Commit 062dcb9

Browse files
Merge pull request geekcomputers#363 from StupidTAO/master
Format code by PEP8
2 parents 41fb608 + afbaae8 commit 062dcb9

18 files changed

+207
-194
lines changed

CountMillionCharacter.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
'''Simple million word count program.
2-
main idea is Python pairs words
3-
with the number of times
4-
that number appears in the triple quoted string.
5-
Credit to William J. Turkel and Adam Crymble for the word
6-
frequency code used below. I just merged the two ideas.
7-
'''
1+
"""
2+
Simple million word count program.
3+
main idea is Python pairs words
4+
with the number of times
5+
that number appears in the triple quoted string.
6+
Credit to William J. Turkel and Adam Crymble for the word
7+
frequency code used below. I just merged the two ideas.
8+
"""
89

910
wordstring = '''SCENE I. Yorkshire. Gaultree Forest.
1011
Enter the ARCHBISHOP OF YORK, MOWBRAY, LORD HASTINGS, and others

Credit_Card_Validator.py

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
#luhn algorithm
1+
# luhn algorithm
2+
23

34
class CreditCard:
45
def __init__(self,card_no):
56
self.card_no = card_no
67

7-
88
@property
99
def company(self):
10-
comp =None
10+
comp = None
1111
if str(self.card_no).startswith('4'):
12-
comp = 'Visa Card'
12+
comp = 'Visa Card'
1313
elif str(self.card_no).startswith(('50', '67', '58','63',)):
1414
comp = 'Maestro Card'
1515
elif str(self.card_no).startswith('5'):
@@ -27,69 +27,57 @@ def company(self):
2727

2828
return 'Company : '+comp
2929

30-
31-
3230
def first_check(self):
33-
if 13<=len(self.card_no)<=19:
31+
if 13 <= len(self.card_no) <= 19:
3432
message = "First check : Valid in terms of length."
3533

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

40-
41-
42-
4338
def validate(self):
44-
#double every second digit from right to left
45-
sum_=0
39+
# double every second digit from right to left
40+
sum_ = 0
4641
crd_no = self.card_no[::-1]
4742
for i in range(len(crd_no)):
48-
if i%2==1:
43+
if i % 2 == 1:
4944
double_it = int(crd_no[i])*2
5045

51-
if len(str(double_it))==2:
46+
if len(str(double_it)) == 2:
5247
sum_ += sum([eval(i) for i in str(double_it)])
5348

5449
else:
55-
sum_+=double_it
50+
sum_ += double_it
5651

5752
else:
58-
sum_+=int(crd_no[i])
53+
sum_ += int(crd_no[i])
5954

60-
61-
62-
if sum_%10==0:
55+
if sum_ % 10 == 0:
6356
response = "Valid Card"
6457
else:
6558
response = 'Invalid Card'
6659

6760
return response
6861

69-
70-
7162
@property
7263
def checksum(self):
7364
return '#CHECKSUM# : '+self.card_no[-1]
7465

75-
7666
@classmethod
7767
def set_card(cls,card_to_check):
7868
return cls(card_to_check)
7969

8070

81-
82-
card_number = input()
71+
card_number = input()
8372
card = CreditCard.set_card(card_number)
8473
print(card.company)
85-
print('Card : ',card.card_no)
74+
print('Card : ', card.card_no)
8675
print(card.first_check())
8776
print(card.checksum)
8877
print(card.validate())
8978

9079

91-
9280
# 79927398713
93-
#4388576018402626
94-
#379354508162306
81+
# 4388576018402626
82+
# 379354508162306
9583

Cricket_score.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77
url = "http://www.cricbuzz.com/cricket-match/live-scores"
88

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

2020

21-
print(score[0],results[0])
22-
toaster.show_toast(title=score[0],msg=results[0])
21+
print(score[0], results[0])
22+
toaster.show_toast(title=score[0], msg=results[0])
2323

backup_automater_services.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@
1212
import os # Load the library module
1313
import shutil # Load the library module
1414

15-
today = datetime.date.today() # Get Today's date
15+
today = datetime.date.today() # Get Today's date
1616
todaystr = today.isoformat() # Format it so we can use the format to create the directory
1717

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" + "/" +
24-
"Automater_services" + todaystr + "/") # Combine several settings to create
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+
# Combine several settings to create
24+
destdir = os.path.join(dropbox, "My_backups" + "/" + "Automater_services" + todaystr + "/")
2525

26-
# the destination backup directory
27-
for file_name in open(conffilename): # Walk through the configuration file
28-
fname = file_name.strip() # Strip out the blank lines from the configuration file
29-
if fname: # For the lines that are not blank
30-
sourcefile = os.path.join(sourcedir, fname) # Get the name of the source files to backup
31-
destfile = os.path.join(destdir, fname) # Get the name of the destination file names
32-
shutil.copytree(sourcefile, destfile) # Copy the directories
26+
# the destination backup directory
27+
for file_name in open(conffilename): # Walk through the configuration file
28+
fname = file_name.strip() # Strip out the blank lines from the configuration file
29+
if fname: # For the lines that are not blank
30+
sourcefile = os.path.join(sourcedir, fname) # Get the name of the source files to backup
31+
destfile = os.path.join(destdir, fname) # Get the name of the destination file names
32+
shutil.copytree(sourcefile, destfile) # Copy the directories

batch_file_rename.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
# batch_file_rename.py
22
# Created: 6th August 2012
33

4-
'''
4+
"""
55
This will batch rename a group of files in a given directory,
66
once you pass the current and new extensions
7-
'''
8-
#just checking
7+
"""
8+
9+
10+
# just checking
911
__author__ = 'Craig Richards'
1012
__version__ = '1.0'
1113

1214
import os
1315
import argparse
1416

17+
1518
def batch_rename(work_dir, old_ext, new_ext):
16-
'''
19+
"""
1720
This will batch rename a group of files in a given directory,
1821
once you pass the current and new extensions
19-
'''
22+
"""
2023
# files = os.listdir(work_dir)
2124
for filename in os.listdir(work_dir):
2225
# Get the file extension
@@ -33,17 +36,19 @@ def batch_rename(work_dir, old_ext, new_ext):
3336
os.path.join(work_dir, newfile)
3437
)
3538

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

47+
4348
def main():
44-
'''
49+
"""
4550
This will be called if the script is directly invoked.
46-
'''
51+
"""
4752
# adding command line argument
4853
parser = get_parser()
4954
args = vars(parser.parse_args())

calculator.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ def calc(term):
4646
# This part is for reading and converting function expressions.
4747
term = term.lower()
4848

49-
for function in functions:
50-
if function in term:
51-
withmath = 'math.' + function
52-
term = term.replace(function, withmath)
49+
for func in functions:
50+
if func in term:
51+
withmath = 'math.' + func
52+
term = term.replace(func, withmath)
5353

5454
try:
5555

chaos.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# A simple program illustrating chaotic behaviour
22

3+
34
def main():
45
print ("This program illustrates a chaotic function")
56

@@ -17,5 +18,6 @@ def main():
1718
x = 3.9 * x * (1-x)
1819
print (x)
1920

21+
2022
if __name__ == '__main__':
2123
main()

check_file.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,24 @@ def usage():
2222
# Readfile Functions which open the file that is passed to the script
2323
def readfile(filename):
2424
with open(filename, 'r') as f: # Ensure file is correctly closed under
25-
file = f.read() # all circumstances
26-
print(file)
25+
read_file = f.read() # all circumstances
26+
print(read_file)
2727
print()
2828
print('#'*80)
2929
print()
3030

31+
3132
def main():
3233
# Check the arguments passed to the script
3334
if len(sys.argv) >= 2:
3435
filenames = sys.argv[1:]
35-
filteredfilenames_1 = list(filenames) #To counter changing in the same list which you are iterating
36+
filteredfilenames_1 = list(filenames) # To counter changing in the same list which you are iterating
3637
filteredfilenames_2 = list(filenames)
3738
# Iterate for each filename passed in command line argument
3839
for filename in filteredfilenames_1:
3940
if not os.path.isfile(filename): # Check the File exists
4041
print('[-] ' + filename + ' does not exist.')
41-
filteredfilenames_2.remove(filename) #remove non existing files from fileNames list
42+
filteredfilenames_2.remove(filename) # remove non existing files from fileNames list
4243
continue
4344

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

5758
else:
58-
usage() # Print usage if not all parameters passed/Checked
59+
usage() # Print usage if not all parameters passed/Checked
5960

6061

6162
if __name__ == '__main__':

check_for_sqlite_files.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from __future__ import print_function
1212
import os
1313

14+
1415
def isSQLite3(filename):
1516
from os.path import isfile, getsize
1617

@@ -28,13 +29,14 @@ def isSQLite3(filename):
2829
else:
2930
return False
3031

31-
log=open('sqlite_audit.txt','w')
32-
for r,d,f in os.walk(r'.'):
33-
for files in f:
34-
if isSQLite3(files):
35-
print(files)
36-
print("[+] '%s' **** is a SQLITE database file **** " % os.path.join(r,files))
37-
log.write("[+] '%s' **** is a SQLITE database file **** " % files+'\n')
38-
else:
39-
log.write("[-] '%s' is NOT a sqlite database file" % os.path.join(r,files)+'\n')
40-
log.write("[-] '%s' is NOT a sqlite database file" % files+'\n')
32+
33+
log = open('sqlite_audit.txt','w')
34+
for r, d, f in os.walk(r'.'):
35+
for files in f:
36+
if isSQLite3(files):
37+
print(files)
38+
print("[+] '%s' **** is a SQLITE database file **** " % os.path.join(r, files))
39+
log.write("[+] '%s' **** is a SQLITE database file **** " % files+'\n')
40+
else:
41+
log.write("[-] '%s' is NOT a sqlite database file" % os.path.join(r, files)+'\n')
42+
log.write("[-] '%s' is NOT a sqlite database file" % files+'\n')

check_input.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ def get_user_input(start,end):
1111
while input invalid asks user again
1212
"""
1313

14-
loop = True # controls while-loop
14+
loop = True # controls while-loop
1515

16-
while (loop):
16+
while loop:
1717

1818
try:
1919

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

2323
# checks whether input is in the given bounds.
24-
if userInput > end or userInput < start:
24+
if user_input > end or user_input < start:
2525

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

39-
return userInput
39+
return user_input
4040

4141

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

0 commit comments

Comments
 (0)