#!/usr/bin/env python
#-*- coding: utf-8 -*-

"""
scrape is a task to scrape rss resources
"""
# @author chengdujin
# @contact chengdujin@gmail.com
# @created Aug. 14, 2013


import sys
reload(sys)
sys.setdefaultencoding('UTF-8')
#sys.path.append('/home/work/newsman/newsman')
#sys.path.append('/home/users/jinyuan/newsman/newsman')
#sys.path.append('/home/ubuntu/newsman/newsman')
#sys.path.append('/home/jinyuan/Downloads/newsman/newsman')

from config.settings import Collection, db
from config.settings import logger
from spider import scraper

# CONSTANTS
from config.settings import FEED_REGISTRAR


def _update(feed_ids):
    """
    update links find in feeds
    """
    if not feed_ids:
        logger.error("No feed found!")
        return None

    try:
        for feed_id in feed_ids:
            updated = scraper.update(feed_id=feed_id)
            if not updated:
                logger.info('Nothing got updated from %s' % feed_id)
            else:
                logger.info('%s got updated' % feed_id)
    except Exception as k:
        logger.error(str(k))
        return None


def _read_feeds(language='en'):
    """
    read feed information from database feeds
    """
    try:
        db_feeds = Collection(db, FEED_REGISTRAR)
        items = db_feeds.find({'language': language})
        if items:
            return [str(item['_id']) for item in items]
        else:
            logger.error("Cannot find any feeds for language %s!" % language)
            return None
    except Exception as k:
        logger.error(str(k))
        return None


def _scrape(language):
    """
    update news from stored feeds
    """
    logger.info('----------------------scraping-------------------------')
    _update(_read_feeds(language))


if __name__ == "__main__":
    language = sys.argv[1]
    _scrape(language)

@@ -220,24 +220,25 @@
 g('UTF-8')%0A#
+ 
 sys.path.app
@@ -264,32 +264,33 @@
 sman/newsman')%0A#
+ 
 sys.path.append(
@@ -321,32 +321,33 @@
 sman/newsman')%0A#
+ 
 sys.path.append(
@@ -379,16 +379,17 @@
 sman')%0A#
+ 
 sys.path
@@ -774,16 +774,23 @@
      for
+ index,
  feed_id
@@ -793,24 +793,34 @@
 d_id in 
+enumerate(
 feed_ids
 :%0A      
@@ -803,32 +803,33 @@
 umerate(feed_ids
+)
 :%0A            up
@@ -860,32 +860,171 @@
 eed_id=feed_id)%0A
+            logger.info('=============== %25s of %25s updated ===============' %25%0A                        (str(index + 1), str(len(feed_ids))))%0A
             if n
@@ -1285,16 +1285,30 @@
 age='en'
+, country='US'
 ):%0A    %22
@@ -1474,16 +1474,38 @@
 language
+, 'countries': country
 %7D)%0A     
@@ -1787,16 +1787,35 @@
 language
+='en', country='US'
 ):%0A    %22
@@ -1880,63 +1880,48 @@
 fo('
-----------------------scraping-------------------------
+############### scraping ###############
 ')%0A 
@@ -1951,16 +1951,25 @@
 language
+, country
 ))%0A%0A%0Aif 
@@ -2019,16 +2019,42 @@
 argv%5B1%5D%0A
+    country = sys.argv%5B2%5D%0A
     _scr
@@ -2057,18 +2057,27 @@
 _scrape(language
+, country
 )%0A

Add more printout in analyzer.py