diff --git a/src/classes/Fetcher.py b/src/classes/Fetcher.py index 1600fc1d..be7456b9 100644 --- a/src/classes/Fetcher.py +++ b/src/classes/Fetcher.py @@ -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:] @@ -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: @@ -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 @@ -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) diff --git a/src/screenipy.py b/src/screenipy.py index 65a55b00..9f410995 100644 --- a/src/screenipy.py +++ b/src/screenipy.py @@ -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)