Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
aa.gusti
/
opensipkd-tools
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 5991130f
authored
Dec 13, 2025
by
aa.gustiana@gmail.com
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
fix: improve parameter handling and logging in various functions
1 parent
ce60ddfa
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
18 deletions
opensipkd/tools/__init__.py
opensipkd/tools/api.py
opensipkd/tools/pbb.py
opensipkd/tools/__init__.py
View file @
5991130
...
...
@@ -139,7 +139,8 @@ def get_params(params, alternate=None):
get_params('devel', False)
"""
settings
=
get_settings
()
result
=
settings
.
get
(
params
,
alternate
)
.
strip
()
or
None
result
=
settings
.
get
(
params
,
alternate
)
or
None
result
=
result
and
result
.
strip
()
or
None
return
result
and
result
or
alternate
...
...
@@ -808,7 +809,7 @@ def pbb_biller_split():
if
not
'pbb_biller'
in
settings
:
return
None
,
None
biller
=
re
.
sub
(
'
\
D'
,
''
,
settings
[
'pbb_biller'
])
biller
=
re
.
sub
(
r
'\D'
,
''
,
settings
[
'pbb_biller'
])
return
biller
[:
2
],
biller
[
2
:]
...
...
@@ -1019,7 +1020,7 @@ def terbilang(n):
def
number_only
(
value
):
return
re
.
sub
(
'
\
D'
,
""
,
value
)
return
re
.
sub
(
r
'\D'
,
""
,
value
)
def
set_user_log
(
message
,
request
,
logobj
=
None
,
user_name
=
None
):
...
...
opensipkd/tools/api.py
View file @
5991130
...
...
@@ -5,6 +5,8 @@ import json
import
sys
from
datetime
import
datetime
,
date
from
requests
import
HTTPError
import
requests
from
pyramid.i18n
import
TranslationStringFactory
from
pyramid_rpc.jsonrpc
import
JsonRpcError
...
...
@@ -268,7 +270,7 @@ def get_seconds(current_time=None):
if
not
current_time
:
current_time
=
datetime
.
utcnow
()
durasi
=
current_time
-
begin_unix_time
log
.
info
(
f
"{current_time} - {begin_unix_time}"
)
log
.
debug
(
"
%
s -
%
s
%
s"
,
current_time
,
begin_unix_time
,
durasi
)
return
int
(
durasi
.
total_seconds
())
...
...
@@ -294,6 +296,7 @@ def json_rpc_header(userid, password, key=None):
password
=
str
(
password
)
signature
=
hmac
.
new
(
key
=
str
.
encode
(
password
),
msg
=
str
.
encode
(
value
),
digestmod
=
hashlib
.
sha256
)
.
digest
()
log
.
debug
(
"signature:
%
s"
,
signature
)
if
sys
.
version
<
'3'
:
encoded_signature
=
base64
.
encodestring
(
signature
)
.
replace
(
'
\n
'
,
''
)
...
...
@@ -319,7 +322,7 @@ def validate_time(request):
lima_menit
=
int
(
settings
[
"diff_server_time"
])
if
not
log
.
parent
.
level
==
logging
.
DEBUG
and
abs
(
now
-
time_stamp
)
>
lima_menit
:
log
.
info
(
f
"req time {time_stamp} server time {now}"
)
log
.
error
(
"req time
%
s server time
%
s diff
%
s"
,
time_stamp
,
now
,
abs
(
now
-
time_stamp
)
)
raise
JsonRpcInvalidTimeError
return
time_stamp
...
...
@@ -351,21 +354,21 @@ def send_rpc(auth, message):
params
=
dict
(
data
=
message
)
data
=
get_jsonrpc
(
auth
[
"method"
],
params
)
timeout
=
'timeout'
in
auth
and
int
(
auth
[
'timeout'
])
or
5
log
.
info
(
"URL:{} timeout:{} detik"
.
format
(
url
,
timeout
)
)
log
.
warning
(
"REQUEST
{}"
.
format
(
data
)
)
log
.
debug
(
"URL:
%
s timeout:
%
s detik"
,
url
,
timeout
)
log
.
warning
(
"REQUEST
%
s"
,
data
)
try
:
res
ults
=
requests
.
post
(
url
,
json
=
data
,
headers
=
headers
,
res
p
=
requests
.
post
(
url
,
json
=
data
,
headers
=
headers
,
timeout
=
timeout
)
# data=jsondata,
except
Exception
as
e
:
except
HTTPError
as
e
:
log
.
warning
(
str
(
e
))
return
if
results
.
status_code
!=
200
:
log
.
info
(
results
)
log
.
info
(
results
.
text
)
return
r
ows
=
results
.
text
and
json
.
loads
(
results
.
text
)
or
None
log
.
warning
(
"RESPONSE
{}"
.
format
(
rows
)
)
return
r
ows
return
{}
if
resp
.
status_code
!=
200
:
log
.
debug
(
resp
)
return
{}
r
esult
=
resp
.
text
and
json
.
loads
(
resp
.
text
)
or
None
log
.
warning
(
"RESPONSE
%
s"
,
result
)
return
r
esult
##############################
...
...
opensipkd/tools/pbb.py
View file @
5991130
...
...
@@ -250,7 +250,7 @@ def hitung_bulan(jatuh_tempo, tanggal=None, max_denda=24):
jatuh_tempo
):
# + timedelta(days=1):
return
0
kini
=
datetime
.
now
()
kini
=
tanggal
x
=
(
kini
.
year
-
jatuh_tempo
.
year
)
*
12
y
=
kini
.
month
-
jatuh_tempo
.
month
bln_tunggakan
=
x
+
y
+
1
...
...
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