Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion News/ExtractMainContent.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

class ExtractMainContent(object):
def __init__(self,source,articleurl):
#import pdb; pdb.set_trace();
self.extractorlist=[HuffingtonPost(),NYT(),BBC(),BloomBerg(),Guardian(),TheHindu(),TimesOfIndia()]
websites=ConfigurationReader().GetWebsiteSupported()
self.Mapping={}
Expand All @@ -23,7 +24,18 @@ def __init__(self,source,articleurl):

def DownloadContent(self):
headers={'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36'}
req=requests.get(self.url,headers=headers)
Configuration = ConfigurationReader()
self.__ProxyIP=Configuration.GetProxyIP()
self.__ProxyPortNumber=Configuration.GetProxyPortNumber()
proxies = {}
if self.__ProxyIP and self.__ProxyPortNumber:
proxies = {
'http': "http://{}:{}".format(self.__ProxyIP,
self.__ProxyPortNumber),
'https': "https://{}:{}".format(self.__ProxyIP,
self.__ProxyPortNumber),
}
req=requests.get(self.url,headers=headers,proxies=proxies)
return req.text

def AddExtractorList(self,extractor):
Expand Down
12 changes: 11 additions & 1 deletion News/NewsPulling.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,19 @@ def PullNews(self):
Configuration = ConfigurationReader()
self.__APIKey=Configuration.GetAPIKEY()
self.__Limit=Configuration.GetLimit()
self.__ProxyIP=Configuration.GetProxyIP()
self.__ProxyPortNumber=Configuration.GetProxyPortNumber()
url='https://newsapi.org/v2/top-headlines?sources='+self.Source+'&sortBy=top&apiKey='+self.__APIKey
proxies = {}
if self.__ProxyIP and self.__ProxyPortNumber:
proxies = {
'http': "http://{}:{}".format(self.__ProxyIP,
self.__ProxyPortNumber),
'https': "https://{}:{}".format(self.__ProxyIP,
self.__ProxyPortNumber),
}
try:
req=requests.get(url)
req=requests.get(url,proxies=proxies)
if(req.status_code==200):
return req
else:
Expand Down
14 changes: 14 additions & 0 deletions News/configReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class ConfigurationReader():
__APIKEY=None
__WebsiteSupported=[]
__Limit=None
__ProxyIP=None
__ProxyPortNumber=None
def __init__(self):
with open("config.yml", 'r') as ymlfile:
cfg = yaml.load(ymlfile)
Expand All @@ -21,6 +23,10 @@ def __init__(self):
#print ConfigurationReader.__Limit
ConfigurationReader.__WebsiteSupported=cfg['WebsiteSupported']
#print ConfigurationReader.__WebsiteSupported
ConfigurationReader.__ProxyIP = cfg['ProxyIP']
# print ConfigurationReader.__ProxyIP
ConfigurationReader.__ProxyPortNumber = cfg['ProxyPortNumber']
# print ConfigurationReader.__ProxyPortNumber
@staticmethod
def GetAPIKEY():
return ConfigurationReader.__APIKEY
Expand All @@ -32,5 +38,13 @@ def GetLimit():
@staticmethod
def GetWebsiteSupported():
return ConfigurationReader.__WebsiteSupported

@staticmethod
def GetProxyIP():
return ConfigurationReader.__ProxyIP

@staticmethod
def GetProxyPortNumber():
return ConfigurationReader.__ProxyPortNumber


2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ To install the module dependencies before running the application, simply naviga
### To install
python setup.py install
newsctl
### If you are accessing the web through a proxy service:
Please add the proxy IP and port number to the config.yml file

# Contributing
We welcome your contributions. Please feel free to fork the code, play with it, make some patches and send us pull requests.
Expand Down
3 changes: 3 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,7 @@ Limit: 10

Apikey: bda5818cc2af461e98330ccdf6fb9cbe

ProxyIP:
ProxyPortNumber: