-
Notifications
You must be signed in to change notification settings - Fork 12
/
keyword-analysis.py
32 lines (28 loc) · 1.14 KB
/
keyword-analysis.py
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
#!/usr/bin/python
# -*- coding: utf-8 -*-
import csv
import os.path
def main():
keywords = ["dump", "pump"] # keywords you want to search for
tweet = []
date = []
name = []
path = 'outputs/csv/btc.csv'
with open(path) as csvfile: # path you want to search for
reader = csv.DictReader(csvfile)
for row in reader:
tweet.append(row["tweets"])
date.append(row["date"])
name.append(row["name"])
for sentence in tweet:
for word in sentence.split():
for keyword in keywords:
if word == keyword:
file_exists = os.path.isfile('keyword_analysis.csv')
with open('keyword_analysis.csv', 'ab') as csvfile:
fieldnames = ["date", "name","tweets", "keyword"]
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
if not file_exists:
writer.writeheader()
writer.writerow({'date': 'date', 'name':'name' ,'tweets': sentence, 'keyword': keyword})
main()