def TickerCharts(self, timeframe='daily', charttype='advanced', out_dir=''): """Download ticker charts. Args: timeframe(str): choice of timeframe (daily, weekly, monthly). charttype(str): choice of type of chart (candle, line, advanced). out_dir(str): output image directory. default none. """ if timeframe not in ['daily','weekly','monthly']: raise ValueError() if charttype not in ['candle', 'line','advanced']: raise ValueError() url_type = 'c' url_ta = '0' if charttype == 'line': url_type = 'l' elif charttype == 'advanced' and timeframe != 'weekly' and timeframe != 'monthly': url_ta = '1' url_timeframe = 'd' if timeframe == 'week': url_timeframe = 'w' elif timeframe == 'monthly': url_timeframe = 'm' chart_url = 'https://finviz.com/chart.ashx?t={ticker}&ty={type}&ta={ta}&p={timeframe}'.format(ticker=self.ticker, type=url_type, ta=url_ta, timeframe=url_timeframe) imageScrap(chart_url, self.ticker, out_dir)
def ScreenerView(self, group='Sector', order='Name', out_dir=''): """Get screener table. Args: group(str): choice of group option. order(str): sort the table by the choice of order. """ if group not in self.group_dict: raise ValueError() if order not in self.order_dict: raise ValueError() self.url = self.BASE_URL.format(group=self.group_dict[group])+'&'+self.order_dict[order] soup = webScrap(self.url) url = 'https://finviz.com/' + soup.findAll('img')[5]['src'] imageScrap(url, group, '')
def TickerCharts(self, timeframe='daily', charttype='advanced', out_dir='', urlonly=False): """Download ticker charts. Args: timeframe(str): choice of timeframe (daily, weekly, monthly). charttype(str): choice of type of chart (candle, line, advanced). out_dir(str): output image directory. default none. urlonly (bool): choice of downloading charts, default: downloading chart Returns: charturl(str): url for the chart """ if timeframe not in ['daily', 'weekly', 'monthly']: raise ValueError("Invalid timeframe '{}'".format(timeframe)) if charttype not in ['candle', 'line', 'advanced']: raise ValueError("Invalid chart type '{}'".format(charttype)) url_type = 'c' url_ta = '0' if charttype == 'line': url_type = 'l' elif charttype == 'advanced' and timeframe != 'weekly' and timeframe != 'monthly': url_ta = '1' url_timeframe = 'd' if timeframe == 'weekly': url_timeframe = 'w' elif timeframe == 'monthly': url_timeframe = 'm' chart_url = 'https://finviz.com/chart.ashx?t={ticker}&ty={type}&ta={ta}&p={timeframe}'.format( ticker=self.ticker, type=url_type, ta=url_ta, timeframe=url_timeframe) if not urlonly: imageScrap(chart_url, self.ticker, out_dir) return chart_url