Moved reading 1pif file into own class.
This commit is contained in:
parent
44686c312d
commit
ae8e35a41d
10
convert.py
10
convert.py
@ -3,6 +3,7 @@
|
||||
import argparse
|
||||
import datetime
|
||||
import json
|
||||
import onepif
|
||||
|
||||
from os.path import splitext
|
||||
from pykeepass import create_database
|
||||
@ -64,14 +65,9 @@ def getField(item, designation):
|
||||
return None
|
||||
|
||||
|
||||
with open("{}/data.1pif".format(args.inpath), "r") as fp:
|
||||
data = fp.read().strip().split("***5642bee8-a5ff-11dc-8314-0800200c9a66***")
|
||||
opif = onepif.OnepifReader("{}/data.1pif".format(args.inpath))
|
||||
|
||||
for line in data:
|
||||
if line.strip() == "":
|
||||
continue
|
||||
|
||||
item = json.loads(line.strip())
|
||||
for item in opif:
|
||||
if item.get("trashed"):
|
||||
continue
|
||||
|
||||
|
26
onepif/OnepifReader.py
Normal file
26
onepif/OnepifReader.py
Normal file
@ -0,0 +1,26 @@
|
||||
import json
|
||||
|
||||
SEPARATOR = "***5642bee8-a5ff-11dc-8314-0800200c9a66***"
|
||||
|
||||
|
||||
class OnepifReader():
|
||||
|
||||
def __init__(self, filename):
|
||||
self.filename = filename
|
||||
self.fp = open(self.filename, "rt")
|
||||
|
||||
def __iter__(self):
|
||||
return self
|
||||
|
||||
def __next__(self):
|
||||
buffer = []
|
||||
is_eof = True
|
||||
for line in self.fp:
|
||||
is_eof = False
|
||||
if line.strip() == SEPARATOR:
|
||||
break
|
||||
buffer.append(line)
|
||||
if is_eof:
|
||||
raise StopIteration
|
||||
jsonstr = "".join(buffer)
|
||||
return json.loads(jsonstr)
|
1
onepif/__init__.py
Normal file
1
onepif/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
from .OnepifReader import *
|
Loading…
x
Reference in New Issue
Block a user