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
import sys
from configparser import ConfigParser
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from opensipkd.aset.pemda.models.aset import AsetKib
BRG_JASA_POLA = [
'barang dan jasa',
'barang & jasa',
'brg jasa',
'brg & jasa']
PEMBELIAN_LABEL = 'Pembelian'
BRG_JASA_LABEL = 'Barang & Jasa'
HIBAH_LABEL = 'Hibah'
conf_file = sys.argv[1]
conf = ConfigParser()
conf.read(conf_file)
db_url = conf.get('main', 'db_url')
engine = create_engine(db_url)
factory = sessionmaker(bind=engine)
db_session = factory()
base_q = db_session.query(AsetKib).filter(AsetKib.cara_perolehan.__eq__(None))
base_q = base_q.order_by(AsetKib.id)
offset = -1
while True:
offset += 1
q = base_q.offset(offset)
row = q.first()
if not row:
break
print(f'ID {row.id} {row.asal_usul}')
asal_usul = row.asal_usul.lower()
found = False
if asal_usul.find('hibah') > -1:
row.cara_perolehan = HIBAH_LABEL
found = True
elif asal_usul.find('beli') > -1:
row.cara_perolehan = PEMBELIAN_LABEL
found = True
else:
for pola in BRG_JASA_POLA:
if asal_usul.find(pola) < 0:
continue
row.cara_perolehan = BRG_JASA_LABEL
found = True
break
if not found:
raise Exception('Tidak ditemukan polanya, silakan konsultasi.')
db_session.add(row)
db_session.flush()
db_session.commit()