Fakultas Ilmu Komputer UI
Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Ahmad Dzikrul Fikri
1806196806-DDP1
Commits
d4ca6691
Commit
d4ca6691
authored
Mar 02, 2020
by
Ahmad Dzikrul Fikri
Browse files
Tugas Pemrograman 5 - Tahap 1 - 1806196806
parent
be108003
Changes
3
Hide whitespace changes
Inline
Side-by-side
TP5_
1_
1806196806.py
→
TP5_1806196806.py
View file @
d4ca6691
File moved
TP5_2_1806196806.py
deleted
100644 → 0
View file @
be108003
import
urllib.request
def
ambil_info_stok
():
page
=
urllib
.
request
.
urlopen
(
"https://ceritanyatuwiter.herokuapp.com/1806196806"
)
text
=
page
.
read
().
decode
(
"utf8"
)
awal
=
text
.
find
(
'Terkini: '
)
akhir
=
text
.
find
(
'</'
,
awal
)
return
text
[
awal
+
len
(
'Terkini: '
):
akhir
]
def
laporkan_stok
(
stok_sekarang
):
param
=
urllib
.
parse
.
urlencode
({
"pesan"
:
stok_sekarang
})
resp
=
urllib
.
request
.
urlopen
(
"https://ceritanyatuwiter.herokuapp.com/1806196806/lapor"
,
param
.
encode
())
def
request_stok
():
laporkan_stok
(
"@burhan request restock untuk saya"
)
stok
=
int
(
ambil_info_stok
())
disalurkan
=
1
while
stok
>
0
and
disalurkan
>
0
:
disalurkan
=
int
(
input
(
"Berapa jumlah tabung gas yang ingin disalurkan:"
))
if
disalurkan
>
0
:
if
disalurkan
>
stok
:
print
(
"Stok tidak cukup"
)
else
:
print
(
"Penyaluran"
,
disalurkan
,
"tabung berhasil, sekarang tersisa"
,
stok
-
disalurkan
)
laporkan_stok
(
"Stok Terkini: "
+
str
(
stok
-
disalurkan
))
if
stok
-
disalurkan
==
0
:
print
(
"
\n
Sedang meminta kak burhan restock tabung gas
\n
"
)
request_stok
()
stok
=
int
(
ambil_info_stok
())
\ No newline at end of file
TP5_3_1806196806.py
deleted
100644 → 0
View file @
be108003
import
urllib.request
def
ambil_info_stok
(
NPM
):
page
=
urllib
.
request
.
urlopen
(
"https://ceritanyatuwiter.herokuapp.com/"
+
NPM
)
text
=
page
.
read
().
decode
(
"utf8"
)
awal
=
text
.
find
(
'Terkini: '
)
akhir
=
text
.
find
(
'</'
,
awal
)
return
text
[
awal
+
len
(
'Terkini: '
):
akhir
]
def
laporkan_stok
(
stok_sekarang
):
param
=
urllib
.
parse
.
urlencode
({
"pesan"
:
stok_sekarang
})
resp
=
urllib
.
request
.
urlopen
(
"https://ceritanyatuwiter.herokuapp.com/1806196806/lapor"
,
param
.
encode
())
def
request_stok
():
laporkan_stok
(
"@burhan request restock untuk saya"
)
perintah
=
""
while
perintah
!=
'keluar'
:
perintah
=
input
(
"Masukkan perintah (salurkan, cek agen, keluar):"
).
lower
()
if
perintah
==
'salurkan'
:
stok
=
int
(
ambil_info_stok
(
'1806196806'
))
disalurkan
=
1
while
stok
>
0
and
disalurkan
>
0
:
disalurkan
=
int
(
input
(
"Berapa jumlah tabung gas yang ingin disalurkan:"
))
if
disalurkan
>
0
:
if
disalurkan
>
stok
:
print
(
"Stok tidak cukup"
)
else
:
print
(
"Penyaluran"
,
disalurkan
,
"tabung berhasil, sekarang tersisa"
,
stok
-
disalurkan
)
laporkan_stok
(
"Stok Terkini: "
+
str
(
stok
-
disalurkan
))
if
stok
-
disalurkan
==
0
:
print
(
"
\n
Sedang meminta kak burhan restock tabung gas
\n
"
)
request_stok
()
stok
=
int
(
ambil_info_stok
(
'1806196806'
))
elif
perintah
.
startswith
(
'cek'
)
==
True
:
npm
=
input
(
"Masukkan NPM agen:"
)
print
(
"stok agen"
,
npm
,
"sejumlah"
,
ambil_info_stok
(
npm
),
"tabung"
)
elif
perintah
==
'keluar'
:
print
(
"Selesai!"
)
else
:
print
(
"Perintah tidak valid"
)
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
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 comment