Skip to content

Instantly share code, notes, and snippets.

@mclemme
Last active December 18, 2015 05:59
Show Gist options
  • Save mclemme/5736279 to your computer and use it in GitHub Desktop.
Save mclemme/5736279 to your computer and use it in GitHub Desktop.
Fetches account balance from Partner-Ads and speaks out how much money you made since it last changed.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#Your unique key from https://partner-ads.com/dk/udtraek.php
KEY='12345'
INTERVAL=600
from urllib2 import urlopen
from xml.etree import ElementTree as ET
from os import system
from time import sleep
from decimal import *
import sys
def fetch_balance():
tree = ET.parse(urlopen('http://partner-ads.com/dk/saldo_xml.php?key='+KEY))
balance_txt = tree.getroot()[0][1].text
return Decimal(balance_txt.replace('.','').replace(',','.'))
def speak(words):
system("espeak '"+words+"' -v da+f3 -m -p 60 -s 120 --stdout|paplay")
balance = fetch_balance()
print 'Initial balance: '+str(balance)
while(True):
new_balance = fetch_balance()
if(new_balance > balance):
difference = new_balance - balance
print '\nEarned: '+str(difference)+' new balance: '+str(new_balance)
kr = difference - (Decimal(difference) % 1)
oere = Decimal(difference) % 1
if(kr and oere):
speak(str(int(kr))+' kroner og '+str(int(100*oere))+' øre tjent')
elif(kr and not oere):
speak(str(int(kr))+' kroner tjent')
elif(oere and not kr):
speak(str(int(100*oere))+' øre tjent')
balance = new_balance
sys.stdout.write('.')
sys.stdout.flush()
sleep(INTERVAL)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment