-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTemporary_1.py
49 lines (36 loc) · 1.12 KB
/
Temporary_1.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import csv
import re
import pickle
data = []
def cleanHTML(raw_html):
cleanr = re.compile('<.*?>')
cleanText = re.sub(cleanr, '', raw_html)
return cleanText
def processTags(qtags):
charToRemove = "<>"
for char in qtags:
if char in charToRemove:
qtags = qtags.replace(char, ' ')
return qtags
count = 0
with open("/home/abhisid/Documents/Queries.csv", encoding="UTF-8") as f_obj:
csvFile = csv.reader(f_obj)
for line in csvFile:
try:
qId = int(line[0])
acceptAnsId = int(line[1])
qBody = cleanHTML(line[6])
qTitle = cleanHTML(line[7])
qTags = processTags(line[8])
if acceptAnsId < 900001:
data.append(
{'qId': qId, 'acceptAnsID': acceptAnsId, 'qBody': qBody, 'qTitle': qTitle, 'qTags': qTags})
count = count + 1
if count % 10000 == 0:
print(count)
except ValueError:
pass
data = sorted(data, key=lambda k: k['qId'])
print('data sorted')
with open('d1', 'wb') as fp:
pickle.dump(data, fp)