-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcleannewlines.py
43 lines (34 loc) · 1.13 KB
/
cleannewlines.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
import redis
from string import whitespace
out = open("./data/game6_clean.txt", "w")
r = redis.Redis(host = 'localhost', port = 6379, db = 0)
for key in r.keys():
if key == 'foo':
r.delete('foo')
continue
# Strip all newlines. Comment out rpush when not processing Game 1/2 data.
# text = r.rpop(key)
#r.rpush(key, text.replace('\n', ' ').strip('"'))
# Split coordinates into their own variables.
try:
coords = r.lindex(key, 1).split(",")
except:
coords = 'NA'
print key
if len(coords) == 2:
llong = coords[0].strip("[")
lat = coords[1].strip("]")
else:
llong = 'NA'
lat = 'NA'
try:
text = r.lindex(key, 2).replace('\n', ' ').strip('"').replace(
'\t', ' ').replace('\015', ' ')
except AttributeError:
continue
#r.linsert(key, "before", text, llong)
#r.linsert(key, "before", text, lat)
# Count # of a's in key, convert to microsecond count.
aCount = key.count('a')
newKey = key.strip('a') + ":%0.2d" % aCount
out.write("%s\t%s\t%s\t%s\t%s\n" % (newKey, r.lindex(key, 0), llong, lat, text))