-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCleaner.py
More file actions
67 lines (33 loc) · 1.4 KB
/
Cleaner.py
File metadata and controls
67 lines (33 loc) · 1.4 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
import csv
import re
# Defines a list - It stores all unique tweets
tweetChecklist = [];
CSVfields = ['created_at', 'text']
def getAllTweets():
AllTweets = [];
with open('DummyAfterCoachellaTweets.csv', encoding='UTF-8') as csvfile:
readCSV = csv.reader(csvfile, delimiter=',')
for row in readCSV:
AllTweets.append(row)
return AllTweets
allTweets = getAllTweets()
def writeCSV(tbody,writer):
writer.writerow(tbody)
with open('AfterFinalCoachellaTweets.csv', 'w', newline='',encoding='utf-8') as csvfile:
tweetwriter = csv.DictWriter(csvfile, delimiter=',', fieldnames=CSVfields) ## initialize the CSV
tweetwriter.writeheader() ## write the header of CSV
for item in allTweets:
#TODO Check for ratio of users
# If tweet doesn't exist in the list item[1] index 1 is the text column
if item[1] not in tweetChecklist:
tweetChecklist.append(item[1])
if item[1].startswith("rt"):
csvObj = {'created_at': item[0],
'text': item[1][2:],
}
writeCSV(csvObj, tweetwriter)
else:
csvObj = {'created_at': item[0],
'text': item[1],
}
writeCSV(csvObj, tweetwriter)