Skip to main content

News at a glance

Project description

newsoverview

News at a glance.

This is my first program, and it might be a bit messy, but I hope to improve it as my skills develop! If you'd like anything added/edited or would like to add/edit something yourself, just let me know.

About

This module is perfect for when you need to have an overview of what's going on in the world.

It's a simple bit of code which uses a news scraper to search Google News, and provides the titles, dates, links and if necessary, a translation of the title at the bottom. The news searches are sorted into different categories, also referred to as classes. These classes include:

  • CoronavirusNews, Protests, TravelWarnings, TerrorNews, EnglishWorldNews, and TranslatedWorldNews

Certain countries and languages are not currently present in this program; as EnglishWorldNews and TranslatedWorldNews use specific country-language combinations found in GoogleNews to search for geo-specific headlines. However, if you would like a country-language combination added to these classes, let me know.

All languages and countries follow a two-character code system (e.g. Ukraine and Russian = UK and ru). There is an attached file named countries_and_lang.txt with all countries and languages in this format. This is because Google News uses these labelling conventions.

Please note that titles in languages other than English are translated, which means that these functions take slightly longer to run.

Contents:

newsoverview

About

Installation Guide

Usage

Usage (advanced)

* EnglishWorldNews

* TranslatedWorldNews

* SimpleSearch

* CoronavirusNews

* TravelWarnings

* Protests

* TerrorNews

License

Links

Installation Guide

  1. First things first: you need to install 'newsoverview'.
pip install newsoverview  
C:> py -m pip install newsoverview  # windows command/terminal
$ python -m pip install newsoverview  # mac and linux

PyPi, GitHub

  1. Import the program and its classes:
import newsoverview
from newsoverview import CoronavirusNews, EnglishWorldNews, Protests, TravelWarnings, TerrorNews, TranslatedWorldNews, SimpleSearch
  1. Fix feedparser.py:

You only need to do this step if you've run step 4, and you get an error relating to feedparser.py. This error links to all modules called with this function, and when it's been fixed it will go away

There is one line of code that needs editing for newsoverview to work properly through pygooglenews. This error is in the module feedparser.py.

There are two ways to fix this problem; you can either:

  • Run the program and use the error to navigate to feedparser.py
    • OR
  • Search for feedparser.py in your interpreter
    • OR
  • Manually navigate to feedparser.py by going to the library root and finding the module:
    • venv > lib > site-packages > feedparser.py
    • it is not in the feedparser folder, it will be at the bottom of the site-packages folder.

Once you are in the feedparser.py module, navigate to line 93 and replace:

_base64decode = getattr(base64, 'decodebytes', base64.decodestring) with base64.decodebytes

Congrats! You just fixed pygooglenews,

  1. Give it a go!

Let's find the top news stories happening in the UK:

news = EnglishWorldNews()  # assigning the EnglishWorldNews class to the variable 'news'
news.uk()  # calling the function 'uk()' from the EnglishWorldNews class 

Or, let's find the most recent news about the paralympics:

my_search = SimpleSearch()
paralympics = my_search.en_search(query='paralympics')

Usage

Installing the module:

pip install newsoverview
from newsoverview import CoronavirusNews, EnglishWorldNews, Protests, TravelWarnings, TerrorNews, TranslatedWorldNews, SimpleSearch 
  • Finding top news in Asia (English) (quick start):
asia_news = EnglishWorldNews().asia()

Main Functions used:

  • Finding all protest news released in the past 12 hours:
protests = Protests().call_protests()

Please note that titles in languages other than English are translated, which means that these functions take slightly longer to run

  • Finding all aeroplane, flight, and travel restriction-related news in the past 12 hours:
travel = TravelWarnings()
flights = travel.aeroplane_disruptions()  # aeroplanes and flight-related news
travel_disruptions = travel.travel_restrictions()  # travel restriction-related news
  • Finding coronavirus and lockdown-related news reported in the last 1 hour:
covid = CoronavirusNews()
covid.coronavirus()  # covid-related news 
covid.lockdown()  # lockdown-related news
  • Finding all terror-related news reported in the last 12 hours:
terror = TerrorNews().terror_search()
  • Finding geo-specific headlines reported in English-speaking countries by continent:
news = EnglishWorldNews()
news.europe()  # UK, Ireland and Latvia
news.asia()  # includes India, Pakistan, Philippines, Singapore, etc
news.africa()  # includes Zimbabwe, South Africa, Kenya, Ethiopia, etc
news.americas()  # only N. America; USA and Canada
news.oceana()  # New Zealand and Australia
  • Finding geo-specific headlines reported in non-English-speaking countries by continent:
tr_news = TranslatedWorldNews()
tr_news.europe_tr()  # includes Russia, Serbia, Sweden, Greece, Belgium, Italy, etc
tr_news.america_n_tr()  # USA (Spanish), Canada (French) and Cuba
tr_news.america_s_tr()  # includes Mexico, Peru, Brazil, Argentina, Chile, etc
tr_news.asia_tr()  # includes China, India, Lebanon, Vietnam, Indonesia, Israel, etc
tr_news.africa_tr()  # Morocco, Senegal and Egypt

# Includes specific MENA (Middle East and North Africa) region function if needed:
tr_news.mena_tr()  # Egypt, Lebanon, Morocco, Saudi Arabia, United Arab Emirates & Israel
  • Using your own query to search for news: All results will be searched for in the past 24 hours.

For the translated search, you need to import GoogleNews. This is because GoogleNews is a parameter that can to be altered with each query, so you can pass specific country/language combinations to refine your news to that country/language.

However, if you are unsure of a country/language combination, use country='GB' or country='US' as almost all languages can be searched from these countries.

More information is provided below in SimpleSearch Class.

from pygooglenews import GoogleNews  # if you're using the translated search, you need to import GoogleNews to make a country-language combination.
my_search = SimpleSearch()
my_search.en_search(query='football')  # English search of the query 'football'
my_search.tr_search(gn=GoogleNews(lang='hi', country='IN'), query='फ़ुटबॉल')  # gives a translated search of the query 'football' in Hindi (hi), as if you're searching in India (IN)

Usage (advanced)

EnglishWorldNews Class

Show a list of all countries listed in the EnglishWorldNews Class:

en_news = EnglishWorldNews()
en_country_list = en_news.en_list()

To call news from individual countries, follow the format en_news.country(), e.g. for Tanzanian headlines, call en_news.tanzania()`. All countries will follow this format.

You can create your own custom en_news function, for example:

def my_countries():
    print("UK headlines")
    en_news.uk()
    print("Canada headlines")
    en_news.canada()
    print("India headlines")
    en_news.india()
    print("Zimbabwe headlines")
    en_news.zimbabwe()

my_countries()  # call your function to print your own list of desired countries

TranslatedWorldNews Class

Show a list of all countries listed in the TranslatedWorldNews Class:

tr_news = TranslatedWorldNews()
tr_country_list = tr_news.tr_list()

To call news from individual countries, follow the format tr_news.country(), e.g. for Slovakian headlines, call tr_news.slovakia(). All countries will follow this format.

Be aware that some countries may have a suffix where they speak more than one language recognised by Google News, e.g. for Belgium. You can call tr_news.belgium_fr() for Belgian headlines in French, or tr_news.belgium_nl() for Belgian headlines in Dutch.

SimpleSearch Class

You can find the correct country/language combinations by going to Google News, and scrolling down to the bottom to 'Language & Region' to see which combinations are supported.

All country codes and language codes are provided in the countries_and_lang.txt file The en_search default is using GoogleNews in the UK (country='GB'). The code for this is gn=GoogleNews(lang='en', country='GB')

CoronavirusNews Class

Show a list of all languages listed in the CoronavirusNews Class:

covid = CoronavirusNews()
covid_lang_list = covid.covid_list()

To call news from individual languages, follow the format covid.language_covid(), e.g. for Arabic headlines, call covid.ar_covid(). All languages will follow this format.

TravelWarnings Class

Show a list of all languages listed in the TravelWarnings Class:

travel = TravelWarnings()
aero_lang_list = travel.lang_aeroplanes()  # for aeroplane and flight-related news
travel_lang_list = travel.lang_travel_restrictions()  # for travel restrictions and border closure-related news
# they both use the same languages

To call news for an individual language in the aeroplane category, follow the format travel.language_aeroplanes(), e.g. for Russian headlines, call travel.ru_aeroplanes().

To call news for an individual language in the travel_restrictions category, follow the format travel.language_travel_restrictions(), e.g. for Portuguese headlines, call travel.pt_travel_restrictions() All languages will follow this format.

Furthermore, you can call both aeroplanes and travel_restrictions together for a particular language using travel.call_language(). If you wanted the French travel news, you can simply use travel.call_fr().

Protests Class

Show a list of all languages listed in the Protests Class:

protests = Protests()
protests_lang_list = protests.lang_protests()

To call news from individual languages, follow the format protests.language_protests(), e.g. for German headlines, call protests.de_protests(). All languages will follow this format.

TerrorNews Class

Show a list of the functions used in the TerrorNews Class:

terror = TerrorNews()
terror_functions = terror.terror_search()

This class only searches in English, and searches for keywords, groups, and terror-related activities occurring within the past 12 hours.

To call all three of these functions, simply use terror.terror_news() and it will output terror-related news articles published in the past 12 hours.

License

This project is licensed under the terms of the MIT License

Links

Github, PyPi

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

newsoverview-0.0.2-py3-none-any.whl (17.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page