def check_args(): """ Checks the arguments passed into the program from terminal. It will exit the program and display the appropriate message if not enough arguments were passed in or an unsupported language name was queried. Returns: None. """ error_msg = "" if len(sys.argv) < 3: error_msg = ("WRONG FORMAT. You should pass in the programming" + " langauge name as the first argument, a class as" + " the second argument, and an optional method name" + " in the third argument.") else: language, _ = get_query(sys.argv) if language not in app.doc_websites.websites: error_msg = ("Unfortunately, " + Text.magenta_text(Text.magenta_text(language)) + " is not a programming language that is currently" + " supported by DoCLine. :(") if error_msg: print_doc(error_msg) exit(0)
def main(): """ Main logic of the program. Returns: None. """ colorama.init() check_args() language, query = get_query(sys.argv) doc_url = app.doc_websites.websites[language] google_search_url = app.web_scraper.query_to_google_url(query, doc_url) google_html = app.web_scraper.get_website_html(google_search_url) soup = BeautifulSoup(google_html, 'html.parser') first_res = soup.find_all('div', class_='g')[0] url = first_res.find('a')['href'] # May return URL with some header. url = app.web_scraper.fix_href_url(url) # Fix the URL. # Check if the website allows us to scrape it for information. if not app.web_scraper.website_allows_scraping(url): text = ("Unfortunately, the documentation website for " + Text.magenta_text(language) + " does not allow scraping." + "The program will now exit.") print text exit(0) doc_html = app.web_scraper.get_website_html(url)