-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
30 lines (25 loc) · 746 Bytes
/
main.py
File metadata and controls
30 lines (25 loc) · 746 Bytes
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
from get_tweets import get_tweets
from cognitiveService import sentiment
import os, json
def main():
#Coletandos os tweets
tweet = get_tweets()
insert_data(tweet)
if(tweet):
#Passando em nossa IA para identificar sentimento
tweet_score = sentiment()
insert_data(tweet_score)
else:
print(tweet)
def insert_data(data):
#Apagando o arquivo caso ele exista
dir = os.listdir()
for file in dir:
if file == "twitters.json":
os.remove(file)
#Inserindo os dados entro do arquivo twitters.json
with open('twitters.json', 'a', encoding='utf-8') as f:
json.dump(data, f)
f.close()
if __name__ == "__main__":
main()