Last active
December 18, 2015 13:19
-
-
Save SamuelMarks/5789380 to your computer and use it in GitHub Desktop.
Python script to help me keep track of how much of the university material I have gotten through up until exams
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import win32com.client # If I can be bothered, will switch to using an Open Source cross-platform API | |
from glob import glob | |
from PyPDF2 import PdfFileReader | |
from os import getcwd | |
from datetime import datetime | |
def pdf_page_count(filename): | |
curr = open(filename, "rb") | |
page_count = PdfFileReader(curr).getNumPages() | |
curr.close() | |
return page_count | |
def presentation_slide_count(filename): | |
Presentation = PowerPoint.Presentations.Open(getcwd() + '\\' + filename) | |
slide_count = len(Presentation.Slides) | |
return slide_count | |
def document_page_count(filename): | |
Doc = Word.Documents.Open(getcwd() + '\\' + filename) | |
page_count = Doc.ActiveWindow.Panes(1).Pages.Count | |
return page_count | |
if __name__ == '__main__': | |
powerpoints = glob('*/*/*.pptx') + glob('*/*/*.ppt') | |
documents = glob('*/*/*.docx') + glob('*/*/*.doc') | |
pdf = glob('*/*/*.pdf') | |
PowerPoint = win32com.client.Dispatch("PowerPoint.Application") | |
#Word = win32com.client.Dispatch("Word.Application") | |
total_pdf_pages = sum([pdf_page_count(pdf) for pdf in pdf]) | |
total_powerpoint_slides = sum([presentation_slide_count(presentation) | |
for presentation in powerpoints]) | |
#document_page_count = sum([document_page_count(document) | |
# for document in documents]) | |
#print 'document_page_count = {0}'.format(document_page_count) | |
print 'total_pdf_pages = {0}'.format(total_pdf_pages) | |
print 'total_powerpoint_slides = {0}'.format(total_powerpoint_slides) | |
total_slide_count = total_pdf_pages + total_powerpoint_slides | |
done = 449.0 | |
exams_start = datetime(year=2013, month=6, day=20, hour=13, minute=20) | |
while exams_start > datetime.now(): | |
done = float(raw_input('\nHow many slides are you through now? [last_count={0}]: '.format(done))) | |
time_left = exams_start - datetime.now() | |
print '{0}% through'.format(done / total_slide_count * 100) | |
print 'Need to do {per_day} for the next {days_left} days and {hours_left} hours'.format( | |
per_day=(total_slide_count - done) / time_left.days, | |
days_left=time_left.days, | |
hours_left=time_left.total_seconds() / (60 * 60) % 24) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment