Skip to content

Instantly share code, notes, and snippets.

View akshaykarnawat's full-sized avatar

Akshay Karnawat akshaykarnawat

View GitHub Profile
@akshaykarnawat
akshaykarnawat / crawlAlumniEventsRIT
Last active August 29, 2015 14:22
Crawl RIT Alumni Events Page
#!/usr/bin/python
import smtplib
import requests
import traceback
from bs4 import BeautifulSoup
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
@akshaykarnawat
akshaykarnawat / list_of_snp500_companies.py
Created June 6, 2017 04:18
List of S&P 500 companies from Wikipedia
import requests
from bs4 import BeautifulSoup
def getWikipediaPageWithListOfStocks():
r = requests.get('https://en.wikipedia.org/wiki/List_of_S%26P_500_companies')
if(r.status_code != 200):
return
return processDocument(r.text)
@akshaykarnawat
akshaykarnawat / finviz_news_info.py
Created June 6, 2017 04:24
Get the news information from FinViz for a particular stock
import json
import requests
from dateutil.parser import parse
from dateutil.parser import parserinfo
from datetime import datetime
from datetime import timedelta
from bs4 import BeautifulSoup
def getNewsFromFinViz(ticker):
@akshaykarnawat
akshaykarnawat / birthday_problem.py
Created June 30, 2017 03:09
Finds the probability of two people sharing the same birthday with the given number of people in the room
import pylab
import numpy as np
# The function finds the probability of two people have the same
# birthday with the given number of people in the room
def findProbability(n):
x = [] # the x range of values to plot
y = [] # the y range of values to plot
p = 1 # the probability
@akshaykarnawat
akshaykarnawat / music_player.py
Last active February 17, 2018 14:39
Terminal music player written in python. Plays the music from the file path specified.
#! usr/bin/python
"""
Plays the music in the directory specified
"""
import sys
from os import listdir, system
from os.path import isfile, isdir, join
def get_music_files(path):
@akshaykarnawat
akshaykarnawat / email_sender.py
Created July 15, 2017 16:32
Python email sender
'''
Email Sender
'''
import smtplib
import traceback
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
@akshaykarnawat
akshaykarnawat / cd_ladder.py
Created July 18, 2017 03:51
Find the benefit of investing in a CD Ladder compared to the High Yield Online Savings account given some assumptions
# coding: utf-8
'''
### Benefits of CD Ladder vs. Online Savings
Find the benefit of investing in a CD Ladder compared to the High Yield Online Savings account given some assumptions.
Assumptions:
* Investment in CD Ladder for various buckets; not the highest CD bucket rate available for the term.
* Only considers CD buckets that have the higher interest rate than the online savings account.
* Equal distribution into each selected bucket; based on the above assumptions.
@akshaykarnawat
akshaykarnawat / multi_processing_pool.py
Created October 11, 2017 02:52
Multi-Processing in python
from multiprocessing.pool import Pool
import requests
import time
def page(symbol):
requests.get(url='https://finviz.com/quote.ashx?t=' + symbol)
start = time.time()
p = Pool()
p.map(page, ['AAPL', 'AMZN', 'GOOG', 'MSFT', 'FB'])
@akshaykarnawat
akshaykarnawat / invesco_fund_holdings.py
Last active February 6, 2018 04:22
Get holding details for invesco ETFs and see %change histogram of historical data within the invesco fund
import io
import json
import math
import requests
import pandas as pd
import datetime as dt
from os import makedirs
from os.path import isdir
from bs4 import BeautifulSoup
from itertools import compress
@akshaykarnawat
akshaykarnawat / recursive_dict_object.py
Created February 6, 2018 03:42
Recursive Object Dictionary in Python
import uuid
import json
max_count = 200 #982 # use sys.setrecursionlimit(1000) for higher limits
count = 0
dd = { 'id': str(uuid.uuid4()), 'obj': None }
def objectOfObject(obj, count, max_count):
# print(obj)
obj['obj'] = { 'id': str(uuid.uuid4()) }