<commit_before>import feedparser
import nltk
import requests
from bs4 import BeautifulSoup as bs
from sklearn.feature_extraction.text import TfidfVectorizer
import networkx as nx
import numpy as np
from nltk.corpus import stopwords
from nltk.stem import RSLPStemmer
from nltk import word_tokenize
from string import punctuation
from detection import detect_language

def rss_to_links(rssurl):
    """Input: url of the rss.
        Output: list of links to news."""
    feed = feedparser.parse(rssurl)
    return [link['link'] for link in feed['entries']]

def scrape_page(url):
    """Input: url of news.
        Output: Text from the page."""
    page = requests.get(url).text
    tree = bs(page, "html.parser")
    title = tree.title.string
    for script in tree(["script","style"]):
        script.extract()
    paragraphs = tree.find_all('p')
    #print paragraphs
    filtered_paragraphs = [paragraph.get_text() for paragraph in paragraphs]
    #print "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"
    #print filtered_paragraphs
    size_paragraphs = [len(para) for para in filtered_paragraphs]
    size_cut = int(sum(size_paragraphs)/len(size_paragraphs))
    texts = [text for text in filtered_paragraphs if len(text) > int(size_cut)]
    #print "##################"
    #print texts
    final_text = []
    for text in texts:#[:-2]:
        if False: #text[0] == "\n":
            break
    #    if text[:5] != "Foto:":
        final_text.append(text)
    #print final_text
    return title, " ".join(final_text)


def textrank(document, language):

    #print document<commit_msg>Change scrape_page to avoid meta data.<commit_after>import feedparser
import nltk
import requests
from bs4 import BeautifulSoup as bs
from sklearn.feature_extraction.text import TfidfVectorizer
import networkx as nx
import numpy as np
from nltk.corpus import stopwords
from nltk.stem import RSLPStemmer
from nltk import word_tokenize
from string import punctuation
from detection import detect_language

def rss_to_links(rssurl):
    """Input: url of the rss.
        Output: list of links to news."""
    feed = feedparser.parse(rssurl)
    return [link['link'] for link in feed['entries']]

def scrape_page(url):
    """Input: url of news.
        Output: Text from the page."""
    page = requests.get(url).text
    tree = bs(page, "html.parser")
    title = tree.title.string
    for script in tree(["script","style"]):
        script.extract()
    all_p = tree.find_all('p')
    t0 = None
    for tag in all_p:
        if t0 == None:
            t0 = tag
        else:
            t1 = tag.parent
            if t1 == t0.parent:
                content = t1
                break
            else:
                t0 = tag

    paragraphs = content.find_all('p')
    filtered_paragraphs = [paragraph.get_text() for paragraph in paragraphs]
    size_paragraphs = [len(para) for para in filtered_paragraphs]
    size_cut = int(sum(size_paragraphs)/len(size_paragraphs))
    texts = [text for text in filtered_paragraphs if len(text) > int(size_cut)]
    final_text = []
    for text in texts:
        if False:
            break
        final_text.append(text)
    return title, " ".join(final_text)


def textrank(document, language):

    #print document
{'fraction_non_alphanumeric': 0.11097372488408037, 'fraction_numerical': 0.00401854714064915, 'mean_word_length': 3.070440251572327, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1097308', 'n_tokens_mistral': 1013, 'n_tokens_neox': 991, 'n_words': 304}