-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkma_client_admin.py
121 lines (100 loc) · 2.89 KB
/
kma_client_admin.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
# -*- coding: utf-8 -*-
from __future__ import print_function, unicode_literals
from pprint import pprint
from PyInquirer import prompt
from examples import custom_style_3
from pyfiglet import Figlet
import os
import xmlrpc.client as xmlrpclib
import uuid
# import paho mqtt
import paho.mqtt.client as mqtt
f = Figlet(font='lean')
s = xmlrpclib.ServerProxy('http://26.53.0.146:32621')
# buat callback on_publish untuk publish data
########################################
def on_publish(client, userdata, result):
print("Pemenang Berhasil Diumumkan \n")
pass
def print_header():
print(f.renderText('KOREAN MUSIC AWARDS'))
print('==================================\n')
menuUtama = [
{
'type': 'list',
'name': 'menuUtama',
'message': 'Welcome To Korean Music Awards Voting',
'choices': ['Generate Kode Voting', 'Melihat Kode Vote' ,'Lihat Hasil Voting' ,'Umumkan Pemenang','Keluar'],
'filter': lambda val: val.lower()
}
]
generate_kode = [
{
'type': 'confirm',
'message': 'Apakah Kode Sudah Di-Copy ?',
'name': 'kirim',
'default': True,
}
]
confirmation = [
{
'type': 'confirm',
'message': 'Confirm?',
'name': 'kirim',
'default': True,
}
]
def menu1():
os.system('cls')
print_header()
answer = prompt(menuUtama, style=custom_style_3)
return answer['menuUtama']
def generate_kode_voting():
os.system('cls')
print_header()
kode = s.generate_code()
print('Kode Voting : ', kode)
prompt(generate_kode, style=custom_style_3)
def lihat_kode_voting():
os.system('cls')
print_header()
kodes = s.get_code()
for kode in kodes:
print('Kode : ',*kode.keys())
print('Sudah Digunakan : ',*kode.values())
prompt(confirmation, style=custom_style_3)
def publish_pemenang():
os.system('cls')
print_header()
a = s.querry_result()
# definisikan nama broker yang akan digunakan
broker_address = "test.mosquitto.org"
client = mqtt.Client(str(uuid.uuid1()))
client.connect(broker_address, port=1883)
client.on_publish = on_publish
client.publish("KMA_WINNER", a)
print('PEMENANG SUDAH DIUMUMKAN')
prompt(confirmation, style=custom_style_3)
def hasil_voting():
os.system('cls')
print_header()
result = s.querry_result()
print(result)
prompt(confirmation, style=custom_style_3)
def main():
os.system('cls')
exit_menu = False
while exit_menu == False:
answer = menu1()
if answer == 'generate kode voting':
generate_kode_voting()
if answer == 'melihat kode vote':
lihat_kode_voting()
if answer == 'lihat hasil voting':
hasil_voting()
if answer == 'umumkan pemenang':
publish_pemenang()
if answer == 'keluar':
exit_menu = True
if __name__ == '__main__':
main()