Browse Source

categories

David 10 years ago
parent
commit
c36dac154f
3 changed files with 12 additions and 3 deletions
  1. 4 1
      news.py
  2. 2 1
      parser.py
  3. 6 1
      web.py

+ 4 - 1
news.py

@@ -23,12 +23,14 @@ class News():
     MATCHES=False
     MATCHING_KW=[]
     TITLE=""
+    CATEGORY=0
 
-    def __init__(self,url,sourceid, sourcename,kw,lang="en",html=None):
+    def __init__(self,url,sourceid, sourcename,sourcecategory,kw,lang="en",html=None):
         url=sanitizeUrl(url)
         self.URL=url
         self.SOURCENAME=sourcename
         self.SOURCE=sourceid
+        self.CATEGORY=sourcecategory
         self.MATCHING_KW=[]
 
         a=None
@@ -87,6 +89,7 @@ class News():
                 "html": self.HTML, 
                 "error": self.ERROR,
                 "deleted": False,
+                "category": self.CATEGORY,
                 "title": self.TITLE
                 }
 

+ 2 - 1
parser.py

@@ -50,6 +50,7 @@ def parseSource(s):
 def news_worker(source,kw):
     source_id=source["_id"]
     source_name=source["name"]
+    source_category=source["category"]
     paid=False
     if "paid" in source and source["paid"]:
         paid=True
@@ -74,7 +75,7 @@ def news_worker(source,kw):
                 p=PaidParser(item)
                 html=p.html
 
-            n=News(item,source_id,source_name,kw,html=html)
+            n=News(item,source_id,source_name,source_category,kw,html=html)
             print("[Thread %s] Finished" % tname)
             d.insert_article(n.get())
         except Exception as e:

+ 6 - 1
web.py

@@ -24,7 +24,12 @@ def add_source():
     if "rss" in json:
         rss=json["rss"]
 
-    d.add_source(json["source"],rss,selector,json["name"])
+    if "category" not in json:
+        json["category"]=1
+
+    
+    json["category"]=int(json["category"])
+    d.add_source(json["source"],rss,selector,json["name"],json["category"])
     return jsonify({'ok': "ok"}) 
 
 @app.route(BASEPATH+'/source/test/', methods=['POST'])