/
pyGestioAjuntaments.py
1109 lines (771 loc) · 38.1 KB
/
pyGestioAjuntaments.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
#!/usr/bin/python
# -*- encoding: utf-8 -*-
# Responsables: SEPAM <grupotic@dipcas.es>
#
#
from Tkinter import *
import tkMessageBox, os, datetime, MySQLdb, smtplib, tkFileDialog
# Configurem el formulari (Altura + Amplada + Possició vertical i horitzonal)
root = Tk()
root.geometry('600x560+350+150')
root.title('Ajuntaments')
root.resizable(0,0)
# Configuracio basica de la base de dades del POW
SERVIDOR = '192.168.5.3'
USUARI = 'root'
CONTRASENYA = 'lacasitos'
BASE_DE_DADES = 'ofisam'
varnombre = StringVar()
varescudo = StringVar()
varincidencias = StringVar()
def Actualitzacions():
os.system("//wofima/sepam/scentrales/general/PKG/pyApps/pyActualitzacions.bat")
def SobreElPrograma():
# Missatge del Acerca de
tkMessageBox.showinfo("Sobre el programa", "Aquest programa serveix als responsables tècnics del SEPAM - Diputació de Castelló.\n\nPer qualsevol incidència escriviu a grupotic@dipcas.es")
def Eixir():
# Eixim del programa
root.destroy()
def ExportFitxaEntitat():
if len(varnombre.get()) == 0:
tkMessageBox.showinfo("Imposible generar TXT", "No es pot generar el TXT perquè no has seleccionat cap entidad.")
return
# Obrim el fitxer de text
#Així es com estava abans quan el ficava a /exportacions ----> f=open("exportacions/fitxa-" + varnombre.get() + ".txt","w")
fitxer = tkFileDialog.asksaveasfilename(defaultextension="*.txt|*.*", filetypes=[('Fitxer TXT','*.txt'),('Tots els fitxers','*.*')])
f = open(fitxer, "w")
f.write("-------------------------------------------------------------------\n")
f.write(varnombre.get() + "\n\n")
f.write("Direccio: " + textdireccion.get() + "\n")
f.write("Codi Postal: " + textcp.get() + "\n")
f.write("Telf: " + texttelefono.get() + "\n")
f.write("FAX: " + textfax.get() + "\n")
f.write("E-mail: " + textmail.get() + "\n")
f.write("Web: " + textweb.get() + "\n")
f.write("Secretari: " + textsecretario.get() + "\n")
f.write("Alcalde: " + textalcalde.get() + "\n")
f.write("Ofisam: " + textofisam.get() + "\n")
f.write("-------------------------------------------------------------------\n")
# Tanquem el fitxer
f.close()
if len(fitxer) > 0:
tkMessageBox.showinfo("TXT Generat", "S'ha generat el document a " + fitxer)
else:
return
def Export1():
if len(varnombre.get()) == 0:
tkMessageBox.showinfo("Imposible generar PDF", "No es pot generar el PDF perquè no has seleccionat cap entidad.")
return
#Exportem les dades de l'Ajuntament actual
from reportlab.lib.pagesizes import A4
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Image
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.lib.units import inch
#Abans ho tenia com les següents línies i ho deixava a /exportacions
#doc = SimpleDocTemplate("exportacions/fitxa-" + varnombre.get() + ".pdf",pagesize=A4,
#rightMargin=72,leftMargin=72,
#topMargin=72,bottomMargin=18)
fitxer = tkFileDialog.asksaveasfilename(defaultextension="*.pdf|*.*", filetypes=[('Fitxer PDF','*.pdf'),('Tots els fitxers','*.*')])
doc = SimpleDocTemplate (fitxer,pagesize=A4,
rightMargin=72,leftMargin=72,
topMargin=72,bottomMargin=18)
#Creem la llista "Story" i iniciem la variable "styles"
Story=[]
styles=getSampleStyleSheet()
ptext = unicode("<font size=17>" + varnombre.get() + "</font>", "iso-8859-1")
Story.append(Paragraph(ptext.strip(), styles["Normal"]))
Story.append(Spacer(1, 14))
ptext = unicode("<font size=10>Direccion: " + textdireccion.get() + "</font>", "iso-8859-1")
Story.append(Paragraph(ptext, styles["Normal"]))
Story.append(Spacer(1, 6))
ptext = unicode("<font size=10>CP: " + textcp.get() + "</font>", "iso-8859-1")
Story.append(Paragraph(ptext, styles["Normal"]))
Story.append(Spacer(1, 6))
ptext = unicode("<font size=10>Telf: " + texttelefono.get() + "</font>", "iso-8859-1")
Story.append(Paragraph(ptext, styles["Normal"]))
Story.append(Spacer(1, 6))
ptext = unicode("<font size=10>FAX: " + textfax.get() + "</font>", "iso-8859-1")
Story.append(Paragraph(ptext, styles["Normal"]))
Story.append(Spacer(1, 6))
ptext = unicode("<font size=10>E-mail: " + textmail.get() + "</font>", "iso-8859-1")
Story.append(Paragraph(ptext, styles["Normal"]))
Story.append(Spacer(1, 6))
ptext = unicode("<font size=10>Web: " + textweb.get() + "</font>", "iso-8859-1")
Story.append(Paragraph(ptext, styles["Normal"]))
Story.append(Spacer(1, 6))
ptext = unicode("<font size=10>Secretari: " + textsecretario.get() + "</font>", "iso-8859-1")
Story.append(Paragraph(ptext, styles["Normal"]))
Story.append(Spacer(1, 6))
ptext = unicode("<font size=10>Alcalde: " + textalcalde.get() + "</font>", "iso-8859-1")
Story.append(Paragraph(ptext, styles["Normal"]))
Story.append(Spacer(1, 6))
ptext = unicode("<font size=10>Ofisam: " + textofisam.get() + "</font>", "iso-8859-1")
Story.append(Paragraph(ptext, styles["Normal"]))
Story.append(Spacer(1, 6))
#Finalment creem el document PDF
doc.build(Story)
if len(fitxer) > 0:
tkMessageBox.showinfo("PDF Generat", "S'ha generat el document a " + fitxer)
else:
return
def Export2():
#Exportamos los datos de todas las entidades
from reportlab.lib.pagesizes import A4
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Image
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.lib.units import inch
#Abans ho tenia com les següents línies i ho deixava a /exportacions
#doc = SimpleDocTemplate("exportacions/totes-les-fitxes.pdf",pagesize=A4,
#rightMargin=72,leftMargin=72,
#topMargin=72,bottomMargin=18)
fitxer = tkFileDialog.asksaveasfilename(defaultextension="*.pdf|*.*", filetypes=[('Fitxer PDF','*.pdf'),('Tots els fitxers','*.*')])
doc = SimpleDocTemplate (fitxer,pagesize=A4,
rightMargin=72,leftMargin=72,
topMargin=72,bottomMargin=18)
#Creem la llista "Story" i iniciem la variable "styles"
Story=[]
styles=getSampleStyleSheet()
# Generamos el select para obtener los datos de la ficha
db=MySQLdb.connect(host=SERVIDOR,user=USUARI, port=4406, passwd=CONTRASENYA,db=BASE_DE_DADES)
cursor=db.cursor()
sql="SELECT CODIGO, MUNICIPIO, DOMICILIO, CP, TELEFONO, FAX, email, web, SECRETARIO, ALCALDE FROM ayuntamientos ORDER BY CODIGO"
cursor.execute(sql)
resultado=cursor.fetchall()
for i in resultado:
ptext = unicode("<font size=17>" + str(i[1]) + "</font>", "iso-8859-1")
Story.append(Paragraph(ptext.strip(), styles["Normal"]))
Story.append(Spacer(1, 14))
ptext = unicode("<font size=10>Direccion: " + str(i[2]) + "</font>", "iso-8859-1")
Story.append(Paragraph(ptext, styles["Normal"]))
Story.append(Spacer(1, 6))
ptext = unicode("<font size=10>CP: " + str(i[3]) + "</font>", "iso-8859-1")
Story.append(Paragraph(ptext, styles["Normal"]))
Story.append(Spacer(1, 6))
ptext = unicode("<font size=10>Telf: " + str(i[4]) + "</font>", "iso-8859-1")
Story.append(Paragraph(ptext, styles["Normal"]))
Story.append(Spacer(1, 6))
ptext = unicode("<font size=10>FAX: " + str(i[5]) + "</font>", "iso-8859-1")
Story.append(Paragraph(ptext, styles["Normal"]))
Story.append(Spacer(1, 6))
ptext = unicode("<font size=10>E-mail: " + str(i[6]) + "</font>", "iso-8859-1")
Story.append(Paragraph(ptext, styles["Normal"]))
Story.append(Spacer(1, 6))
ptext = unicode("<font size=10>Web: " + str(i[7]) + "</font>", "iso-8859-1")
Story.append(Paragraph(ptext, styles["Normal"]))
Story.append(Spacer(1, 6))
ptext = unicode("<font size=10>Secretari: " + str(i[8]) + "</font>", "iso-8859-1")
Story.append(Paragraph(ptext, styles["Normal"]))
Story.append(Spacer(1, 6))
ptext = unicode("<font size=10>Alcalde: " + str(i[9]) + "</font>", "iso-8859-1")
Story.append(Paragraph(ptext, styles["Normal"]))
Story.append(Spacer(1, 6))
ptext = unicode("<font size=10>- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -</font>", "iso-8859-1")
Story.append(Paragraph(ptext, styles["Normal"]))
Story.append(Spacer(1, 20))
#Finalment creem el document PDF
doc.build(Story)
if len(fitxer) > 0:
tkMessageBox.showinfo("PDF Generat", "S'ha generat la fitxa de totes les entitats a " + fitxer)
else:
return
def Export3():
#Exportem els codis INE
from reportlab.lib.pagesizes import A4
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Image
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.lib.units import inch
#doc = SimpleDocTemplate("exportacions/codis-INE.pdf",pagesize=A4,
#rightMargin=72,leftMargin=72,
#topMargin=72,bottomMargin=18)
fitxer = tkFileDialog.asksaveasfilename(defaultextension="*.pdf|*.*", filetypes=[('Fitxer PDF','*.pdf'),('Tots els fitxers','*.*')])
doc = SimpleDocTemplate (fitxer,pagesize=A4,
rightMargin=72,leftMargin=72,
topMargin=72,bottomMargin=18)
#Creem la llista "Story" i iniciem la variable "styles"
Story=[]
styles=getSampleStyleSheet()
# Generem el select para obtenir els codis INE i nom de les entitats
db=MySQLdb.connect(host=SERVIDOR,user=USUARI, port=4406, passwd=CONTRASENYA,db=BASE_DE_DADES)
cursor=db.cursor()
sql="SELECT CODIGO, MUNICIPIO FROM ayuntamientos ORDER BY CODIGO"
cursor.execute(sql)
resultado=cursor.fetchall()
for i in resultado:
ptext = unicode("<font size=10>" + str(i[0]) + "\t - \t" + str(i[1]) + "</font>", "iso-8859-1")
Story.append(Paragraph(ptext, styles["Normal"]))
Story.append(Spacer(1, 6))
#Finalment creem el document PDF
doc.build(Story)
if len(fitxer) > 0:
tkMessageBox.showinfo("PDF Generat", "S'ha generat la fitxa amb tots els codis INE a " + fitxer)
else:
return
def Export4():
#Exportem els telefons de tots els ajuntaments
from reportlab.lib.pagesizes import A4
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Image
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.lib.units import inch
#doc = SimpleDocTemplate("exportacions/telefons-ajuntaments.pdf",pagesize=A4,
#rightMargin=72,leftMargin=72,
#topMargin=72,bottomMargin=18)
fitxer = tkFileDialog.asksaveasfilename(defaultextension="*.pdf|*.*", filetypes=[('Fitxer PDF','*.pdf'),('Tots els fitxers','*.*')])
doc = SimpleDocTemplate (fitxer,pagesize=A4,
rightMargin=72,leftMargin=72,
topMargin=72,bottomMargin=18)
#Creem la llista "Story" i iniciem la variable "styles"
Story=[]
styles=getSampleStyleSheet()
# Generem el select para obtenir els telefons de les entitats
db=MySQLdb.connect(host=SERVIDOR,user=USUARI, port=4406, passwd=CONTRASENYA,db=BASE_DE_DADES)
cursor=db.cursor()
sql="SELECT MUNICIPIO, TELEFONO FROM ayuntamientos ORDER BY CODIGO"
cursor.execute(sql)
resultado=cursor.fetchall()
for i in resultado:
ptext = unicode("<font size=10>" + str(i[0]) + " \t - \t " + str(i[1]) + "</font>", "iso-8859-1")
Story.append(Paragraph(ptext, styles["Normal"]))
Story.append(Spacer(1, 6))
#Finalment creem el document PDF
doc.build(Story)
if len(fitxer) > 0:
tkMessageBox.showinfo("PDF Generat", "S'ha generat la fitxa amb el telèfons a " + fitxer)
else:
return
def ExportTotesEntitats():
# Obrim el fitxer de text
#Així es com estava abans quan el ficava a /exportacions ----> f=open("exportacions/totes-les-fitxes.txt","w")
fitxer = tkFileDialog.asksaveasfilename(defaultextension="*.txt|*.*", filetypes=[('Fitxer TXT','*.txt'),('Tots els fitxers','*.*')])
f = open(fitxer, "w")
# Generamos el select para obtener los datos de la ficha
db=MySQLdb.connect(host=SERVIDOR,user=USUARI, port=4406, passwd=CONTRASENYA,db=BASE_DE_DADES)
cursor=db.cursor()
sql="SELECT CODIGO, MUNICIPIO, DOMICILIO, CP, TELEFONO, FAX, email, web, SECRETARIO, ALCALDE, OFISAM FROM ayuntamientos ORDER BY CODIGO"
cursor.execute(sql)
resultado=cursor.fetchall()
for i in resultado:
f.write(str(i[1]) + '\n\n')
f.write(str(i[2]) + '\n')
f.write(str(i[3]) + '\n')
f.write(str(i[4]) + '\n')
f.write(str(i[5]) + '\n')
f.write(str(i[6]) + '\n')
f.write(str(i[7]) + '\n')
f.write(str(i[8]) + '\n')
f.write("\n\n-------------------------------------------------------------------\n\n")
#tanquem el fitxer
f.close()
if len(fitxer) > 0:
tkMessageBox.showinfo("TXT Generat", "S'ha generat la fitxa de totes les entitats a C:/pyApps/exportacions/totes-les-fitxes.txt")
else:
return
def ExportCodigosINE():
# Obrim el fitxer de text
#Així es com estava abans quan el ficava a /exportacions ----> f=open("exportacions/codis-INE.txt","w")
fitxer = tkFileDialog.asksaveasfilename(defaultextension="*.txt|*.*", filetypes=[('Fitxer TXT','*.txt'),('Tots els fitxers','*.*')])
f = open(fitxer, "w")
# Generamos el select para obtener los datos de la ficha
db=MySQLdb.connect(host=SERVIDOR,user=USUARI, port=4406, passwd=CONTRASENYA,db=BASE_DE_DADES)
cursor=db.cursor()
sql="SELECT CODIGO, MUNICIPIO, DOMICILIO, CP, TELEFONO, FAX, email, web, SECRETARIO, ALCALDE, OFISAM FROM ayuntamientos ORDER BY CODIGO"
cursor.execute(sql)
resultado=cursor.fetchall()
for i in resultado:
f.write(str(i[0]) + ' - ' + str(i[1]) + '\n')
#tanquem el fitxer
f.close()
if len(fitxer) > 0:
tkMessageBox.showinfo("TXT Generat", "S'ha generat la fitxa amb tots els codis INE a " + fitxer)
else:
return
def ExportCorreusEntitats():
# Obrim el fitxer de text
#Així es com estava abans quan el ficava a /exportacions ----> f=open("exportacions/emails-ajuntaments.txt","w")
fitxer = tkFileDialog.asksaveasfilename(defaultextension="*.txt|*.*", filetypes=[('Fitxer TXT','*.txt'),('Tots els fitxers','*.*')])
f = open(fitxer, "w")
# Generem el select para obtenir els emails de les entitats
db=MySQLdb.connect(host=SERVIDOR,user=USUARI, port=4406, passwd=CONTRASENYA,db=BASE_DE_DADES)
cursor=db.cursor()
sql="SELECT MUNICIPIO, email FROM ayuntamientos ORDER BY CODIGO"
cursor.execute(sql)
resultado=cursor.fetchall()
for i in resultado:
f.write(str(i[0]) + ' - ' + str(i[1]) + '\n')
#tanquem el fitxer
f.close()
if len(fitxer) > 0:
tkMessageBox.showinfo("TXT Generat", "S'ha generat la fitxa amb el e-mails a " + fitxer)
else:
return
def Export5():
#Exportem els e-mails de totes les entitats
from reportlab.lib.pagesizes import A4
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Image
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.lib.units import inch
#doc = SimpleDocTemplate("exportacions/emails-ajuntaments.pdf",pagesize=A4,
#rightMargin=72,leftMargin=72,
#topMargin=72,bottomMargin=18)
fitxer = tkFileDialog.asksaveasfilename(defaultextension="*.pdf|*.*", filetypes=[('Fitxer PDF','*.pdf'),('Tots els fitxers','*.*')])
doc = SimpleDocTemplate (fitxer,pagesize=A4,
rightMargin=72,leftMargin=72,
topMargin=72,bottomMargin=18)
#Creem la llista "Story" i iniciem la variable "styles"
Story=[]
styles=getSampleStyleSheet()
# Generem el select para obtenir els emails de les entitats
db=MySQLdb.connect(host=SERVIDOR,user=USUARI, port=4406, passwd=CONTRASENYA,db=BASE_DE_DADES)
cursor=db.cursor()
sql="SELECT MUNICIPIO, email FROM ayuntamientos ORDER BY MUNICIPIO"
cursor.execute(sql)
resultado=cursor.fetchall()
for i in resultado:
ptext = unicode("<font size=10>" + str(i[0]) + " \t - \t " + str(i[1]) + "</font>", "iso-8859-1")
Story.append(Paragraph(ptext, styles["Normal"]))
Story.append(Spacer(1, 6))
#Finalment creem el document PDF
doc.build(Story)
if len(fitxer) > 0:
tkMessageBox.showinfo("PDF Generat", "S'ha generat la fitxa amb el e-mails a " + fitxer)
else:
return
def ExportTelefonsEntitats():
# Obrim el fitxer de text
#Així es com estava abans quan el ficava a /exportacions ----> f=open("exportacions/telefons-ajuntaments.txt","w")
fitxer = tkFileDialog.asksaveasfilename(defaultextension="*.txt|*.*", filetypes=[('Fitxer TXT','*.txt'),('Tots els fitxers','*.*')])
f = open(fitxer, "w")
# Generamos el select para obtener los datos de la ficha
db=MySQLdb.connect(host=SERVIDOR,user=USUARI, port=4406, passwd=CONTRASENYA,db=BASE_DE_DADES)
cursor=db.cursor()
sql="SELECT CODIGO, MUNICIPIO, DOMICILIO, CP, TELEFONO, FAX, email, web, SECRETARIO, ALCALDE, OFISAM FROM ayuntamientos ORDER BY CODIGO"
cursor.execute(sql)
resultado=cursor.fetchall()
for i in resultado:
f.write(str(i[1]) + ' - ' + str(i[4]) + '\n')
#tanquem el fitxer
f.close()
if len(fitxer) > 0:
tkMessageBox.showinfo("TXT Generat", "S'ha generat la fitxa amb el telèfons a " + fitxer)
else:
return
def ExportDominisEntitats():
# Obrim el fitxer de text
#Així es com estava abans quan el ficava a /exportacions ----> f=open("exportacions/dominis-ajuntaments.txt","w")
fitxer = tkFileDialog.asksaveasfilename(defaultextension="*.txt|*.*", filetypes=[('Fitxer TXT','*.txt'),('Tots els fitxers','*.*')])
f = open(fitxer, "w")
# Generamos el select para obtener los datos de la ficha
db=MySQLdb.connect(host=SERVIDOR,user=USUARI, port=4406, passwd=CONTRASENYA,db=BASE_DE_DADES)
cursor=db.cursor()
sql="SELECT MUNICIPIO, web FROM ayuntamientos ORDER BY MUNICIPIO"
cursor.execute(sql)
resultado=cursor.fetchall()
for i in resultado:
f.write(str(i[0]) + ' - ' + str(i[1]) + '\n')
#tanquem el fitxer
f.close()
if len(fitxer) > 0:
tkMessageBox.showinfo("TXT Generat", "S'ha generat la fitxa amb el dominis a " + fitxer)
else:
return
def Export6():
#Exportem els dominis de totes les entitats
from reportlab.lib.pagesizes import A4
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Image
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.lib.units import inch
#doc = SimpleDocTemplate("exportacions/dominis-ajuntaments.pdf",pagesize=A4,
#rightMargin=72,leftMargin=72,
#topMargin=72,bottomMargin=18)
fitxer = tkFileDialog.asksaveasfilename(defaultextension="*.pdf|*.*", filetypes=[('Fitxer PDF','*.pdf'),('Tots els fitxers','*.*')])
doc = SimpleDocTemplate (fitxer,pagesize=A4,
rightMargin=72,leftMargin=72,
topMargin=72,bottomMargin=18)
#Creem la llista "Story" i iniciem la variable "styles"
Story=[]
styles=getSampleStyleSheet()
# Generem el select per a obtenir els dominis de totes les entitats
db=MySQLdb.connect(host=SERVIDOR,user=USUARI, port=4406, passwd=CONTRASENYA,db=BASE_DE_DADES)
cursor=db.cursor()
sql="SELECT MUNICIPIO, web FROM ayuntamientos ORDER BY MUNICIPIO"
cursor.execute(sql)
resultado=cursor.fetchall()
for i in resultado:
ptext = unicode("<font size=10>" + str(i[0]) + " \t - \t " + str(i[1]) + "</font>", "iso-8859-1")
Story.append(Paragraph(ptext, styles["Normal"]))
Story.append(Spacer(1, 6))
#Finalment creem el document PDF
doc.build(Story)
if len(fitxer) > 0:
tkMessageBox.showinfo("PDF Generat", "S'ha generat la fitxa amb el dominis a " + fitxer)
else:
return
def ExportAlcaldes():
# Obrim el fitxer de text
#Així es com estava abans quan el ficava a /exportacions ----> f=open("exportacions/alcaldes-ajuntaments.txt","w")
fitxer = tkFileDialog.asksaveasfilename(defaultextension="*.txt|*.*", filetypes=[('Fitxer TXT','*.txt'),('Tots els fitxers','*.*')])
f = open(fitxer, "w")
# Generamos el select para obtener los datos de la ficha
db=MySQLdb.connect(host=SERVIDOR,user=USUARI, port=4406, passwd=CONTRASENYA,db=BASE_DE_DADES)
cursor=db.cursor()
sql="SELECT MUNICIPIO, ALCALDE FROM ayuntamientos ORDER BY MUNICIPIO"
cursor.execute(sql)
resultado=cursor.fetchall()
for i in resultado:
f.write(str(i[0]) + ' - ' + str(i[1]) + '\n')
#tanquem el fitxer
f.close()
if len(fitxer) > 0:
tkMessageBox.showinfo("TXT Generat", "S'ha generat la fitxa amb els alcaldes a " + fitxer)
else:
return
def Export7():
#Exportem els alcaldes de totes les entitats
from reportlab.lib.pagesizes import A4
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Image
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.lib.units import inch
#doc = SimpleDocTemplate("exportacions/alcaldes-ajuntaments.pdf",pagesize=A4,
#rightMargin=72,leftMargin=72,
#topMargin=72,bottomMargin=18)
fitxer = tkFileDialog.asksaveasfilename(defaultextension="*.pdf|*.*", filetypes=[('Fitxer PDF','*.pdf'),('Tots els fitxers','*.*')])
doc = SimpleDocTemplate (fitxer,pagesize=A4,
rightMargin=72,leftMargin=72,
topMargin=72,bottomMargin=18)
#Creem la llista "Story" i iniciem la variable "styles"
Story=[]
styles=getSampleStyleSheet()
# Generem el select per a obtenir els alcaldes de totes les entitats
db=MySQLdb.connect(host=SERVIDOR,user=USUARI, port=4406, passwd=CONTRASENYA,db=BASE_DE_DADES)
cursor=db.cursor()
sql="SELECT MUNICIPIO, ALCALDE FROM ayuntamientos ORDER BY MUNICIPIO"
cursor.execute(sql)
resultado=cursor.fetchall()
for i in resultado:
ptext = unicode("<font size=10>" + str(i[0]) + " \t - \t " + str(i[1]) + "</font>", "iso-8859-1")
Story.append(Paragraph(ptext, styles["Normal"]))
Story.append(Spacer(1, 6))
#Finalment creem el document PDF
doc.build(Story)
if len(fitxer) > 0:
tkMessageBox.showinfo("PDF Generat", "S'ha generat la fitxa amb els alcaldes a " + fitxer)
else:
return
def ExportSecretaris():
# Obrim el fitxer de text
#Així es com estava abans quan el ficava a /exportacions ----> f=open("exportacions/secretaris-ajuntaments.txt","w")
fitxer = tkFileDialog.asksaveasfilename(defaultextension="*.txt|*.*", filetypes=[('Fitxer TXT','*.txt'),('Tots els fitxers','*.*')])
f = open(fitxer, "w")
# Generamos el select para obtener los datos de la ficha
db=MySQLdb.connect(host=SERVIDOR,user=USUARI, port=4406, passwd=CONTRASENYA,db=BASE_DE_DADES)
cursor=db.cursor()
sql="SELECT MUNICIPIO, SECRETARIO FROM ayuntamientos ORDER BY MUNICIPIO"
cursor.execute(sql)
resultado=cursor.fetchall()
for i in resultado:
f.write(str(i[0]) + ' - ' + str(i[1]) + '\n')
#tanquem el fitxer
f.close()
if len(fitxer) > 0:
tkMessageBox.showinfo("TXT Generat", "S'ha generat la fitxa amb els secretaris a " + fitxer)
else:
return
def Export8():
#Exportem els secretaris de totes les entitats
from reportlab.lib.pagesizes import A4
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Image
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.lib.units import inch
#doc = SimpleDocTemplate("exportacions/secretaris-ajuntaments.pdf",pagesize=A4,
#rightMargin=72,leftMargin=72,
#topMargin=72,bottomMargin=18)
fitxer = tkFileDialog.asksaveasfilename(defaultextension="*.pdf|*.*", filetypes=[('Fitxer PDF','*.pdf'),('Tots els fitxers','*.*')])
doc = SimpleDocTemplate (fitxer,pagesize=A4,
rightMargin=72,leftMargin=72,
topMargin=72,bottomMargin=18)
#Creem la llista "Story" i iniciem la variable "styles"
Story=[]
styles=getSampleStyleSheet()
# Generem el select per a obtenir els secretaris de totes les entitats
db=MySQLdb.connect(host=SERVIDOR,user=USUARI, port=4406, passwd=CONTRASENYA,db=BASE_DE_DADES)
cursor=db.cursor()
sql="SELECT MUNICIPIO, SECRETARIO FROM ayuntamientos ORDER BY MUNICIPIO"
cursor.execute(sql)
resultado=cursor.fetchall()
for i in resultado:
ptext = unicode("<font size=10>" + str(i[0]) + " \t - \t " + str(i[1]) + "</font>", "iso-8859-1")
Story.append(Paragraph(ptext, styles["Normal"]))
Story.append(Spacer(1, 6))
#Finalment creem el document PDF
doc.build(Story)
if len(fitxer) > 0:
tkMessageBox.showinfo("PDF Generat", "S'ha generat la fitxa amb els secretaris a " + fitxer)
else:
return
def InsertarIncidencia():
os.system('C:\Python24\python.exe software/pyPOW.py')
def ResponsablesWeb():
os.system('C:\Python24\python.exe software/pyResponsablesWeb.py')
def QueOfisam(variableofisam):
# Generamos el select para obtener los datos de la ofisam
db=MySQLdb.connect(host=SERVIDOR,user=USUARI, port=4406, passwd=CONTRASENYA,db=BASE_DE_DADES)
cursor=db.cursor()
sql="SELECT CODIGO, MUNICIPIO FROM CENTROS WHERE CODIGO='"+ variableofisam + "'"
cursor.execute(sql)
resultado2=cursor.fetchall()
datos_ofisam = resultado2[0]
return datos_ofisam[1]
def ContadorIncidencias(variablecontador):
# Generamos el select para obtener el total de incidencies del municipi passat
db=MySQLdb.connect(host=SERVIDOR,user=USUARI, port=4406, passwd=CONTRASENYA,db=BASE_DE_DADES)
cursor=db.cursor()
sql="SELECT COUNT(*) FROM incidencia where estat_Incidencia='1' AND entitat='" + variablecontador + "'"
cursor.execute(sql)
resultado3=cursor.fetchall()
# Aci estic passant el resultat del count(*) que es un long (2L) a un integer short
datos_contador = resultado3[0]
sumadortotal = reduce(lambda x, y: (x<<8) + y, datos_contador)
# Este es el numero de incidencias
return str(sumadortotal)
def GuardarCambios():
db=MySQLdb.connect(host=SERVIDOR,user=USUARI, port=4406, passwd=CONTRASENYA,db=BASE_DE_DADES)
cursor=db.cursor()
sql1="UPDATE ayuntamientos SET DOMICILIO='" + textdireccion.get() + "' where CODIGO='" + entry0.get() + "'"
sql2="UPDATE ayuntamientos SET CP='" + textcp.get() + "' where CODIGO='" + entry0.get() + "'"
sql3="UPDATE ayuntamientos SET TELEFONO='" + texttelefono.get() + "' where CODIGO='" + entry0.get() + "'"
sql4="UPDATE ayuntamientos SET FAX='" + textfax.get() + "' where CODIGO='" + entry0.get() + "'"
sql5="UPDATE ayuntamientos SET email='" + textmail.get() + "' where CODIGO='" + entry0.get() + "'"
sql6="UPDATE ayuntamientos SET web='" + textweb.get() + "' where CODIGO='" + entry0.get() + "'"
sql7="UPDATE ayuntamientos SET SECRETARIO='" + textsecretario.get() + "' where CODIGO='" + entry0.get() + "'"
sql8="UPDATE ayuntamientos SET ALCALDE='" + textalcalde.get() + "' where CODIGO='" + entry0.get() + "'"
cursor.execute(sql1)
resultado1=cursor.fetchall()
cursor.execute(sql2)
resultado2=cursor.fetchall()
cursor.execute(sql3)
resultado3=cursor.fetchall()
cursor.execute(sql4)
resultado4=cursor.fetchall()
cursor.execute(sql5)
resultado5=cursor.fetchall()
cursor.execute(sql6)
resultado6=cursor.fetchall()
cursor.execute(sql7)
resultado7=cursor.fetchall()
cursor.execute(sql8)
resultado8=cursor.fetchall()
print "\nAhora, tras el borrado, el ENTRY0 ES: " + entry0.get()
print "\n\n-----GUARDADO---\n\n"
tkMessageBox.showinfo("Dades guardades", "Els canvis han segut guardats correctament.")
def LimpiarCampos():
photo = PhotoImage(file="")
textdireccion.delete(0,END)
texttelefono.delete(0,END)
textcp.delete(0,END)
texttelefono.delete(0,END)
textfax.delete(0,END)
textmail.delete(0,END)
textweb.delete(0,END)
textalcalde.delete(0,END)
textsecretario.delete(0,END)
textofisam.delete(0,END)
def MuestraDatos():
# Esborrem els camps dels entrys
LimpiarCampos()
# Generem el select per obtenir les dades de la fitxa
db=MySQLdb.connect(host=SERVIDOR,user=USUARI, port=4406, passwd=CONTRASENYA,db=BASE_DE_DADES)
cursor=db.cursor()
sql="SELECT CODIGO, MUNICIPIO, DOMICILIO, CP, TELEFONO, FAX, email, web, SECRETARIO, ALCALDE, escut, OFISAM FROM ayuntamientos where Codigo='"+llista1.get(ACTIVE)[0:4] +"'"
cursor.execute(sql)
resultado=cursor.fetchall()
#fiquem a una sola tupla el resultat del SELECT
datos_ayuntamiento = resultado[0]
print '\n\n\n'
print datos_ayuntamiento
campo_codigo = datos_ayuntamiento[0]
campo_nombre = datos_ayuntamiento[1]
campo_direccion= datos_ayuntamiento[2]
campo_cpostal = datos_ayuntamiento[3]
campo_telefono = datos_ayuntamiento[4]
campo_fax = datos_ayuntamiento[5]
campo_mail = datos_ayuntamiento[6]
campo_web = datos_ayuntamiento[7]
campo_secretario = datos_ayuntamiento[8]
campo_alcalde = datos_ayuntamiento[9]
campo_escut = datos_ayuntamiento[10]
campo_ofisam = datos_ayuntamiento[11]
QueOfisam(campo_ofisam)
campo_ofisam_comprensible = QueOfisam(campo_ofisam)
campo_contadorincidencias = ContadorIncidencias(campo_codigo)
# Vamos poniendo los datos
entry0.delete(0,END)
entry0.insert(0, campo_codigo)
photo = PhotoImage(file="imatges/escuts/" + campo_escut)
w = Label(frame_nomajunt, image=photo)
w.photo = photo
w.grid(row=1, column=0, sticky=W)
varnombre.set(campo_nombre)
textdireccion.insert(0, campo_direccion)
textcp.insert(0, campo_cpostal)
texttelefono.insert(0, campo_telefono)
textfax.insert(0, campo_fax)
textmail.insert(0, campo_mail)
textweb.insert(0, campo_web)
textalcalde.insert(0, campo_alcalde)
textsecretario.insert(0, campo_secretario)
textofisam.insert(0, campo_ofisam_comprensible)
varescudo.set("Ruta del logo/escut: escuts/" + campo_escut)
varincidencias.set("Incidències obertes al POW: " + str(campo_contadorincidencias))
#
#
# INICI
#
#
#
# Aci iniciem l'aplicacio i lo primer que mirarem es si existeixen actualitzacions
# Per a aixo, el que fem es comprovar si existeix el fitxer "actualitzacio-SI.txt"
# al repositori pyApps de Wofima.
#
#
Actualitzacions()
#######################################################################
# PANTALLA1: Pantalla principal
#######################################################################
# El menu del programa
menubar = Menu(root)
filemenu1 = Menu(menubar, tearoff= 0)
filemenu2 = Menu(menubar, tearoff= 0)
filemenu3 = Menu(menubar, tearoff= 0)
filemenu4 = Menu(menubar, tearoff= 0)
filemenu1.add_command(label="Insertar Incidència", command=InsertarIncidencia)
filemenu1.add_command(label="Gestió Responables Webs Municipals", command=ResponsablesWeb)
filemenu1.add_separator()
filemenu1.add_command(label="Eixir del programa", command=Eixir)
filemenu2.add_command(label="Copiar")
filemenu2.add_command(label="Tallar")
filemenu2.add_command(label="Enganxar")
filemenu2.add_separator()
filemenu2.add_command(label="Guardar els canvis", command=GuardarCambios)
filemenu3.add_command(label="Fitxa de l'entitat actual (TXT)", command=ExportFitxaEntitat)
filemenu3.add_command(label="Fitxa de l'entitat actual (PDF)", command=Export1)
filemenu3.add_command(label="Fitxa de totes las entidats (TXT)", command=ExportTotesEntitats)
filemenu3.add_command(label="Fitxa de totes las entidats (PDF)", command=Export2)
filemenu3.add_command(label="Codi INE de las entidats (TXT)", command=ExportCodigosINE)
filemenu3.add_command(label="Codi INE de las entidats (PDF)", command=Export3)
filemenu3.add_command(label="Telèfons de las entitats (TXT)", command=ExportTelefonsEntitats)
filemenu3.add_command(label="Telèfons de las entitats (PDF)", command=Export4)
filemenu3.add_command(label="Emails de les entidats (TXT)", command=ExportCorreusEntitats)
filemenu3.add_command(label="Emails de les entidats (PDF)", command=Export5)
filemenu3.add_command(label="Dominis web de les entidats (TXT)", command=ExportDominisEntitats)
filemenu3.add_command(label="Dominis web de les entidats (PDF)", command=Export6)
filemenu3.add_command(label="Tots els Alcaldes (TXT)", command=ExportAlcaldes)
filemenu3.add_command(label="Tots els Alcaldes (PDF)", command=Export7)
filemenu3.add_command(label="Tots els Secretaris (TXT)", command=ExportSecretaris)
filemenu3.add_command(label="Tots els Secretaris (PDF)", command=Export8)
filemenu4.add_command(label="Sobre el programa", command=SobreElPrograma)
menubar.add_cascade(label="Arxiu", menu = filemenu1)
menubar.add_cascade(label="Editar", menu = filemenu2)
menubar.add_cascade(label="Exportar", menu = filemenu3)
menubar.add_cascade(label="Ajuda", menu = filemenu4)
root.config(menu=menubar)
# Frame superior: Afegim la imatge de l'aplicacio
frame_logo = Frame(root)
frame_logo.grid(row=0, column=1, sticky=W)
photo = PhotoImage(file="imatges/logo.gif")
w = Label(frame_logo, image=photo)
w.photo = photo
w.grid(row=1, sticky=N+W)
# Frames de baix on afegim els widgets
frame_contenedor = Frame(root, height=550)
frame_contenedor.grid(row=1, column=1)
# Frames de baix on afegim els widgets
frame_esquerra = Frame(frame_contenedor, height=450, width=200)
frame_esquerra.grid(row=1, column=1)
# llistat noms de les categories
frame_llista1 = Frame(frame_esquerra)
frame_llista1.pack(fill=Y)
scroll1 = Scrollbar(frame_llista1, bg='grey')
scroll1.pack(side=RIGHT, fill=Y)
llista1 = Listbox(frame_llista1, exportselection=0, yscrollcommand=scroll1.set, height="31", width="36", bg='white')
llista1.pack()
db=MySQLdb.connect(host=SERVIDOR,user=USUARI, port=4406, passwd=CONTRASENYA,db=BASE_DE_DADES)
cursor_llista1=db.cursor()
sql_llista1='SELECT CODIGO, MUNICIPIO From ayuntamientos ORDER BY CODIGO'
cursor_llista1.execute(sql_llista1)