import feedparser
from docclass import Classifier
from docclass import getwords


def stripHTML(h):
  p=''
  s=0
  for c in h:
    if c=='<': s=1
    elif c=='>':
      s=0
      p+=' '
    elif s==0:
      p+=c
  return p


trainTech=['http://rss.chip.de/c/573/f/7439/index.rss',
           'http://feeds.feedburner.com/netzwelt',
           'http://rss1.t-online.de/c/11/53/06/84/11530684.xml',
           'http://www.computerbild.de/rssfeed_2261.xml?node=13',
           'http://www.heise.de/newsticker/heise-top-atom.xml']

trainNonTechOriginal=['http://newsfeed.zeit.de/index',
              'http://newsfeed.zeit.de/wirtschaft/index',
              'http://www.welt.de/politik/?service=Rss',
              'http://www.spiegel.de/schlagzeilen/tops/index.rss',
              'http://www.sueddeutsche.de/app/service/rss/alles/rss.xml'
              ]
#Wirtschaftsfeeds
trainNonTech=[
              'http://newsfeed.zeit.de/wirtschaft/index',
              'http://www.handelsblatt.com/contentexport/feed/schlagzeilen',
              'http://www.manager-magazin.de/news/index.rss',
              'http://www.wiwo.de/contentexport/feed/rss/schlagzeilen'
              ]

test=["http://rss.golem.de/rss.php?r=sw&feed=RSS0.91",
          'http://newsfeed.zeit.de/politik/index',  
          'http://www.welt.de/?service=Rss'
           ]

countnews={}
countnews['tech']=0
countnews['nontech']=0
countnews['test']=0


c = Classifier(getwords, a = "Tech", b = "NonTech", initprob=0.5)

print "--------------------News from trainTech------------------------"
for feed in trainTech:
    f=feedparser.parse(feed)
    for e in f.entries:
        print '\n---------------------------'
        fulltext=stripHTML(e.title+' '+e.description)
        print fulltext
        countnews['tech']+=1

        c.train(fulltext,"Tech")

print "----------------------------------------------------------------"
print "----------------------------------------------------------------"
print "----------------------------------------------------------------"

print "--------------------News from trainNonTech------------------------"
for feed in trainNonTech:
    f=feedparser.parse(feed)
    for e in f.entries:
        print '\n---------------------------'
        fulltext=stripHTML(e.title+' '+e.description)
        print fulltext
        countnews['nontech']+=1
        c.train(fulltext, "NonTech")

print "----------------------------------------------------------------"
print "----------------------------------------------------------------"
print "----------------------------------------------------------------"

print "--------------------News from test------------------------"
for feed in test:
    f=feedparser.parse(feed)
    for e in f.entries:
        print '\n---------------------------'
        fulltext=stripHTML(e.title+' '+e.description)
        print fulltext
        countnews['test']+=1

        print("Klassifikation: " + c.classify(fulltext))

print "----------------------------------------------------------------"
print "----------------------------------------------------------------"
print "----------------------------------------------------------------"

print 'Number of used trainings samples in categorie tech',countnews['tech']
print 'Number of used trainings samples in categorie notech',countnews['nontech']
print 'Number of used test samples',countnews['test']
print '--'*30





@@ -537,16 +537,8 @@
 Tech
-Original
 =%5B'h
@@ -560,32 +560,32 @@
 zeit.de/index',%0A
+
               'h
@@ -842,325 +842,8 @@
    %5D
-%0A#Wirtschaftsfeeds%0AtrainNonTech=%5B%0A              'http://newsfeed.zeit.de/wirtschaft/index',%0A              'http://www.handelsblatt.com/contentexport/feed/schlagzeilen',%0A              'http://www.manager-magazin.de/news/index.rss',%0A              'http://www.wiwo.de/contentexport/feed/rss/schlagzeilen'%0A              %5D
 %0A%0Ate
@@ -1084,16 +1084,16 @@
 t'%5D=0%0A%0A%0A
+
 c = Clas
@@ -1112,35 +1112,8 @@
 rds,
- a = %22Tech%22, b = %22NonTech%22,
  ini

reset parseTechFeed.py to the original state with no additional categories.