Skip to content

Instantly share code, notes, and snippets.

@vinovator
vinovator / RateCalculator.py
Last active December 18, 2015 16:04
A python program that makes use of decorator. Our imaginary software consultant/ contractor uses this program to generate invoice for his various services
# RateCalculator.py
# Python 2.7.6
"""
A python program that makes use of decorator. Our imaginary software
consultant/ contractor uses this program to generate invoice for his
various services
"""
@vinovator
vinovator / myDecorator.py
Last active December 17, 2015 22:56
A simple decorator example in python
# python 2.7.6
# myDecorator.py
"""
A simple decorator example in python
"""
class SimpleClass:
"""
A simple class with add and subtract methods, undecorated
@vinovator
vinovator / extractXmlFromXL.py
Last active December 10, 2015 17:36
Script to download all xml files from the urls specified in the excel report. Requires requests, tkinter and openpyxl modules
# Python 2.7.6
# extractXmlFromXl.py
"""
Script to download all xml files from the urls specified in the excel report
Requires requests and openpyxl modules
"""
import requests
from requests.auth import HTTPDigestAuth # To access url with digest authentication
@vinovator
vinovator / tktk.py
Last active December 8, 2015 22:31
Tinkering with Tkinter
# tktk.py
# Python 2.7.6
"""
A simple form that prompts for name and prints it back
"""
import Tkinter as tk # use "tkinter" for python 3.x
# All widgets belong to a parent which is defined first
@vinovator
vinovator / pptPlay.py
Last active April 9, 2025 03:38
Creating & editing PPT documents using python-pptx module
# pptPlay.py
# Python 2.76
# Importing python-pptx module
from pptx import Presentation
# This is the template based on which PPT will be created
# If None is passed then blank ppt with no slides will be created
PPT_TEMPLATE = None
@vinovator
vinovator / CombinePDF_Py2.py
Created November 17, 2015 10:36
Combine 2 PDF files into a single file using PyPDF2 module. Python 2.7.6 version
#Python 2.7.6
#CombinePDF_Py2.py
#Gets raw_inputs of 2 PDF file names from user and combines them into 1
import PyPDF2
import os
def getFileNameFromUser (file, path):
pdf_file_name = raw_input("Enter {0} name: ".format(file))
if pdf_file_name in os.listdir(path):
@vinovator
vinovator / DemergePDF.py
Created November 17, 2015 10:35
Divide a PDF file into 2 separate PDF files using PyPDF2 module
#Python 2.7.6
#DemergePDF.py
#Gets raw_inputs of 1 PDF file names from user and demerge into 2
import PyPDF2
import os
def getFileNameFromUser (file, path):
pdf_file_name = raw_input("Enter {0} name: ".format(file))
if pdf_file_name in os.listdir(path):
@vinovator
vinovator / persistListOfDicts1.py
Created November 16, 2015 17:13
Persist dicts using Json instead of pickle
# persistListOfDicts.py
# Python 2.7.6
import json
import os
json_path = "./JSON"
# Write dicts into a pickle file each
@vinovator
vinovator / Logger.py
Last active November 16, 2015 17:20
Basic logging example using logging module
# Logger.py
# Python2.7.6
# For more details - https://docs.python.org/3/howto/logging.html#logging-basic-tutorial
# logging.error - just displays the error message
# logging.exception - displays the stack trace along with the error message
import logging # For logs
import sys # To read parameters from command line
# Define the format of the logging
@vinovator
vinovator / persistListOfDicts.py
Last active November 13, 2015 16:28
Persist a list of dicts using pickle
# persistListOfDicts.py
# Python 2.7.6
import json
import os
import pickle # To persist each dict
json_path = "./JSON"