Package: newsoverview
newsoverviewNews 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.AboutThis 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 TranslatedWorldNewsCertain 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 namedcountries_and_lang.txtwith 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:newsoverviewAboutInstallation GuideUsageUsage (advanced)*EnglishWorldNews*TranslatedWorldNews*SimpleSearch*CoronavirusNews*TravelWarnings*Protests*TerrorNews*HospitalNews*KWSearchLicenseLinksInstallation GuideFirst 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 linuxPyPi,GitHub,ColabImport the program and its classes:importnewsoverviewfromnewsoverviewimportCoronavirusNews,EnglishWorldNews,Protests,TravelWarnings,TerrorNews,TranslatedWorldNews,SimpleSearch,HospitalNews,KWSearchFixfeedparser.py:You only need to do this step if you've run step 4, and you get an error relating tofeedparser.py. This error links to all modules called with this function, and when it's been fixed it will go awayThere is one line of code that needs editing fornewsoverviewto work properly throughpygooglenews.This error is in the modulefeedparser.py.There are two ways to fix this problem; you can either:Run the program and use the error to navigate tofeedparser.pyORSearch forfeedparser.pyin your interpreterORManually navigate tofeedparser.pyby going to the library root and finding the module:venv > lib > site-packages > feedparser.pyit isnotin thefeedparserfolder, it will be at the bottom of the site-packages folder.Once you are in thefeedparser.pymodule, navigate to line 93 and replace:_base64decode = getattr(base64, 'decodebytes', base64.decodestring)withbase64.decodebytesCongrats! You just fixedpygooglenews,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 classOr, let's find the most recent news about the paralympics:my_search=SimpleSearch()paralympics=my_search.en_search(query='paralympics')UsageInstalling the module:pipinstallnewsoverviewfromnewsoverviewimportCoronavirusNews,EnglishWorldNews,Protests,TravelWarnings,TerrorNews,TranslatedWorldNews,SimpleSearch,HospitalNews,KWSearchFinding top news in Asia (English) (quick start):asia_news=EnglishWorldNews().asia()Main Functions used:Finding allprotestnews 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 runFinding allaeroplane, flight,andtravel restriction-related news in the past 12 hours:travel=TravelWarnings()flights=travel.aeroplane_disruptions()# aeroplanes and flight-related newstravel_disruptions=travel.travel_restrictions()# travel restriction-related newsFindingcoronavirusandlockdown-related news reported in the last1 hour:covid=CoronavirusNews()covid.coronavirus()# covid-related newscovid.lockdown()# lockdown-related newsFinding allterror-related news reported in the last 12 hours:terror=TerrorNews().terror_search()Finding allincident-related news reported in the last 10 hours:incidents=KWSearch().incidents_reports()Findinggeo-specific headlinesreported inEnglish-speaking countries by continent:news=EnglishWorldNews()news.europe()# UK, Ireland and Latvianews.asia()# includes India, Pakistan, Philippines, Singapore, etcnews.africa()# includes Zimbabwe, South Africa, Kenya, Ethiopia, etcnews.americas()# only N. America; USA and Canadanews.oceana()# New Zealand and AustraliaFindinggeo-specific headlinesreported innon-English-speaking countries by continent:tr_news=TranslatedWorldNews()tr_news.europe_tr()# includes Russia, Serbia, Sweden, Greece, Belgium, Italy, etctr_news.america_n_tr()# USA (Spanish), Canada (French) and Cubatr_news.america_s_tr()# includes Mexico, Peru, Brazil, Argentina, Chile, etctr_news.asia_tr()# includes China, India, Lebanon, Vietnam, Indonesia, Israel, etctr_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 & IsraelUsingyour own queryto search for news:
All results will be searched for in thepast 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,usecountry='GB'orcountry='US'as almost all languages can be searched from these countries.More information is provided below in SimpleSearch Class.frompygooglenewsimportGoogleNews# 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 ClassShow a list of allcountrieslisted in theEnglishWorldNewsClass:en_news=EnglishWorldNews()en_country_list=en_news.en_list()To call news from individual countries, follow the formaten_news.country(), e.g.  for Tanzanian headlines, call  en_news.tanzania()`. All countries will follow this format.You can create your own customen_newsfunction, for example:defmy_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 countriesTranslatedWorldNews ClassShow a list of allcountrieslisted in theTranslatedWorldNewsClass:tr_news=TranslatedWorldNews()tr_country_list=tr_news.tr_list()To call news from individual countries, follow the formattr_news.country(), e.g.  for Slovakian headlines, calltr_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 calltr_news.belgium_fr()for Belgian headlines in French, ortr_news.belgium_nl()for Belgian headlines in Dutch.SimpleSearch ClassYou 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 thecountries_and_lang.txtfile
Theen_searchdefault is using GoogleNews in the UK (country='GB'). The code for this isgn=GoogleNews(lang='en', country='GB')CoronavirusNews ClassShow a list of alllanguageslisted in theCoronavirusNewsClass:covid=CoronavirusNews()covid_lang_list=covid.covid_list()To call news from individual languages, follow the formatcovid.language_covid(), e.g.  for Arabic headlines, callcovid.ar_covid(). All languages will follow this format.TravelWarnings ClassShow a list of alllanguageslisted in theTravelWarningsClass:travel=TravelWarnings()aero_lang_list=travel.lang_aeroplanes()# for aeroplane and flight-related newstravel_lang_list=travel.lang_travel_restrictions()# for travel restrictions and border closure-related news# they both use the same languagesTo call news for an individual language in the aeroplane category, follow the formattravel.language_aeroplanes(), e.g. for Russian headlines, calltravel.ru_aeroplanes().To call news for an individual language in the travel_restrictions category, follow the formattravel.language_travel_restrictions(), e.g.  for Portuguese headlines, calltravel.pt_travel_restrictions()All languages will follow this format.Furthermore, you can call bothaeroplanesandtravel_restrictionstogether for a particular language usingtravel.call_language(). If you wanted the French travel news, you can simply usetravel.call_fr().Protests ClassShow a list of alllanguageslisted in theProtestsClass:protests=Protests()protests_lang_list=protests.lang_protests()To call news from individual languages, follow the formatprotests.language_protests(), e.g. for German headlines, callprotests.de_protests(). All languages will follow this format.TerrorNews ClassShow a list of the functions used in theTerrorNewsClass: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 useterror.terror_news()and it will output terror-related news articles published in the past 12 hours.HospitalNews ClassCalling the function to see if any hospital-related news has been reported in the past 12 hours, and see which languages are included in the search:hospital_news=HospitalNews().call_hospitals()hospital_langs=HospitalNews().lang_hospitals()KWSearch ClassKeywords for incident, raid, hostage, and clash-related news; only in English:incidents=KWSearch().incidents_reports()includesincidents(),raids(),hostages(), andclashes()within theKWSearch()class.LicenseThis project is licensed under the terms of the MIT LicenseLinksGithub,PyPi,Colab