def get(soup, data, dictionary): """Tar et BeautifulSoup objekt og returnerer et map av data Modifiserer dictionary argumentet du gir inn.""" # Steg 1: Ting som alltid er sant: dictionary['fb_like'] = None #0 dictionary['others_share'] = None #0 dictionary['fb_share'] = len(soup.select(".share-facebook")) dictionary['googleplus_share'] = len(soup.select(".share-googleplus")) dictionary['twitter_share'] = len(soup.select(".share-twitter")) dictionary['email_share'] = len(soup.select(".share-mail")) # tror ikke disse har noen aside... dictionary['related_stories_box_les'] = len(soup.select("aside.articlewidgets article")) # related thematic (found in footer part of page) dictionary['related_stories_box_thematic'] = 0 # grab that footer part with data-relation-limit attr related_thematic = soup.find_all(has_data_relation_limit) # loop for el in related_thematic: #check divs for div in el.select("div"): if has_data_id(div): dictionary['related_stories_box_thematic'] +=1 # re related stories is the combined previous two dictionary['related_stories'] = dictionary['related_stories_box_les'] + dictionary['related_stories_box_thematic'] # antall js dokumenter dictionary['js'] = count_js(soup, data, dictionary) # = len(re.findall("<iframe src=", data)) # .js # remove javascript. [s.decompose() for s in soup.body.article('script')] # I believe this is what creates the somewhat awkward line-breaks in the soup # Find author(s) byline = soup.find('div', 'byline') authors = [] try: for address, li in izip(byline.find_all('address'), byline.find_all('li', 'icon-email')): authorName = address.strong.text #address.find(class_='fn').string.encode('utf-8') # NRK is still trying to hide the email address from spammers. #href = li.a['href'] authorMail = None # 'abandon this? too hard?'#unquote(href[21:-1])[7:] # Antakelsen er at epost vil holde seg til ASCII. authorRole = address.span.text #address.find(class_='role').string.strip().encode('utf-8') author = [authorName, authorMail, authorRole] authors.append(author) # and remove author image (so not to count it later..) address.figure.decompose() except AttributeError: # Finner ingen forfatter(e) new_logger.warn("Ingen forfattere \"{0}\". Oppgir \"<UKJENT>\" som forfatter".format(dictionary['url'])) #print authors.append([None, None, None]) dictionary['authors'] = authors # Find published datetime try: dictionary['published'] = strptime(soup.time['datetime'][0:19], "%Y-%m-%dT%H:%M:%S") except TypeError: new_logger.info("finner ikke publiseringsdato") dictionary['published'] = None new_logger.debug("published: %s", type(dictionary['published'])) # Find update datetime try: updated = soup.find('span', 'update-date') dictionary['updated'] = datetime.strptime(updated.time['datetime'][0:19], "%Y-%m-%dT%H:%M:%S") except: new_logger.info("finner ikke oppdateringsdato") dictionary['updated'] = None # Find headline try: dictionary['headline'] = soup.body.article.find('h1').text.strip() #dictionary['headline'] = soup.header.find('div', 'articletitle').h1.text # .text gived unicode, .string gives 'bs4.element.NavigableString' except AttributeError: new_logger.debug( "NB: bruker doc-title..." ) dictionary['headline'] = soup.title.text # Find fact-boxes : # Should be removes from body, but includes in LIX. Right? faktabokser = [] #for boks in soup.find_all("section", class_="articlewidget cf facts lp_faktaboks"): for boks in soup.find_all("section", class_="facts"): faktaboks_text = boks.text.strip() lix = Lix(faktaboks_text) faktaboks_analysis = lix.analyzeText(faktaboks_text) faktabokser.append({"text":faktaboks_text, "links":boks.find_all("a"), "wordcount":faktaboks_analysis['wordCount']}) # and remove from soup #boks.decompose() #ikke fjern boks'n fra suppa. # NB, this also removes pictures if any in the fact-box dictionary['factbox'] = faktabokser new_logger.debug("faktabokser: %s", len(dictionary['factbox'])) # Find full text # article MINUS .universes OR is it .lp_related ? # remove the related section # try: # soup.body.article.find('section', 'lp_related').decompose() # except: # pass # # remove div.published (the top-bar) # soup.body.article.find('div', 'published').decompose() # # remove div.shareurl (the sharebar) # soup.body.article.find('div', 'sharing').decompose() # Find self declared url # get this before decomposing the header this is found in.. dictionary['url_self_link'] = soup.select("time > a")[0]['href'] # remove header with sharing links and date soup.select(".bulletin-header")[0].decompose() # store body text dictionary['body'] = soup.body.article.text.strip() # .stripped_strings option? # soup.get_text("|", strip=True) perhaps? # Find char count, line count, word count and Lix lix = Lix(dictionary['body']) analyse = lix.analyzeText(dictionary['body']) try: dictionary['char_count'] = len(dictionary['body']) dictionary['word_count'] = analyse['wordCount'] dictionary['line_count'] = analyse['sentenceCount'] dictionary['lesbahet'] = analyse['lixScore'] except TypeError: new_logger.error("Kunne ikke kjøre lix", dictionary['body']) dictionary['line_count'] = None dictionary['word_count'] = None dictionary['char_count'] = None dictionary['lesbahet'] = -1.0 # look through the last part of the body text to find news bureau # add more in settings.py dictionary['news_bureau'] = matches_pattern(dictionary['body'].strip()[-200:], syndicators) # Find language. Defaults can be tampered with in settings.py (language, certainty) = langid.classify(soup.body.article.text) new_logger.debug( "(language, certainty) (%s, %s)" % (language, certainty)) language_code = uncertain_language_string if (certainty > language_identification_threshold): language_code = language dictionary['language'] = language_code get_video(soup.body.article, data, dictionary) # flash (untested) dictionary['flash_file'] = get_flash(soup.body.article, data, dictionary) # Tell opp iframe. dictionary['iframe'] = count_iframes(soup, data, dictionary) # Tell opp css (karakterer) dictionary['css'] = count_css(soup, data, dictionary) # Finnes det en form for kommentarer her? I de nyere NRK sidene er det tydeligvis kun det på Ytring. # Men vi søker generelt nå, og håper på det beste. I verste fall vil et interessant krasj fortelle meg at dette ikke er tilfellet. –Haakon dictionary['comment_fields'] = 0 dictionary['comment_number'] = 0 if len(re.findall('<div id="disqus_thread"', data)) != 0: dictionary['comment_fields'] = 1 dictionary['comment_number'] = None # -9999#num_comments(dictionary) # tar seg av lenker i siden count_links(soup, data, dictionary) # antall bilder. # Beautiful Soup teller feil her og. Noe er galt. # Regex matching gir riktig resultat så vi får gå for det. #result = soup.article.find_all('figure', 'image') #print len(result) #new_logger.debug( "antall bilder: %s", len(re.findall("<img src=\"http:", data)) ) dictionary['images'] = count_images(soup.body.article, data, dictionary) # bildesamlinger dictionary['image_collection'] = len(soup.select(".slideshow")) # er dette nok? # Som diskutert med Eirik, dette henter ut bildetekstene og deler dem med pipe symboler. imgtagger = re.findall(u"<img src=\"http.*\n.*", str(soup.body.article) ) bildetekst = "" for imgtag in imgtagger: funn = re.findall("alt=\".*\"", imgtag) if len(funn) > 0: bildetekst += ((funn[0])[5:-1] + " | ") bildetekst = bildetekst[:-3] # Fjerner siste pipen dictionary['image_captions'] = bildetekst dictionary['map'] = count_map(soup.body.article, data, dictionary) dictionary['poll'] = None # -9999 dictionary['game'] = None # -9999 dictionary['interactive_elements'] = count_interactive( \ dictionary['comment_fields'] , dictionary['image_collection'] , \ dictionary['video_files'] , dictionary['video_files_nrk'] , \ dictionary['fb_like'] , dictionary['fb_share'] , \ dictionary['googleplus_share'] , dictionary['twitter_share'] , \ dictionary['others_share'] , dictionary['email_share'] , \ dictionary['map'] , dictionary['poll'] , dictionary['game']) return dictionary
def nrk_2013_template(soup, data, dictionary): """Tar et BeautifulSoup objekt og returnerer et map av data Modifiserer dictionary argumentet du gir inn.""" # Steg 1: Ting som alltid er sant: dictionary['fb_like'] = 1 dictionary['fb_share'] = 1 dictionary['googleplus_share'] = 1 dictionary['twitter_share'] = 1 dictionary['others_share'] = 0 dictionary['email_share'] = 1 dictionary['related_stories'] = 6 # remove javascript. # if we want to measure amount of js or numbers of .js docs, do it here. [s.decompose() for s in soup.body.article('script')] # I believe this is what creates the somewhat awkward line-breaks in the soup # Finn forfatter(e) byline = soup.find('div', 'byline') authors = [] try: for address, li in izip(byline.find_all('address'), byline.find_all('li', 'icon-email')): authorName = address.strong.text #address.find(class_='fn').string.encode('utf-8') # NRK is still trying to hide the email address from spammers. #href = li.a['href'] authorMail = 'abandon this? too hard?'#unquote(href[21:-1])[7:] # Antakelsen er at epost vil holde seg til ASCII. authorRole = address.span.text #address.find(class_='role').string.strip().encode('utf-8') author = [authorName, authorMail, authorRole] authors.append(author) except AttributeError: # Finner ingen forfatter(e) print "[ERROR]: Kunne ikke finne forfattere for artikkel \"{0}\". Oppgir \"<UKJENT>\" som forfatter".format(dictionary['url']) authors.append(["Ukjent", "Ukjent", "Ukjent"]) dictionary['authors'] = authors # Finn publiseringsdato try: dictionary['published'] = strptime(soup.time['datetime'][0:19], "%Y-%m-%dT%H:%M:%S") except TypeError: dictionary['published'] = "NULL" # Finn evnt. oppdateringer try: updated = soup.find('span', 'update-date') dictionary['updated'] = datetime.strptime(updated.time['datetime'][0:19], "%Y-%m-%dT%H:%M:%S") except: dictionary['updated'] = False # Finn overskrift try: dictionary['headline'] = soup.header.find('div', 'articletitle').h1.text # .text gived unicode, .string gives 'bs4.element.NavigableString' except AttributeError: dictionary['headline'] = soup.title.text # Find fack-boxes : # disse bør fjernes bra body, men inkluderes i LIX. Rimelig? faktabokser = [] #for boks in soup.find_all("section", class_="articlewidget cf facts lp_faktaboks"): for boks in soup.find_all("section", class_="facts"): #print len(boks), boks.text #ok text = boks.text.strip() #print text lix = Lix(text) analysis = lix.analyzeText(text) faktabokser.append({"text":text, "links":boks.find_all("a"), "wordcount":analysis['wordCount']}) # and remove from soup boks.decompose() # NB, this also removes pictures if any in the fact-box dictionary['factbox'] = faktabokser # Finn brødtekst # article MINUS .universes OR is it .lp_related ? # remove the related section try: soup.body.article.find('section', 'lp_related').decompose() except: pass # remove div.published (the top-bar) soup.body.article.find('div', 'published').decompose() # remove div.shareurl (the sharebar) soup.body.article.find('div', 'sharing').decompose() # store body text # add some strip functions here? dictionary['body'] = soup.body.article.text.strip() # Finn ut av antall tegn, linjer og ord, og kjør lesbarhetsindekstesten. lix = Lix(dictionary['body']) analyse = lix.analyzeText(dictionary['body']) try: dictionary['char_count'] = len(dictionary['body']) dictionary['word_count'] = analyse['wordCount'] dictionary['line_count'] = analyse['sentenceCount'] dictionary['lesbahet'] = lix.get_lix_score() except TypeError: print "[ERROR] Kunne ikke opprette analyse." print "[DEBUG] Body:" print dictionary['body'] print "[DEBUG] /Body" dictionary['line_count'] = -1 dictionary['word_count'] = -1 dictionary['char_count'] = -1 dictionary['lesbahet'] = -1.0 # eksempler fra nrk.no: (NTB), (©NTB), (NRK/Reuters), (NTB/Reuters), (AFP), (NRK/Reuters/AFP/AP), (NTB-AFP), '(Kilde: BBC, The Guardian, NTB)' syndicators = ['NTB', '©NTB', 'NRK/Reuters', '©NRK','AFP', 'NRK/Reuters/AFP/AP', 'NTB-AFP','NRK-NTB-AFP-Reuters'] # andre kjente: # flere her: http://en.wikipedia.org/wiki/News_agency syndicators.extend(['ANSA','APA', 'Xinhua', 'ITAR-TASS','ABC', 'ACN', 'EPA','Fox News','FOX','Reuters','PA','AP','DPA', 'UPI','BNO','AHN','ANSA','NYT', 'NBC','BBC']) # burde ikke fanges opp: (FBI), (ORHA), (SAS), def matches_pattern(s, pats): pat = "|".join("(\(.?%s.?\w*\))" % p for p in pats) #print pat mObj = re.search(pat, s, re.I) #print mObj.group() if bool(mObj): print u"Nyhetabyrå: %s" % mObj.group() return mObj.group() else: return u'NA' # look through the last part of the body text to find news bureau dictionary['news_bureau'] = matches_pattern(dictionary['body'].strip()[-200:], syndicators) # Finn ut av språket. Merk at du kan stille inn innstillinger i settings.py.ta (language, certainty) = langid.classify(soup.body.article.text) language_code = uncertain_language_string if (certainty > language_identification_threshold): language_code = language dictionary['language'] = language_code # Finn ut av medieting de har. (Se lang kommentar) ''' Så her er greien: Når vi laster ned via pythons requests, får vi ikke den "ferdige" nettsiden. Vi får rå html med javascript kall som evt. setter inn videoer. Da kan vi ikke bare løpe gjennom den vakre suppen vår, men må istedenfor finne ut av hva NRK kaller for å få ut en ny videofil. Heldigvis har NRK vært grusomt greie mot oss og ikke fjernet unødvendig whitespace fra javascriptkoden sin. Og siden de som koder for NRK er flinke, er det lett å lese hva som gjør hva. Da blir det enkelt å telle videoer og bilder. Artig nok blir share-button tingene deres også laget derifra. For de nye sidene er dette statisk, så vi trenger ikke ta noe hensyn til hva som gjør hva, og vi slipper dermed å gjøre noe: Vet vi at det er en ny side, vet vi også hva som kan deles og hvordan. ^_^ Det store problemet jeg har er at Beautiful Soup ikke ser ut til å få med seg hele siden, alltid. Se eksempelet http://www.nrk.no/valg2013/se-partiledernes-foredrag-1.11168181, beautiful soup tar ikke med hele siden. – Haakon ''' # Tell opp videoer: dictionary['video_files_nrk'] = len(re.findall('<div class="video-player">', data)) dictionary['flash_file'] = len(re.findall('class="youtube-player"', data)) dictionary['video_files'] = dictionary['flash_file'] + dictionary['video_files_nrk'] # Tell opp iframe. BeautifulSoup teller feil på "http://www.nrk.no/mr/enorm-nedgang-i-antall-filmbutikker-1.11261850", så vi bruker en regex her istedenfor. # Hvis noen finner ut hvordan jeg bruker BS istedenfor, gi meg en lyd. (soup.find_all("iframe") hvirket ikke) – Haakon dictionary['iframe'] = len(re.findall("<iframe src=", data)) # Finnes det en form for kommentarer her? I de nyere NRK sidene er det tydeligvis kun det på Ytring. # Men vi søker generelt nå, og håper på det beste. I verste fall vil et interessant krasj fortelle meg at dette ikke er tilfellet. –Haakon dictionary['comment_fields'] = 0 dictionary['comment_number'] = 0 if len(re.findall('<div id="disqus_thread"', data)) != 0: dictionary['comment_fields'] = 1 dictionary['comment_number'] = num_comments(dictionary) # tar seg av lenker i siden tell(soup, data, dictionary) # url_self_link Vi jukser litt her. vi VET at input boksen den kommer fra ser SLIK ut: # <input value="[lenke]" readonly="readonly" type="text"> # Dermed håper vi at det ikke er noen andre ting som ser like ut, og kjører på. # Dersom det ER andre ting som ser like ut er det ikke noe vi kan gjøre uansett. # Da får vi gi en feilmelding i alle fall. # – Haakon search = re.findall('<input type="text" value=".*" readonly="readonly"', data) if len(search) > 1: print "ERROR: MORE THAN ONE SELF-LINK" dictionary['url_self_link'] = (search[0])[26:-21] # antall bilder. # Beautiful Soup teller feil her og. Noe er galt. # Regex matching gir riktig resultat så vi får gå for det. dictionary['images'] = len(re.findall("<img src=\"http:", data)) imgtagger = re.findall(u"<img src=\"http.*\n.*", data) # Som diskutert med Eirik, dette henter ut bildetekstene og deler dem med pipe symboler. # Måtte den som kommer etterpå ikke himle så altfor mye med øynene når de ser dette... :o bildetekst = "" for imgtag in imgtagger: funn = re.findall("alt=\".*\"", imgtag) if len(funn) > 0: bildetekst += ((funn[0])[5:-1] + " | ") bildetekst = bildetekst[:-3] # Fjerner siste pipen dictionary['image_captions'] = bildetekst # Dette er de data jeg ikke har fått til enda. # Dersom noen kan peke meg i retning av noen eksempler på sider med slike data på seg, blir jeg kjempeglad. # Jeg har sittet i flere timer på let, så jeg er litt frustrert over disse... ^_^ dictionary['map'] = -1 dictionary['image_collection'] = -1 dictionary['poll'] = -1 dictionary['game'] = -1 # Jeg trenger litt hjelp til å finne gode eksempler på disse. # Send meg gjerne lenker! dictionary['interactive_elements'] = dictionary['iframe'] # Disse rakk jeg rett og slett ikke å bli ferdig med. # Beklager! ;_; dictionary['related_stories_box_les'] = -1 dictionary['related_stories_box_thematic'] = -1 return dictionary
Denne loven har hverken Høyre eller Idrettsforbundet planer om å avskaffe. – I teorien er vi like langt. På grunn av knockoutloven vil ikke Cecilia Brækhus få bokse i Norge. Hun bokser nemlig 20-minutters kamper, knockoutloven tillater bare 12-minutters kamper. I tillegg sier knockoutloven at du må bokse med hjelm, og det gjør ikke Cecilia, forklarer Nilsen. Kan søke om dispensasjon Boksere kan imidlertid søke om dispensasjon fra knockoutloven, og dermed gir opphevingen av proffbokseforbudet en teoretisk mulighet for Brækhus til å bokse i Norge. – Det hadde vært helt enormt. Det hadde vært en utrolig avslutning på en bra karriere. Men om det skjer i min tid, gjenstår å se. Det hadde vært norsk idrettshistorie, sa Brækhus til NRK.no i september. Brækhus har bokset 23 proffkamper i løpet av karrieren - alle er vunnet og alle sammen er gjennomført utenfor Norges grenser. Hennes tre siste kamper har foregått i Frederikshavn i Danmark. NRK.no oppdaterer saken""" lix = Lix(test_text) # oppretter instans print lix.get_lix_score() # printer LIX score too_high_lix = """Omtrent 13 000 soldater deltar i øvelsen fra 11.-21. februar med deltakere fra syv land: Thailand, USA, Singapore, Indonesia, Japan Sør-Korea og Malaysia deltar i Cobra Gold 2013, som er en multinasjonal militærøvelse. Cobra Gold fokuserer på å vedlikeholde og forbedre forhold mellom militæret i nasjoner som har felles mål og forpliktelser når det gjelder sikkerhet i Asia-/Stillehavsregionen. Multinasjonal øvelse Det er en årlig øvelse som foregår rundt om i hele Thailand. Soldatene som deltar får være med på alt fra kamptrening til katastrofehjelp under øvelsen som avsluttes 21. februar. Vil oppnå fred og stabilitet Under åpningsseremonien sa admiral Samuel Locklear, sjef i styret for den amerikanske Stillehavskysten, at den årlige øvelsen viser et engasjement fra de deltakende nasjonene for å oppnå fred og stabilitet i regionen. Slik som hvert år, omfatter øvelsene i år krigføring i jungelen, sivil evakuering og tiltak mot kjemiske, biologiske og kjernefysiske angrep. Soldatene lærer også hvordan de skal bidra i humanitære og kommunale bistandsprosjekter. 20 nasjoner observerer for første gang
def get(soup, data, dictionary): """Tar et BeautifulSoup objekt og returnerer et map av data Modifiserer dictionary argumentet du gir inn.""" # Steg 1: Ting som alltid er sant: dictionary['fb_like'] = None #len(soup.select(".pluginButtonLabel")) dictionary['others_share'] = None dictionary['fb_share'] = len(soup.select(".share-facebook")) dictionary['googleplus_share'] = len(soup.select(".share-googleplus")) dictionary['twitter_share'] = len(soup.select(".share-twitter")) dictionary['email_share'] = len(soup.select(".share-mail")) # "les også" føljetong (sidebar) om om dette presise # dette må gjøres før vi fjerner js (ser det ut til..) # den første her ligger alltid inni .articlewrapper dictionary['related_stories_box_les'] = len(soup.select("aside.articlewidgets article")) #-9999 # related thematic (found in footer part of page) dictionary['related_stories_box_thematic'] = 0 # grab that footer part with data-relation-limit attr related_thematic = soup.find_all(has_data_relation_limit) # loop for el in related_thematic: #check divs for div in el.select("div"): if has_data_id(div): dictionary['related_stories_box_thematic'] +=1 # re related stories is the combined previous two dictionary['related_stories'] = dictionary['related_stories_box_les'] + dictionary['related_stories_box_thematic'] # antall js dokumenter dictionary['js'] = count_js(soup, data, dictionary) # = len(re.findall("<iframe src=", data)) # .js # remove javascript. it is spread through the site like spots on a Dalmatian # I believe this is what creates the somewhat awkward line-breaks in the soup [s.decompose() for s in soup.body.article('script')] # Find author(s) byline = soup.find('div', 'byline') authors = [] try: for address in byline.find_all('address'): authorName = address.find('a', 'fn').text # alternatively .find('a', 'email') #address.a.text authorMail = None # midlertidig gitt opp # not all have a span role if (address.find('span', 'role')): authorRole = address.find('span', 'role').text #address.span.text else: authorRole = None author = [authorName, authorMail, authorRole] authors.append(author) # address does not always come with figure, if it does, decompose # check http://www.nrk.no/ho/nekter-for-at-hun-var-med-pa-ran-1.11415954 if (address.figure): address.figure.decompose() # remove tag cos it contains imgs we do not want to count later. except: new_logger.info("Ingen forfatter, oppgir ukjent, url: %s", dictionary['url']) authors.append([None, None, None]) # this is not very slick.. dictionary['authors'] = authors #print dictionary['authors'] # # dette failer # try: # for address, li in izip(byline.find_all('address'), byline.find_all('li', 'icon-email')): # authorName = address.strong.text #address.find(class_='fn').string.encode('utf-8') # # NRK is still trying to hide the email address from spammers. #href = li.a['href'] # authorMail = None # 'abandon this? too hard?'#unquote(href[21:-1])[7:] # Antakelsen er at epost vil holde seg til ASCII. # authorRole = address.span.text #address.find(class_='role').string.strip().encode('utf-8') # author = [authorName, authorMail, authorRole] # authors.append(author) # # and remove author image (so not to count it later..) # address.figure.decompose() # except AttributeError: # # Finner ingen forfatter(e) # new_logger.error("fant ingen forfatter, oppgir ukjent, url: %s", dictionary['url']) # #print "[ERROR]: Kunne ikke finne forfattere for artikkel \"{0}\". Oppgir \"<UKJENT>\" som forfatter".format(dictionary['url']) # authors.append([None, None, None]) # dictionary['authors'] = authors # Find published datetime try: dictionary['published'] = strptime(soup.time['datetime'][0:19], "%Y-%m-%dT%H:%M:%S") except TypeError: dictionary['published'] = None # Find update datetime try: updated = soup.find('span', 'update-date') dictionary['updated'] = datetime.strptime(updated.time['datetime'][0:19], "%Y-%m-%dT%H:%M:%S") except: dictionary['updated'] = None # Find headline try: dictionary['headline'] = soup.body.article.find('h1').text.strip() #dictionary['headline'] = soup.header.find('div', 'articletitle').h1.text # .text gived unicode, .string gives 'bs4.element.NavigableString' except AttributeError: new_logger.warn("NB: bruker doc-title...") dictionary['headline'] = soup.title.text # Find full text # article MINUS stuff.. try: # remove the related section soup.body.article.find('section', 'lp_related').decompose() except: pass # remove div.published (the top-bar) soup.body.article.find('div', 'published').decompose() # remove div.shareurl (the sharebar) soup.body.article.find('div', 'sharing').decompose() # store body text dictionary['body'] = soup.body.article.text.strip() # Debugg fact-boxes: # print dictionary['url'] # print dictionary['body'] # if soup.find_all("section", class_="facts"): # print "*" *70 # import sys # sys.exit(0) # .stripped_strings option? # soup.get_text("|", strip=True) perhaps? # Find char count, line count, word count and Lix lix = Lix(dictionary['body']) analyse = lix.analyzeText(dictionary['body']) try: dictionary['char_count'] = len(dictionary['body']) dictionary['word_count'] = analyse['wordCount'] dictionary['line_count'] = analyse['sentenceCount'] dictionary['lesbahet'] = analyse['lixScore'] except TypeError: new_logger.error( "Kunne ikke kjøre lix", dictionary['body'] ) dictionary['line_count'] = None dictionary['word_count'] = None dictionary['char_count'] = None dictionary['lesbahet'] = -1.0 # Find fact-boxes : # Should be included in both word-count, LIX, image-count, video-count, etc. faktabokser = [] #for boks in soup.find_all("section", class_="articlewidget cf facts lp_faktaboks"): img_from_factbox = 0 for boks in soup.find_all("section", class_="facts"): #print "FAKTA! " * 10 faktaboks_text = boks.text.strip() lix = Lix(faktaboks_text) faktaboks_analysis = lix.analyzeText(faktaboks_text) faktabokser.append({"text":faktaboks_text, "links":boks.find_all("a"), "wordcount":faktaboks_analysis['wordCount']}) # boks.decompose() # fact-boxes should be includes, so not removed. img_from_factbox += count_images(boks, data, dictionary) ## add img count from factboks #print "images from factboks: %s" % (img_from_factbox) dictionary['factbox'] = faktabokser # look through the last part of the body text to find news bureau # add more in settings.py dictionary['news_bureau'] = matches_pattern(dictionary['body'].strip()[-200:], syndicators) # Find language. Defaults can be tampered with in settings.py (language, certainty) = langid.classify(soup.body.article.text) language_code = uncertain_language_string if (certainty > language_identification_threshold): language_code = language dictionary['language'] = language_code # video # sets dictionary['video_files'], dictionary['video_files_nrk'] # only send the stuff in article-tag as soup get_video(soup.body.article, data, dictionary) # flash (untested) dictionary['flash_file'] = get_flash(soup.body.article, data, dictionary) # Tell opp iframe. dictionary['iframe'] = count_iframes(soup, data, dictionary) # Tell opp css (karakterer) dictionary['css'] = count_css(soup, data, dictionary) # Finnes det en form for kommentarer her? I de nyere NRK sidene er det tydeligvis kun det på Ytring. # Men vi søker generelt nå, og håper på det beste. I verste fall vil et interessant krasj fortelle meg at dette ikke er tilfellet. –Haakon dictionary['comment_fields'] = 0 dictionary['comment_number'] = 0 if len(re.findall('<div id="disqus_thread"', data)) != 0: dictionary['comment_fields'] = 1 dictionary['comment_number'] = None #-9999#num_comments(dictionary) # tar seg av lenker i siden count_links(soup, data, dictionary) # Find self declared url search = re.findall('<input type="text" value=".*" readonly="readonly"', data) if len(search) > 1: print "ERROR: MORE THAN ONE SELF-LINK" dictionary['url_self_link'] = (search[0])[26:-21] # antall bilder. # Beautiful Soup teller feil her og. Noe er galt. # Regex matching gir riktig resultat så vi får gå for det. #print len(re.findall("<img src=\"http:", data)) # se nærmere på denne.. #print soup.article.find_all('figure') # includes img of author... #result = soup.article.find_all('figure', 'image') #print len(result) img_from_header = count_images(soup.body.article.header, data, dictionary) img_from_article_text = count_images(soup.select(".articlebody")[0], data, dictionary) dictionary['images'] = img_from_header+img_from_article_text+img_from_factbox # -9999# len(re.findall("<img src=\"http:", data)) #print "images: %s og %s og tilsammen: %s" % (img_from_header,img_from_article_text, img_from_header+img_from_article_text) # på videoer gjør vi slik: soup.select('figure.video') Kanskje det er noe også her, (tror dette loades via js) # bildesamlinger dictionary['image_collection'] = len(soup.select(".slideshow")) # er dette nok? # Som diskutert med Eirik, dette henter ut bildetekstene og deler dem med pipe symboler. imgtagger = re.findall(u"<img src=\"http.*\n.*", data) bildetekst = "" for imgtag in imgtagger: funn = re.findall("alt=\".*\"", imgtag) if len(funn) > 0: bildetekst += ((funn[0])[5:-1] + " | ") bildetekst = bildetekst[:-3] # Fjerner siste pipen dictionary['image_captions'] = bildetekst # !!! trenger flere eksempler på dette dictionary['map'] = count_map(soup.body.article, data, dictionary) dictionary['poll'] = None #-9999 dictionary['game'] = None #-9999 # sum interactive # dictionary['interactive_elements'] = dictionary['comment_fields'] + dictionary['image_collection'] + \ # dictionary['video_files'] + dictionary['video_files_nrk'] + \ # dictionary['fb_like'] + dictionary['fb_share'] + \ # dictionary['googleplus_share'] + dictionary['twitter_share'] + \ # dictionary['others_share'] + dictionary['email_share'] + \ # dictionary['map'] + dictionary['poll'] + dictionary['game'] dictionary['interactive_elements'] = count_interactive( \ dictionary['comment_fields'] , dictionary['image_collection'] , \ dictionary['video_files'] , dictionary['video_files_nrk'] , \ dictionary['fb_like'] , dictionary['fb_share'] , \ dictionary['googleplus_share'] , dictionary['twitter_share'] , \ dictionary['others_share'] , dictionary['email_share'] , \ dictionary['map'] , dictionary['poll'] , dictionary['game']) return dictionary
def get(soup, data, dictionary): """Tar et BeautifulSoup objekt og returnerer et map av data Modifiserer dictionary argumentet du gir inn.""" # Steg 1: Ting som alltid er sant: dictionary['fb_like'] = None #len(soup.select(".pluginButtonLabel")) dictionary['others_share'] = None dictionary['fb_share'] = len(soup.select(".share-facebook")) dictionary['googleplus_share'] = len(soup.select(".share-googleplus")) dictionary['twitter_share'] = len(soup.select(".share-twitter")) dictionary['email_share'] = len(soup.select(".share-mail")) # "les også" føljetong (sidebar) om om dette presise # dette må gjøres før vi fjerner js (ser det ut til..) # den første her ligger alltid inni .articlewrapper dictionary['related_stories_box_les'] = len( soup.select("aside.articlewidgets article")) #-9999 # related thematic (found in footer part of page) dictionary['related_stories_box_thematic'] = 0 # grab that footer part with data-relation-limit attr related_thematic = soup.find_all(has_data_relation_limit) # loop for el in related_thematic: #check divs for div in el.select("div"): if has_data_id(div): dictionary['related_stories_box_thematic'] += 1 # re related stories is the combined previous two dictionary['related_stories'] = dictionary[ 'related_stories_box_les'] + dictionary['related_stories_box_thematic'] # antall js dokumenter dictionary['js'] = count_js( soup, data, dictionary) # = len(re.findall("<iframe src=", data)) # .js # remove javascript. it is spread through the site like spots on a Dalmatian # I believe this is what creates the somewhat awkward line-breaks in the soup [s.decompose() for s in soup.body.article('script')] # Find author(s) byline = soup.find('div', 'byline') authors = [] try: for address in byline.find_all('address'): authorName = address.find( 'a', 'fn').text # alternatively .find('a', 'email') #address.a.text authorMail = None # midlertidig gitt opp # not all have a span role if (address.find('span', 'role')): authorRole = address.find('span', 'role').text #address.span.text else: authorRole = None author = [authorName, authorMail, authorRole] authors.append(author) # address does not always come with figure, if it does, decompose # check http://www.nrk.no/ho/nekter-for-at-hun-var-med-pa-ran-1.11415954 if (address.figure): address.figure.decompose( ) # remove tag cos it contains imgs we do not want to count later. except: new_logger.info("Ingen forfatter, oppgir ukjent, url: %s", dictionary['url']) authors.append([None, None, None]) # this is not very slick.. dictionary['authors'] = authors #print dictionary['authors'] # # dette failer # try: # for address, li in izip(byline.find_all('address'), byline.find_all('li', 'icon-email')): # authorName = address.strong.text #address.find(class_='fn').string.encode('utf-8') # # NRK is still trying to hide the email address from spammers. #href = li.a['href'] # authorMail = None # 'abandon this? too hard?'#unquote(href[21:-1])[7:] # Antakelsen er at epost vil holde seg til ASCII. # authorRole = address.span.text #address.find(class_='role').string.strip().encode('utf-8') # author = [authorName, authorMail, authorRole] # authors.append(author) # # and remove author image (so not to count it later..) # address.figure.decompose() # except AttributeError: # # Finner ingen forfatter(e) # new_logger.error("fant ingen forfatter, oppgir ukjent, url: %s", dictionary['url']) # #print "[ERROR]: Kunne ikke finne forfattere for artikkel \"{0}\". Oppgir \"<UKJENT>\" som forfatter".format(dictionary['url']) # authors.append([None, None, None]) # dictionary['authors'] = authors # Find published datetime try: dictionary['published'] = strptime(soup.time['datetime'][0:19], "%Y-%m-%dT%H:%M:%S") except TypeError: dictionary['published'] = None # Find update datetime try: updated = soup.find('span', 'update-date') dictionary['updated'] = datetime.strptime( updated.time['datetime'][0:19], "%Y-%m-%dT%H:%M:%S") except: dictionary['updated'] = None # Find headline try: dictionary['headline'] = soup.body.article.find('h1').text.strip() #dictionary['headline'] = soup.header.find('div', 'articletitle').h1.text # .text gived unicode, .string gives 'bs4.element.NavigableString' except AttributeError: new_logger.warn("NB: bruker doc-title...") dictionary['headline'] = soup.title.text # Find full text # article MINUS stuff.. try: # remove the related section soup.body.article.find('section', 'lp_related').decompose() except: pass # remove div.published (the top-bar) soup.body.article.find('div', 'published').decompose() # remove div.shareurl (the sharebar) soup.body.article.find('div', 'sharing').decompose() # store body text dictionary['body'] = soup.body.article.text.strip() # Debugg fact-boxes: # print dictionary['url'] # print dictionary['body'] # if soup.find_all("section", class_="facts"): # print "*" *70 # import sys # sys.exit(0) # .stripped_strings option? # soup.get_text("|", strip=True) perhaps? # Find char count, line count, word count and Lix lix = Lix(dictionary['body']) analyse = lix.analyzeText(dictionary['body']) try: dictionary['char_count'] = len(dictionary['body']) dictionary['word_count'] = analyse['wordCount'] dictionary['line_count'] = analyse['sentenceCount'] dictionary['lesbahet'] = analyse['lixScore'] except TypeError: new_logger.error("Kunne ikke kjøre lix", dictionary['body']) dictionary['line_count'] = None dictionary['word_count'] = None dictionary['char_count'] = None dictionary['lesbahet'] = -1.0 # Find fact-boxes : # Should be included in both word-count, LIX, image-count, video-count, etc. faktabokser = [] #for boks in soup.find_all("section", class_="articlewidget cf facts lp_faktaboks"): img_from_factbox = 0 for boks in soup.find_all("section", class_="facts"): #print "FAKTA! " * 10 faktaboks_text = boks.text.strip() lix = Lix(faktaboks_text) faktaboks_analysis = lix.analyzeText(faktaboks_text) faktabokser.append({ "text": faktaboks_text, "links": boks.find_all("a"), "wordcount": faktaboks_analysis['wordCount'] }) # boks.decompose() # fact-boxes should be includes, so not removed. img_from_factbox += count_images( boks, data, dictionary) ## add img count from factboks #print "images from factboks: %s" % (img_from_factbox) dictionary['factbox'] = faktabokser # look through the last part of the body text to find news bureau # add more in settings.py dictionary['news_bureau'] = matches_pattern( dictionary['body'].strip()[-200:], syndicators) # Find language. Defaults can be tampered with in settings.py (language, certainty) = langid.classify(soup.body.article.text) language_code = uncertain_language_string if (certainty > language_identification_threshold): language_code = language dictionary['language'] = language_code # video # sets dictionary['video_files'], dictionary['video_files_nrk'] # only send the stuff in article-tag as soup get_video(soup.body.article, data, dictionary) # flash (untested) dictionary['flash_file'] = get_flash(soup.body.article, data, dictionary) # Tell opp iframe. dictionary['iframe'] = count_iframes(soup, data, dictionary) # Tell opp css (karakterer) dictionary['css'] = count_css(soup, data, dictionary) # Finnes det en form for kommentarer her? I de nyere NRK sidene er det tydeligvis kun det på Ytring. # Men vi søker generelt nå, og håper på det beste. I verste fall vil et interessant krasj fortelle meg at dette ikke er tilfellet. –Haakon dictionary['comment_fields'] = 0 dictionary['comment_number'] = 0 if len(re.findall('<div id="disqus_thread"', data)) != 0: dictionary['comment_fields'] = 1 dictionary['comment_number'] = None #-9999#num_comments(dictionary) # tar seg av lenker i siden count_links(soup, data, dictionary) # Find self declared url search = re.findall('<input type="text" value=".*" readonly="readonly"', data) if len(search) > 1: print "ERROR: MORE THAN ONE SELF-LINK" dictionary['url_self_link'] = (search[0])[26:-21] # antall bilder. # Beautiful Soup teller feil her og. Noe er galt. # Regex matching gir riktig resultat så vi får gå for det. #print len(re.findall("<img src=\"http:", data)) # se nærmere på denne.. #print soup.article.find_all('figure') # includes img of author... #result = soup.article.find_all('figure', 'image') #print len(result) img_from_header = count_images(soup.body.article.header, data, dictionary) img_from_article_text = count_images( soup.select(".articlebody")[0], data, dictionary) dictionary[ 'images'] = img_from_header + img_from_article_text + img_from_factbox # -9999# len(re.findall("<img src=\"http:", data)) #print "images: %s og %s og tilsammen: %s" % (img_from_header,img_from_article_text, img_from_header+img_from_article_text) # på videoer gjør vi slik: soup.select('figure.video') Kanskje det er noe også her, (tror dette loades via js) # bildesamlinger dictionary['image_collection'] = len( soup.select(".slideshow")) # er dette nok? # Som diskutert med Eirik, dette henter ut bildetekstene og deler dem med pipe symboler. imgtagger = re.findall(u"<img src=\"http.*\n.*", data) bildetekst = "" for imgtag in imgtagger: funn = re.findall("alt=\".*\"", imgtag) if len(funn) > 0: bildetekst += ((funn[0])[5:-1] + " | ") bildetekst = bildetekst[:-3] # Fjerner siste pipen dictionary['image_captions'] = bildetekst # !!! trenger flere eksempler på dette dictionary['map'] = count_map(soup.body.article, data, dictionary) dictionary['poll'] = None #-9999 dictionary['game'] = None #-9999 # sum interactive # dictionary['interactive_elements'] = dictionary['comment_fields'] + dictionary['image_collection'] + \ # dictionary['video_files'] + dictionary['video_files_nrk'] + \ # dictionary['fb_like'] + dictionary['fb_share'] + \ # dictionary['googleplus_share'] + dictionary['twitter_share'] + \ # dictionary['others_share'] + dictionary['email_share'] + \ # dictionary['map'] + dictionary['poll'] + dictionary['game'] dictionary['interactive_elements'] = count_interactive( \ dictionary['comment_fields'] , dictionary['image_collection'] , \ dictionary['video_files'] , dictionary['video_files_nrk'] , \ dictionary['fb_like'] , dictionary['fb_share'] , \ dictionary['googleplus_share'] , dictionary['twitter_share'] , \ dictionary['others_share'] , dictionary['email_share'] , \ dictionary['map'] , dictionary['poll'] , dictionary['game']) return dictionary
def get(soup, data, dictionary): """Tar et BeautifulSoup objekt og returnerer et map av data Modifiserer dictionary argumentet du gir inn.""" # Steg 1: Ting som alltid er sant: dictionary['fb_like'] = None #0 dictionary['others_share'] = None #0 dictionary['fb_share'] = len(soup.select(".share-facebook")) dictionary['googleplus_share'] = len(soup.select(".share-googleplus")) dictionary['twitter_share'] = len(soup.select(".share-twitter")) dictionary['email_share'] = len(soup.select(".share-mail")) # tror ikke disse har noen aside... dictionary['related_stories_box_les'] = len( soup.select("aside.articlewidgets article")) # related thematic (found in footer part of page) dictionary['related_stories_box_thematic'] = 0 # grab that footer part with data-relation-limit attr related_thematic = soup.find_all(has_data_relation_limit) # loop for el in related_thematic: #check divs for div in el.select("div"): if has_data_id(div): dictionary['related_stories_box_thematic'] += 1 # re related stories is the combined previous two dictionary['related_stories'] = dictionary[ 'related_stories_box_les'] + dictionary['related_stories_box_thematic'] # antall js dokumenter dictionary['js'] = count_js( soup, data, dictionary) # = len(re.findall("<iframe src=", data)) # .js # remove javascript. [s.decompose() for s in soup.body.article('script')] # I believe this is what creates the somewhat awkward line-breaks in the soup # Find author(s) byline = soup.find('div', 'byline') authors = [] try: for address, li in izip(byline.find_all('address'), byline.find_all('li', 'icon-email')): authorName = address.strong.text #address.find(class_='fn').string.encode('utf-8') # NRK is still trying to hide the email address from spammers. #href = li.a['href'] authorMail = None # 'abandon this? too hard?'#unquote(href[21:-1])[7:] # Antakelsen er at epost vil holde seg til ASCII. authorRole = address.span.text #address.find(class_='role').string.strip().encode('utf-8') author = [authorName, authorMail, authorRole] authors.append(author) # and remove author image (so not to count it later..) address.figure.decompose() except AttributeError: # Finner ingen forfatter(e) new_logger.warn( "Ingen forfattere \"{0}\". Oppgir \"<UKJENT>\" som forfatter". format(dictionary['url'])) #print authors.append([None, None, None]) dictionary['authors'] = authors # Find published datetime try: dictionary['published'] = strptime(soup.time['datetime'][0:19], "%Y-%m-%dT%H:%M:%S") except TypeError: new_logger.info("finner ikke publiseringsdato") dictionary['published'] = None new_logger.debug("published: %s", type(dictionary['published'])) # Find update datetime try: updated = soup.find('span', 'update-date') dictionary['updated'] = datetime.strptime( updated.time['datetime'][0:19], "%Y-%m-%dT%H:%M:%S") except: new_logger.info("finner ikke oppdateringsdato") dictionary['updated'] = None # Find headline try: dictionary['headline'] = soup.body.article.find('h1').text.strip() #dictionary['headline'] = soup.header.find('div', 'articletitle').h1.text # .text gived unicode, .string gives 'bs4.element.NavigableString' except AttributeError: new_logger.debug("NB: bruker doc-title...") dictionary['headline'] = soup.title.text # Find fact-boxes : # Should be removes from body, but includes in LIX. Right? faktabokser = [] #for boks in soup.find_all("section", class_="articlewidget cf facts lp_faktaboks"): for boks in soup.find_all("section", class_="facts"): faktaboks_text = boks.text.strip() lix = Lix(faktaboks_text) faktaboks_analysis = lix.analyzeText(faktaboks_text) faktabokser.append({ "text": faktaboks_text, "links": boks.find_all("a"), "wordcount": faktaboks_analysis['wordCount'] }) # and remove from soup #boks.decompose() #ikke fjern boks'n fra suppa. # NB, this also removes pictures if any in the fact-box dictionary['factbox'] = faktabokser new_logger.debug("faktabokser: %s", len(dictionary['factbox'])) # Find full text # article MINUS .universes OR is it .lp_related ? # remove the related section # try: # soup.body.article.find('section', 'lp_related').decompose() # except: # pass # # remove div.published (the top-bar) # soup.body.article.find('div', 'published').decompose() # # remove div.shareurl (the sharebar) # soup.body.article.find('div', 'sharing').decompose() # Find self declared url # get this before decomposing the header this is found in.. dictionary['url_self_link'] = soup.select("time > a")[0]['href'] # remove header with sharing links and date soup.select(".bulletin-header")[0].decompose() # store body text dictionary['body'] = soup.body.article.text.strip() # .stripped_strings option? # soup.get_text("|", strip=True) perhaps? # Find char count, line count, word count and Lix lix = Lix(dictionary['body']) analyse = lix.analyzeText(dictionary['body']) try: dictionary['char_count'] = len(dictionary['body']) dictionary['word_count'] = analyse['wordCount'] dictionary['line_count'] = analyse['sentenceCount'] dictionary['lesbahet'] = analyse['lixScore'] except TypeError: new_logger.error("Kunne ikke kjøre lix", dictionary['body']) dictionary['line_count'] = None dictionary['word_count'] = None dictionary['char_count'] = None dictionary['lesbahet'] = -1.0 # look through the last part of the body text to find news bureau # add more in settings.py dictionary['news_bureau'] = matches_pattern( dictionary['body'].strip()[-200:], syndicators) # Find language. Defaults can be tampered with in settings.py (language, certainty) = langid.classify(soup.body.article.text) new_logger.debug("(language, certainty) (%s, %s)" % (language, certainty)) language_code = uncertain_language_string if (certainty > language_identification_threshold): language_code = language dictionary['language'] = language_code get_video(soup.body.article, data, dictionary) # flash (untested) dictionary['flash_file'] = get_flash(soup.body.article, data, dictionary) # Tell opp iframe. dictionary['iframe'] = count_iframes(soup, data, dictionary) # Tell opp css (karakterer) dictionary['css'] = count_css(soup, data, dictionary) # Finnes det en form for kommentarer her? I de nyere NRK sidene er det tydeligvis kun det på Ytring. # Men vi søker generelt nå, og håper på det beste. I verste fall vil et interessant krasj fortelle meg at dette ikke er tilfellet. –Haakon dictionary['comment_fields'] = 0 dictionary['comment_number'] = 0 if len(re.findall('<div id="disqus_thread"', data)) != 0: dictionary['comment_fields'] = 1 dictionary['comment_number'] = None # -9999#num_comments(dictionary) # tar seg av lenker i siden count_links(soup, data, dictionary) # antall bilder. # Beautiful Soup teller feil her og. Noe er galt. # Regex matching gir riktig resultat så vi får gå for det. #result = soup.article.find_all('figure', 'image') #print len(result) #new_logger.debug( "antall bilder: %s", len(re.findall("<img src=\"http:", data)) ) dictionary['images'] = count_images(soup.body.article, data, dictionary) # bildesamlinger dictionary['image_collection'] = len( soup.select(".slideshow")) # er dette nok? # Som diskutert med Eirik, dette henter ut bildetekstene og deler dem med pipe symboler. imgtagger = re.findall(u"<img src=\"http.*\n.*", str(soup.body.article)) bildetekst = "" for imgtag in imgtagger: funn = re.findall("alt=\".*\"", imgtag) if len(funn) > 0: bildetekst += ((funn[0])[5:-1] + " | ") bildetekst = bildetekst[:-3] # Fjerner siste pipen dictionary['image_captions'] = bildetekst dictionary['map'] = count_map(soup.body.article, data, dictionary) dictionary['poll'] = None # -9999 dictionary['game'] = None # -9999 dictionary['interactive_elements'] = count_interactive( \ dictionary['comment_fields'] , dictionary['image_collection'] , \ dictionary['video_files'] , dictionary['video_files_nrk'] , \ dictionary['fb_like'] , dictionary['fb_share'] , \ dictionary['googleplus_share'] , dictionary['twitter_share'] , \ dictionary['others_share'] , dictionary['email_share'] , \ dictionary['map'] , dictionary['poll'] , dictionary['game']) return dictionary
Denne loven har hverken Høyre eller Idrettsforbundet planer om å avskaffe. – I teorien er vi like langt. På grunn av knockoutloven vil ikke Cecilia Brækhus få bokse i Norge. Hun bokser nemlig 20-minutters kamper, knockoutloven tillater bare 12-minutters kamper. I tillegg sier knockoutloven at du må bokse med hjelm, og det gjør ikke Cecilia, forklarer Nilsen. Kan søke om dispensasjon Boksere kan imidlertid søke om dispensasjon fra knockoutloven, og dermed gir opphevingen av proffbokseforbudet en teoretisk mulighet for Brækhus til å bokse i Norge. – Det hadde vært helt enormt. Det hadde vært en utrolig avslutning på en bra karriere. Men om det skjer i min tid, gjenstår å se. Det hadde vært norsk idrettshistorie, sa Brækhus til NRK.no i september. Brækhus har bokset 23 proffkamper i løpet av karrieren - alle er vunnet og alle sammen er gjennomført utenfor Norges grenser. Hennes tre siste kamper har foregått i Frederikshavn i Danmark. NRK.no oppdaterer saken""" lix = Lix(test_text) # oppretter instans print lix.get_lix_score() # printer LIX score too_high_lix = """Omtrent 13 000 soldater deltar i øvelsen fra 11.-21. februar med deltakere fra syv land: Thailand, USA, Singapore, Indonesia, Japan Sør-Korea og Malaysia deltar i Cobra Gold 2013, som er en multinasjonal militærøvelse. Cobra Gold fokuserer på å vedlikeholde og forbedre forhold mellom militæret i nasjoner som har felles mål og forpliktelser når det gjelder sikkerhet i Asia-/Stillehavsregionen. Multinasjonal øvelse Det er en årlig øvelse som foregår rundt om i hele Thailand. Soldatene som deltar får være med på alt fra kamptrening til katastrofehjelp under øvelsen som avsluttes 21. februar. Vil oppnå fred og stabilitet Under åpningsseremonien sa admiral Samuel Locklear, sjef i styret for den amerikanske Stillehavskysten, at den årlige øvelsen viser et engasjement fra de deltakende nasjonene for å oppnå fred og stabilitet i regionen. Slik som hvert år, omfatter øvelsene i år krigføring i jungelen, sivil evakuering og tiltak mot kjemiske, biologiske og kjernefysiske angrep. Soldatene lærer også hvordan de skal bidra i humanitære og kommunale bistandsprosjekter.