Пример #1
0
def summaryFromURL(url):
    
    #   Grab the JSON
    entry = JSONFromURL(url)

    #   Retrieve the overview
    entryText = entry["overview"].get_text()

    #   Ensure the overview is well formed
    overview = BeautifulSoup(entryText)

    #   Summarize and return the overview
    return getSummary(overview)
Пример #2
0
def parseWiki(search):

    url = 'http://en.wikipedia.org/w/api.php?format=json&action=opensearch&search=' + search + '&prop=revisions&rvprop=content'

    r = urlopen(url).read()

    dict1 = json.loads(r)

    dict2 = dict1['1'][0]

    url2 = 'http://en.wikipedia.org/wiki/' + dict2

    '''
    #Finding page id:
    dict3 = dict2.split(" ")
    if dict3.length() > 1:
        dict3 = dict2[0]
        for i in range(1, company.length()):
             dict3 = dict3 + '_' + dict2.split(" ")[i]

    url2 = 'http://en.wikipedia.org/wiki/' + dict3
    http://en.wikipedia.org/w/api.php?action=query&titles=Albert%20Einstein&prop=info&format=jsonfm
    '''
    #parse article
    p = 'http://en.wikipedia.org/w/api.php?action=parse&prop=text&page=' + dict2 + '&format=json'
    p1 = urlopen(p).read()
    p2 = json.loads(p1)
    p3 = p2['parse']['text']['*']
    p4 = BeautifulSoup(p3)
    p5 = p4.find_all('p')
    p6 = p5[0]
    p7 = p6.getText()

    #create bitly shortlink
    shortapi = "https://api-ssl.bitly.com/v3/shorten?access_token=794e02fd047d7fcc0c44543742d0f471e2f9ebc8&longUrl=" + url2
    shortLink = json.loads( urlopen(shortapi).read() )
    shortened = shortLink['data']['url']


    #   Return a list of messages to send
    return separate(getSummary(p7 ) + str(shortened)[7:15]+str(shortened)[15:])