Advertisement
Guest User

Untitled

a guest
Jun 1st, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.36 KB | None | 0 0
  1. import json
  2. from watson_developer_cloud import ToneAnalyzerV3Beta
  3. import urllib.request
  4. import codecs
  5. import csv
  6. import os
  7. import re
  8. import sys
  9. import collections
  10. import glob
  11. import xlwt
  12. ipath = 'C:/TEMP/' # input folder
  13. opath = 'C:/TEMP/' # output folder
  14. reader = codecs.getreader("utf-8")
  15. tone_analyzer = ToneAnalyzerV3Beta(
  16. url='https://gateway.watsonplatform.net/tone-analyzer/api',
  17. username='ID',
  18. password='Pass',
  19. version='2016-02-11')
  20. path = 'C:/TEMP/*.html'
  21. file = glob.glob(path)
  22. # iterate over the list getting each file
  23. for fle in file:
  24. # open the file and then call .read() to get the text
  25. with open(fle) as f:
  26. text = f.read
  27. # tone analysis
  28. data=tone_analyzer.tone(text='text')
  29.  
  30. # iterate through tone analysis data
  31. tonename=[]; tonescore=[]
  32. for cat in data['document_tone']['tone_categories']:1
  33. for tone in cat['tones']:
  34. tonename.append(tone['tone_name'])
  35. tonescore.append(tone['score'])
  36. print(tone['tone_name'],tone['score'])
  37. # output tone name and score to file
  38. output = fle.replace('.html', '')
  39. X=output
  40. with open(X+'_tonename.csv', mode = 'w') as csvfile1:
  41. writer = csv.writer(csvfile1)
  42. for i in tonename:
  43. writer.writerows((tone['tone_name'],tone['score']) for tone in cat['tones'])
  44.  
  45. <HTML>
  46. <HEAD>
  47. <STYLE TYPE="text/css"><!--
  48. .c0 { text-align: center; }
  49. .c1 { text-align: center; margin-top: 0em; margin-bottom: 0em; }
  50. .c2 { font-family: 'Times New Roman'; font-size: 10pt; font-style: normal; font-weight: normal; color: #000000; text-decoration: none; }
  51. .c3 { text-align: center; margin-left: 13%; margin-right: 13%; }
  52. .c4 { font-family: 'Times New Roman'; font-size: 10pt; font-style: normal; font-weight: bold; color: #CC0033; text-decoration: none; }
  53. .c5 { text-align: left; }
  54. .c6 { text-align: left; margin-top: 0em; margin-bottom: 0em; }
  55. .c7 { font-family: 'Times New Roman'; font-size: 14pt; font-style: normal; font-weight: bold; color: #000000; text-decoration: none; }
  56. .c8 { font-family: 'Times New Roman'; font-size: 10pt; font-style: normal; font-weight: bold; color: #000000; text-decoration: none; }
  57. .c9 { text-align: left; margin-top: 1em; margin-bottom: 0em; }
  58. .c10 { page-break-before: always; }
  59. --></STYLE>
  60. <!-- LXNComment 2827:564001881 -->
  61. <TITLE>&nbsp;</TITLE>
  62. <META TOPIC="null" DOCUMENTS="2" UPDATED="Wednesday, June 01, 2016 16:04:15 EST" /></HEAD>
  63. <BODY>
  64. <A NAME="DOC_ID_0_0"></A><!-- Hide XML section from browser
  65. <DOC NUMBER=1>
  66. <DOCFULL> -->
  67. <BR><DIV CLASS="c0"><P CLASS="c1"><SPAN CLASS="c2">1 of 4 DOCUMENTS</SPAN></P>
  68. </DIV>
  69. <BR><DIV CLASS="c0"><BR><P CLASS="c1"><SPAN CLASS="c2">FD (Fair Disclosure) Wire</SPAN></P>
  70. </DIV>
  71. <BR><DIV CLASS="c3"><P CLASS="c1"><SPAN CLASS="c4">April</SPAN><SPAN CLASS="c2"> **26, 2016 Tuesday<**/SPAN></P>
  72. </DIV>
  73. <BR><DIV CLASS="c5"><P CLASS="c6"><SPAN CLASS="c7">Q2 2016 Apple Inc Earnings Call - Final</SPAN></P>
  74. </DIV>
  75. <BR><DIV CLASS="c5"><P CLASS="c6"><SPAN CLASS="c8">LENGTH: </SPAN><SPAN CLASS="c2">8726 words</SPAN></P>
  76. </DIV>
  77. <BR><DIV CLASS="c5"><P CLASS="c9"><SPAN CLASS="c2">Corporate Participants</SPAN></P>
  78. <P CLASS="c9"><SPAN CLASS="c2">* Nancy Paxton</SPAN></P>
  79. <P CLASS="c9"><SPAN CLASS="c2">Apple Inc. - Senior Director of IR</SPAN></P>
  80. <P CLASS="c9"><SPAN CLASS="c2">* Tim Cook</SPAN></P>
  81. <P CLASS="c9"><SPAN CLASS="c2">**Apple Inc.** - CEO</SPAN></P>
  82. <P CLASS="c9"><SPAN CLASS="c2">*
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement