-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
68 lines (52 loc) · 1.99 KB
/
main.py
File metadata and controls
68 lines (52 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import urllib.request, json
import pandas as pd
from analyser import SentimentAnalyser
#pega a o json dentro da url e bota todos os tópicos mais populares dentro da variável "data"
# with urllib.request.urlopen("http://reddit.com/r/Bitcoin/.json") as url:
# data = json.loads(url.read())['data']['children']
# with open('data.txt', 'w') as outfile:
# json.dump(data, outfile)
'''
urls = []
topics_id = []
counter = 0
with open('data.txt') as json_file:
data = json.load(json_file)
#pega a url de acesso aos tópicos
for topic in data:
urls.append("http://reddit.com"+topic["data"]["permalink"])
topics_id.append(topic["data"]["id"])
for url in urls:
print(url)
print(topics_id[counter])
counter = counter + 1
#INÍCIO DO CÒDIGO PARA COMEÇAR A MONTAR A TABELA DE COMENTÁRIOS
# with urllib.request.urlopen(url) as url_aux:
# data = json.loads(url_aux.read())['data']['children']
# with open('comment_table.txt', 'w') as outfile:
# json.dump(data, outfile)
'''
df = pd.read_csv('csv/comments_data', sep='\t')
analyser = SentimentAnalyser()
analyser.build_person_comment(df)
""" emotions = []
for x in df['comment']:
analyser = SentimentAnalyser()
dic_emotion = analyser.analyseSentence(x)
str_emotion = ""
positive = 0
negative = 0
for (emotion, value) in dic_emotion.items():
print(emotion)
if emotion in 'positive-emotion':
positive = value
elif emotion in "negative-emotion":
negative = value
emotion_value = str(positive - negative)
print(emotion_value)
emotions.append(emotion_value) """
"""
d = {'id': df['id'], 'subreddit_id': df['subreddit_id'], 'subreddit': df['subreddit'], 'date_collect': df['date_collect'], 'comment': df['comment'], 'permalink': df['permalink'], 'created': df['created'], 'ups': df['ups'], 'score': df['score'], 'author': df['author'], 'parent_id': df['parent_id'], 'sentiments': emotions}
df = pd.DataFrame(data=d)
df.to_csv("csv/comments_data_and_sentiments.csv", sep='\t', encoding='utf-8') """
comment_table = []