This repository has been archived by the owner on Feb 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
find_sections.py
executable file
·78 lines (70 loc) · 1.94 KB
/
find_sections.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
66
67
68
69
70
71
72
73
74
75
76
77
78
#-*- coding: utf-8 -*-
import find_between
import re
import peweetest
def returnKeyValueFromString(string):
"""Return record key,value from line with string contain '=' separator"""
record = {}
name, value = string.partition("=")[::2]
name = name.lower()
value = value.rstrip('\r\n')
value = value.decode("windows-1250")
value = value.encode("utf-8")
record[name] = value
#print record
return record
def returnDictFromFile():
"""Return Info dict from edi.txt file"""
Info = {}
Okres = {}
Dokument = {}
Dokument['identyfikatordok']=0
name = 'Start'
Start = {"start": "1"}
with open('edi.txt') as line:
for s in line:
print s #if s.strip() == '[Dokument]':
if re.match("\[",s):
#print (vars()[name])
#print dir(vars()[name])
#peweetest.pushFieldToDatabase(name,vars()[name])
name = find_between.find_between(s,'[',']')
#vars()[name] = {}
#print (vars()[name])
if name == 'Info':
Info = {}
current_table = Info
if name == 'Okres':
Okres = {}
current_table = Okres
if name == 'Dokument':
Dokument = {}
current_table = Dokument
if name == 'ZawartoscDokumentu':
table_name = 'Paragony'
print Dokument
peweetest.pushFieldToDatabase(table_name,Dokument)
print 'Push Dokument dict as record to sql database'
#print Dokument
if re.match("\[Poz",s):
poz = {}
current_table = poz
print "Start make 'Poz' dict"
else:
if s == '\r\n':
pass
else:
current_table.update(returnKeyValueFromString(s))
#if Dokument['identyfikatordok']:
# docId = Dokument['identyfikatordok']
# print docId
#if s == '[Dokument]/r/n':
# documentId = Dokument['IdentyfikatorDok']
# print u'Here we are in Dokument dict'
# print documentId
print 'Info dict is'
print Dokument['identyfikatordok']
print Okres
return Info
if __name__ == "__main__":
print returnDictFromFile()