def search(keyword, repeat, style): global htmlParsedPage query = keyword if len(query): color.print_line('---'*45) color.print_heading('*\t'*4+"The Free Online Dictionary, Thesaurus and Encyclopedia\t" +'\t'+'*\t'*5) color.print_line('---'*45) color.print_word(query.upper()+'\n') try: htmlParsedPage = get_parsed_page(keyword) #parse to find the meaning soupPage = BeautifulSoup(htmlParsedPage) div = soupPage.findAll('div', attrs = {'id': 'MainTxt'}) meaning = div[0].findAll('div', attrs = {'class':'ds-list'}) if meaning == "": meaning = div[0].findAll('div', attrs = {'class' : 'ds-single'}) for i in range(len(meaning)): color.print_meaning('\t'+parser.strip_tags(str(meaning[i]))+'\n') except: color.print_error('Keyword not found in the Dictionary') color.print_line('---'*45) color.print_heading('\t'*6+'*****@*****.**') color.print_line('---'*45) speak(keyword, repeat, style) else: color.print_error('Empty Keyword!')
def speak(keyword, repeat, style): global htmlParsedPage, browser pronouce_style = ['normal', 'us', 'uk', ''] if repeat > 0 and len(keyword) and any(style in item for item in pronouce_style): if htmlParsedPage == '': htmlParsedPage = get_parsed_page(keyword) soupPage = BeautifulSoup(htmlParsedPage) htmlParsedPage = '' div = soupPage.findAll('div', attrs={'id': 'MainTxt'}) try: if style.lower() == 'normal' or style.lower() == '': mean_sound = str( parser.strip_tags(str( div[0].findAll('script')[0]))).split('"')[1] sound_url = 'http://img.tfd.com/hm/mp3/' + mean_sound + '.mp3' elif style.lower() == 'uk': sample = soupPage.findAll('td', attrs={'id': 'MainTitle'}) mean_sound = str( parser.strip_tags(str(sample[0])).split("'")[3]) sound_url = 'http://img2.tfd.com/pron/mp3/' + mean_sound + '.mp3' elif style.lower() == 'us': sample = soupPage.findAll('td', attrs={'id': 'MainTitle'}) mean_sound = str( parser.strip_tags(str(sample[0])).split("'")[1]) sound_url = 'http://img2.tfd.com/pron/mp3/' + mean_sound + '.mp3' sound_path = browser.retrieve(sound_url) pronounce.play(sound_path[0], repeat) except: color.print_error( 'Pronouciation not found!\nTry with different style.') elif repeat: color.print_error('Empty Keyword or Unknown Style!')
def speak(keyword, repeat, style): global htmlParsedPage, browser pronouce_style = ['normal', 'us', 'uk', ''] if repeat >0 and len(keyword) and any(style in item for item in pronouce_style): if htmlParsedPage == '': htmlParsedPage = get_parsed_page(keyword) soupPage = BeautifulSoup(htmlParsedPage) htmlParsedPage = '' div = soupPage.findAll('div', attrs = {'id': 'MainTxt'}) try: if style.lower() == 'normal' or style.lower() == '': mean_sound = str(parser.strip_tags(str(div[0].findAll('script')[0]))).split('"')[1] sound_url = 'http://img.tfd.com/hm/mp3/' + mean_sound +'.mp3' elif style.lower() == 'uk': sample = soupPage.findAll('td', attrs = {'id': 'MainTitle'}) mean_sound = str(parser.strip_tags(str(sample[0])).split("'")[3]) sound_url = 'http://img2.tfd.com/pron/mp3/' + mean_sound + '.mp3' elif style.lower() == 'us': sample = soupPage.findAll('td', attrs = {'id': 'MainTitle'}) mean_sound = str(parser.strip_tags(str(sample[0])).split("'")[1]) sound_url = 'http://img2.tfd.com/pron/mp3/' + mean_sound + '.mp3' sound_path = browser.retrieve(sound_url) pronounce.play(sound_path[0], repeat) except: color.print_error('Pronouciation not found!\nTry with different style.') elif repeat: color.print_error('Empty Keyword or Unknown Style!')
def parse(self, response): self.log("\n\n\n We got data! \n\n\n") self.make_dataset() json_response = json.loads(response.body) f = open(os.getcwd() + '/linkedin_users.csv', 'w') for person in dpath.util.get(json_response, '/content/page/voltron_unified_search_json/search/results'): # Try to get the person dict -> continue if not found try: person_dict = dpath.util.get(person, "/person") except: continue item = User( first_name=person_dict.get("firstName", "LinkedIn"), last_name=person_dict.get("lastName", "Member"), ) # Try to split the position and company if person_dict.get("fmt_headline", None): position_company = strip_tags(person_dict["fmt_headline"]) if " bei " in position_company: position_company = position_company.partition(" bei ") else: position_company = position_company.partition(" at ") item['position'] = position_company[0] item['company'] = position_company[2] if person_dict.get("fmt_location", None): city_country = person_dict["fmt_location"] if " und Umgebung," in city_country: location = person_dict["fmt_location"].partition(" und Umgebung,") else: location = person_dict["fmt_location"].partition(" Area,") item['city'] = location[0] item["country"] = location[2] self.dataset.append([item.get(field) for field in self.dataset.headers]) f.write(self.dataset.csv) print("File generated at: {}".format(os.path.abspath(f.name)))
def search(keyword, repeat, style): global htmlParsedPage query = keyword if len(query): color.print_line('---' * 45) color.print_heading( '*\t' * 4 + "The Free Online Dictionary, Thesaurus and Encyclopedia\t" + '\t' + '*\t' * 5) color.print_line('---' * 45) color.print_word(query.upper() + '\n') try: htmlParsedPage = get_parsed_page(keyword) #parse to find the meaning soupPage = BeautifulSoup(htmlParsedPage) div = soupPage.findAll('div', attrs={'id': 'MainTxt'}) meaning = div[0].findAll('div', attrs={'class': 'ds-list'}) if meaning == "": meaning = div[0].findAll('div', attrs={'class': 'ds-single'}) for i in range(len(meaning)): color.print_meaning('\t' + parser.strip_tags(str(meaning[i])) + '\n') except: color.print_error('Keyword not found in the Dictionary') color.print_line('---' * 45) color.print_heading('\t' * 6 + '*****@*****.**') color.print_line('---' * 45) speak(keyword, repeat, style) else: color.print_error('Empty Keyword!')