def getNewsClimate(max_articles=20): gn = GoogleNews(lang='en', country='US') climate_news = gn.topic_headlines('CAAqBwgKMKeh0wEw-sE1') search = climate_news['entries'][:max_articles] rtn = {} for i in range(len(search)): rtn[i] = { 'title': search[i].title, 'href': search[i]['links'][0]['href'] } return rtn
def handle_topic(irc: IRC, google_news: GoogleNews, target: str, topic: str) -> None: """Handle a topic request.""" irc.send_message(target, "Working on it") logger.info("Fetching news for topic %s", topic) try: news = google_news.topic_headlines(topic) for entry in news["entries"][:5]: irc.send_message(target, entry["title"]) except Exception as exception: # pylint: disable=broad-except if str(exception) == "unsupported topic": # See: https://github.com/kotartemiy/pygooglenews#stories-by-topic-1 irc.send_message( target, "That topic is not supported. Supported topics are:") irc.send_message( target, "world, nation, business, technology, entertainment, science, sports, health" ) else: raise exception
for i in range(n_classes): plt.plot(fpr[i], tpr[i], label='ROC curve of {0} (area = {1:0.9f})' ''.format(category_id_df[category_id_df['category_id'] == i].Category, roc_auc[i])) plt.plot([0, 1], [0, 1], 'k--') plt.xlabel('False Positive Rate') plt.ylabel('True Positive Rate') plt.legend(loc="lower right") plt.show() pip install pygooglenews from pygooglenews import GoogleNews # default GoogleNews instance gn = GoogleNews(lang = 'en', country = 'US') business = gn.topic_headlines('BUSINESS', proxies=None, scraping_bee = None) pip install newsapi-python from newsapi import NewsApiClient api = NewsApiClient(api_key='b1b6e4269a814e8bbe8a477b3226e918') business = api.get_top_headlines(category = 'business', language = 'en', country='us') sport = api.get_top_headlines(category = 'sports', language = 'en', country='us') enter = api.get_top_headlines(category = 'entertainment', language = 'en', country='us') tech = api.get_top_headlines(category = 'technology', language = 'en', country='us')
var_issue_counter = int(f_issue.readline()) f_issue.close() var_issue_counter += 1 f_issue = open(Issue_counter_filename, "w") f_issue.write(str(var_issue_counter)) f_issue.close() else: var_issue_counter = 1 f_issue = open(Issue_counter_filename, "w") f_issue.write(str(var_issue_counter)) f_issue.close() issue_counter_flg=1 today = date.today() issue_date = today.strftime("%B %d %Y") gn = GoogleNews(lang='en', country='IN') covid_news = gn.topic_headlines('CAAqIggKIhxDQkFTRHdvSkwyMHZNREZqY0hsNUVnSmxiaWdBUAE') covid_news_local=gn.search(f'coronavirus {loc}') f_more = open(more_stories_filename, encoding='utf-8', mode="a") f_more.write('<!DOCTYPE html>') f_more.write('<html>') f_more.write('<body>') f = open(html_filename, encoding='utf-8', mode="a") f.write('<!DOCTYPE html>') f.write('<html>') f.write('<body>') f.write('<div>') cover_image_idx=np.random.randint(0,7) cover_image=coverpic_li[cover_image_idx] f.write(f'<img src={cover_image} width="1000" height="400">') f.write( f'<p style="font-family:sans-serif;color:#686868;font-size:12px;"><b>Issue Date: {issue_date} Issue: {var_issue_counter}</b></p>')