Skip to content

Instantly share code, notes, and snippets.

@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"
@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 / 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 / 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 / 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 / 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 / gistsDownloader.py
Created December 20, 2015 12:57
Download all gists from a specific user
# gistsDownloader.py
# Python 3.4
import requests
username = "vinovator"
url = "https://api.github.com/users/" + username + "/gists"
resp = requests.get(url)
@vinovator
vinovator / keywordExtractor.py
Created January 11, 2016 13:30
Extract keywords from a text by eliminating stop words, punctuations etc
# keywordExtractor.py
# Python 2.7.6
import requests
import re
from collections import Counter
"""
Step 1: Obtain Text
Step 2: Strip punctuation, special characters, etc.
@vinovator
vinovator / Cricinfoscraper_py2.py
Last active January 21, 2016 13:57
Simple webscraper to download cartoon strips from cricinfo site.
# python 2.7.6
# Cricinfoscraper_py2.py
"""
Simple webscraper to download cartoons from cricinfo site.
The url is http://www.espncricinfo.com/ci/content/story/author.html?author=333
Changed the code to dynamically scroll the page to fetch more cartoons.
Using Splinter/ Selenium library to fetch javascript rendered content
"""