-
Notifications
You must be signed in to change notification settings - Fork 5
/
parse.py
65 lines (57 loc) · 1.48 KB
/
parse.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python
# http://pypi.python.org/pypi/phpserialize
import sys
import csv
import StringIO
class LineReader:
def __init__(self):
self.line = ''
self.seperator = "\n"
self.window = []
def add(self, character):
self.window.append(character)
self.line += character
###print "'%s'" % self.line
if len(self.window) > len(self.seperator):
self.window.pop(0)
def found_line(self):
if ''.join(self.window) == self.seperator:
rv = self.line
self.line = ''
return rv
else:
return False
def process(row):
if len(row) < 8:
return False
if not row[7] == "'image'":
return False
if not row[8] == "'gif'":
return False
# print [row[0],row[7],row[8]]
# print row
return True
reader = LineReader()
inside_insert = False
search = 'INSERT INTO `image` VALUES'
while True:
c = sys.stdin.read(1)
if not len(c) > 0:
break
reader.add(c)
line = reader.found_line()
if len(reader.line) > len(search) and reader.line.startswith(search):
inside_insert = True
reader.line = ''
reader.seperator = '),'
if not inside_insert:
continue
if not line:
continue
# strip out '(' at beginning and '),' at end
string = line[1:-2]
# print line[1:-2]
string_array = string.split(',')
rv = process(string_array)
if rv is True:
print line