Skip to content

Commit

Permalink
Proxy auth error fixed for Index-wise search
Browse files Browse the repository at this point in the history
  • Loading branch information
pranjal-joshi committed Jun 21, 2021
1 parent 0d87b80 commit ed8103e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 7 additions & 4 deletions src/classes/Fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __init__(self, configManager):
self.configManager = configManager
pass

def fetchCodes(self, tickerOption):
def fetchCodes(self, tickerOption,proxyServer=None):
listStockCodes = []
if tickerOption == 12:
return list(nse.get_stock_codes(cached=False))[1:]
Expand All @@ -54,7 +54,10 @@ def fetchCodes(self, tickerOption):
url = tickerMapping.get(tickerOption)

try:
res = requests.get(url)
if proxyServer:
res = requests.get(url,proxies={'https':proxyServer})
else:
res = requests.get(url)
cr = csv.reader(res.text.strip().split('\n'))
next(cr) # skipping first line
for row in cr:
Expand All @@ -65,7 +68,7 @@ def fetchCodes(self, tickerOption):
return listStockCodes

# Fetch all stock codes from NSE
def fetchStockCodes(self, tickerOption):
def fetchStockCodes(self, tickerOption, proxyServer=None):
listStockCodes = []
if tickerOption == 0:
stockCode = None
Expand All @@ -77,7 +80,7 @@ def fetchStockCodes(self, tickerOption):
else:
print(colorText.BOLD +
"[+] Getting Stock Codes From NSE... ", end='')
listStockCodes = self.fetchCodes(tickerOption)
listStockCodes = self.fetchCodes(tickerOption,proxyServer=proxyServer)
if len(listStockCodes) > 10:
print(colorText.GREEN + ("=> Done! Fetched %d stock codes." %
len(listStockCodes)) + colorText.END)
Expand Down
2 changes: 1 addition & 1 deletion src/screenipy.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def main(testing=False):
f'[+] Create the watchlist.xlsx file in {os.getcwd()} and Restart the Program!' + colorText.END)
sys.exit(0)
else:
listStockCodes = fetcher.fetchStockCodes(tickerOption)
listStockCodes = fetcher.fetchStockCodes(tickerOption, proxyServer=proxyServer)
except urllib.error.URLError:
print(colorText.BOLD + colorText.FAIL +
"\n\n[+] Oops! It looks like you don't have an Internet connectivity at the moment! Press any key to exit!" + colorText.END)
Expand Down

0 comments on commit ed8103e

Please sign in to comment.