Package: gnews
GNews 📰A Happy and lightweight Python Package that Provides an API to search for articles on Google News and returns a usable JSON response! 🚀If you like ❤️ GNews or find it useful 🌟, support the project by buying me a coffee ☕.🚀 View Demo·🐞 Report Bug·🚀 Request FeatureTable of Contents 📑About 🚩Demo 📺Getting Started 🚀Installation 📦Setup with Docker 🐳Usage 🧩Top News 🌟News by Keywords 🔎News by Major Topics 🚀News by GEO Location 🌎Supported Countries 🌐Supported Languages 🌍Article Properties 📝Getting Full Article 📰To Do 📋Roadmap 🛣️Contributing 🤝License ⚖️Contact 📬Acknowledgements 🙏About GNews🚩 GNews is A Happy and lightweight Python Package that searches Google News RSS Feed and returns a usable JSON
response🚩 As well as you can fetch full article (No need to write scrappers for articles fetching anymore)Google News cover across141+ countrieswith41+ languages. On the bottom left side of the Google News page you
may find aLanguage & regionsection where you can find all of the supported combinations.DemoGetting StartedThis is an example of how you may give instructions on setting up your project locally. To get a local copy up and
running follow these simple example steps.InstallationpipinstallgnewsSetup with DockerDeveloping with dockerInstalldocker and docker-compose.Set-up your .env environment placing the mongo db credentials.Rundocker-compose up --buildInstall using cloneClone this repositoryhttps://github.com/ranahaani/GNews.gitStart your virtual environmentvirtualenv gnewsInstall the requirements withpip install -r requirements.txtExample usagefromgnewsimportGNewsgoogle_news=GNews()pakistan_news=google_news.get_news('Pakistan')print(pakistan_news[0])[{
'publisher': 'Aljazeera.com',
 'description': 'Pakistan accuses India of stoking conflict in Indian Ocean  '
                'Aljazeera.com',
 'published date': 'Tue, 16 Feb 2021 11:50:43 GMT',
 'title': 'Pakistan accuses India of stoking conflict in Indian Ocean - '
          'Aljazeera.com',
 'url': 'https://www.aljazeera.com/news/2021/2/16/pakistan-accuses-india-of-nuclearizing-indian-ocean'
 },
 ...]Get top newsGNews.get_top_news()Get news by keywordGNews.get_news(keyword)Get news by major topicGNews.get_news_by_topic(topic)Available topics:WORLD, NATION, BUSINESS, TECHNOLOGY, ENTERTAINMENT, SPORTS, SCIENCE, HEALTH.Get news by geo locationGNews.get_news_by_location(location)location can be name of city/state/countryGet news by siteGNews.get_news_by_site(site)site should be in the format of:"cnn.com"Results specificationIt's possible to pass proxy, country, language, period, start date, end date exclude websites and size during initializationgoogle_news=GNews(language='en',country='US',period='7d',start_date=None,end_date=None,max_results=10,exclude_websites=['yahoo.com','cnn.com'],proxy=proxy)Or change it to an existing objectgoogle_news.period='7d'# News from last 7 daysgoogle_news.max_results=10# number of responses across a keywordgoogle_news.country='United States'# News from a specific countrygoogle_news.language='english'# News in a specific languagegoogle_news.exclude_websites=['yahoo.com','cnn.com']# Exclude news from specific website i.e Yahoo.com and CNN.comgoogle_news.start_date=(2020,1,1)# Search from 1st Jan 2020google_news.end_date=(2020,3,1)# Search until 1st March 2020The format of the timeframe is a string comprised of a number, followed by a letter representing the time operator. For
example 1y would signify 1 year. Full list of operators below:- h = hours (eg: 12h)
 - d = days (eg: 7d)
 - m = months (eg: 6m)
 - y = years (eg: 1y)Setting the start and end dates can be done by passing in either a datetime or a tuple in the form (YYYY, MM, DD).Supported Countriesprint(google_news.AVAILABLE_COUNTRIES){'Australia':'AU','Botswana':'BW','Canada ':'CA','Ethiopia':'ET','Ghana':'GH','India ':'IN','Indonesia':'ID','Ireland':'IE','Israel ':'IL','Kenya':'KE','Latvia':'LV','Malaysia':'MY','Namibia':'NA','New Zealand':'NZ','Nigeria':'NG','Pakistan':'PK','Philippines':'PH','Singapore':'SG','South Africa':'ZA','Tanzania':'TZ','Uganda':'UG','United Kingdom':'GB','United States':'US','Zimbabwe':'ZW','Czech Republic':'CZ','Germany':'DE','Austria':'AT','Switzerland':'CH','Argentina':'AR','Chile':'CL','Colombia':'CO','Cuba':'CU','Mexico':'MX','Peru':'PE','Venezuela':'VE','Belgium ':'BE','France':'FR','Morocco':'MA','Senegal':'SN','Italy':'IT','Lithuania':'LT','Hungary':'HU','Netherlands':'NL','Norway':'NO','Poland':'PL','Brazil':'BR','Portugal':'PT','Romania':'RO','Slovakia':'SK','Slovenia':'SI','Sweden':'SE','Vietnam':'VN','Turkey':'TR','Greece':'GR','Bulgaria':'BG','Russia':'RU','Ukraine ':'UA','Serbia':'RS','United Arab Emirates':'AE','Saudi Arabia':'SA','Lebanon':'LB','Egypt':'EG','Bangladesh':'BD','Thailand':'TH','China':'CN','Taiwan':'TW','Hong Kong':'HK','Japan':'JP','Republic of Korea':'KR'}Supported Languagesprint(google_news.AVAILABLE_LANGUAGES){'english':'en','indonesian':'id','czech':'cs','german':'de','spanish':'es-419','french':'fr','italian':'it','latvian':'lv','lithuanian':'lt','hungarian':'hu','dutch':'nl','norwegian':'no','polish':'pl','portuguese brasil':'pt-419','portuguese portugal':'pt-150','romanian':'ro','slovak':'sk','slovenian':'sl','swedish':'sv','vietnamese':'vi','turkish':'tr','greek':'el','bulgarian':'bg','russian':'ru','serbian':'sr','ukrainian':'uk','hebrew':'he','arabic':'ar','marathi':'mr','hindi':'hi','bengali':'bn','tamil':'ta','telugu':'te','malyalam':'ml','thai':'th','chinese simplified':'zh-Hans','chinese traditional':'zh-Hant','japanese':'ja','korean':'ko'}Article PropertiesGet news returns the list with following keys:title,published_date,description,url,publisher.PropertiesDescriptionExampletitleTitle of the articleIMF Staff and Pakistan Reach Staff-Level Agreement on the Pending Reviews Under the Extended Fund FacilityurlGoogle news link to articleArticle Linkpublished datePublished dateWed, 07 Jun 2017 07:01:30 GMTdescriptionShort description of articleIMF Staff and Pakistan Reach Staff-Level Agreement on the Pending Reviews Under the Extended Fund Facility ...publisherPublisher of articleThe GuardianGetting full articleTo read a full article you can either:Navigate to the url directly in your browser, orUsenewspaper3klibrary to scrape the articleThe article url, needed for both methods, is accessed asarticle['url'].Using newspaper3kInstall the library -pip3 install newspaper3k.Useget_full_articlemethod fromGNews, that creates annewspaper.article.Articleobject from the url.fromgnewsimportGNewsgoogle_news=GNews()json_resp=google_news.get_news('Pakistan')article=google_news.get_full_article(json_resp[0]['url'])# newspaper3k instance, you can access newspaper3k all attributes in articleThis new object containstitle,text(full article) orimagesattributes. Examples:article.titleIMF Staff and Pakistan Reach Staff-Level Agreement on the Pending Reviews Under the Extended Fund Facility'article.textEnd-of-Mission press releases include statements of IMF staff teams that convey preliminary findings after a mission. The views expressed are those of the IMF staff and do not necessarily represent the views of the IMF’s Executive Board.\n\nIMF staff and the Pakistani authorities have reached an agreement on a package of measures to complete second to fifth reviews of the authorities’ reform program supported by the IMF Extended Fund Facility (EFF) ..... (full article)article.images{'https://www.imf.org/~/media/Images/IMF/Live-Page/imf-live-rgb-h.ashx?la=en', 'https://www.imf.org/-/media/Images/IMF/Data/imf-logo-eng-sep2019-update.ashx', 'https://www.imf.org/-/media/Images/IMF/Data/imf-seal-shadow-sep2019-update.ashx', 'https://www.imf.org/-/media/Images/IMF/Social/TW-Thumb/twitter-seal.ashx', 'https://www.imf.org/assets/imf/images/footer/IMF_seal.png'}article.authors[]Read full documentation fornewspaper3knewspaper3kTodoSave to MongoDBSave to SQLiteSave to JSONSave to .CSV fileMore than 100 articlesRoadmapSee theopen issuesfor a list of proposed features (and known issues).ContributingContributions are what make the open source community such an amazing place to be learn, inspire, and create. Any
contributions you make aregreatly appreciated.Fork the ProjectCreate your Feature Branch (git checkout -b feature/AmazingFeature)Commit your Changes (git commit -m 'Add some AmazingFeature')Push to the Branch (git push origin feature/AmazingFeature)Open a Pull RequestLicenseDistributed under the MIT License. SeeLICENSEfor more information.ContactMuhammad Abdullah -@ranahaani-ranahaani@gmail.comProject Link:https://github.com/ranahaani/GNewsProject Link:https://github.com/ranahaani/GNews