#!/usr/bin/python

# Author: www.sven-seeberg.de

# /*
# *This program is free software; you can redistribute it and/or modify 
# * it under the terms of the GNU General Public License as published by 
# * the Free Software Foundation; either version 2 of the License, or 
# * (at your option) any later version.
# * 
# * This program is distributed in the hope that it will be useful, but 
# * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
# * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 
# * for more details.
# * 
# * You should have received a copy of the GNU General Public License along 
# * with this program; if not, write to the Free Software Foundation, Inc., 
# * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# */

from pynotify import *
import sys
import httplib
import time
date_alt=""
while 1==1:
  
  tagesschau = httplib.HTTPConnection("www.tagesschau.de")
  tagesschau.request("GET", "/nachrichtenticker/")
  result = tagesschau.getresponse()
  data = result.read()
  tagesschau.close()
  
  start = data.find("<span class=\"topline\">")
  endespan = data.find("</span>",start)
  h2_anfang = data.find("<h2>",start)
  h2_ende = data.find("</h2>",start)
  text_ende = data.find("</p>",start)
  date = data[start+28:endespan]
  if date!=date_alt:
    ueberschrift = date
    ueberschrift += " "
    ueberschrift += data[h2_anfang+4:h2_ende]
    text = data[h2_ende+9:text_ende]
    n = Notification(ueberschrift, text)
    n.show()
    date_alt=date
  time.sleep(10)

