Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Owo Sugiana
/
iso8583-web
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 47bf07df
authored
Jun 23, 2020
by
Owo Sugiana
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Lebih banyak opsi untuk web_client.py
1 parent
c865e1be
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
132 additions
and
113 deletions
CHANGES.txt
README.rst
contrib/web-client.py → iso8583_web/scripts/web_client.py
setup.py
CHANGES.txt
View file @
47bf07d
0.1.7 2020-05-12
0.1.7 2020-05-12
----------------
----------------
- Bug fixed append_others()
- Bug fixed append_others()
- web-client.py tidak lagi berada di contrib melainkan sebagai
bin/iso8583_web_client
0.1.6 2020-04-09
0.1.6 2020-04-09
----------------
----------------
...
...
README.rst
View file @
47bf07d
...
@@ -107,7 +107,7 @@ membuat aplikasi teller bank. Pada ``test-bjb.ini`` aktifkan section
...
@@ -107,7 +107,7 @@ membuat aplikasi teller bank. Pada ``test-bjb.ini`` aktifkan section
Kemudian restart daemon-nya. Setelah *echo established* dengan daemon pemda
Kemudian restart daemon-nya. Setelah *echo established* dengan daemon pemda
lakukan *echo request* dengan cara::
lakukan *echo request* dengan cara::
$ ~/env/bin/
python contrib/web-client.py
$ ~/env/bin/
iso8583_web_client
Hasilnya menjadi seperti ini::
Hasilnya menjadi seperti ini::
...
...
contrib/web-
client.py
→
iso8583_web/scripts/web_
client.py
View file @
47bf07d
...
@@ -16,6 +16,20 @@ end_threads = []
...
@@ -16,6 +16,20 @@ end_threads = []
durations
=
{}
durations
=
{}
json_responses
=
{}
json_responses
=
{}
default_url
=
'http://localhost:7000/rpc'
default_host
=
'pemda'
default_count
=
1
help_url
=
'default '
+
default_url
help_host
=
'default '
+
default_host
help_count
=
'default {}'
.
format
(
default_count
)
help_invoice_id
=
'wajib saat --payment dan --reversal'
help_amount
=
'wajib saat --payment dan --reversal'
help_ntb
=
'opsional saat --payment, wajib saat --reversal'
help_stan
=
'opsional saat --payment, wajib saat --reversal'
help_bit
=
'bit tambahan, contoh: --bit=42:TOKOPEDIA'
help_conf
=
'konfigurasi tambahan, contoh untuk multi: --conf=pajak:bphtb'
def
error
(
s
):
def
error
(
s
):
print
(
'ERROR: {}'
.
format
(
s
))
print
(
'ERROR: {}'
.
format
(
s
))
...
@@ -29,27 +43,6 @@ def required(name, default=None):
...
@@ -29,27 +43,6 @@ def required(name, default=None):
p
[
name
]
=
value
or
default
p
[
name
]
=
value
or
default
def
create_thread
(
func
,
args
=
[]):
thread
=
Thread
(
target
=
func
,
args
=
args
)
# Exit the server thread when the main thread terminates
thread
.
daemon
=
True
return
thread
def
send
(
p
):
key
=
p
[
'id'
]
log_info
(
'Request: {}'
.
format
(
p
))
start
=
time
()
try
:
resp
=
requests
.
post
(
url
,
data
=
json
.
dumps
(
p
),
headers
=
headers
)
durations
[
key
]
=
time
()
-
start
json_resp
=
resp
.
json
()
log_info
(
'Response: {}'
.
format
(
json_resp
))
json_responses
[
key
]
=
json_resp
finally
:
end_threads
.
append
(
key
)
def
log_info
(
s
):
def
log_info
(
s
):
t
=
datetime
.
now
()
.
strftime
(
'
%
Y-
%
m-
%
d
%
H:
%
M:
%
S.
%
f'
)
t
=
datetime
.
now
()
.
strftime
(
'
%
Y-
%
m-
%
d
%
H:
%
M:
%
S.
%
f'
)
t
=
t
[:
-
3
]
t
=
t
[:
-
3
]
...
@@ -57,93 +50,116 @@ def log_info(s):
...
@@ -57,93 +50,116 @@ def log_info(s):
print
(
msg
)
print
(
msg
)
default_url
=
'http://localhost:7000/rpc'
def
get_option
(
argv
):
default_host
=
'pemda'
parser
=
ArgumentParser
()
default_count
=
1
parser
.
add_argument
(
'--url'
,
default
=
default_url
,
help
=
help_url
)
default_method
=
'echo'
parser
.
add_argument
(
'--host'
,
default
=
default_host
,
help
=
help_host
)
parser
.
add_argument
(
help_url
=
'default '
+
default_url
'--count'
,
type
=
int
,
default
=
default_count
,
help
=
help_count
)
help_host
=
'default '
+
default_host
parser
.
add_argument
(
'--invoice-id'
,
help
=
help_invoice_id
)
help_count
=
'default {}'
.
format
(
default_count
)
parser
.
add_argument
(
'--payment'
,
action
=
'store_true'
)
help_method
=
'default '
+
default_method
parser
.
add_argument
(
'--reversal'
,
action
=
'store_true'
)
help_invoice_id
=
'dibutuhkan saat --method inquiry, payment, atau reversal'
parser
.
add_argument
(
'--amount'
,
type
=
int
,
help
=
help_amount
)
help_amount
=
'dibutuhkan saat --method payment dan reversal'
parser
.
add_argument
(
'--ntb'
,
help
=
help_ntb
)
help_ntb
=
'dibutuhkan saat --method payment dan reversal'
parser
.
add_argument
(
'--stan'
,
help
=
help_stan
)
help_stan
=
'dibutuhkan saat --method payment dan reversal'
parser
.
add_argument
(
'--bit'
,
help
=
help_bit
)
help_bit
=
'bit tambahan, contoh: --bit=42:TOKOPEDIA'
parser
.
add_argument
(
'--conf'
,
help
=
help_conf
)
help_conf
=
'konfigurasi tambahan, contoh untuk multi: --conf=pajak:bphtb'
return
parser
.
parse_args
(
argv
)
parser
=
ArgumentParser
()
parser
.
add_argument
(
'--url'
,
default
=
default_url
,
help
=
help_url
)
class
App
:
parser
.
add_argument
(
'--host'
,
default
=
default_host
,
help
=
help_host
)
def
__init__
(
self
,
argv
):
parser
.
add_argument
(
self
.
option
=
get_option
(
argv
)
'--count'
,
type
=
int
,
default
=
default_count
,
help
=
help_count
)
parser
.
add_argument
(
'--method'
,
default
=
default_method
,
help
=
help_method
)
def
set_transaction
(
self
,
p
):
parser
.
add_argument
(
'--invoice-id'
,
help
=
help_invoice_id
)
p
[
'invoice_id'
]
=
self
.
option
.
invoice_id
parser
.
add_argument
(
'--amount'
,
type
=
int
,
help
=
help_amount
)
if
self
.
option
.
payment
or
self
.
option
.
reversal
:
parser
.
add_argument
(
'--ntb'
,
help
=
help_ntb
)
required
(
'amount'
)
parser
.
add_argument
(
'--stan'
,
help
=
help_stan
)
if
self
.
option
.
method
==
'payment'
:
parser
.
add_argument
(
'--bit'
,
help
=
help_bit
)
required
(
'ntb'
,
datetime
.
now
()
.
strftime
(
'
%
m
%
d
%
H
%
m
%
s'
))
parser
.
add_argument
(
'--conf'
,
help
=
help_conf
)
required
(
'stan'
,
datetime
.
now
()
.
strftime
(
'
%
H
%
M
%
S'
))
option
=
parser
.
parse_args
(
sys
.
argv
[
1
:])
else
:
required
(
'ntb'
)
url
=
option
.
url
required
(
'stan'
)
count
=
option
.
count
if
self
.
option
.
bit
:
p
=
dict
(
host
=
option
.
host
)
bits
=
dict
()
if
option
.
method
!=
'echo'
:
for
t
in
self
.
option
.
bit
.
split
(
','
):
p
[
'invoice_id'
]
=
option
.
invoice_id
bit
,
value
=
t
.
split
(
':'
)
if
option
.
method
in
(
'payment'
,
'reversal'
):
bits
[
bit
]
=
value
required
(
'amount'
)
p
[
'bits'
]
=
bits
if
option
.
method
==
'payment'
:
if
self
.
option
.
conf
:
required
(
'ntb'
,
datetime
.
now
()
.
strftime
(
'
%
y
%
m
%
d
%
H
%
m
%
s'
))
conf
=
dict
()
required
(
'stan'
,
datetime
.
now
()
.
strftime
(
'
%
H
%
M
%
S'
))
for
t
in
self
.
option
.
conf
.
split
(
','
):
key
,
val
=
t
.
split
(
':'
)
conf
[
key
]
=
val
p
[
'conf'
]
=
conf
def
send
(
self
,
p
):
key
=
p
[
'id'
]
log_info
(
'Request: {}'
.
format
(
p
))
start
=
time
()
try
:
resp
=
requests
.
post
(
self
.
option
.
url
,
data
=
json
.
dumps
(
p
),
headers
=
headers
)
durations
[
key
]
=
time
()
-
start
json_resp
=
resp
.
json
()
log_info
(
'Response: {}'
.
format
(
json_resp
))
json_responses
[
key
]
=
json_resp
finally
:
end_threads
.
append
(
key
)
def
create_thread
(
self
,
args
=
[]):
thread
=
Thread
(
target
=
self
.
send
,
args
=
args
)
# Exit the server thread when the main thread terminates
thread
.
daemon
=
True
return
thread
def
run
(
self
):
p
=
dict
(
host
=
self
.
option
.
host
)
if
self
.
option
.
invoice_id
:
self
.
set_transaction
(
p
)
if
self
.
option
.
payment
:
method
=
'payment'
elif
self
.
option
.
reversal
:
method
=
'reversal'
else
:
method
=
'inquiry'
else
:
else
:
required
(
'ntb'
)
method
=
'echo'
required
(
'stan'
)
data
=
dict
(
method
=
method
,
params
=
[
p
],
jsonrpc
=
'2.0'
)
if
option
.
bit
:
for
i
in
range
(
self
.
option
.
count
):
bits
=
dict
()
data
[
'id'
]
=
i
for
t
in
option
.
bit
.
split
(
','
):
thread
=
self
.
create_thread
([
dict
(
data
)])
bit
,
value
=
t
.
split
(
':'
)
threads
[
i
]
=
thread
bits
[
bit
]
=
value
for
key
in
threads
:
p
[
'bits'
]
=
bits
thread
=
threads
[
key
]
if
option
.
conf
:
thread
.
start
()
conf
=
dict
()
sleep
(
0.2
)
for
t
in
option
.
conf
.
split
(
','
):
while
threads
:
key
,
val
=
t
.
split
(
':'
)
sleep
(
1
)
conf
[
key
]
=
val
if
not
end_threads
:
p
[
'conf'
]
=
conf
continue
data
=
dict
(
method
=
option
.
method
,
params
=
[
p
],
jsonrpc
=
'2.0'
)
i
=
end_threads
[
0
]
if
i
in
threads
:
for
i
in
range
(
count
):
thread
=
threads
[
i
]
data
[
'id'
]
=
i
thread
.
join
()
thread
=
create_thread
(
send
,
[
dict
(
data
)])
del
threads
[
i
]
threads
[
i
]
=
thread
index
=
end_threads
.
index
(
i
)
del
end_threads
[
index
]
for
key
in
threads
:
for
key
in
durations
:
thread
=
threads
[
key
]
val
=
durations
[
key
]
thread
.
start
()
resp
=
json_responses
[
key
]
sleep
(
0.2
)
if
'error'
in
resp
:
break
while
threads
:
result
=
resp
[
'result'
]
sleep
(
1
)
if
result
[
'code'
]
==
0
:
if
not
end_threads
:
stan
=
result
[
'data'
][
'11'
]
continue
else
:
i
=
end_threads
[
0
]
stan
=
'-'
if
i
in
threads
:
msg
=
'thread {} stan {} {} detik'
.
format
(
key
,
stan
,
val
)
thread
=
threads
[
i
]
log_info
(
msg
)
thread
.
join
()
del
threads
[
i
]
index
=
end_threads
.
index
(
i
)
def
main
(
argv
=
sys
.
argv
[
1
:]):
del
end_threads
[
index
]
app
=
App
(
argv
)
app
.
run
()
for
key
in
durations
:
val
=
durations
[
key
]
resp
=
json_responses
[
key
]
if
'error'
in
resp
:
break
result
=
resp
[
'result'
]
if
result
[
'code'
]
==
0
:
stan
=
result
[
'data'
][
'11'
]
else
:
stan
=
'-'
print
(
'thread {} stan {} {} detik'
.
format
(
key
,
stan
,
val
))
setup.py
View file @
47bf07d
...
@@ -47,7 +47,7 @@ tests_require = [
...
@@ -47,7 +47,7 @@ tests_require = [
setup
(
setup
(
name
=
'iso8583_web'
,
name
=
'iso8583_web'
,
version
=
version
,
version
=
version
,
description
=
'
Web untuk menampilkan log ISO8583
'
,
description
=
'
Daemon ISO8583 yang memiliki web service
'
,
long_description
=
README
+
'
\n\n
'
+
CHANGES
,
long_description
=
README
+
'
\n\n
'
+
CHANGES
,
classifiers
=
[
classifiers
=
[
'Programming Language :: Python'
,
'Programming Language :: Python'
,
...
@@ -71,8 +71,9 @@ setup(
...
@@ -71,8 +71,9 @@ setup(
'main = iso8583_web:main'
,
'main = iso8583_web:main'
,
],
],
'console_scripts'
:
[
'console_scripts'
:
[
'initialize_iso8583_web_db = iso8583_web.scripts.initialize_db:main'
,
'iso8583 = iso8583_web.scripts.forwarder:main'
,
'iso8583 = iso8583_web.scripts.forwarder:main'
,
'iso8583_web_client = iso8583_web.scripts.web_client:main'
,
'initialize_iso8583_web_db = iso8583_web.scripts.initialize_db:main'
,
]
]
},
},
)
)
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment