Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- from watson_developer_cloud import ToneAnalyzerV3Beta
- import urllib.request
- import codecs
- import csv
- import os
- import re
- import sys
- import collections
- import glob
- import xlwt
- ipath = 'C:/TEMP/' # input folder
- opath = 'C:/TEMP/' # output folder
- reader = codecs.getreader("utf-8")
- tone_analyzer = ToneAnalyzerV3Beta(
- url='https://gateway.watsonplatform.net/tone-analyzer/api',
- username='ID',
- password='Pass',
- version='2016-02-11')
- path = 'C:/TEMP/*.html'
- file = glob.glob(path)
- # iterate over the list getting each file
- for fle in file:
- # open the file and then call .read() to get the text
- with open(fle) as f:
- text = f.read
- # tone analysis
- data=tone_analyzer.tone(text='text')
- # iterate through tone analysis data
- tonename=[]; tonescore=[]
- for cat in data['document_tone']['tone_categories']:1
- for tone in cat['tones']:
- tonename.append(tone['tone_name'])
- tonescore.append(tone['score'])
- print(tone['tone_name'],tone['score'])
- # output tone name and score to file
- output = fle.replace('.html', '')
- X=output
- with open(X+'_tonename.csv', mode = 'w') as csvfile1:
- writer = csv.writer(csvfile1)
- for i in tonename:
- writer.writerows((tone['tone_name'],tone['score']) for tone in cat['tones'])
- <HTML>
- <HEAD>
- <STYLE TYPE="text/css"><!--
- .c0 { text-align: center; }
- .c1 { text-align: center; margin-top: 0em; margin-bottom: 0em; }
- .c2 { font-family: 'Times New Roman'; font-size: 10pt; font-style: normal; font-weight: normal; color: #000000; text-decoration: none; }
- .c3 { text-align: center; margin-left: 13%; margin-right: 13%; }
- .c4 { font-family: 'Times New Roman'; font-size: 10pt; font-style: normal; font-weight: bold; color: #CC0033; text-decoration: none; }
- .c5 { text-align: left; }
- .c6 { text-align: left; margin-top: 0em; margin-bottom: 0em; }
- .c7 { font-family: 'Times New Roman'; font-size: 14pt; font-style: normal; font-weight: bold; color: #000000; text-decoration: none; }
- .c8 { font-family: 'Times New Roman'; font-size: 10pt; font-style: normal; font-weight: bold; color: #000000; text-decoration: none; }
- .c9 { text-align: left; margin-top: 1em; margin-bottom: 0em; }
- .c10 { page-break-before: always; }
- --></STYLE>
- <!-- LXNComment 2827:564001881 -->
- <TITLE> </TITLE>
- <META TOPIC="null" DOCUMENTS="2" UPDATED="Wednesday, June 01, 2016 16:04:15 EST" /></HEAD>
- <BODY>
- <A NAME="DOC_ID_0_0"></A><!-- Hide XML section from browser
- <DOC NUMBER=1>
- <DOCFULL> -->
- <BR><DIV CLASS="c0"><P CLASS="c1"><SPAN CLASS="c2">1 of 4 DOCUMENTS</SPAN></P>
- </DIV>
- <BR><DIV CLASS="c0"><BR><P CLASS="c1"><SPAN CLASS="c2">FD (Fair Disclosure) Wire</SPAN></P>
- </DIV>
- <BR><DIV CLASS="c3"><P CLASS="c1"><SPAN CLASS="c4">April</SPAN><SPAN CLASS="c2"> **26, 2016 Tuesday<**/SPAN></P>
- </DIV>
- <BR><DIV CLASS="c5"><P CLASS="c6"><SPAN CLASS="c7">Q2 2016 Apple Inc Earnings Call - Final</SPAN></P>
- </DIV>
- <BR><DIV CLASS="c5"><P CLASS="c6"><SPAN CLASS="c8">LENGTH: </SPAN><SPAN CLASS="c2">8726 words</SPAN></P>
- </DIV>
- <BR><DIV CLASS="c5"><P CLASS="c9"><SPAN CLASS="c2">Corporate Participants</SPAN></P>
- <P CLASS="c9"><SPAN CLASS="c2">* Nancy Paxton</SPAN></P>
- <P CLASS="c9"><SPAN CLASS="c2">Apple Inc. - Senior Director of IR</SPAN></P>
- <P CLASS="c9"><SPAN CLASS="c2">* Tim Cook</SPAN></P>
- <P CLASS="c9"><SPAN CLASS="c2">**Apple Inc.** - CEO</SPAN></P>
- <P CLASS="c9"><SPAN CLASS="c2">*
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement