# Path: malware_crawl/defaults.py
# REQUESTS_SESSIONS = {
#     "api": requests.Session(),
#     "probe": requests.Session()
# }


import tweepy
import re
import feedparser
import subprocess
import redis
from six.moves import map
from celery import task
from malware_crawl.defaults import redis_db, REQUESTS_SESSIONS

feeds = (
    'http://newsrss.bbc.co.uk/rss/newsonline_world_edition/front_page/rss.xml',
    'http://www.nytimes.com/services/xml/rss/nyt/HomePage.xml',
    'http://www.guardian.co.uk/rssfeed/0,,1,00.xml',
    'http://www.washingtonpost.com/wp-dyn/rss/print/asection/index.xml',
    'http://www.huffingtonpost.com/thenewswire/full_rss.rdf',
    'http://www.npr.org/rss/rss.php?id=2',
    'http://online.wsj.com/xml/rss/3_7077.xml'
)


def to_unicode(obj, encoding='utf-8'):
    # http://farmdev.com/talks/unicode/
    if isinstance(obj, basestring):
        if not isinstance(obj, unicode):
            obj = unicode(obj, encoding)
    return obj


def camelCaseToSentenceCase(string):
    # http://stackoverflow.com/a/9283563
    return re.sub(r'((?<=[a-z])[A-Z]|(?<!\A)[A-Z](?=[a-z]))', r' \1', string)


def rssListParse(urlList):
    def rssParse(url):
        response = requests.get(url)
        if(response.status_code != requests.codes.ok):
            #print 'Error when downloading rss feed with url: '+url

# Path: malware_crawl/defaults.py
# REQUESTS_SESSIONS = {
#     "api": requests.Session(),
#     "probe": requests.Session()
# }


# Path: malware_crawl/source.py
import tweepy
import re
import feedparser
import subprocess
import redis
from six.moves import map
from celery import task
from malware_crawl.defaults import redis_db, REQUESTS_SESSIONS


feeds = (
    'http://newsrss.bbc.co.uk/rss/newsonline_world_edition/front_page/rss.xml',
    'http://www.nytimes.com/services/xml/rss/nyt/HomePage.xml',
    'http://www.guardian.co.uk/rssfeed/0,,1,00.xml',
    'http://www.washingtonpost.com/wp-dyn/rss/print/asection/index.xml',
    'http://www.huffingtonpost.com/thenewswire/full_rss.rdf',
    'http://www.npr.org/rss/rss.php?id=2',
    'http://online.wsj.com/xml/rss/3_7077.xml'
)


def to_unicode(obj, encoding='utf-8'):
    # http://farmdev.com/talks/unicode/
    if isinstance(obj, basestring):
        if not isinstance(obj, unicode):
            obj = unicode(obj, encoding)
    return obj


def camelCaseToSentenceCase(string):
    # http://stackoverflow.com/a/9283563
    return re.sub(r'((?<=[a-z])[A-Z]|(?<!\A)[A-Z](?=[a-z]))', r' \1', string)


def rssListParse(urlList):
    def rssParse(url):
        response = requests.get(url)
        if(response.status_code != requests.codes.ok):
            #print 'Error when downloading rss feed with url: '+url

            return []