forked from aniversarioperu/publibot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_handler.py
More file actions
executable file
·50 lines (39 loc) · 903 Bytes
/
data_handler.py
File metadata and controls
executable file
·50 lines (39 loc) · 903 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/python
import json
import cgi
import cgitb
import codecs
import re
import string
import sys
import dataset
import config
cgitb.enable()
data = cgi.FieldStorage()
def make_query(start):
f = codecs.open("cherry_tweets.json", "r", "utf-8")
lines = []
start = int(start)
end = int(start) + 20
for i, line in enumerate(f):
if i >= start and i < end:
lines.append(json.loads(line))
f.close()
return lines
def sanitize(s):
s = s.replace("'", "")
s = s.replace('"', "")
s = s.replace("/", "")
s = s.replace("\\", "")
s = s.replace(";", "")
s = s.replace("=", "")
s = s.replace("*", "")
s = s.replace("%", "")
return s
if 'start' in data:
start = sanitize(data['start'].value)
data = make_query(start)
print "Content-Type: application/json\n"
print json.dumps({"out": data})
else:
pass