Skip to content
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
11 changes: 5 additions & 6 deletions example/curses/orig/snake.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/env python3
"""
Testing out the curses lib.

Expand All @@ -7,7 +7,6 @@
#from curses import wrapper
import curses
import random
from curses import KEY_RIGHT, KEY_LEFT, KEY_UP, KEY_DOWN

def main(screen):
"""
Expand Down Expand Up @@ -66,16 +65,16 @@ def main(screen):
screen.refresh()
curses.napms(2500)
break
elif key == KEY_UP:
elif key == curses.KEY_UP:
dirs["y"] = -1
dirs["x"] = 0
elif key == KEY_DOWN:
elif key == curses.KEY_DOWN:
dirs["y"] = 1
dirs["x"] = 0
elif key == KEY_LEFT:
elif key == curses.KEY_LEFT:
dirs["x"] = -1
dirs["y"] = 0
elif key == KEY_RIGHT:
elif key == curses.KEY_RIGHT:
dirs["x"] = 1
dirs["y"] = 0

Expand Down
6 changes: 3 additions & 3 deletions example/excel/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Python to Excel
================

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

The example will contain two versions, one simple and one more advanced.
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.
The more advanced script will show a user dialog where it lets the user select excel-file, date, hours and project.
The more advanced script will show a user dialog where it lets the user select excel-file, date, hours and project.

OpenPyXL
===========

The script uses the import [OpenPyXL](https://openpyxl.readthedocs.org/en/default/).
The script uses the import [OpenPyXL](https://openpyxl.readthedocs.org/en/default/).
173 changes: 94 additions & 79 deletions example/excel/advanced-worked-hours-tracker.py
Original file line number Diff line number Diff line change
@@ -1,79 +1,94 @@
import os
import time

from openpyxl import load_workbook, Workbook
from openpyxl.worksheet.properties import WorksheetProperties, PageSetupProperties
from openpyxl.styles import Font

def main():
"""Main function of script"""

intro()

time_file = input("Enter file (don't forget .xlsx): ")
date = input("Enter date - Day/Month/Year\n(write \"now\" to use todays date): ")
hours = input("Enter worked hours: ")
project = input("Enter project name: ")

logToExcel(time_file, [date, hours, project])

def intro():
"""Intro to the script"""
print("\nThis is a worked hours tracker, made by Felix Khoi.\n")
print("This script will save given date, hours and project to given excel-file.")
print("If the file doesn't exist, it will create a new excel-file.\n")

def logToExcel(time_file, worked_hours):
"""Function that logs to excel-file"""

print("\nStarting to search for file...")

#Checks if file already exists
if(os.path.isfile(time_file)):
print("\nFound " + time_file + "!")

#Loading excel file
time_tracker_sheet = load_workbook(filename = time_file)

#Activates writing for given file
writer = time_tracker_sheet.active
else:
#If file doesn't exist, create new excel-file
time_tracker_sheet = Workbook()

#Activates writer for new excel-file
writer = time_tracker_sheet.active

#Writes headers into new excel-file
writer['A1'] = "Date"
writer['B1'] = "Number of hours"
writer['C1'] = "Project"

#Adding bold and increasing font size
writer['A1'].font = Font(bold=True, size=16)
writer['B1'].font = Font(bold=True, size=16)
writer['C1'].font = Font(bold=True, size=16)

date = worked_hours[0]

#Checks if user wants to use today's date
if(worked_hours[0] == "now"):
#Gets today's date
date = time.strftime("%d/%m/%Y")

#Appends worked hours to excel-file
writer.append([date, worked_hours[1], worked_hours[2]])

#Sets the width of the columns "A", "B", "C"
writer.column_dimensions["A"].width = 50.0
writer.column_dimensions["B"].width = 50.0
writer.column_dimensions["C"].width = 50.0

#Saves excel-file
time_tracker_sheet.save(time_file)

print("\nDone, saved to " + time_file + "\n")


if __name__ == "__main__":
main()
"""
Python to Excel
================

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

The example will contain two versions, one simple and one more advanced.
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.
The more advanced script will show a user dialog where it lets the user select excel-file, date, hours and project.

OpenPyXL
===========

The script uses the import [OpenPyXL](https://openpyxl.readthedocs.org/en/default/).
"""


import os
import time

from openpyxl import load_workbook, Workbook
from openpyxl.styles import Font

def main():
"""Main function of script"""

intro()

time_file = input("Enter file (don't forget .xlsx): ")
date = input("Enter date - Day/Month/Year\n(write \"now\" to use todays date): ")
hours = input("Enter worked hours: ")
project = input("Enter project name: ")

logToExcel(time_file, [date, hours, project])

def intro():
"""Intro to the script"""
print("\nThis is a worked hours tracker, made by Felix Khoi.\n")
print("This script will save given date, hours and project to given excel-file.")
print("If the file doesn't exist, it will create a new excel-file.\n")

def logToExcel(time_file, worked_hours):
"""Function that logs to excel-file"""

print("\nStarting to search for file...")

#Checks if file already exists
if os.path.isfile(time_file):
print("\nFound " + time_file + "!")

#Loading excel file
time_tracker_sheet = load_workbook(filename=time_file)

#Activates writing for given file
writer = time_tracker_sheet.active
else:
#If file doesn't exist, create new excel-file
time_tracker_sheet = Workbook()

#Activates writer for new excel-file
writer = time_tracker_sheet.active

#Writes headers into new excel-file
writer['A1'] = "Date"
writer['B1'] = "Number of hours"
writer['C1'] = "Project"

#Adding bold and increasing font size
writer['A1'].font = Font(bold=True, size=16)
writer['B1'].font = Font(bold=True, size=16)
writer['C1'].font = Font(bold=True, size=16)

date = worked_hours[0]

#Checks if user wants to use today's date
if worked_hours[0] == "now":
#Gets today's date
date = time.strftime("%d/%m/%Y")

#Appends worked hours to excel-file
writer.append([date, worked_hours[1], worked_hours[2]])

#Sets the width of the columns "A", "B", "C"
writer.column_dimensions["A"].width = 50.0
writer.column_dimensions["B"].width = 50.0
writer.column_dimensions["C"].width = 50.0

#Saves excel-file
time_tracker_sheet.save(time_file)

print("\nDone, saved to " + time_file + "\n")

if __name__ == "__main__":
main()
89 changes: 52 additions & 37 deletions example/excel/simple-worked-hours-tracker.py
Original file line number Diff line number Diff line change
@@ -1,57 +1,72 @@
"""
Python to Excel
================

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

The example will contain two versions, one simple and one more advanced.
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.
The more advanced script will show a user dialog where it lets the user select excel-file, date, hours and project.

OpenPyXL
===========

The script uses the import [OpenPyXL](https://openpyxl.readthedocs.org/en/default/).
"""

import os
import time

from openpyxl import load_workbook, Workbook
from openpyxl.worksheet.properties import WorksheetProperties, PageSetupProperties
from openpyxl.styles import Font

def main():
"""Main function of script"""
"""Main function of script"""

#Checks if file already exists
if(os.path.isfile("time-tracker.xlsx")):
print("Found time tracker file!")
#Checks if file already exists
if os.path.isfile("time-tracker.xlsx"):
print("Found time tracker file!")

#Loading excel file
time_tracker_sheet = load_workbook(filename = 'time-tracker.xlsx')
#Loading excel file
time_tracker_sheet = load_workbook(filename='time-tracker.xlsx')

#Activates writing for given file
writer = time_tracker_sheet.active
else:
#If file doesn't exist, create new excel-file
time_tracker_sheet = Workbook()
#Activates writing for given file
writer = time_tracker_sheet.active
else:
#If file doesn't exist, create new excel-file
time_tracker_sheet = Workbook()

#Activates writer for new excel-file
writer = time_tracker_sheet.active
#Activates writer for new excel-file
writer = time_tracker_sheet.active

#Writes headers into new excel-file
writer['A1'] = "Date"
writer['B1'] = "Number of hours"
writer['C1'] = "Project"
#Writes headers into new excel-file
writer['A1'] = "Date"
writer['B1'] = "Number of hours"
writer['C1'] = "Project"

#Adding bold and increasing font size
writer['A1'].font = Font(bold=True, size=16)
writer['B1'].font = Font(bold=True, size=16)
writer['C1'].font = Font(bold=True, size=16)
#Adding bold and increasing font size
writer['A1'].font = Font(bold=True, size=16)
writer['B1'].font = Font(bold=True, size=16)
writer['C1'].font = Font(bold=True, size=16)

#Gets today's date
dateAndTime = time.strftime("%d/%m/%Y")
#Gets today's date
dateAndTime = time.strftime("%d/%m/%Y")

#Appends worked hours to excel-file
writer.append([dateAndTime, 3, "Python Project 1"])
writer.append([dateAndTime, 7, "Python Project 3"])
writer.append(["03/12/2015", 6, "Python Project 2"])
writer.append(["05/12/2015", 1, "Python Project 4"])
#Appends worked hours to excel-file
writer.append([dateAndTime, 3, "Python Project 1"])
writer.append([dateAndTime, 7, "Python Project 3"])
writer.append(["03/12/2015", 6, "Python Project 2"])
writer.append(["05/12/2015", 1, "Python Project 4"])

#Sets the width of the columns "A", "B", "C"
writer.column_dimensions["A"].width = 50.0
writer.column_dimensions["B"].width = 50.0
writer.column_dimensions["C"].width = 50.0
#Sets the width of the columns "A", "B", "C"
writer.column_dimensions["A"].width = 50.0
writer.column_dimensions["B"].width = 50.0
writer.column_dimensions["C"].width = 50.0

#Saves excel-file
time_tracker_sheet.save("time-tracker.xlsx")
#Saves excel-file
time_tracker_sheet.save("time-tracker.xlsx")

print("Done, saved to time-tracker.xlsx")
print("Done, saved to time-tracker.xlsx")

if __name__ == "__main__":
main()
main()
4 changes: 2 additions & 2 deletions example/ping/ping.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

"""
Example of how to ping a webpage for a status code, basically just
to check that the page is there and the webserver is replying with
to check that the page is there and the webserver is replying with
a positive code, such as 200.

More information: http://stackoverflow.com/a/13641613
Expand All @@ -15,8 +15,8 @@

print(__doc__)

import requests
import time
import requests


url = "http://dbwebb.se/humans.txt"
Expand Down
Loading