-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransiro.py
1046 lines (850 loc) · 34.8 KB
/
transiro.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import os
import re
import sys
import sqlalchemy
import datetime
import time
from datetime import date
from sqlalchemy import create_engine
from sqlalchemy.orm import Session
from sqlalchemy import *
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import create_session
import transir_grupoj
import transir_uk
from TabelTransiro import TabelTransiro
################
# ueadb module was generated using
# sqlacodegen postgresql://postgres:[email protected]/ueadb_11072017 > ueadb.py
#
###############
import ueadb
################
# ueadb module was generated using
# sqlacodegen postgresql://postgres:[email protected]/retdb > retdb.py
#
###############
import retdb
################
# ueadb module was generated using
# sqlacodegen mysql://root:@127.0.0.1/uea_11072017 > ueamsql.py
#
###############
import ueamsql
################
# ueadb module was generated using
# sqlacodegen mysql://root:@127.0.0.1/novuea > novuea.py
#
###############
import novuea
class TransirError(Exception):
"""Base class for exceptions in this module."""
pass
class NeUnikaError(TransirError):
"""Kiam ni uzas datumbazon kaj la rezulto devus esti unika sed ne estas."""
pass
class MalplenaError(TransirError):
"""Kiam ni uzas datumbazon, ni atendas rezulton sed ĝi malplenas."""
pass
class DevusEkzistiError(TransirError):
"""Kiam ni uzas datumbazon, ni atendas rezulton sed ĝi malplenas."""
pass
class NeDevusEstiNone(TransirError):
"""Variable kiu ne devus esti None, estas."""
pass
class NeValidaLando(TransirError):
"""Ne valida datumo."""
pass
class NeValidaUeaKodo(TransirError):
"""Ne valida ueakodo."""
pass
Base = declarative_base()
#Connect to the old ueadb
engine_ueadb = create_engine('postgresql://postgres:[email protected]:5432/ueadb_11072017')
#Create a session to use the tables
session_ueadb = create_session(bind=engine_ueadb)
#Connect to the old retdb
engine_retdb = create_engine('postgresql://postgres:[email protected]:5432/retdb')
#Create a session to use the tables
session_retdb = create_session(bind=engine_retdb)
#Connect to the old uea_mysql
engine_ueamsql = create_engine('mysql://[email protected]:3306/uea_11072017')
#Create a session to use the tables
session_ueamsql = create_session(bind=engine_ueamsql)
#bonvolu kredi la bazon kun la collation utf8_bin
#Connect to the new db
engine_novuea = create_engine('mysql://root:@127.0.0.1:3306/novuea?charset=utf8' )
session_novuea = create_session(bind=engine_novuea)
metadata = MetaData()
metadata.create_all(engine_novuea)
############################# HELPAJ FUNKCIOJ #############################
def db_encode(vorto):
if vorto is None:
return ""
else :
return vorto.encode('utf-8')
#Por nun, ni nur havas landkategorio A kaj B.
#Mi ne trovis tiun informon en datumbazo do mi mane metas
def konverti_landkategorio(session_ueadb):
session_novuea.begin()
titolo = "A"
priskribo = ""
#TODO
def konverti_lando_landkategorion(session_ueadb):
nop
#TODO
def valid_ueakodo(ueakodo):
if(len(ueakodo) == 4):
return ueakodo
if(len(ueakodo) == 6):
return ueakodo[:4]
else :
raise NeValidaUeaKodo
date_pattern = re.compile('([0-9]{4})\/([0-9]{2})\/([0-9]{2})')
def karakteroj_al_dato(karakteroj):
global date_pattern
if karakteroj is None:
return None
res = date_pattern.match(karakteroj)
if res is None:
print("Ne povis krei daton "+karakteroj)
return None
(jaro, monato, tago) = (int(res.group(1)), int(res.group(2)), int(res.group(3)))
if monato == 0:
monato = 1
if tago == 0:
tago = 1
return datetime.date(jaro, monato, tago)
############################# HELPAJ FUNKCIOJ FINO #############################
class Lando(Base):
__tablename__ = 'lando'
id = Column(Integer, primary_key=True)
nomoLoka = Column(String(255, 'utf8_unicode_ci'))
radikoEo = Column(String(255, 'utf8_unicode_ci'))
finajxoEo = Column(String(255, 'utf8_unicode_ci'))
landkodo = Column(String(255, 'utf8_unicode_ci'))
class TabelTransirLando(TabelTransiro):
def __init__(self):
TabelTransiro.__init__(self)
def konverti(self, session_ueadb):
landkodojlist = session_ueadb.query(ueadb.t_landkodoj).all()
for lando in landkodojlist:
print("Land: {}, ".format(db_encode(lando.landoradiko)))
novlando = novuea.Lando(
nomoLoka=db_encode(lando.landotraduko),
radikoEo=db_encode(lando.landoradiko),
finajxoEo=db_encode(lando.landofinajxo),
landkodo=lando.landduliter)
self.add(novlando.landkodo, novlando)
def get_id(self, landkodo):
if type(landkodo) is bytes:
landkodo = str(landkodo)
if landkodo == "nev":
raise NeValidaLando("nev")
if landkodo == "mrt":
raise NeValidaLando("mrt")
if landkodo is None:
print("ne devus None")
raise NeDevusEstiNone("landkodo is None, cannot get id lando")
res = self.trovi(landkodo)
if(res is None):
print("no rezult for "+str(landkodo))
raise MalplenaError("get lando: malplena rezulto: "+str(landkodo))
else :
return res.id
################### URBO ########################
class Urbo(Base):
__tablename__ = 'urbo'
id = Column(Integer, primary_key=True)
nomoLoka = Column(String(255, 'utf8_unicode_ci'))
nomoEo = Column(String(255, 'utf8_unicode_ci'))
provinco= Column(String(255, 'utf8_unicode_ci'))
idLando = Column(Integer)
class TabelTransirUrbo(TabelTransiro):
def __init__(self, transir_lando):
TabelTransiro.__init__(self)
self.transir_lando = transir_lando
def add_urbo(self, unomo, unomoEo, uProvinco, ulandokodo):
if self.ene(unomo) :
#Ni vidas ĉu ni povas riĉigi la objekton
nunaUrbo = self.trovi(unomo)
if nunaUrbo.nomoEo is None:
nunaUrbo.nomoEo = unomoEo
if nunaUrbo.provinco is None:
nunaUrbo.provinco = uProvinco
if nunaUrbo.idLando is None:
try:
nunaUrbo.idlando = self.transir_lando.get_id(ulandokodo)
except (NeValidaLando, NeDevusEstiNone, MalplenaError):
nunaUrbo.idLando = None
print("create type :"+str(type(unomo)))
print("create val :"+str((unomo)))
self.add(unomo, nunaUrbo)
return
try:
idlando = self.transir_lando.get_id(ulandokodo)
novurbo = novuea.Urbo(
nomoLoka=unomo,
nomoEo=unomoEo,
provinco=uProvinco,
idLando=idlando
)
print("create type :"+str(type(unomo)))
print("create val :"+str((unomo)))
self.add(unomo, novurbo)
except (MalplenaError, NeValidaLando, NeDevusEstiNone):
if unomo is not None and ulandokodo is None:
print("Urbo "+str(unomo)+" ne havas validan landokodon. Aldonita sen ligilo al lando)")
novurbo = novuea.Urbo(
nomoLoka=unomo,
nomoEo=unomoEo,
provinco=uProvinco,
idLando=None
)
print("create type :"+str(type(unomo)))
print("create val :"+str((unomo)))
self.add(unomo, novurbo)
elif unomo is not None:
print("Ne povis ligi "+str(unomo)+" al lando (landokodo "+str(ulandokodo)+" ne valida)")
else :
print("Urbo ne havas nomon: ne-konsiderita.")
def get_id(self, urbonomo):
if type(urbonomo) is str:
urbonomo = bytes(urbonomo, 'utf8')
res = self.trovi(urbonomo)
if(res is None):
print ("get urbo: ne trovita "+str(type(urbonomo)))
print ("get urbo: ne trovita "+str(urbonomo))
raise MalplenaError("get urbo: ne trovita "+str(urbonomo))
else :
return res.id
def konverti(self, session_ueadb):
#el tabelo urboj
urbolist = session_ueadb.query(ueadb.t_urboj).all()
for urbo in urbolist:
self.add_urbo(db_encode(urbo.nomo), "",
db_encode(urbo.provinco), urbo.landokodo)
#el tabelo asocio
uzantolist = session_ueadb.query(ueadb.t_tuta1).all()
for uzanto in uzantolist:
self.add_urbo(db_encode(uzanto.urbo), "", "", uzanto.landokodo)
#el tabelo tuta1 (uzanto)
asociolist = session_ueadb.query(ueadb.t_tuta1).all()
for asocio in asociolist:
self.add_urbo(db_encode(asocio.urbo), "", "", None)
################### URBO FINO ########################
class TabelTransirFaktemo(TabelTransiro):
def __init__(self):
TabelTransiro.__init__(self)
def konverti(self, session_retdb):
fakasociolist = session_retdb.query(retdb.t_fakasocioj).add_column("kategorio").distinct()
for fakasocio in fakasociolist:
novfako = novuea.Faktemo(
nomo=db_encode(fakasocio.kategorio),
priskribo=db_encode(fakasocio.kategorio)
)
self.add(novfako.nomo, novfako)
################### ILOJ RILATE AL GRUPAJ KATEGORIOJ ########################
def get_grupkategorioj():
return transir_grupoj.grupa_kategorio()
class Kategorioj(Base):
__tablename__ = 'grupo'
id = Column(Integer, primary_key=True)
nomo = Column(String(255, 'utf8_unicode_ci'))
class TabelTransirKategorio(TabelTransiro):
def __init__(self):
TabelTransiro.__init__(self)
def konverti(self, katj):
for k_nomo, kat in katj.items() :
self.add(k_nomo, kat)
def get_id(self, nomo):
res = self.trovi(nomo)
if(res is None):
raise MalplenaError("get kategorio: ne konata kategorio: "+ nomo)
else :
return res.id
################### ILOJ RILATE AL GRUPOJ ########################
def get_grupojn():
return transir_grupoj.get_grupojn()
def get_grupojn_no_kat():
grupoj = {}
for kat, kat_grupoj in transir_grupoj.get_grupojn().items():
grupoj.update(kat_grupoj)
return grupoj
def in_grupoj(grupo, grupoj):
for kat_grupoj in grupoj:
if grupo in kat_grupoj:
return True
return False
class TabelTransirGrupo(TabelTransiro):
def konstkat_konvertilo(self, string, grupoj):
sep =';'
i = 0
konstkat_grupoj = set()
for code in string.split(sep):
code = re.sub('#[0-9]*', "", code)
if in_grupoj(code, grupoj):
konstkat_grupoj.add(self.get_id(code))
i = i+1
else:
print(code+" ne trovita en la grupoj sed atendita.")
return konstkat_grupoj
def __init__(self):
TabelTransiro.__init__(self)
def konverti(self, katgrupoj):
for k_kat, grupoj in katgrupoj.items() :
for k_mlg, grupo in grupoj.items() :
self.add(k_mlg, grupo)
def get_id(self, mallongigilo):
res = self.trovi(mallongigilo)
if(res is None):
raise MalplenaError("get grupo: ne konata grupo: "+ mallongigilo)
else :
return res.id
class TabelTransirGrupo_Kategorio(TabelTransiro):
def __init__(self):
TabelTransiro.__init__(self)
def konverti(self, katgrupoj, tabelGrupoj, tabelKatj):
i = 0
for k_kat, grupoj in katgrupoj.items() :
for k_mlg, grupo in grupoj.items() :
id_kat = tabelKatj.get_id(k_kat)
id_grup = tabelGrupoj.get_id(k_mlg)
self.add(i , novuea.RefGrupoGrupaKategorio(
idGrupo = id_grup,
idGrupaKategorio = id_kat ,
))
i = i + 1
################### FINO ILOJ RILATE AL GRUPOJ ########################
#Iom specifa ĉar plenigita nur de TabelTransirAsocio kaj TabelTransirUzanto
def TabelTransirAsocioAuxUzanto(TabelTransiro):
def __init__(self):
TabelTransiro.__init__(self)
################### RILATE AL ASOCIOJ ########################
#globala variablo: permesas sinkronigi la id de la tabeloj uzantoAuxAsocio, asocio kaj uzanto.
venonta_id_uzantoAuxAsocio = 1
venonta_id_uzantoAuxAsocio = 1
class TabelTransirAsocio(TabelTransiro):
def __init__(self, transir_urbo, transir_asocioAuxUzanto, transir_grupoj):
TabelTransiro.__init__(self)
self.transir_urbo = transir_urbo
self.transir_asocioAuxUzanto = transir_asocioAuxUzanto
self.transir_grupoj = transir_grupoj
self.email2asocio = {}
def estas_faka(self, ueadb_asocio):
set_grupoj = self.transir_grupoj.konstkat_konvertilo(ueadb_asocio.konstkat , get_grupojn())
#if intersection is not empty, then True
return len ({"fa.a", "fa.k", "fa.n", "fs.a"} & set_grupoj) != 0
def estas_landa(self, ueadb_asocio):
set_grupoj = self.transir_grupoj.konstkat_konvertilo(ueadb_asocio.konstkat , get_grupojn())
#if intersection is not empty, then True
return len ({"la.a", "la.n", "ls.a", "ls.n"} & set_grupoj) != 0
def estas_junulara(self, ueadb_asocio):
set_grupoj = self.transir_grupoj.konstkat_konvertilo(ueadb_asocio.konstkat , get_grupojn())
#if intersection is not empty, then True
return len ({"fs.a", "ls.a", "ls.n"} & set_grupoj) != 0
def get_asocio_el_retadreso(self, retadreso):
return self.email2asocio[retadreso]
def konverti(self, session_ueadb ):
global venonta_id_uzantoAuxAsocio
asociolist = session_ueadb.query(ueadb.t_asocioj).all()
#fakasociolist = session_retdb.query(retdb.t_fakasocioj).add_column("kategorio").distinct()
for asocio in asociolist:
novUzantoAuxAsocio = novuea.UzantoAuxAsocio(
id = venonta_id_uzantoAuxAsocio,
ueakodo = asocio.ueakodo
)
idurbo = None
asocia_nomo = asocio.familianomo
if(asocia_nomo is None):
asocia_nomo = asocio.personanomo
try :
print("use type :"+str(type(asocio.urbo)))
print("use val :"+str((asocio.urbo)))
idurbo = self.transir_urbo.get_id(asocio.urbo)
except (NeUnikaError, MalplenaError) :
if asocio.urbo is None:
print("Asocio: la asocio "+asocia_nomo+" ne estas ligita al iu urbo")
else:
print("Asocio "+asocia_nomo+": Ne povis ligi "+asocio.urbo+" al urbo ĉar la nomo estas plurfoje trovita en la datumbazo")
idurbo= None
self.transir_asocioAuxUzanto.add(novUzantoAuxAsocio.ueakodo, novUzantoAuxAsocio)
novAsocio = novuea.Asocio(
id = venonta_id_uzantoAuxAsocio ,
nomo= asocia_nomo,
siglo= "",
adreso= asocio.adreso,
fondigxdato= None,
posxtkodo= asocio.posxtkodo,
idUrbo= idurbo ,
idFako= None,
lando= None,
telhejmo= asocio.telhejmo,
retposxto= asocio.retposxto,
delegFako= asocio.deleg_fako,
tttpagxo= asocio.tttpagxo,
junulara= self.estas_junulara(asocio),
faka= self.estas_faka(asocio),
landa= self.estas_landa(asocio),
abc= asocio.abc
)
self.email2asocio[asocio.retposxto] = venonta_id_uzantoAuxAsocio
venonta_id_uzantoAuxAsocio = venonta_id_uzantoAuxAsocio + 1
self.add(novAsocio.nomo, novAsocio)
################### FINO RILATE AL ASOCIOJ ########################
################### RILATE AL UZANTOJ ########################
def get_titolon_personan_nomon(personanomo):
abrevs = ["S-ro", "S-ino", "D-ro", "D-ino", "F-o", "F-ino", "Prof.", "Mag.", "Inĝ.", "G-o", "G-ino", "D-o", "D-ino" ]
def check_abrev (nomo, abrev):
if personanomo is None:
return (None, None)
pattern = re.compile(abrev+' (.*)')
res = pattern.match(personanomo)
if res is None:
return (None, personanomo)
else:
return (abrev, res.group(1))
titolo = ""
found = 1
while found == 1:
found = 0
for abrev in abrevs:
(novtitolo, personanomo) = check_abrev(personanomo, abrev)
if novtitolo is not None:
found = 1
titolo = titolo +" "+ novtitolo
return (titolo, personanomo)
class TabelTransirUzanto(TabelTransiro):
def __init__(self, transir_lando, transir_urbo, transir_asocioAuxUzanto):
TabelTransiro.__init__(self)
self.transir_lando = transir_lando
self.transir_urbo = transir_urbo
self.transir_asocioAuxUzanto = transir_asocioAuxUzanto
self.email2uzanto = {}
def konverti(self, session_ueadb ):
global venonta_id_uzantoAuxAsocio
uzantolist = session_ueadb.query(ueadb.t_tuta1).all()
for uzanto in uzantolist:
novUzantoAuxAsocio = novuea.UzantoAuxAsocio(
id = venonta_id_uzantoAuxAsocio,
ueakodo = uzanto.ueakodo
)
self.transir_asocioAuxUzanto.add(novUzantoAuxAsocio.ueakodo,novUzantoAuxAsocio)
lando = None
valida = True
morta = False
try:
lando = self.transir_lando.get_id(uzanto.landokodo)
except NeValidaLando as e:
lando = None
if str(e) == "nev":
valida = False
if str(e) == "mrt":
morta = True
except MalplenaError :
lando = None
urbo = None
try:
urbo = self.transir_urbo.get_id(uzanto.urbo)
except MalplenaError:
urbo = None
(titolo, personanomo) = get_titolon_personan_nomon(uzanto.personanomo)
novUzanto = novuea.Uzanto(
id = venonta_id_uzantoAuxAsocio,
personanomo = personanomo,
familianomo = uzanto.familianomo,
titolo = titolo,
bildo = "",
personanomoIdentigilo = "",
familianomoIdentigilo = "",
adreso = uzanto.adreso,
posxtkodo = uzanto.posxtkodo,
idLogxurbo = urbo,
idlando = lando,
naskigxtago = karakteroj_al_dato(uzanto.naskigxtago),
morta = morta,
mortdatekscio = None,
mortdato = None,
notoj = uzanto.notoj,
profesio = uzanto.profesio,
retposxto = uzanto.retposxto,
telhejmo = uzanto.telhejmo,
teloficejo = uzanto.teloficejo,
telportebla = uzanto.portebla,
kerekzameno = False,
kernivelo = None,
kerdato = None,
tttpagxo = uzanto.tttpagxo,
validaKonto = valida,
abc = uzanto.abc
)
self.email2uzanto[uzanto.retposxto] = venonta_id_uzantoAuxAsocio
self.add((novUzanto.personanomo, novUzanto.familianomo), novUzanto)
venonta_id_uzantoAuxAsocio = venonta_id_uzantoAuxAsocio + 1
def get_id_uzanto_aux_asocio(familianomo, personanomo, transir_asocio, transir_uzanto):
#ni unue rigardas ene de la asocioj
res = transir_asocio.trovi(familianomo)
if(res is None ):
#ni rigardu ĉe uzantoj
res = transir_uzanto.trovi((personanomo, familianomo))
if(res is None):
raise MalplenaError("uzanto ne trovita: "+personanomo+" "+familianomo)
else :
return res.id
else :
return res.id
def get_id_uzanto_aux_asocio_from_ueakodo(ueakodo, transir_asocioAuxUzanto):
print("ueakodo: "+ueakodo)
res=transir_asocioAuxUzanto.trovi(ueakodo)
if(res is None):
raise MalplenaError("uzanto ne trovita: "+ueakodo)
return res.id
def get_id_uzanto_aux_asocio_from_retadreso(retadreso, transir_asocio, transir_uzanto):
res = transir_asocio.get_asocio_el_retadreso(retadreso)
if(res is None ):
#ni rigardu ĉe uzantoj
res = transir_uzanto.get_uzanto_el_retadreso(retadreso)
if(res is None):
raise MalplenaError("uzanto ne trovita laû retadreso: "+retadreso)
else :
return res.id
else :
return res.id
def print_uzanto_aux_asocio(familianomo, personanomo):
if familianomo is None:
return personanomo
elif personanomo is None:
return familianomo
else:
return personanomo +" "+ familianomo
class TabelTransirPeranto(TabelTransiro):
def __init__(self, transir_asocio, transir_uzanto, transir_lando):
TabelTransiro.__init__(self)
self.transir_asocio = transir_asocio
self.transir_uzanto = transir_uzanto
self.transir_lando = transir_lando
def konverti(self, session_ueadb):
perantolist = session_ueadb.query(ueadb.t_perant).all()
for peranto in perantolist:
(titolo, personanomo) = get_titolon_personan_nomon(peranto.personanomo)
id_uzantoAuxAsocio = get_id_uzanto_aux_asocio(peranto.familianomo, personanomo, self.transir_asocio, self.transir_uzanto)
novPeranto = novuea.Peranto(
idUeakodo = id_uzantoAuxAsocio,
idLando = self.transir_lando.get_id(peranto.landokodo)
)
self.add(novPeranto.idUeakodo, novPeranto)
################### RILATE AL ANECO ########################
#Iom specifa ĉar plenigita nur de TabelTransirAsocio kaj TabelTransirUzanto
class TabelTransirAneco(TabelTransiro):
def __init__(self):
TabelTransiro.__init__(self)
self.jarkat_pattern = re.compile('([a-zA-Z]*)([0-9]*)')
def jarkat_konvertilo(self, string, grupoj):
sep =';'
kat_grupoj = {}
if string is None:
return kat_grupoj
for code in string.split(sep):
pat_jaro = re.match(self.jarkat_pattern, code)
if pat_jaro is None:
print("None for " + string )
print("specifically " + code)
else:
grupo= pat_jaro.group(1)
jaro = None
try:
jaro = pat_jaro.group(2)
except:
jaro = None
#por korekti pasintecon
if grupo == "mak":
grupo = "mat";
if grupo == "mjk":
grupo = "mjt";
if grupo in grupoj:
kat_grupo = set()
try:
kat_grupo = kat_grupoj[grupo]
except:
kat_grupo = set()
kat_grupo.add(jaro)
kat_grupoj[grupo] = kat_grupo
else:
print(code+" ne trovita en la grupoj sed atendita.")
return kat_grupoj
def konverti(self, session_ueadb, tabel_grupo, tabel_asocio, tabel_uzanto):
uzantolist = session_ueadb.query(ueadb.t_tuta1).all()
i = 0
for uzanto in uzantolist:
#enhavas la grupojn de la uzanto laû jaroj
uzanto_personanomo = get_titolon_personan_nomon(uzanto.personanomo)[1]
tbl_jar_grup = self.jarkat_konvertilo(uzanto.jarkat, get_grupojn_no_kat())
idAno = get_id_uzanto_aux_asocio(uzanto.familianomo, uzanto_personanomo, tabel_asocio, tabel_uzanto)
for grupo, jaroj in tbl_jar_grup.items():
id_grupo = tabel_grupo.get_id(grupo)
for jaro in jaroj:
komencadato = None
findato = None
if jaro is not None :
komencdato = karakteroj_al_dato(jaro+"/01/01")
findato = karakteroj_al_dato(jaro+"/12/31")
try :
aneco = novuea.Aneco (
idAno = idAno,
idGrupo = id_grupo,
komencdato = komencdato,
findato = findato,
dumviva = False
)
self.add(i, aneco)
i = i+1
except:
print("Malvalidan grupon por uzanto " + print_uzanto_aux_asocio(uzanto.familianomo, uzanto.personanomo) + ": " + grupo)
################### FINO RILATE AL ANECO ########################
################### RILATE AL DISSENDO ########################
class TabelTransirDissendo(TabelTransiro):
def __init__(self):
TabelTransiro.__init__(self)
def get_ueakodo_from_retuzanto(self, session_ueamsql, uznomo):
print("uznomo: "+uznomo)
if (uznomo == "manuela"):
return "ronc"
elif (uznomo == "osmo"):
return "osmo"
elif (uznomo == "maritza"):
return "itza"
elif (uznomo == "james"):
return "jrpi"
elif (uznomo == "rocxjo"):
return "uurm"
elif (uznomo == "fiskot"):
return "pfko"
elif (uznomo == "mevamevo"):
return "mevc"
elif (uznomo == "Roxane"):
return "rfrn"
else:
uzanto = session_ueamsql.query(ueamsql.Uzantoj).filter(ueamsql.Uzantoj.uznomo == uznomo).first()
if uzanto is None:
print ("Ne Valida uzanto: "+uznomo)
raise NeValidaUeaKodo
return uzanto.kodo
def konverti(self, session_ueamsql, transir_asocioAuxUzanto):
dissendolist = session_ueamsql.query(ueamsql.Dissendoj).all()
for dissendo in dissendolist:
try:
novdissendo = novuea.Dissendo (
id= dissendo.id,
dissendanto = get_id_uzanto_aux_asocio_from_ueakodo(
self.get_ueakodo_from_retuzanto(session_ueamsql, dissendo.nomo),
transir_asocioAuxUzanto
),
nomede = dissendo.nomede,
dato = dissendo.kiam,
temo = dissendo.temo,
teksto = dissendo.teksto
)
self.add(dissendo.id, novdissendo)
except NeValidaUeaKodo:
print ("ne povis aldono dissendo pro nevalida nomo de dissendanto: " + dissendo.nomo)
class TabelTransirDissendoDemanderoj(TabelTransiro):
def __init__(self):
TabelTransiro.__init__(self)
def konverti(self, session_ueamsql):
demanderojlist = session_ueamsql.query(ueamsql.DissendojEnketoj).all()
for demandero in demanderojlist:
novdemandero = novuea.DissendoDemandero(
id= demandero.id,
idDissendo = demandero.dissendo,
demNum = demandero.dem_num,
demTeksto = demandero.dem_teksto
)
self.add(id, novdemandero)
class TabelTransirDissendoRespondoj(TabelTransiro):
def __init__(self):
TabelTransiro.__init__(self)
def konverti(self, session_ueamsql, transir_asocio, transir_uzanto):
respondojlist = session_ueamsql.query(ueamsql.DissendojRespondoj).all()
for respondo in respondojlist:
retposxto = None
idUzantoAuxAsocio = None
try:
idUzantoAuxAsocio = get_id_uzanto_aux_asocio_from_retadreso(
respondo.retposxto,
transir_asocio,
transir_uzanto)
except MalplenaError:
retposxto = respondo.retposxto
idUzantoAuxAsocio= None
novrespondo = novuea.RefDissendoRespondoj(
idUzantoAuxAsocio = idUzantoAuxAsocio,
retposxto = retposxto,
idDissendoDemandero = respondo.enketo
)
self.add(i, novrespondo)
class TabelTransirRetlisto(TabelTransiro):
def __init__(self):
TabelTransiro.__init__(self)
def konverti(self, session_retdb):
retlistolist= session_retdb.query(retdb.t_abonoj).add_column("abono").distinct()
i = 0
for retlisto in retlistolist:
novretlisto= novuea.Retlisto(
id = i,
nomo = retlisto.abono,
priskribo = None
)
self.add(novretlisto.nomo, novrespondo)
i = i+1
class TabelTransirRetlistoAbono(TabelTransiro):
def __init__(self):
TabelTransiro.__init__(self)
def konverti(self, session_retdb, transir_retlisto):
list= session_retdb.query(retdb.t_abonoj).add_column("abono").distinct()
retlistolist= session_retdb.query(retdb.t_abonoj).add_column("abono").distinct()
i = 0
for retlisto in retlistolist:
novretlisto= novuea.Retlisto(
ekde = retlisto.tempo,
abono = transir_retlisto.trovi(retlisto.abono),
idUzanto = get_id_uzanto_aux_asocio_from_ueakodo(
valid_ueakodo(retlisto.ueakodo)),
formato_html = retlisto.formato == "html",
kodigxo_utf8 = retlisto.kodigo == "utf",
retadreso = retlisto.retadreso
)
self.add(i, novretlisto)
i = i+1
class TabelTransirKongreso (TabelTransiro):
def __init__(self):
TabelTransiro.__init__(self)
def konverti(self, transir_urbo):
kongreso_kat_uk = novuea.KongresaKategorio(
id = 1,
nomo = "UK"
)
self.add("UK", kongreso_kat_uk)
kongresolist = transir_uk.get_ukj()
id_kongreso = 0
for kongreso in retlistolist:
novkongreso = novuea.Kongreso(
id = id_kongreso,
titolo= kongreso.titolo,
bildo = "",
idUrbo = transir_urbo.get_id(kongreso.urbo),
jaro = kongreso.jaro,
numero = kongreso.numero ,
komencdato= NULL,
temo = kongreso.temo,
priskribo = "",
aligxinto= kongreso.aligxinto,
findato = NULL
)
ref_kongreso_kat_kongreso = novuea.RefKongresaKategorioKongreso(
idKongresaKategorio = 1,
idKongreso= id_kongreso
)
id_kongreso = id_kongreso +1
self.add(kongreso.jaro, novkongreso)
#class TabelTransirAntauxPostKongreso (TabelTransiro):
#
# def __init__(self):
# TabelTransiro.__init__(self)
#
# def konverti(self, transir_urbo):
# akpklist= session_ueamsql.query(ueamsql.t_akpk).all()
# for akpk in akpklist:
# novkongreso = novuea.Kongreso(
# titolo= akpk.titolo,
# bildo = "",
# idUrbo = ,
# jaro = kongreso.jaro,
# numero = ,
# komencdato= NULL,
# temo = kongreso.temo,
# priskribo = "",
# aligxinto= kongreso.aligxinto,
# findato = NULL
# )
# self.add(kongreso.jaro, novkongreso)
################### FINO RILATE AL DISENDO ########################
def clear_db():
session_novuea.begin()
for table in reversed(metadata.sorted_tables):
con.execute(table.delete())
print (table + "cleared")
session_novuea.commit()
session_novuea.close()
clear_db()
komenco = time.clock()
konv_landon = TabelTransirLando()
konv_landon.konverti(session_ueadb)
konv_landon.commit(session_novuea)
post_lando = time.clock()
print("time post lando : "+ str(post_lando - komenco))
konv_urbon = TabelTransirUrbo(konv_landon)
konv_urbon.konverti(session_ueadb)
konv_urbon.commit(session_novuea)
post_urbo = time.clock()
print("time post urbo : "+ str(post_urbo - post_lando))
konv_faktemon = TabelTransirFaktemo()
konv_faktemon.konverti(session_retdb)
konv_faktemon.commit(session_novuea)
post_faktemo= time.clock()
print("time post faktemo: "+ str(post_faktemo - post_urbo))
#konv_kategorion = TabelTransirKategorio()
#konv_kategorion.konverti(get_grupkategorioj())
#konv_kategorion.commit(session_novuea)
#
#post_kategorio= time.clock()
#print("time post kategorio: "+ str(post_kategorio - post_faktemo))
#
konv_grupon = TabelTransirGrupo()
konv_grupon.konverti(get_grupojn())
konv_grupon.commit(session_novuea)
post_grupo= time.clock()
#print("time post grupo: "+ str(post_grupo - post_kategorio))
#konv_grupon_kat = TabelTransirGrupo_Kategorio()
#konv_grupon_kat.konverti(get_grupojn(), konv_grupon, konv_kategorion)
#konv_grupon_kat.commit(session_novuea)
#
#post_grupo_kat= time.clock()
#print("time post grupo_kat: "+ str(post_grupo_kat - post_grupo))
konv_asocionAuxUzanto = TabelTransiro()
konv_asocion = TabelTransirAsocio(konv_urbon, konv_asocionAuxUzanto, konv_grupon)
konv_asocion.konverti(session_ueadb, )
konv_asocion.commit(session_novuea)
post_asocio= time.clock()
#print("time post asocio: "+ str(post_asocio - post_grupo_kat))
konv_uzanton = TabelTransirUzanto(konv_landon, konv_urbon, konv_asocionAuxUzanto)