Skip to content

Instantly share code, notes, and snippets.

View davetromp's full-sized avatar

Dave Tromp davetromp

View GitHub Profile
@davetromp
davetromp / dtnt-regression.ipynb
Created November 4, 2019 22:28
dtnt-regression.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#!/usr/bin/python3
"""
http://www.davetromp.net/2017/03/learn-how-to-code-with-python-lesson-1.html
Learn how to code with python: Lesson 1 - Hello World!
Lesson 1
Basics
Programming paradigms
- Scripting ***
- Procedural **
- Object oriented *
import urllib.request
def getData(ticker):
url = "http://chart.finance.yahoo.com/table.csv?s={}&a=1&b=12&c=2017&d=2&e=12&f=2017&g=d&ignore=.csv".format(ticker)
data = urllib.request.urlopen(url)
doc = open("yahoo_finance_{}.csv".format(ticker), 'w')
doc.write(data.read().decode("utf8"))
doc.close()
# the code is explained here: https://youtu.be/Eex4zBc9r7Y
import os
def main():
files = os.listdir("./")
for f in files:
if f.lower()[-3:] == "mp4":
print "processing", f
process(f)
@davetromp
davetromp / plus500tickers.py
Last active February 28, 2017 22:38
Get links to data referenced by plus500.com
import re
import time
import mechanize
br = mechanize.Browser()
br.set_handle_robots(False) # ignore robots
br.set_handle_refresh(False) # can sometimes hang without this
br.addheaders = [('User-agent', 'Firefox')]
@davetromp
davetromp / SiteMonitor.py
Created May 25, 2013 21:30
A simple website monitor in python
#!/usr/bin/env python
## Check out: https://github.com/davetromp/SiteMonitor for the complete and current code
import urllib
import smtplib
import time
import datetime
import sys
@davetromp
davetromp / csv2loc.py
Created February 24, 2013 22:47
# This python script will loop through a csv file and put the first column in # the id field and the second in the description field of a localization file. # The csv file needs to be UTF-8 encoded. Delimiter is a comma, no quotes please.
import sys
# DT 24-2-2013
# This python script will loop through a csv file and put the first column in
# in the id field and the second in the description field of a localization file.
# The csv file needs to be UTF-8 encoded. Delimiter is a comma, no quotes please.
#write the standaard output to a file
sys.stdout = open('output.xml', 'w')
@echo off
:: This script checks a files size
:: If it is less then a certain size, it will be switched by a previous
:: version of the file. If the filesize is OK it will be copied to a backup location.
setlocal
:: location of the file
set dir=D:\import
@davetromp
davetromp / sharpratio.sh
Created December 9, 2012 22:49
This bash script calculates the sharpratio on yahoo finance data
#!/bin/bash
# this script will read in a ohlc file from yahoo finance line by line
# putting every line in a list / array as an element
# and then do some basic calculations on the numbers
# we will calculate the absolute return, the avarage daily differences,
# the standard deviation of the daily differences and finally the sharp ratio
fname=$1
readin(){
@davetromp
davetromp / UpOrDown.sh
Created November 28, 2012 22:29
Bash script that checks if a site is up or down and emails notifications
#!/bin/bash
################################################################################
# This script will check to see if a website is up/down by pinging the url
# If there is no response an email wil be send via an external smtp mail server
# If the site status is down an email will be send when the site is up again
# set your check interval here :-) #############################################
interval=3600 # hour