Skip to content

Commit b352f3f

Browse files
committed
Merge pull request dbwebb-se#17 from feeloor/master
Validation errors
2 parents 22f4a90 + ee54198 commit b352f3f

6 files changed

Lines changed: 164 additions & 136 deletions

File tree

‎example/curses/orig/snake.py‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python3
1+
#!/usr/bin/env python3
22
"""
33
Testing out the curses lib.
44
@@ -7,7 +7,6 @@
77
#from curses import wrapper
88
import curses
99
import random
10-
from curses import KEY_RIGHT, KEY_LEFT, KEY_UP, KEY_DOWN
1110

1211
def main(screen):
1312
"""
@@ -66,16 +65,16 @@ def main(screen):
6665
screen.refresh()
6766
curses.napms(2500)
6867
break
69-
elif key == KEY_UP:
68+
elif key == curses.KEY_UP:
7069
dirs["y"] = -1
7170
dirs["x"] = 0
72-
elif key == KEY_DOWN:
71+
elif key == curses.KEY_DOWN:
7372
dirs["y"] = 1
7473
dirs["x"] = 0
75-
elif key == KEY_LEFT:
74+
elif key == curses.KEY_LEFT:
7675
dirs["x"] = -1
7776
dirs["y"] = 0
78-
elif key == KEY_RIGHT:
77+
elif key == curses.KEY_RIGHT:
7978
dirs["x"] = 1
8079
dirs["y"] = 0
8180

‎example/excel/README.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
Python to Excel
22
================
33

4-
This example scripts will go over how you can write from Python to Excel.
4+
This example scripts is written by Felix Khoi and will go over how you can write from Python to Excel.
55

66
The example will contain two versions, one simple and one more advanced.
77
In the simple one you will have to manually write code to write to Excel, it just contains a example of how you do it.
8-
The more advanced script will show a user dialog where it lets the user select excel-file, date, hours and project.
8+
The more advanced script will show a user dialog where it lets the user select excel-file, date, hours and project.
99

1010
OpenPyXL
1111
===========
1212

13-
The script uses the import [OpenPyXL](https://openpyxl.readthedocs.org/en/default/).
13+
The script uses the import [OpenPyXL](https://openpyxl.readthedocs.org/en/default/).
Lines changed: 94 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,94 @@
1-
import os
2-
import time
3-
4-
from openpyxl import load_workbook, Workbook
5-
from openpyxl.worksheet.properties import WorksheetProperties, PageSetupProperties
6-
from openpyxl.styles import Font
7-
8-
def main():
9-
"""Main function of script"""
10-
11-
intro()
12-
13-
time_file = input("Enter file (don't forget .xlsx): ")
14-
date = input("Enter date - Day/Month/Year\n(write \"now\" to use todays date): ")
15-
hours = input("Enter worked hours: ")
16-
project = input("Enter project name: ")
17-
18-
logToExcel(time_file, [date, hours, project])
19-
20-
def intro():
21-
"""Intro to the script"""
22-
print("\nThis is a worked hours tracker, made by Felix Khoi.\n")
23-
print("This script will save given date, hours and project to given excel-file.")
24-
print("If the file doesn't exist, it will create a new excel-file.\n")
25-
26-
def logToExcel(time_file, worked_hours):
27-
"""Function that logs to excel-file"""
28-
29-
print("\nStarting to search for file...")
30-
31-
#Checks if file already exists
32-
if(os.path.isfile(time_file)):
33-
print("\nFound " + time_file + "!")
34-
35-
#Loading excel file
36-
time_tracker_sheet = load_workbook(filename = time_file)
37-
38-
#Activates writing for given file
39-
writer = time_tracker_sheet.active
40-
else:
41-
#If file doesn't exist, create new excel-file
42-
time_tracker_sheet = Workbook()
43-
44-
#Activates writer for new excel-file
45-
writer = time_tracker_sheet.active
46-
47-
#Writes headers into new excel-file
48-
writer['A1'] = "Date"
49-
writer['B1'] = "Number of hours"
50-
writer['C1'] = "Project"
51-
52-
#Adding bold and increasing font size
53-
writer['A1'].font = Font(bold=True, size=16)
54-
writer['B1'].font = Font(bold=True, size=16)
55-
writer['C1'].font = Font(bold=True, size=16)
56-
57-
date = worked_hours[0]
58-
59-
#Checks if user wants to use today's date
60-
if(worked_hours[0] == "now"):
61-
#Gets today's date
62-
date = time.strftime("%d/%m/%Y")
63-
64-
#Appends worked hours to excel-file
65-
writer.append([date, worked_hours[1], worked_hours[2]])
66-
67-
#Sets the width of the columns "A", "B", "C"
68-
writer.column_dimensions["A"].width = 50.0
69-
writer.column_dimensions["B"].width = 50.0
70-
writer.column_dimensions["C"].width = 50.0
71-
72-
#Saves excel-file
73-
time_tracker_sheet.save(time_file)
74-
75-
print("\nDone, saved to " + time_file + "\n")
76-
77-
78-
if __name__ == "__main__":
79-
main()
1+
"""
2+
Python to Excel
3+
================
4+
5+
This example scripts is written by Felix Khoi and will go over how you can write from Python to Excel.
6+
7+
The example will contain two versions, one simple and one more advanced.
8+
In the simple one you will have to manually write code to write to Excel, it just contains a example of how you do it.
9+
The more advanced script will show a user dialog where it lets the user select excel-file, date, hours and project.
10+
11+
OpenPyXL
12+
===========
13+
14+
The script uses the import [OpenPyXL](https://openpyxl.readthedocs.org/en/default/).
15+
"""
16+
17+
18+
import os
19+
import time
20+
21+
from openpyxl import load_workbook, Workbook
22+
from openpyxl.styles import Font
23+
24+
def main():
25+
"""Main function of script"""
26+
27+
intro()
28+
29+
time_file = input("Enter file (don't forget .xlsx): ")
30+
date = input("Enter date - Day/Month/Year\n(write \"now\" to use todays date): ")
31+
hours = input("Enter worked hours: ")
32+
project = input("Enter project name: ")
33+
34+
logToExcel(time_file, [date, hours, project])
35+
36+
def intro():
37+
"""Intro to the script"""
38+
print("\nThis is a worked hours tracker, made by Felix Khoi.\n")
39+
print("This script will save given date, hours and project to given excel-file.")
40+
print("If the file doesn't exist, it will create a new excel-file.\n")
41+
42+
def logToExcel(time_file, worked_hours):
43+
"""Function that logs to excel-file"""
44+
45+
print("\nStarting to search for file...")
46+
47+
#Checks if file already exists
48+
if os.path.isfile(time_file):
49+
print("\nFound " + time_file + "!")
50+
51+
#Loading excel file
52+
time_tracker_sheet = load_workbook(filename=time_file)
53+
54+
#Activates writing for given file
55+
writer = time_tracker_sheet.active
56+
else:
57+
#If file doesn't exist, create new excel-file
58+
time_tracker_sheet = Workbook()
59+
60+
#Activates writer for new excel-file
61+
writer = time_tracker_sheet.active
62+
63+
#Writes headers into new excel-file
64+
writer['A1'] = "Date"
65+
writer['B1'] = "Number of hours"
66+
writer['C1'] = "Project"
67+
68+
#Adding bold and increasing font size
69+
writer['A1'].font = Font(bold=True, size=16)
70+
writer['B1'].font = Font(bold=True, size=16)
71+
writer['C1'].font = Font(bold=True, size=16)
72+
73+
date = worked_hours[0]
74+
75+
#Checks if user wants to use today's date
76+
if worked_hours[0] == "now":
77+
#Gets today's date
78+
date = time.strftime("%d/%m/%Y")
79+
80+
#Appends worked hours to excel-file
81+
writer.append([date, worked_hours[1], worked_hours[2]])
82+
83+
#Sets the width of the columns "A", "B", "C"
84+
writer.column_dimensions["A"].width = 50.0
85+
writer.column_dimensions["B"].width = 50.0
86+
writer.column_dimensions["C"].width = 50.0
87+
88+
#Saves excel-file
89+
time_tracker_sheet.save(time_file)
90+
91+
print("\nDone, saved to " + time_file + "\n")
92+
93+
if __name__ == "__main__":
94+
main()
Lines changed: 52 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,72 @@
1+
"""
2+
Python to Excel
3+
================
4+
5+
This example scripts is written by Felix Khoi and will go over how you can write from Python to Excel.
6+
7+
The example will contain two versions, one simple and one more advanced.
8+
In the simple one you will have to manually write code to write to Excel, it just contains a example of how you do it.
9+
The more advanced script will show a user dialog where it lets the user select excel-file, date, hours and project.
10+
11+
OpenPyXL
12+
===========
13+
14+
The script uses the import [OpenPyXL](https://openpyxl.readthedocs.org/en/default/).
15+
"""
16+
117
import os
218
import time
319

420
from openpyxl import load_workbook, Workbook
5-
from openpyxl.worksheet.properties import WorksheetProperties, PageSetupProperties
621
from openpyxl.styles import Font
722

823
def main():
9-
"""Main function of script"""
24+
"""Main function of script"""
1025

11-
#Checks if file already exists
12-
if(os.path.isfile("time-tracker.xlsx")):
13-
print("Found time tracker file!")
26+
#Checks if file already exists
27+
if os.path.isfile("time-tracker.xlsx"):
28+
print("Found time tracker file!")
1429

15-
#Loading excel file
16-
time_tracker_sheet = load_workbook(filename = 'time-tracker.xlsx')
30+
#Loading excel file
31+
time_tracker_sheet = load_workbook(filename='time-tracker.xlsx')
1732

18-
#Activates writing for given file
19-
writer = time_tracker_sheet.active
20-
else:
21-
#If file doesn't exist, create new excel-file
22-
time_tracker_sheet = Workbook()
33+
#Activates writing for given file
34+
writer = time_tracker_sheet.active
35+
else:
36+
#If file doesn't exist, create new excel-file
37+
time_tracker_sheet = Workbook()
2338

24-
#Activates writer for new excel-file
25-
writer = time_tracker_sheet.active
39+
#Activates writer for new excel-file
40+
writer = time_tracker_sheet.active
2641

27-
#Writes headers into new excel-file
28-
writer['A1'] = "Date"
29-
writer['B1'] = "Number of hours"
30-
writer['C1'] = "Project"
42+
#Writes headers into new excel-file
43+
writer['A1'] = "Date"
44+
writer['B1'] = "Number of hours"
45+
writer['C1'] = "Project"
3146

32-
#Adding bold and increasing font size
33-
writer['A1'].font = Font(bold=True, size=16)
34-
writer['B1'].font = Font(bold=True, size=16)
35-
writer['C1'].font = Font(bold=True, size=16)
47+
#Adding bold and increasing font size
48+
writer['A1'].font = Font(bold=True, size=16)
49+
writer['B1'].font = Font(bold=True, size=16)
50+
writer['C1'].font = Font(bold=True, size=16)
3651

37-
#Gets today's date
38-
dateAndTime = time.strftime("%d/%m/%Y")
52+
#Gets today's date
53+
dateAndTime = time.strftime("%d/%m/%Y")
3954

40-
#Appends worked hours to excel-file
41-
writer.append([dateAndTime, 3, "Python Project 1"])
42-
writer.append([dateAndTime, 7, "Python Project 3"])
43-
writer.append(["03/12/2015", 6, "Python Project 2"])
44-
writer.append(["05/12/2015", 1, "Python Project 4"])
55+
#Appends worked hours to excel-file
56+
writer.append([dateAndTime, 3, "Python Project 1"])
57+
writer.append([dateAndTime, 7, "Python Project 3"])
58+
writer.append(["03/12/2015", 6, "Python Project 2"])
59+
writer.append(["05/12/2015", 1, "Python Project 4"])
4560

46-
#Sets the width of the columns "A", "B", "C"
47-
writer.column_dimensions["A"].width = 50.0
48-
writer.column_dimensions["B"].width = 50.0
49-
writer.column_dimensions["C"].width = 50.0
61+
#Sets the width of the columns "A", "B", "C"
62+
writer.column_dimensions["A"].width = 50.0
63+
writer.column_dimensions["B"].width = 50.0
64+
writer.column_dimensions["C"].width = 50.0
5065

51-
#Saves excel-file
52-
time_tracker_sheet.save("time-tracker.xlsx")
66+
#Saves excel-file
67+
time_tracker_sheet.save("time-tracker.xlsx")
5368

54-
print("Done, saved to time-tracker.xlsx")
69+
print("Done, saved to time-tracker.xlsx")
5570

5671
if __name__ == "__main__":
57-
main()
72+
main()

‎example/ping/ping.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
"""
55
Example of how to ping a webpage for a status code, basically just
6-
to check that the page is there and the webserver is replying with
6+
to check that the page is there and the webserver is replying with
77
a positive code, such as 200.
88
99
More information: http://stackoverflow.com/a/13641613
@@ -15,8 +15,8 @@
1515

1616
print(__doc__)
1717

18-
import requests
1918
import time
19+
import requests
2020

2121

2222
url = "http://dbwebb.se/humans.txt"

0 commit comments

Comments
 (0)