Пример #1
0
def get_news_articles(search_terms, date, fileName):
    bing_news = PyBingNewsSearch('q8VQn8X56yeuUuBFdoA8NKiVULvZV+RzgcJVUX60MSk',
                                 search_terms)
    first_fifty_results = bing_news.search(limit=5000, format='json')
    for news in first_fifty_results:
        #if the date is out of a certain range...
        #cut everything from 't' on
        date = news.date
        date = date[:date.rfind('T')]
        #new date format is yyyy-mm-dd
        d = datetime.datetime.strptime(date, "%Y-%m-%d")
        newDate = datetime.date.strftime(d, "%m%d%y")
        toBeComparedDate = datetime.datetime.strptime(newDate, "%m%d%y")
        print(toBeComparedDate)
        ## new date is in the format 062116 or mmddyy
        date1 = '060109'
        date2 = '123109'
        minDate = datetime.datetime.strptime(date1, '%m%d%y')
        maxDate = datetime.datetime.strptime(date2, '%m%d%y')

        if (toBeComparedDate < maxDate and toBeComparedDate > minDate):
            print(news.url)
            newsList = []
            newsList.append(news.url)
            f = open(fileName, 'a')
            f.write('\n'.join(newsList))
            f.write("\n")
Пример #2
0
def write_html():
    # cur_dir = 'riots_LA'
    cur_dir = 'riots_africa'
    with open(riots_file) as listofriots:
        for i, l in enumerate(listofriots):
            if i < 0:
                continue
            try:
                print "looking at riot %d" % i
                name = l.strip()
                # idx = int(l.split("\t")[0].strip())
                # name  = l.split("-")[1].strip().split('(')[0].strip()
                bing_news = PyBingNewsSearch(api_key, name)
                news = bing_news.search(limit=5, format='json')
                time.sleep(3)
                try:
                    shutil.rmtree("%s/riot_%04d" % (cur_dir, idx))
                except OSError:
                    pass
                os.mkdir("%s/riot_%04d" % (cur_dir, idx))
                for j, new in enumerate(news):
                    with open('%s/riot_%04d/%d.html' % (cur_dir, idx, j),
                              'w') as riot_file:
                        web = requests.get(new.url)
                        riot_file.write(web.text.encode('utf-8').strip())
                        # riot_file.write(new.description.encode('utf-8').strip())
            except:
                continue
Пример #3
0
def getScore(search_term):
    bing_news = PyBingNewsSearch('/kTKVdRbZwkXtIWdbGVGpOO1rm8s8GSA9rypv4T1+hA',
                                 search_term)

    with codecs.open(
            'positive-words.txt', 'rU',
            encoding='utf-8') as f:  #'f = open('positive-words.txt', 'r')
        results20 = bing_news.search(limit=20, format='json')
        score = 0
        j = 0

        for line in f:
            if '\n' in line:
                line = line.replace('\n', '')
            j += 1
            for result in results20:
                sresult = result.description
                if line in sresult:
                    if score < 100:
                        score += 1
                        print score
                        print line

    with codecs.open('negative-words.txt', 'rU', encoding='ISO-8859-1'
                     ) as f:  # 'f = open('positive-words.txt', 'r')
        results20 = bing_news.search(limit=10, format='json')
        j = 0

        for line in f:
            if '\n' in line:
                line = line.replace('\n', '')
            j += 1
            for result in results20:
                sresult = result.description
                if line in sresult:
                    if score < 100:
                        score -= 1
                        print score
                        print line
    return score


#getScore('berkeley')
Пример #4
0
	def getfrombing(self, apikey, text, limit, operation):
		if operation == 'moderateimagesearch':
			bing_obj = PyBingImageSearch(apikey, text, custom_params="&Adult='Moderate'")
		elif operation == 'strictimagesearch':
			bing_obj = PyBingImageSearch(apikey, text, custom_params="&Adult='Strict'")
		elif operation == 'adultimagesearch':
			bing_obj = PyBingImageSearch(apikey, text, custom_params="&Adult='Off'")
		elif operation == 'websearch':
			bing_obj = PyBingWebSearch(apikey, text, web_only=False)
		elif operation == 'videosearch':
			bing_obj = PyBingVideoSearch(apikey, text)
		elif operation == 'newssearch':
			bing_obj = PyBingNewsSearch(apikey, text)
		result = bing_obj.search(limit=limit, format='json')
		return result
Пример #5
0
from py_bing_search import PyBingNewsSearch
query = 'Apple'
bing_news = PyBingNewsSearch(api_key, query)
result = bing_news.search(limit=10, format='json')
Пример #6
0
 def test_search_all(self):
     web_bing = PyBingNewsSearch(SECRET_KEY, "Python Software Foundation")
     result_one = web_bing.search_all(limit=60)
     self.assertTrue(len(result_one) == 60)
     self.assertTrue("Python" in result_one[0].title)
Пример #7
0
 def test_search_all(self):
     web_bing = PyBingNewsSearch(SECRET_KEY, "Python Software Foundation")
     result_one = web_bing.search_all(limit=60)
     self.assertTrue(len(result_one) == 60)
     self.assertTrue("Python" in result_one[0].title)
Пример #8
0
def get_bing_news_articles(query, limit=100):
    api_key = 'uMbXJDSBqOpPB696+Ez0s+NcznWvurhuAKUruZuWXTA'
    bing_news = PyBingNewsSearch(api_key, query)
    results = bing_news.search(limit=limit, format='json')
    print(results)
    return results
 def test_can_search(self):
     web_bing = PyBingNewsSearch(SECRET_KEY, "Python")
     result_one = web_bing.search(limit=50)
     self.assertTrue(len(result_one) > 0)
     self.assertTrue("Python" in result_one[0].title)
Пример #10
0
 def test_can_search(self):
     web_bing = PyBingNewsSearch(SECRET_KEY, "Python")
     result_one = web_bing.search(limit=50)
     self.assertTrue(len(result_one) > 0)
     self.assertTrue("Python" in result_one[0].title)