From d8150829e719bf4adf998bd5df818dbef8856229 Mon Sep 17 00:00:00 2001 From: kaisarabdans Date: Mon, 15 Mar 2021 22:16:08 +0700 Subject: [PATCH 001/164] TugasKaisar1184093 --- Chapter02/Kaisar1184093.py | 72 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 Chapter02/Kaisar1184093.py diff --git a/Chapter02/Kaisar1184093.py b/Chapter02/Kaisar1184093.py new file mode 100644 index 0000000..0ab1c87 --- /dev/null +++ b/Chapter02/Kaisar1184093.py @@ -0,0 +1,72 @@ +import time +import os +from random import randint +from threading import Thread,currentThread + + +class Kaisar1184093 (Thread): + def __init__(self, name,thread_number, duration): + Thread.__init__(self) + self.name = name + self.duration = duration + self.thread_number = thread_number + def run(self): + print ("\n"+str(self.thread_number)+". ---> " + self.name + " running, belonging to process ID "+ str(os.getpid()) + "\n") + x=randint(1,9) + y=randint(1,9) + self.pangkat(x, y, 1500000) + print (str(self.thread_number)+". ---> " + self.name + " over, sleep duration : " +str(self.duration) +" second") + print (", Realname of Thread : " + currentThread().getName()) + + def pangkat(self, x, y, z): + while z>0: + x=x*y/2 + z=z-1 + +def main(): + start_time = time.time() + + # Thread Creation + thread1 = Kaisar1184093("Thread#1 ", 1,15) + thread2 = Kaisar1184093("Thread#2 ", 2,15) + thread3 = Kaisar1184093("Thread#3 ", 3,15) + thread4 = Kaisar1184093("Thread#4 ", 4,15) + thread5 = Kaisar1184093("Thread#5 ", 5,15) + thread6 = Kaisar1184093("Thread#6 ", 6,15) + thread7 = Kaisar1184093("Thread#7 ", 7,15) + thread8 = Kaisar1184093("Thread#8 ", 8,15) + thread9 = Kaisar1184093("Thread#9 ", 9,15) + + # Thread Running + thread1.start() + thread2.start() + thread3.start() + thread4.start() + thread5.start() + thread6.start() + thread7.start() + thread8.start() + thread9.start() + + # Thread joining + thread1.join() + thread2.join() + thread3.join() + thread4.join() + thread5.join() + thread6.join() + thread7.join() + thread8.join() + thread9.join() + + # End + print("End") + + #Execution Time + print("--- %s seconds ---" % (time.time() - start_time)) + return True + + + + + From c4c7ded1dd34320e23e3e09e3ede8b16300b01f6 Mon Sep 17 00:00:00 2001 From: kaisarabdans <57064199+kaisarabdans@users.noreply.github.com> Date: Mon, 15 Mar 2021 22:22:02 +0700 Subject: [PATCH 002/164] Update test_app.py --- test_app.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test_app.py b/test_app.py index 4720042..957cc26 100644 --- a/test_app.py +++ b/test_app.py @@ -25,8 +25,8 @@ def tearDown(self): # response = multiprocessing_test.multiprocessing_test() # self.assertEqual(response, True) - def test_02_rolly_113040087(self): - from Chapter02.Rolly113040087 import main + def test_02_kaisar_1184093(self): + from Chapter02.Kaisar1184093 import main response = main() self.assertEqual(response, True) From 3db70e1f6e6d60a9621652918480de6a35db7785 Mon Sep 17 00:00:00 2001 From: kaisarabdans <57064199+kaisarabdans@users.noreply.github.com> Date: Mon, 15 Mar 2021 22:46:11 +0700 Subject: [PATCH 003/164] Update Kaisar1184093.py --- Chapter02/Kaisar1184093.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Chapter02/Kaisar1184093.py b/Chapter02/Kaisar1184093.py index 0ab1c87..f84b9a1 100644 --- a/Chapter02/Kaisar1184093.py +++ b/Chapter02/Kaisar1184093.py @@ -14,7 +14,7 @@ def run(self): print ("\n"+str(self.thread_number)+". ---> " + self.name + " running, belonging to process ID "+ str(os.getpid()) + "\n") x=randint(1,9) y=randint(1,9) - self.pangkat(x, y, 1500000) + self.pangkat(x, y, 5000000) print (str(self.thread_number)+". ---> " + self.name + " over, sleep duration : " +str(self.duration) +" second") print (", Realname of Thread : " + currentThread().getName()) From 309af8deec20c528f6067bf691c486832ef1e1e0 Mon Sep 17 00:00:00 2001 From: rizaluardi Date: Tue, 16 Mar 2021 12:05:50 +0700 Subject: [PATCH 004/164] Perbaikan Konflik Rizaluardi1184102 --- Chapter02/Rizaluardi1184102.py | 72 ++++++++++++++++++++++++++++++++++ test_app.py | 13 ++++-- 2 files changed, 82 insertions(+), 3 deletions(-) create mode 100644 Chapter02/Rizaluardi1184102.py diff --git a/Chapter02/Rizaluardi1184102.py b/Chapter02/Rizaluardi1184102.py new file mode 100644 index 0000000..87d5635 --- /dev/null +++ b/Chapter02/Rizaluardi1184102.py @@ -0,0 +1,72 @@ +import time +import os +from random import randint +from threading import Thread,currentThread + + +class Rizaluardi1184102 (Thread): + def __init__(self, name,thread_number, duration): + Thread.__init__(self) + self.name = name + self.duration = duration + self.thread_number = thread_number + def run(self): + print ("\n"+str(self.thread_number)+". ---> " + self.name + " running, belonging to process ID "+ str(os.getpid()) + "\n") + num=randint(3,12) + nom=randint(3,12) + self.rank(num, nom, 6600000) + print (str(self.thread_number)+". ---> " + self.name + " over, sleep duration : " +str(self.duration) +" second") + print (", Realname of Thread : " + currentThread().getName()) + + def rank(self, num, nom, hasil): + while hasil>0: + num=num*nom/3 + hasil=hasil-1 + +def main(): + start_time = time.time() + + # Thread Creation + thread1 = Rizaluardi1184102("Thread#1 ", 1,12) + thread2 = Rizaluardi1184102("Thread#2 ", 2,12) + thread3 = Rizaluardi1184102("Thread#3 ", 3,12) + thread4 = Rizaluardi1184102("Thread#4 ", 4,12) + thread5 = Rizaluardi1184102("Thread#5 ", 5,12) + thread6 = Rizaluardi1184102("Thread#6 ", 6,12) + thread7 = Rizaluardi1184102("Thread#7 ", 7,12) + thread8 = Rizaluardi1184102("Thread#8 ", 8,12) + thread9 = Rizaluardi1184102("Thread#9 ", 9,12) + + # Thread Running + thread1.start() + thread2.start() + thread3.start() + thread4.start() + thread5.start() + thread6.start() + thread7.start() + thread8.start() + thread9.start() + + # Thread joining + thread1.join() + thread2.join() + thread3.join() + thread4.join() + thread5.join() + thread6.join() + thread7.join() + thread8.join() + thread9.join() + + # End + print("End") + + #Execution Time + print("--- %s seconds ---" % (time.time() - start_time)) + return True + + + + + diff --git a/test_app.py b/test_app.py index 957cc26..5460f46 100644 --- a/test_app.py +++ b/test_app.py @@ -25,8 +25,15 @@ def tearDown(self): # response = multiprocessing_test.multiprocessing_test() # self.assertEqual(response, True) - def test_02_kaisar_1184093(self): - from Chapter02.Kaisar1184093 import main - response = main() + # def test_02_kaisar_1184093(self): + # from Chapter02.Kaisar1184093 import main + # response = main() + # self.assertEqual(response, True) + + def test_02_rizaluardi_1184102(self): + from Chapter02.Rizaluardi1184102 import main + response = main() self.assertEqual(response, True) + + From 9bf709dc96d4f7d45d95b6c3955f95b9ef7bd9f3 Mon Sep 17 00:00:00 2001 From: rizaluardi Date: Tue, 16 Mar 2021 12:11:17 +0700 Subject: [PATCH 005/164] Perbaikan Konflik Rizaluardi1184102 --- test_app.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test_app.py b/test_app.py index 5460f46..bd16b48 100644 --- a/test_app.py +++ b/test_app.py @@ -29,9 +29,8 @@ def tearDown(self): # from Chapter02.Kaisar1184093 import main # response = main() # self.assertEqual(response, True) - - def test_02_rizaluardi_1184102(self): - from Chapter02.Rizaluardi1184102 import main + def test_02_rizaluardi_1184102(self): + from Chapter02.Rizaluardi1184102 import main response = main() self.assertEqual(response, True) From 10beb341e1b51da88098f6985a58a2924541d48f Mon Sep 17 00:00:00 2001 From: zanwar Date: Tue, 16 Mar 2021 12:26:46 +0700 Subject: [PATCH 006/164] Update Konflik --- Chapter02/Zanwar1184050.py | 67 ++++++++++++++++++++++++++++++++++++++ test_app.py | 6 ++++ 2 files changed, 73 insertions(+) create mode 100644 Chapter02/Zanwar1184050.py diff --git a/Chapter02/Zanwar1184050.py b/Chapter02/Zanwar1184050.py new file mode 100644 index 0000000..420c0f9 --- /dev/null +++ b/Chapter02/Zanwar1184050.py @@ -0,0 +1,67 @@ +import time +import os +from random import randint +from threading import Thread,currentThread + + +class Zanwar1184050 (Thread): + def __init__(self, name,thread_number): + Thread.__init__(self) + self.name = name + self.thread_number = thread_number + def run(self): + print ("\n"+str(self.thread_number)+". ---> " + self.name + " running, belonging to process ID "+ str(os.getpid()) + "\n") + self.urut_angka("", randint(1,99), randint(1,99), 500000) + print (str(self.thread_number)+". ---> " + self.name + " over.") + print (", Realname of Thread : " + currentThread().getName()) + + def urut_angka(self, string, x, y, i): + string = "" + while i>0: + z = (x**2 + y**2) + z = z ** 0.5 + string = string+str(z) + i = i-1 + +def main(): + start_time = time.time() + + # Thread Creation + thread1 = Zanwar1184050("Thread#1 ", 1) + thread2 = Zanwar1184050("Thread#2 ", 2) + thread3 = Zanwar1184050("Thread#3 ", 3) + thread4 = Zanwar1184050("Thread#4 ", 4) + thread5 = Zanwar1184050("Thread#5 ", 5) + thread6 = Zanwar1184050("Thread#6 ", 6) + thread7 = Zanwar1184050("Thread#7 ", 7) + thread8 = Zanwar1184050("Thread#8 ", 8) + thread9 = Zanwar1184050("Thread#9 ", 9) + + # Thread Running + thread1.start() + thread2.start() + thread3.start() + thread4.start() + thread5.start() + thread6.start() + thread7.start() + thread8.start() + thread9.start() + + # Thread joining + thread1.join() + thread2.join() + thread3.join() + thread4.join() + thread5.join() + thread6.join() + thread7.join() + thread8.join() + thread9.join() + + # End + print("End") + + #Execution Time + print("--- %s seconds ---" % (time.time() - start_time)) + return True \ No newline at end of file diff --git a/test_app.py b/test_app.py index bd16b48..936bbf3 100644 --- a/test_app.py +++ b/test_app.py @@ -29,10 +29,16 @@ def tearDown(self): # from Chapter02.Kaisar1184093 import main # response = main() # self.assertEqual(response, True) + def test_02_rizaluardi_1184102(self): from Chapter02.Rizaluardi1184102 import main response = main() self.assertEqual(response, True) + + def test_02_zanwar_1184050(self): + from Chapter02.Zanwar1184050 import main + response = main() + self.assertEqual(response, True) From 085fe09312a9b0e352433903ae020237738074d9 Mon Sep 17 00:00:00 2001 From: zanwar Date: Tue, 16 Mar 2021 12:35:03 +0700 Subject: [PATCH 007/164] Update Konflik --- test_app.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test_app.py b/test_app.py index 936bbf3..b0393ba 100644 --- a/test_app.py +++ b/test_app.py @@ -34,8 +34,8 @@ def test_02_rizaluardi_1184102(self): from Chapter02.Rizaluardi1184102 import main response = main() self.assertEqual(response, True) - - def test_02_zanwar_1184050(self): + + def test_02_zanwar_1184050(self): from Chapter02.Zanwar1184050 import main response = main() self.assertEqual(response, True) From 59f2cf40a7d67ce18cae85150da0801390677e5e Mon Sep 17 00:00:00 2001 From: FerdyBerlianoP Date: Tue, 16 Mar 2021 12:53:59 +0700 Subject: [PATCH 008/164] Merge ulang --- Chapter02/Ferdy1184112.py | 73 +++++++++++++++++++++++++++++++++++++++ test_app.py | 20 ++++++----- 2 files changed, 85 insertions(+), 8 deletions(-) create mode 100644 Chapter02/Ferdy1184112.py diff --git a/Chapter02/Ferdy1184112.py b/Chapter02/Ferdy1184112.py new file mode 100644 index 0000000..2cb23bc --- /dev/null +++ b/Chapter02/Ferdy1184112.py @@ -0,0 +1,73 @@ +import time +import os +from random import randint +from threading import Thread,currentThread + + +class Ferdy1184112 (Thread): + def __init__(self, name,thread_number, duration): + Thread.__init__(self) + self.name = name + self.duration = duration + self.thread_number = thread_number + def run(self): + print ("\n"+str(self.thread_number)+". ---> " + self.name + " running, belonging to process ID "+ str(os.getpid()) + "\n") + time.sleep(self.duration) + out_list = list() + self.do_something(randint(1,14), 1000000) + print (str(self.thread_number)+". ---> " + self.name + " over, sleep duration : " +str(self.duration) +" second") + print (", Realname of Thread : " + currentThread().getName()) + + def do_something(self, x, y): + while y > 0: + for x in range(15): + h = 2**x + y = y-1 + +def main(): + start_time = time.time() + + # Thread Creation + thread1 = Ferdy1184112("Thread#1 ", 1,randint(1,10)) + thread2 = Ferdy1184112("Thread#2 ", 2,randint(1,10)) + thread3 = Ferdy1184112("Thread#3 ", 3,randint(1,10)) + thread4 = Ferdy1184112("Thread#4 ", 4,randint(1,10)) + thread5 = Ferdy1184112("Thread#5 ", 5,randint(1,10)) + thread6 = Ferdy1184112("Thread#6 ", 6,randint(1,10)) + thread7 = Ferdy1184112("Thread#7 ", 7,randint(1,10)) + thread8 = Ferdy1184112("Thread#8 ", 8,randint(1,10)) + thread9 = Ferdy1184112("Thread#9 ", 9,randint(1,10)) + + # Thread Running + thread1.start() + thread2.start() + thread3.start() + thread4.start() + thread5.start() + thread6.start() + thread7.start() + thread8.start() + thread9.start() + + # Thread joining + thread1.join() + thread2.join() + thread3.join() + thread4.join() + thread5.join() + thread6.join() + thread7.join() + thread8.join() + thread9.join() + + # End + print("End") + + #Execution Time + print("--- %s seconds ---" % (time.time() - start_time)) + return True + + + + + diff --git a/test_app.py b/test_app.py index b0393ba..9bb45f2 100644 --- a/test_app.py +++ b/test_app.py @@ -30,15 +30,19 @@ def tearDown(self): # response = main() # self.assertEqual(response, True) - def test_02_rizaluardi_1184102(self): - from Chapter02.Rizaluardi1184102 import main - response = main() - self.assertEqual(response, True) + # def test_02_rizaluardi_1184102(self): + # from Chapter02.Rizaluardi1184102 import main + # response = main() + # self.assertEqual(response, True) - def test_02_zanwar_1184050(self): - from Chapter02.Zanwar1184050 import main - response = main() - self.assertEqual(response, True) + # def test_02_zanwar_1184050(self): + # from Chapter02.Zanwar1184050 import main + # response = main() + # self.assertEqual(response, True) + def test_02_ferdy_1184112(self): + from Chapter02.Ferdy1184112 import main + response = main() + self.assertEqual(response, True) From de7c88899eccfc9ad3a8f95efc83fac513172297 Mon Sep 17 00:00:00 2001 From: 69AllDayFun Date: Tue, 16 Mar 2021 13:19:25 +0700 Subject: [PATCH 009/164] Tugas Irfan Hernandez 1184014 --- Chapter02/IrfanHernandez1184014.py | 76 ++++++++++++++++++++++++++++++ test_app.py | 19 +++++--- 2 files changed, 88 insertions(+), 7 deletions(-) create mode 100644 Chapter02/IrfanHernandez1184014.py diff --git a/Chapter02/IrfanHernandez1184014.py b/Chapter02/IrfanHernandez1184014.py new file mode 100644 index 0000000..7326e1f --- /dev/null +++ b/Chapter02/IrfanHernandez1184014.py @@ -0,0 +1,76 @@ +import time +import os +from random import randint +from threading import Thread,currentThread + + +class IrfanHernandez1184014 (Thread): + def __init__(self, name,thread_number, duration): + Thread.__init__(self) + self.name = name + self.duration = duration + self.thread_number = thread_number + def run(self): + print ("\n"+str(self.thread_number)+". ---> " + self.name + " running, belonging to process ID "+ str(os.getpid()) + "\n") + time.sleep(self.duration) + out_list = [2,54,38,76,23,56,84,90] + self.do_something(out_list) + print (str(self.thread_number)+". ---> " + self.name + " over, sleep duration : " +str(self.duration) +" second") + print (", Realname of Thread : " + currentThread().getName()) + + def do_something(self,out_list): + for j in range(len(out_list)-1,-1,-1): + hole = j + while hole <(len(out_list)-1) and out_list[hole+1]>out_list[hole]: + out_list[hole] = out_list[hole+1] + hole = hole+1 + out_list[hole] = out_list[j] + out_list = list() + +def main(): + start_time = time.time() + + # Thread Creation + thread1 = IrfanHernandez1184014("Thread#1 ", 1,randint(1,10)) + thread2 = IrfanHernandez1184014("Thread#2 ", 2,randint(1,10)) + thread3 = IrfanHernandez1184014("Thread#3 ", 3,randint(1,10)) + thread4 = IrfanHernandez1184014("Thread#4 ", 4,randint(1,10)) + thread5 = IrfanHernandez1184014("Thread#5 ", 5,randint(1,10)) + thread6 = IrfanHernandez1184014("Thread#6 ", 6,randint(1,10)) + thread7 = IrfanHernandez1184014("Thread#7 ", 7,randint(1,10)) + thread8 = IrfanHernandez1184014("Thread#8 ", 8,randint(1,10)) + thread9 = IrfanHernandez1184014("Thread#9 ", 9,randint(1,10)) + + # Thread Running + thread1.start() + thread2.start() + thread3.start() + thread4.start() + thread5.start() + thread6.start() + thread7.start() + thread8.start() + thread9.start() + + # Thread joining + thread1.join() + thread2.join() + thread3.join() + thread4.join() + thread5.join() + thread6.join() + thread7.join() + thread8.join() + thread9.join() + + # End + print("End") + + #Execution Time + print("--- %s seconds ---" % (time.time() - start_time)) + return True + + + + + diff --git a/test_app.py b/test_app.py index b0393ba..d492651 100644 --- a/test_app.py +++ b/test_app.py @@ -30,14 +30,19 @@ def tearDown(self): # response = main() # self.assertEqual(response, True) - def test_02_rizaluardi_1184102(self): - from Chapter02.Rizaluardi1184102 import main - response = main() - self.assertEqual(response, True) + #def test_02_rizaluardi_1184102(self): + # from Chapter02.Rizaluardi1184102 import main + # response = main() + # self.assertEqual(response, True) - def test_02_zanwar_1184050(self): - from Chapter02.Zanwar1184050 import main - response = main() + #def test_02_zanwar_1184050(self): + # from Chapter02.Zanwar1184050 import main + # response = main() + # self.assertEqual(response, True) + + def test_02_hernandez_1184014(self): + from Chapter02.IrfanHernandez1184014 import main + response = main() self.assertEqual(response, True) From 785370811dd6cba64ec2f81524b2b11a95bd3ad8 Mon Sep 17 00:00:00 2001 From: idafatriniputri Date: Tue, 16 Mar 2021 13:35:52 +0700 Subject: [PATCH 010/164] TugasIda1184113 --- Chapter02/Ida1184113.py | 69 +++++++++++++++++++++++++++++++++++++++++ test_app.py | 4 +++ 2 files changed, 73 insertions(+) create mode 100644 Chapter02/Ida1184113.py diff --git a/Chapter02/Ida1184113.py b/Chapter02/Ida1184113.py new file mode 100644 index 0000000..2358fa1 --- /dev/null +++ b/Chapter02/Ida1184113.py @@ -0,0 +1,69 @@ +import time +import os +from random import randint +from threading import Thread,currentThread + + +class Ida1184113 (Thread): + def __init__(self, name,thread_number): + Thread.__init__(self) + self.name = name + self.thread_number = thread_number + def run(self): + print ("\n"+str(self.thread_number)+". ---> " + self.name + " running, belonging to process ID "+ str(os.getpid()) + "\n") + self.do_something(randint(200, 999), 170000) + print (str(self.thread_number)+". ---> " + self.name + " over.") + print (", Realname of Thread : " + currentThread().getName()) + + def do_something(self, n, x): + while x > 0: + n = n*3 + x = x-1 + +def main(): + start_time = time.time() + + # Thread Creation + thread1 = Ida1184113("Thread#1 ", 1) + thread2 = Ida1184113("Thread#2 ", 2) + thread3 = Ida1184113("Thread#3 ", 3) + thread4 = Ida1184113("Thread#4 ", 4) + thread5 = Ida1184113("Thread#5 ", 5) + thread6 = Ida1184113("Thread#6 ", 6) + thread7 = Ida1184113("Thread#7 ", 7) + thread8 = Ida1184113("Thread#8 ", 8) + thread9 = Ida1184113("Thread#9 ", 9) + + # Thread Running + thread1.start() + thread2.start() + thread3.start() + thread4.start() + thread5.start() + thread6.start() + thread7.start() + thread8.start() + thread9.start() + + # Thread joining + thread1.join() + thread2.join() + thread3.join() + thread4.join() + thread5.join() + thread6.join() + thread7.join() + thread8.join() + thread9.join() + + # End + print("End") + + #Execution Time + print("--- %s seconds ---" % (time.time() - start_time)) + return True + + + + + diff --git a/test_app.py b/test_app.py index 9bb45f2..b60ca92 100644 --- a/test_app.py +++ b/test_app.py @@ -45,4 +45,8 @@ def test_02_ferdy_1184112(self): response = main() self.assertEqual(response, True) + def test_02_ida_1184113(self): + from Chapter02.Ida1184113 import main + response = main() + self.assertEqual(response, True) From 33e00f99087002d9b925f26811f40eee4490c604 Mon Sep 17 00:00:00 2001 From: Okky Yudistira Date: Tue, 16 Mar 2021 13:49:02 +0700 Subject: [PATCH 011/164] tugas perbaikan okky --- Chapter02/okky1184087.py | 73 ++++++++++++++++++++++++++++++++++++++++ test_app.py | 6 +++- 2 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 Chapter02/okky1184087.py diff --git a/Chapter02/okky1184087.py b/Chapter02/okky1184087.py new file mode 100644 index 0000000..95cca0a --- /dev/null +++ b/Chapter02/okky1184087.py @@ -0,0 +1,73 @@ +import time +import os +from random import randint +from threading import Thread,currentThread + + +class okky1184087 (Thread): + def __init__(self, name,thread_number, duration): + Thread.__init__(self) + self.name = name + self.duration = duration + self.thread_number = thread_number + def run(self): + print ("\n"+str(self.thread_number)+". ---> " + self.name + " running, belonging to process ID "+ str(os.getpid()) + "\n") + time.sleep(self.duration) + out_list = list() + self.do_something(randint(1,10),1000000) + print (str(self.thread_number)+". ---> " + self.name + " over, sleep duration : " +str(self.duration) +" second") + print (", Realname of Thread : " + currentThread().getName()) + + def do_something(self,count,out_list): + out_list =1 + count = 5 + for i in range(2, count+ 1): + out_list *= i + +def main(): + start_time = time.time() + + # Thread Creation + thread1 = okky1184087("Thread#1 ", 1,randint(1,10)) + thread2 = okky1184087("Thread#2 ", 2,randint(1,10)) + thread3 = okky1184087("Thread#3 ", 3,randint(1,10)) + thread4 = okky1184087("Thread#4 ", 4,randint(1,10)) + thread5 = okky1184087("Thread#5 ", 5,randint(1,10)) + thread6 = okky1184087("Thread#6 ", 6,randint(1,10)) + thread7 = okky1184087("Thread#7 ", 7,randint(1,10)) + thread8 = okky1184087("Thread#8 ", 8,randint(1,10)) + thread9 = okky1184087("Thread#9 ", 9,randint(1,10)) + + # Thread Running + thread1.start() + thread2.start() + thread3.start() + thread4.start() + thread5.start() + thread6.start() + thread7.start() + thread8.start() + thread9.start() + + # Thread joining + thread1.join() + thread2.join() + thread3.join() + thread4.join() + thread5.join() + thread6.join() + thread7.join() + thread8.join() + thread9.join() + + # End + print("End") + + #Execution Time + print("--- %s seconds ---" % (time.time() - start_time)) + return True + + + + + diff --git a/test_app.py b/test_app.py index b60ca92..18c2878 100644 --- a/test_app.py +++ b/test_app.py @@ -49,4 +49,8 @@ def test_02_ida_1184113(self): from Chapter02.Ida1184113 import main response = main() self.assertEqual(response, True) - + + def test_02_okky_1184087(self): + from Chapter02.okky1184087 import main + response = main() + self.assertEqual(response, True) \ No newline at end of file From f58b34b9f941d49e0febac30cc2203cef2d9c9a6 Mon Sep 17 00:00:00 2001 From: 69AllDayFun Date: Tue, 16 Mar 2021 14:02:30 +0700 Subject: [PATCH 012/164] Tugas Irfan Hernandez --- Chapter02/IrfanHernandez1184014.py | 76 ++++++++++++++++++++++++++++++ test_app.py | 10 +++- 2 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 Chapter02/IrfanHernandez1184014.py diff --git a/Chapter02/IrfanHernandez1184014.py b/Chapter02/IrfanHernandez1184014.py new file mode 100644 index 0000000..7326e1f --- /dev/null +++ b/Chapter02/IrfanHernandez1184014.py @@ -0,0 +1,76 @@ +import time +import os +from random import randint +from threading import Thread,currentThread + + +class IrfanHernandez1184014 (Thread): + def __init__(self, name,thread_number, duration): + Thread.__init__(self) + self.name = name + self.duration = duration + self.thread_number = thread_number + def run(self): + print ("\n"+str(self.thread_number)+". ---> " + self.name + " running, belonging to process ID "+ str(os.getpid()) + "\n") + time.sleep(self.duration) + out_list = [2,54,38,76,23,56,84,90] + self.do_something(out_list) + print (str(self.thread_number)+". ---> " + self.name + " over, sleep duration : " +str(self.duration) +" second") + print (", Realname of Thread : " + currentThread().getName()) + + def do_something(self,out_list): + for j in range(len(out_list)-1,-1,-1): + hole = j + while hole <(len(out_list)-1) and out_list[hole+1]>out_list[hole]: + out_list[hole] = out_list[hole+1] + hole = hole+1 + out_list[hole] = out_list[j] + out_list = list() + +def main(): + start_time = time.time() + + # Thread Creation + thread1 = IrfanHernandez1184014("Thread#1 ", 1,randint(1,10)) + thread2 = IrfanHernandez1184014("Thread#2 ", 2,randint(1,10)) + thread3 = IrfanHernandez1184014("Thread#3 ", 3,randint(1,10)) + thread4 = IrfanHernandez1184014("Thread#4 ", 4,randint(1,10)) + thread5 = IrfanHernandez1184014("Thread#5 ", 5,randint(1,10)) + thread6 = IrfanHernandez1184014("Thread#6 ", 6,randint(1,10)) + thread7 = IrfanHernandez1184014("Thread#7 ", 7,randint(1,10)) + thread8 = IrfanHernandez1184014("Thread#8 ", 8,randint(1,10)) + thread9 = IrfanHernandez1184014("Thread#9 ", 9,randint(1,10)) + + # Thread Running + thread1.start() + thread2.start() + thread3.start() + thread4.start() + thread5.start() + thread6.start() + thread7.start() + thread8.start() + thread9.start() + + # Thread joining + thread1.join() + thread2.join() + thread3.join() + thread4.join() + thread5.join() + thread6.join() + thread7.join() + thread8.join() + thread9.join() + + # End + print("End") + + #Execution Time + print("--- %s seconds ---" % (time.time() - start_time)) + return True + + + + + diff --git a/test_app.py b/test_app.py index 18c2878..303dbcc 100644 --- a/test_app.py +++ b/test_app.py @@ -53,4 +53,12 @@ def test_02_ida_1184113(self): def test_02_okky_1184087(self): from Chapter02.okky1184087 import main response = main() - self.assertEqual(response, True) \ No newline at end of file + self.assertEqual(response, True) + + + def test_02_Nandez_1184014(self): + from Chapter02.IrfanHernandez1184014 import main + response = main() + self.assertEqual(response, True) + + \ No newline at end of file From f5f96aa5c65d11781c51a9b3c21a94f0aa09b7b7 Mon Sep 17 00:00:00 2001 From: alif721 Date: Tue, 16 Mar 2021 14:58:52 +0700 Subject: [PATCH 013/164] tugas alif perbaikan --- Chapter02/Alif1184068.py | 71 ++++++++++++++++++++++++++++++++++++++++ test_app.py | 35 +++++++++++--------- 2 files changed, 91 insertions(+), 15 deletions(-) create mode 100644 Chapter02/Alif1184068.py diff --git a/Chapter02/Alif1184068.py b/Chapter02/Alif1184068.py new file mode 100644 index 0000000..c7f9877 --- /dev/null +++ b/Chapter02/Alif1184068.py @@ -0,0 +1,71 @@ +import time +import os +from random import randint +from threading import Thread,currentThread + + +class Alif1184068 (Thread): + def __init__(self, name,thread_number, duration): + Thread.__init__(self) + self.name = name + self.duration = duration + self.thread_number = thread_number + def run(self): + print ("\n"+str(self.thread_number)+". ---> " + self.name + " running, belonging to process ID "+ str(os.getpid()) + "\n") + awal = 1 + akhir = 30000 + self.bil_geometri(awal,akhir) + print (str(self.thread_number)+". ---> " + self.name + " over, sleep duration : " +str(self.duration) +" second") + print (", Realname of Thread : " + currentThread().getName()) + + def bil_geometri(self,awal,akhir): + for n in range(1,30000): + suku = 1*(2**(n-1)) + +def main(): + start_time = time.time() + + # Thread Creation + thread1 = Alif1184068("Thread#1 ", 1,randint(1,10)) + thread2 = Alif1184068("Thread#2 ", 2,randint(1,10)) + thread3 = Alif1184068("Thread#3 ", 3,randint(1,10)) + thread4 = Alif1184068("Thread#4 ", 4,randint(1,10)) + thread5 = Alif1184068("Thread#5 ", 5,randint(1,10)) + thread6 = Alif1184068("Thread#6 ", 6,randint(1,10)) + thread7 = Alif1184068("Thread#7 ", 7,randint(1,10)) + thread8 = Alif1184068("Thread#8 ", 8,randint(1,10)) + thread9 = Alif1184068("Thread#9 ", 9,randint(1,10)) + + # Thread Running + thread1.start() + thread2.start() + thread3.start() + thread4.start() + thread5.start() + thread6.start() + thread7.start() + thread8.start() + thread9.start() + + # Thread joining + thread1.join() + thread2.join() + thread3.join() + thread4.join() + thread5.join() + thread6.join() + thread7.join() + thread8.join() + thread9.join() + + # End + print("End") + + #Execution Time + print("--- %s seconds ---" % (time.time() - start_time)) + return True + + + + + diff --git a/test_app.py b/test_app.py index 303dbcc..1e8f675 100644 --- a/test_app.py +++ b/test_app.py @@ -40,25 +40,30 @@ def tearDown(self): # response = main() # self.assertEqual(response, True) - def test_02_ferdy_1184112(self): - from Chapter02.Ferdy1184112 import main - response = main() - self.assertEqual(response, True) + #def test_02_ferdy_1184112(self): + # from Chapter02.Ferdy1184112 import main + # response = main() + # self.assertEqual(response, True) - def test_02_ida_1184113(self): - from Chapter02.Ida1184113 import main - response = main() - self.assertEqual(response, True) + #def test_02_ida_1184113(self): + # from Chapter02.Ida1184113 import main + # response = main() + # self.assertEqual(response, True) - def test_02_okky_1184087(self): - from Chapter02.okky1184087 import main - response = main() - self.assertEqual(response, True) + #def test_02_okky_1184087(self): + # from Chapter02.okky1184087 import main + # response = main() + # self.assertEqual(response, True) - def test_02_Nandez_1184014(self): - from Chapter02.IrfanHernandez1184014 import main - response = main() + #def test_02_Nandez_1184014(self): + # from Chapter02.IrfanHernandez1184014 import main + # response = main() + # self.assertEqual(response, True) + + def test_02_alif_1184068(self): + from Chapter02.Alif1184068 import main + response = main() self.assertEqual(response, True) \ No newline at end of file From 9c4b7e0d0bf9fad7e8e4ea8fae949a61abacb91a Mon Sep 17 00:00:00 2001 From: baharandili Date: Tue, 16 Mar 2021 15:10:56 +0700 Subject: [PATCH 014/164] tugas bahar revisi --- Chapter02/baharandili1184002.py | 81 +++++++++++++++++++++++++++++++++ test_app.py | 5 +- 2 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 Chapter02/baharandili1184002.py diff --git a/Chapter02/baharandili1184002.py b/Chapter02/baharandili1184002.py new file mode 100644 index 0000000..688a81f --- /dev/null +++ b/Chapter02/baharandili1184002.py @@ -0,0 +1,81 @@ +# -*- coding: utf-8 -*- +""" +Created on Tue Mar 16 11:01:27 2021 + +@author: HP +""" + +import time +import os +from random import randint +from threading import Thread,currentThread + + +class baharandili1184002 (Thread): + def __init__(self, name,thread_number, duration): + Thread.__init__(self) + self.name = name + self.duration = duration + self.thread_number = thread_number + def run(self): + print ("\n"+str(self.thread_number)+". ---> " + self.name + " running, belonging to process ID "+ str(os.getpid()) + "\n") + a = 1 + b = 4 + n = 0 + self.aritmatika(a,b,n) + print (str(self.thread_number)+". ---> " + self.name + " over, sleep duration : " +str(self.duration) +" second") + print (", Realname of Thread : " + currentThread().getName()) + + + def aritmatika(self, a, b, n): + for n in range (2500000): + n = n + 1 + a = a + b + +def main(): + start_time = time.time() + + # Thread Creation + thread1 = baharandili1184002("Thread#1 ", 1,randint(1,10)) + thread2 = baharandili1184002("Thread#2 ", 2,randint(1,10)) + thread3 = baharandili1184002("Thread#3 ", 3,randint(1,10)) + thread4 = baharandili1184002("Thread#4 ", 4,randint(1,10)) + thread5 = baharandili1184002("Thread#5 ", 5,randint(1,10)) + thread6 = baharandili1184002("Thread#6 ", 6,randint(1,10)) + thread7 = baharandili1184002("Thread#7 ", 7,randint(1,10)) + thread8 = baharandili1184002("Thread#8 ", 8,randint(1,10)) + thread9 = baharandili1184002("Thread#9 ", 9,randint(1,10)) + + # Thread Running + thread1.start() + thread2.start() + thread3.start() + thread4.start() + thread5.start() + thread6.start() + thread7.start() + thread8.start() + thread9.start() + + # Thread joining + thread1.join() + thread2.join() + thread3.join() + thread4.join() + thread5.join() + thread6.join() + thread7.join() + thread8.join() + thread9.join() + + # End + print("End") + + #Execution Time + print("--- %s seconds ---" % (time.time() - start_time)) + return True + + + + + diff --git a/test_app.py b/test_app.py index 1e8f675..87c177c 100644 --- a/test_app.py +++ b/test_app.py @@ -66,4 +66,7 @@ def test_02_alif_1184068(self): response = main() self.assertEqual(response, True) - \ No newline at end of file + def test_02_bahar_1184002(self): + from Chapter02.baharandili1184002 import main + response = main() + self.assertEqual(response, True) \ No newline at end of file From bdfebe2aca48a3a461257e8a5a9e97ee244c6d93 Mon Sep 17 00:00:00 2001 From: IraDwita Date: Tue, 16 Mar 2021 15:32:19 +0700 Subject: [PATCH 015/164] TugasIra1184024 --- Chapter02/IraDwita1184024.py | 70 ++++++++++++++++++++++++++++++++++++ test_app.py | 5 +++ 2 files changed, 75 insertions(+) create mode 100644 Chapter02/IraDwita1184024.py diff --git a/Chapter02/IraDwita1184024.py b/Chapter02/IraDwita1184024.py new file mode 100644 index 0000000..b30762a --- /dev/null +++ b/Chapter02/IraDwita1184024.py @@ -0,0 +1,70 @@ +import time +import os +from random import randint +from threading import Thread,currentThread + + +class IraDwita1184024 (Thread): + def __init__(self, name,thread_number, duration): + Thread.__init__(self) + self.name = name + self.duration = duration + self.thread_number = thread_number + def run(self): + print ("\n"+str(self.thread_number)+". ---> " + self.name + " running, belonging to process ID "+ str(os.getpid()) + "\n") + self.do_something(randint(300,999),1000000) + print (str(self.thread_number)+". ---> " + self.name + " over, sleep duration : " +str(self.duration) +" second") + print (", Realname of Thread : " + currentThread().getName()) + + def do_something(self, n, x): + while x > 0: + n = n /3 + x = x -1 + +def main(): + start_time = time.time() + + # Thread Creation + thread2 = IraDwita1184024("Thread#2 ", 2,randint(1,10)) + thread3 = IraDwita1184024("Thread#3 ", 3,randint(1,10)) + thread1 = IraDwita1184024("Thread#1 ", 1,randint(1,10)) + thread4 = IraDwita1184024("Thread#4 ", 4,randint(1,10)) + thread5 = IraDwita1184024("Thread#5 ", 5,randint(1,10)) + thread6 = IraDwita1184024("Thread#6 ", 6,randint(1,10)) + thread7 = IraDwita1184024("Thread#7 ", 7,randint(1,10)) + thread8 = IraDwita1184024("Thread#8 ", 8,randint(1,10)) + thread9 = IraDwita1184024("Thread#9 ", 9,randint(1,10)) + + # Thread Running + thread1.start() + thread2.start() + thread3.start() + thread4.start() + thread5.start() + thread6.start() + thread7.start() + thread8.start() + thread9.start() + + # Thread joining + thread1.join() + thread2.join() + thread3.join() + thread4.join() + thread5.join() + thread6.join() + thread7.join() + thread8.join() + thread9.join() + + # End + print("End") + + #Execution Time + print("--- %s seconds ---" % (time.time() - start_time)) + return True + + + + + diff --git a/test_app.py b/test_app.py index 1e8f675..d11a422 100644 --- a/test_app.py +++ b/test_app.py @@ -65,5 +65,10 @@ def test_02_alif_1184068(self): from Chapter02.Alif1184068 import main response = main() self.assertEqual(response, True) + + def test_02_iradwita_1184024(self): + from Chapter02.IraDwita1184024 import main + response = main() + self.assertEqual(response, True) \ No newline at end of file From 6f7ad6203d6f3811ccb214745149fa01e7614e7c Mon Sep 17 00:00:00 2001 From: HanifWp Date: Tue, 16 Mar 2021 15:48:21 +0700 Subject: [PATCH 016/164] Tugas Hanif --- Chapter02/Hanif1184058.py | 72 +++++++++++++++++++++++++++++++++++++++ test_app.py | 5 +++ 2 files changed, 77 insertions(+) create mode 100644 Chapter02/Hanif1184058.py diff --git a/Chapter02/Hanif1184058.py b/Chapter02/Hanif1184058.py new file mode 100644 index 0000000..96a1a50 --- /dev/null +++ b/Chapter02/Hanif1184058.py @@ -0,0 +1,72 @@ +import time +import os +from random import randint +from threading import Thread,currentThread + + +class Hanif1184058 (Thread): + def __init__(self, name,thread_number, duration): + Thread.__init__(self) + self.name = name + self.duration = duration + self.thread_number = thread_number + def run(self): + print ("\n"+str(self.thread_number)+". ---> " + self.name + " running, belonging to process ID "+ str(os.getpid()) + "\n") + time.sleep(self.duration) + out_list = list() + self.do_something(1000000,out_list) + print (str(self.thread_number)+". ---> " + self.name + " over, sleep duration : " +str(self.duration) +" second") + print (", Realname of Thread : " + currentThread().getName()) + + def do_something(self,count,out_list): + for out_list in range(count): + if out_list % 2 == 1: + out_list = list() + +def main(): + start_time = time.time() + + # Thread Creation + thread1 = Hanif1184058("Thread#1 ", 1,randint(1,10)) + thread2 = Hanif1184058("Thread#2 ", 2,randint(1,10)) + thread3 = Hanif1184058("Thread#3 ", 3,randint(1,10)) + thread4 = Hanif1184058("Thread#4 ", 4,randint(1,10)) + thread5 = Hanif1184058("Thread#5 ", 5,randint(1,10)) + thread6 = Hanif1184058("Thread#6 ", 6,randint(1,10)) + thread7 = Hanif1184058("Thread#7 ", 7,randint(1,10)) + thread8 = Hanif1184058("Thread#8 ", 8,randint(1,10)) + thread9 = Hanif1184058("Thread#9 ", 9,randint(1,10)) + + # Thread Running + thread1.start() + thread2.start() + thread3.start() + thread4.start() + thread5.start() + thread6.start() + thread7.start() + thread8.start() + thread9.start() + + # Thread joining + thread1.join() + thread2.join() + thread3.join() + thread4.join() + thread5.join() + thread6.join() + thread7.join() + thread8.join() + thread9.join() + + # End + print("End") + + #Execution Time + print("--- %s seconds ---" % (time.time() - start_time)) + return True + + + + + diff --git a/test_app.py b/test_app.py index 55b4c15..89c42fa 100644 --- a/test_app.py +++ b/test_app.py @@ -74,4 +74,9 @@ def test_02_iradwita_1184024(self): def test_02_bahar_1184002(self): from Chapter02.baharandili1184002 import main response = main() + self.assertEqual(response, True) + + def test_02_hanif_1184058(self): + from Chapter02.Hanif1184058 import main + response = main() self.assertEqual(response, True) \ No newline at end of file From 5d3b1cd7f9d9780aaf3a14d15ae9df129eaa1fc0 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 16 Mar 2021 16:18:52 +0700 Subject: [PATCH 017/164] tugas_wahyukurniasari1184001 --- test_app.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test_app.py b/test_app.py index 89c42fa..1f2199b 100644 --- a/test_app.py +++ b/test_app.py @@ -79,4 +79,10 @@ def test_02_bahar_1184002(self): def test_02_hanif_1184058(self): from Chapter02.Hanif1184058 import main response = main() + self.assertEqual(response, True) + + + def test_02_wahyukurniasari_1184001(self): + from Chapter02.wahyukurniasari1184001 import main + response = main() self.assertEqual(response, True) \ No newline at end of file From 5612b3b938ed23cae4a63aca0989cc39880976af Mon Sep 17 00:00:00 2001 From: Anisarosalina Date: Tue, 16 Mar 2021 16:22:36 +0700 Subject: [PATCH 018/164] Tugas Anisa 1184016 --- Chapter02/Anisa1184016.py | 70 +++++++++++++++++++++++++++++++++++++++ test_app.py | 7 +++- 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 Chapter02/Anisa1184016.py diff --git a/Chapter02/Anisa1184016.py b/Chapter02/Anisa1184016.py new file mode 100644 index 0000000..07dc905 --- /dev/null +++ b/Chapter02/Anisa1184016.py @@ -0,0 +1,70 @@ +import time +import os +from random import randint +from threading import Thread,currentThread + + +class AnisaRos1184016 (Thread): + def __init__(self, name,thread_number, duration): + Thread.__init__(self) + self.name = name + self.duration = duration + self.thread_number = thread_number + def run(self): + print ("\n"+str(self.thread_number)+". ---> " + self.name + " running, belonging to process ID "+ str(os.getpid()) + "\n") + self.pangkat(randint(2,19), 50) + print (str(self.thread_number)+". ---> " + self.name + " over.") + print (", Realname of Thread : " + currentThread().getName()) + + def pangkat(self, x, y): + while y>0: + x=x**2 + y=y-1 + +def main(): + start_time = time.time() + + # Thread Creation + thread1 = AnisaRos1184016 ("Thread#1 ", 1,randint(1,10)) + thread2 = AnisaRos1184016 ("Thread#2 ", 2,randint(1,10)) + thread3 = AnisaRos1184016 ("Thread#3 ", 3,randint(1,10)) + thread4 = AnisaRos1184016 ("Thread#4 ", 4,randint(1,10)) + thread5 = AnisaRos1184016 ("Thread#5 ", 5,randint(1,10)) + thread6 = AnisaRos1184016 ("Thread#6 ", 6,randint(1,10)) + thread7 = AnisaRos1184016 ("Thread#7 ", 7,randint(1,10)) + thread8 = AnisaRos1184016 ("Thread#8 ", 8,randint(1,10)) + thread9 = AnisaRos1184016 ("Thread#9 ", 9,randint(1,10)) + + # Thread Running + thread1.start() + thread2.start() + thread3.start() + thread4.start() + thread5.start() + thread6.start() + thread7.start() + thread8.start() + thread9.start() + + # Thread joining + thread1.join() + thread2.join() + thread3.join() + thread4.join() + thread5.join() + thread6.join() + thread7.join() + thread8.join() + thread9.join() + + # End + print("End") + + #Execution Time + print("--- %s seconds ---" % (time.time() - start_time)) + return True + + + + + diff --git a/test_app.py b/test_app.py index 89c42fa..8074e16 100644 --- a/test_app.py +++ b/test_app.py @@ -56,7 +56,7 @@ def tearDown(self): # self.assertEqual(response, True) - #def test_02_Nandez_1184014(self): + #def test_02_nandez_1184014(self): # from Chapter02.IrfanHernandez1184014 import main # response = main() # self.assertEqual(response, True) @@ -79,4 +79,9 @@ def test_02_bahar_1184002(self): def test_02_hanif_1184058(self): from Chapter02.Hanif1184058 import main response = main() + self.assertEqual(response, True) + + def test_02_anisa_1184016(self): + from Chapter02.Anisa1184016 import main + response = main() self.assertEqual(response, True) \ No newline at end of file From a60f37a17f996635487aca209652a665a4b503b4 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 16 Mar 2021 16:32:18 +0700 Subject: [PATCH 019/164] Tgs2_vicky1184037 --- Chapter01/do_something.py | 18 ++++++--- Chapter02/vicky1184037.py | 84 +++++++++++++++++++++++++++++++++++++++ test_app.py | 5 +++ 3 files changed, 102 insertions(+), 5 deletions(-) create mode 100644 Chapter02/vicky1184037.py diff --git a/Chapter01/do_something.py b/Chapter01/do_something.py index db4c9f6..f13f422 100644 --- a/Chapter01/do_something.py +++ b/Chapter01/do_something.py @@ -1,6 +1,14 @@ -import random - -def do_something(count,out_list): - for i in range(count): - out_list.append(random.random()) +import time +from do_something import +if __name__ == "__main__" : + start_time = time.time() + size = 10000000 + n_exec = 10 + for i in range(0, n_exec) : + out_list = list() + do_something(size, out_list) + + print ("List processing complate.") + end_time = time.time() + print("serial time-", end_time - start_time) \ No newline at end of file diff --git a/Chapter02/vicky1184037.py b/Chapter02/vicky1184037.py new file mode 100644 index 0000000..3846402 --- /dev/null +++ b/Chapter02/vicky1184037.py @@ -0,0 +1,84 @@ +import time +import os +from random import randint +from threading import Thread,currentThread + + +class vicky1184037 (Thread): + def __init__(self, name,thread_number, duration): + Thread.__init__(self) + self.name = name + self.duration = duration + self.thread_number = thread_number + def run(self): + print ("\n"+str(self.thread_number)+". ---> " + self.name + " running, belonging to process ID "+ str(os.getpid()) + "\n") + time.sleep(self.duration) + out_list = list() + self.do_something(1000000,out_list) + print (str(self.thread_number)+". ---> " + self.name + " over, sleep duration : " +str(self.duration) +" second") + print (", Realname of Thread : " + currentThread().getName()) + +import time +from do_something import + +if __name__ == "__main__" : + start_time = time.time() + size = 10000000 + n_exec = 10 + for i in range(0, n_exec) : + out_list = list() + do_something(size, out_list) + + print ("List processing complate.") + end_time = time.time() + print("serial time-", end_time - start_time) + + + +def main(): + start_time = time.time() + + # Thread Creation + thread1 = vicky1184037("Thread#1 ", 1,randint(1,10)) + thread2 = vicky1184037("Thread#2 ", 2,randint(1,10)) + thread3 = vicky1184037("Thread#3 ", 3,randint(1,10)) + thread4 = vicky1184037("Thread#4 ", 4,randint(1,10)) + thread5 = vicky1184037("Thread#5 ", 5,randint(1,10)) + thread6 = vicky1184037("Thread#6 ", 6,randint(1,10)) + thread7 = vicky1184037("Thread#7 ", 7,randint(1,10)) + thread8 = vicky1184037("Thread#8 ", 8,randint(1,10)) + thread9 = vicky1184037("Thread#9 ", 9,randint(1,10)) + + # Thread Running + thread1.start() + thread2.start() + thread3.start() + thread4.start() + thread5.start() + thread6.start() + thread7.start() + thread8.start() + thread9.start() + + # Thread joining + thread1.join() + thread2.join() + thread3.join() + thread4.join() + thread5.join() + thread6.join() + thread7.join() + thread8.join() + thread9.join() + + # End + print("End") + + #Execution Time + print("--- %s seconds ---" % (time.time() - start_time)) + return True + + + + + diff --git a/test_app.py b/test_app.py index 18c2878..e86f421 100644 --- a/test_app.py +++ b/test_app.py @@ -53,4 +53,9 @@ def test_02_ida_1184113(self): def test_02_okky_1184087(self): from Chapter02.okky1184087 import main response = main() + self.assertEqual(response, True) + + def test_02_vicky_1184037(self): + from Chapter02.vicky1184037 import main + response = main() self.assertEqual(response, True) \ No newline at end of file From af63fef85d7a8cc37ac592a1a5317faeaf2d5ce3 Mon Sep 17 00:00:00 2001 From: parhanhambali Date: Tue, 16 Mar 2021 16:48:45 +0700 Subject: [PATCH 020/164] Tugas Chapter02 Parhan --- Chapter02/Parhan1184042.py | 76 ++++++++++++++++++++++++++++++++++++++ test_app.py | 5 +++ 2 files changed, 81 insertions(+) create mode 100644 Chapter02/Parhan1184042.py diff --git a/Chapter02/Parhan1184042.py b/Chapter02/Parhan1184042.py new file mode 100644 index 0000000..8c9f316 --- /dev/null +++ b/Chapter02/Parhan1184042.py @@ -0,0 +1,76 @@ +import time +import os +import random +from random import randint +from threading import Thread,currentThread + + +class Parhan1184042 (Thread): + def __init__(self, name,thread_number, duration): + Thread.__init__(self) + self.name = name + self.duration = duration + self.thread_number = thread_number + def run(self): + print ("\n"+str(self.thread_number)+". ---> " + self.name + " running, belonging to process ID "+ str(os.getpid()) + "\n") + color_number={'red','yellow','blue','green','black','pink','orange','jingga','Abu abu','blue black','coklat'} + self.get_color(1000000) + print (str(self.thread_number)+". ---> " + self.name + " over, sleep duration : " +str(self.duration) +" second") + print (", Realname of Thread : " + currentThread().getName()) + + def get_color(color_number=10): + color_number = int(color_number) + def do_something(color_number): + student_array = [] + for i in range(1000000): + random_color_number = random.randint(0, 4) + color = get_color(random_color_number) + student_array.append(color) + +def main(): + start_time = time.time() + + # Thread Creation + thread1 = Parhan1184042("Thread#1 ", 1,randint(1,10)) + thread2 = Parhan1184042("Thread#2 ", 2,randint(1,10)) + thread3 = Parhan1184042("Thread#3 ", 3,randint(1,10)) + thread4 = Parhan1184042("Thread#4 ", 4,randint(1,10)) + thread5 = Parhan1184042("Thread#5 ", 5,randint(1,10)) + thread6 = Parhan1184042("Thread#6 ", 6,randint(1,10)) + thread7 = Parhan1184042("Thread#7 ", 7,randint(1,10)) + thread8 = Parhan1184042("Thread#8 ", 8,randint(1,10)) + thread9 = Parhan1184042("Thread#9 ", 9,randint(1,10)) + + # Thread Running + thread1.start() + thread2.start() + thread3.start() + thread4.start() + thread5.start() + thread6.start() + thread7.start() + thread8.start() + thread9.start() + + # Thread joining + thread1.join() + thread2.join() + thread3.join() + thread4.join() + thread5.join() + thread6.join() + thread7.join() + thread8.join() + thread9.join() + + # End + print("End") + + #Execution Time + print("--- %s seconds ---" % (time.time() - start_time)) + return True + + + + + diff --git a/test_app.py b/test_app.py index 89c42fa..9556003 100644 --- a/test_app.py +++ b/test_app.py @@ -79,4 +79,9 @@ def test_02_bahar_1184002(self): def test_02_hanif_1184058(self): from Chapter02.Hanif1184058 import main response = main() + self.assertEqual(response, True) + + def test_02_parhan_1184042(self): + from Chapter02.Parhan1184042 import main + response = main() self.assertEqual(response, True) \ No newline at end of file From d76542945ec9354891206cb87e2ffb6c6bf53aa9 Mon Sep 17 00:00:00 2001 From: ravirahmatulfajri Date: Tue, 16 Mar 2021 17:17:13 +0700 Subject: [PATCH 021/164] Chapter02 Ravi Terlambat --- Chapter02/Ravi1184040.py | 90 ++++++++++++++++++++++++++++++++++++++++ test_app.py | 41 ++++++++++-------- 2 files changed, 113 insertions(+), 18 deletions(-) create mode 100644 Chapter02/Ravi1184040.py diff --git a/Chapter02/Ravi1184040.py b/Chapter02/Ravi1184040.py new file mode 100644 index 0000000..85135af --- /dev/null +++ b/Chapter02/Ravi1184040.py @@ -0,0 +1,90 @@ +import time +import os +from random import randint +from threading import Thread,currentThread + + +class Ravi1184040 (Thread): + def __init__(self, name,thread_number, duration): + Thread.__init__(self) + self.name = name + self.duration = duration + self.thread_number = thread_number + def run(self): + print ("\n"+str(self.thread_number)+". ---> " + self.name + " running, belonging to process ID "+ str(os.getpid()) + "\n") + m=randint(1,15) + n=randint(1,15) + self.hore(m, n, 500000) + print (str(self.thread_number)+". ---> " + self.name + " over, sleep duration : " +str(self.duration) +" second") + print (", Realname of Thread : " + currentThread().getName()) + + def hore(self, m, n, o): + while o>0: + m=m*n/2 + o=o-1 + +def main(): + start_time = time.time() + + # Thread Creation + thread1 = Ravi1184040("Thread#1 ", 1,15) + thread2 = Ravi1184040("Thread#2 ", 2,15) + thread3 = Ravi1184040("Thread#3 ", 3,15) + thread4 = Ravi1184040("Thread#4 ", 4,15) + thread5 = Ravi1184040("Thread#5 ", 5,15) + thread6 = Ravi1184040("Thread#6 ", 6,15) + thread7 = Ravi1184040("Thread#7 ", 7,15) + thread8 = Ravi1184040("Thread#8 ", 8,15) + thread9 = Ravi1184040("Thread#9 ", 9,15) + thread10 = Ravi1184040("Thread#10 ", 10,15) + thread11 = Ravi1184040("Thread#11 ", 11,15) + thread12 = Ravi1184040("Thread#12 ", 12,15) + thread13 = Ravi1184040("Thread#13 ", 13,15) + thread14 = Ravi1184040("Thread#14 ", 14,15) + thread15 = Ravi1184040("Thread#15 ", 15,15) + + # Thread Running + thread1.start() + thread2.start() + thread3.start() + thread4.start() + thread5.start() + thread6.start() + thread7.start() + thread8.start() + thread9.start() + thread10.start() + thread11.start() + thread12.start() + thread13.start() + thread14.start() + thread15.start() + + # Thread joining + thread1.join() + thread2.join() + thread3.join() + thread4.join() + thread5.join() + thread6.join() + thread7.join() + thread8.join() + thread9.join() + thread10.join() + thread11.join() + thread12.join() + thread13.join() + thread14.join() + thread15.join() + + # End + print("End") + + #Execution Time + print("--- %s seconds ---" % (time.time() - start_time)) + return True + + + + + diff --git a/test_app.py b/test_app.py index 9556003..c682561 100644 --- a/test_app.py +++ b/test_app.py @@ -61,27 +61,32 @@ def tearDown(self): # response = main() # self.assertEqual(response, True) - def test_02_alif_1184068(self): - from Chapter02.Alif1184068 import main - response = main() - self.assertEqual(response, True) +# def test_02_alif_1184068(self): +# from Chapter02.Alif1184068 import main +# response = main() + # self.assertEqual(response, True) - def test_02_iradwita_1184024(self): - from Chapter02.IraDwita1184024 import main - response = main() - self.assertEqual(response, True) +# def test_02_iradwita_1184024(self): +# from Chapter02.IraDwita1184024 import main +# response = main() + # self.assertEqual(response, True) - def test_02_bahar_1184002(self): - from Chapter02.baharandili1184002 import main - response = main() - self.assertEqual(response, True) + # def test_02_bahar_1184002(self): +# from Chapter02.baharandili1184002 import main + # response = main() + # self.assertEqual(response, True) - def test_02_hanif_1184058(self): - from Chapter02.Hanif1184058 import main - response = main() - self.assertEqual(response, True) + # def test_02_hanif_1184058(self): + # from Chapter02.Hanif1184058 import main + # response = main() + # self.assertEqual(response, True) - def test_02_parhan_1184042(self): - from Chapter02.Parhan1184042 import main + # def test_02_parhan_1184042(self): + # from Chapter02.Parhan1184042 import main + # response = main() + # self.assertEqual(response, True) + # + def test_02_ravi_1184040(self): + from Chapter02.Ravi1184040 import main response = main() self.assertEqual(response, True) \ No newline at end of file From 4467c302fdf5430bfe0bdd8462e6f6dc9304cc6d Mon Sep 17 00:00:00 2001 From: ravirahmatulfajri Date: Tue, 16 Mar 2021 17:27:00 +0700 Subject: [PATCH 022/164] Chapter02 Ravi Terlambat --- Chapter02/Ravi1184040.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Chapter02/Ravi1184040.py b/Chapter02/Ravi1184040.py index 85135af..52e7812 100644 --- a/Chapter02/Ravi1184040.py +++ b/Chapter02/Ravi1184040.py @@ -14,7 +14,7 @@ def run(self): print ("\n"+str(self.thread_number)+". ---> " + self.name + " running, belonging to process ID "+ str(os.getpid()) + "\n") m=randint(1,15) n=randint(1,15) - self.hore(m, n, 500000) + self.hore(m, n, 5000000) print (str(self.thread_number)+". ---> " + self.name + " over, sleep duration : " +str(self.duration) +" second") print (", Realname of Thread : " + currentThread().getName()) From 9839611fa151e579e9c57c993dfd0b0ee474cc63 Mon Sep 17 00:00:00 2001 From: josua1111 Date: Tue, 16 Mar 2021 19:11:37 +0700 Subject: [PATCH 023/164] Tugas Josuansef Pardede 1184091 --- Chapter02/josua_1184091.py | 115 +++++++++++++++++++++++++++++++++++++ test_app.py | 26 +-------- 2 files changed, 118 insertions(+), 23 deletions(-) create mode 100644 Chapter02/josua_1184091.py diff --git a/Chapter02/josua_1184091.py b/Chapter02/josua_1184091.py new file mode 100644 index 0000000..a10eb54 --- /dev/null +++ b/Chapter02/josua_1184091.py @@ -0,0 +1,115 @@ +# -*- coding: utf-8 -*- +""" +Created on Mon Mar 15 16:56:22 2021 + +@author: Josuansef Pardede (1184091) +""" + +import time +import os +from random import randint +from threading import Thread,currentThread + + +class josua_1184091 (Thread): + def __init__(self, name,thread_number, duration): + Thread.__init__(self) + self.name = name + self.duration = duration + self.thread_number = thread_number + def run(self): + print ("\n"+str(self.thread_number)+". ---> " + self.name + " running, belonging to process ID "+ str(os.getpid()) + "\n") + d=randint(1,20) + e=randint(1,20) + self.josh(d, e, 1500000) + print (str(self.thread_number)+". ---> " + self.name + " over, sleep duration : " +str(self.duration) +" second") + print (", Realname of Thread : " + currentThread().getName()) + + def josh(self, d, e, f): + while f>0: + d=d*e/400 + f=f-2 + + +def main(): + start_time = time.time() + + # Thread Creation + #thread1 = MyThreadClass("Thread#1 ", randint(1,10)) + thread1 = josua_1184091("Thread#1 ", 1,20) + thread2 = josua_1184091("Thread#2 ", 2,20) + thread3 = josua_1184091("Thread#3 ", 3,20) + thread4 = josua_1184091("Thread#4 ", 4,20) + thread5 = josua_1184091("Thread#5 ", 5,20) + thread6 = josua_1184091("Thread#6 ", 6,20) + thread7 = josua_1184091("Thread#7 ", 7,20) + thread8 = josua_1184091("Thread#8 ", 8,20) + thread9 = josua_1184091("Thread#9 ", 9,20) + thread10 = josua_1184091("Thread#10 ", 10,20) + thread11 = josua_1184091("Thread#11 ", 11,20) + thread12 = josua_1184091("Thread#12 ", 12,20) + thread13 = josua_1184091("Thread#13", 13,20) + thread14 = josua_1184091("Thread#14", 14,20) + thread15 = josua_1184091("Thread#15", 15,20) + thread16 = josua_1184091("Thread#16", 16,20) + thread17 = josua_1184091("Thread#17", 17,20) + thread18 = josua_1184091("Thread#18", 18,20) + thread19 = josua_1184091("Thread#19", 19,20) + thread20 = josua_1184091("Thread#20", 20,20) + # Thread Running + thread1.start() + thread2.start() + thread3.start() + thread4.start() + thread5.start() + thread6.start() + thread7.start() + thread8.start() + thread9.start() + thread10.start() + thread11.start() + thread12.start() + thread13.start() + thread14.start() + thread15.start() + thread16.start() + thread17.start() + thread18.start() + thread19.start() + thread20.start() + + # Thread joining + thread1.join() + thread2.join() + thread3.join() + thread4.join() + thread5.join() + thread6.join() + thread7.join() + thread8.join() + thread9.join() + thread10.join() + thread11.join() + thread12.join() + thread13.join() + thread14.join() + thread15.join() + thread16.join() + thread17.join() + thread18.join() + thread19.join() + thread20.join() + + # End + print("End") + + #Execution Time + print("--- %s seconds ---" % (time.time() - start_time)) + + +if __name__ == "__main__": + main() + + + + diff --git a/test_app.py b/test_app.py index 9556003..f3c235f 100644 --- a/test_app.py +++ b/test_app.py @@ -60,28 +60,8 @@ def tearDown(self): # from Chapter02.IrfanHernandez1184014 import main # response = main() # self.assertEqual(response, True) - - def test_02_alif_1184068(self): - from Chapter02.Alif1184068 import main - response = main() - self.assertEqual(response, True) - - def test_02_iradwita_1184024(self): - from Chapter02.IraDwita1184024 import main - response = main() - self.assertEqual(response, True) - - def test_02_bahar_1184002(self): - from Chapter02.baharandili1184002 import main - response = main() - self.assertEqual(response, True) - - def test_02_hanif_1184058(self): - from Chapter02.Hanif1184058 import main - response = main() - self.assertEqual(response, True) - - def test_02_parhan_1184042(self): - from Chapter02.Parhan1184042 import main + + def test_02_josua_1184091(self): + from Chapter02.josua_1184091 import main response = main() self.assertEqual(response, True) \ No newline at end of file From 3cf548a461497b114ec17279aa8fcb225539001e Mon Sep 17 00:00:00 2001 From: josua1111 Date: Tue, 16 Mar 2021 19:36:41 +0700 Subject: [PATCH 024/164] Revisi Tugas Josuansef Pardede 1184091 --- Chapter02/josua_1184091.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Chapter02/josua_1184091.py b/Chapter02/josua_1184091.py index a10eb54..852a46b 100644 --- a/Chapter02/josua_1184091.py +++ b/Chapter02/josua_1184091.py @@ -21,13 +21,13 @@ def run(self): print ("\n"+str(self.thread_number)+". ---> " + self.name + " running, belonging to process ID "+ str(os.getpid()) + "\n") d=randint(1,20) e=randint(1,20) - self.josh(d, e, 1500000) + self.josh(d, e, 3000000) print (str(self.thread_number)+". ---> " + self.name + " over, sleep duration : " +str(self.duration) +" second") print (", Realname of Thread : " + currentThread().getName()) def josh(self, d, e, f): while f>0: - d=d*e/400 + d=d*e/40 f=f-2 @@ -105,10 +105,7 @@ def main(): #Execution Time print("--- %s seconds ---" % (time.time() - start_time)) - - -if __name__ == "__main__": - main() + return True From 653d901d13a82ed8737162a56cff535309c47b3a Mon Sep 17 00:00:00 2001 From: 69AllDayFun Date: Thu, 25 Mar 2021 18:03:54 +0700 Subject: [PATCH 025/164] update --- Chapter02/IrfanHernandez1184014.py | 76 +++++++++++++++++++++++++++ Chapter02/rollyDua113040087.py | 83 ------------------------------ 2 files changed, 76 insertions(+), 83 deletions(-) create mode 100644 Chapter02/IrfanHernandez1184014.py delete mode 100644 Chapter02/rollyDua113040087.py diff --git a/Chapter02/IrfanHernandez1184014.py b/Chapter02/IrfanHernandez1184014.py new file mode 100644 index 0000000..7326e1f --- /dev/null +++ b/Chapter02/IrfanHernandez1184014.py @@ -0,0 +1,76 @@ +import time +import os +from random import randint +from threading import Thread,currentThread + + +class IrfanHernandez1184014 (Thread): + def __init__(self, name,thread_number, duration): + Thread.__init__(self) + self.name = name + self.duration = duration + self.thread_number = thread_number + def run(self): + print ("\n"+str(self.thread_number)+". ---> " + self.name + " running, belonging to process ID "+ str(os.getpid()) + "\n") + time.sleep(self.duration) + out_list = [2,54,38,76,23,56,84,90] + self.do_something(out_list) + print (str(self.thread_number)+". ---> " + self.name + " over, sleep duration : " +str(self.duration) +" second") + print (", Realname of Thread : " + currentThread().getName()) + + def do_something(self,out_list): + for j in range(len(out_list)-1,-1,-1): + hole = j + while hole <(len(out_list)-1) and out_list[hole+1]>out_list[hole]: + out_list[hole] = out_list[hole+1] + hole = hole+1 + out_list[hole] = out_list[j] + out_list = list() + +def main(): + start_time = time.time() + + # Thread Creation + thread1 = IrfanHernandez1184014("Thread#1 ", 1,randint(1,10)) + thread2 = IrfanHernandez1184014("Thread#2 ", 2,randint(1,10)) + thread3 = IrfanHernandez1184014("Thread#3 ", 3,randint(1,10)) + thread4 = IrfanHernandez1184014("Thread#4 ", 4,randint(1,10)) + thread5 = IrfanHernandez1184014("Thread#5 ", 5,randint(1,10)) + thread6 = IrfanHernandez1184014("Thread#6 ", 6,randint(1,10)) + thread7 = IrfanHernandez1184014("Thread#7 ", 7,randint(1,10)) + thread8 = IrfanHernandez1184014("Thread#8 ", 8,randint(1,10)) + thread9 = IrfanHernandez1184014("Thread#9 ", 9,randint(1,10)) + + # Thread Running + thread1.start() + thread2.start() + thread3.start() + thread4.start() + thread5.start() + thread6.start() + thread7.start() + thread8.start() + thread9.start() + + # Thread joining + thread1.join() + thread2.join() + thread3.join() + thread4.join() + thread5.join() + thread6.join() + thread7.join() + thread8.join() + thread9.join() + + # End + print("End") + + #Execution Time + print("--- %s seconds ---" % (time.time() - start_time)) + return True + + + + + diff --git a/Chapter02/rollyDua113040087.py b/Chapter02/rollyDua113040087.py deleted file mode 100644 index 2bedfb8..0000000 --- a/Chapter02/rollyDua113040087.py +++ /dev/null @@ -1,83 +0,0 @@ -from threading import Thread,currentThread, Lock, RLock, Semaphore -import requests -import os - -semaphore = Semaphore(0) -hasilperhitungan=0 - -class rollySemaphoreDeleteFile (Thread): - def __init__(self,name,thread_number,namafile): - Thread.__init__(self) - self.threadLock = Lock() - self.name = name - self.thread_number = thread_number - self.namafile=os.path.join(os.path.dirname(__file__), namafile) - self.semaphore = semaphore - - def run(self): - print("\n"+str(self.thread_number)+". ---> " + self.name + "jalan") - print('mau menjalankan semaphore acquire untuk baca dan delete file') - self.threadLock.acquire() - self.semaphore.acquire() - print('melakukan baca file : '+self.namafile) - self.readfile() - print('melakukan rename file : '+self.namafile) - self.renamefile() - self.threadLock.release() - print("\n"+str(self.thread_number)+". ---> " + currentThread().getName() + "selesai") - - def readfile(self): - f = open(self.namafile, "r") - print("Isi Filenya : "+f.read()) - - def renamefile(self): - os.rename(self.namafile,self.namafile+'.croot') - -class rollyDua113040087 (Thread): - def __init__(self, name,thread_number,a,b ,namafile): - Thread.__init__(self) - self.threadLock = Lock() - self.semaphore = semaphore - self.rlock = RLock() - self.name = name - self.namafile=os.path.join(os.path.dirname(__file__), namafile) - self.thread_number = thread_number - self.a=a - self.b=b - - def run(self): - print("\n"+str(self.thread_number)+". ---> " + self.name + "jalan") - self.threadLock.acquire() - print("threeadlock acquire utama") - self.hitung() - self.threadLock.release() - print("\n"+str(self.thread_number)+". ---> " + currentThread().getName() + "selesai") - - def apipangkat(self): - with self.rlock: - print('didalam rlock apipangkat, akses web service...') - apiurl='https://api.mathjs.org/v4/?expr=' - eq=str(self.a)+'^'+str(self.b) - response = requests.get(apiurl+eq) - html=response.content.decode(response.encoding) - hasil = int(html) - print("hasil : "+str(hasil)) - self.createfile(hasil) - - def hitung(self): - with self.rlock: - print('rlock hitung') - self.apipangkat() - - def createfile(self,isi): - print('membuat file baru : '+ self.namafile) - f = open(self.namafile, "x") - f.write(str(isi)) - f.close() - print('sudah membuat file baru, mau relese semaphore') - self.semaphore.release() - print('di dalam Semaphore release, semaphore sudah di release') - - - - From e2e538285b9cf4110a46f54f71eb74fc9fd5565f Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 25 Mar 2021 19:53:22 +0700 Subject: [PATCH 026/164] tugas03 --- .vscode/launch.json | 15 +++++ Chapter02/WahyuKurniasariDua1184001.py | 87 ++++++++++++++++++++++++++ test_app.py | 17 ++++- 3 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 .vscode/launch.json create mode 100644 Chapter02/WahyuKurniasariDua1184001.py diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..17e15f2 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Python: Current File", + "type": "python", + "request": "launch", + "program": "${file}", + "console": "integratedTerminal" + } + ] +} \ No newline at end of file diff --git a/Chapter02/WahyuKurniasariDua1184001.py b/Chapter02/WahyuKurniasariDua1184001.py new file mode 100644 index 0000000..9348092 --- /dev/null +++ b/Chapter02/WahyuKurniasariDua1184001.py @@ -0,0 +1,87 @@ +from threading import Thread,currentThread, Lock, RLock, Semaphore +import requests +import os + +semaphore = Semaphore(0) + +class WahyuKurniaSariSemaphoreDeleteFile (Thread): + def __init__(self,name,threadNumber,filename): + Thread.__init__(self) + self.lock = Lock() + self.name = name + self.threadNumber = threadNumber + self.filename = filename + self.filelocation=os.path.join(os.path.dirname(__file__), filename) + self.semaphore = semaphore + + def run(self): + print("\n"+str(self.threadNumber)+". menjalankan " + self.name ) + self.lock.acquire() + self.readAndRename() + self.lock.release() + print("\n"+str(self.threadNumber)+". " + currentThread().getName() + " selesai") + + def readAndRename(self): + self.semaphore.acquire() + self.renamefile() + + def renamefile(self): + os.rename(self.filelocation,self.filelocation+'.txt') + +class WahyuKurniaSariDua1184001 (Thread): + def __init__(self, name,threadNumber, pokemon,filename): + Thread.__init__(self) + self.lock = Lock() + self.semaphore = semaphore + self.rlock = RLock() + self.name = name + self.pokemon = pokemon + self.filename = filename + self.filelocation=os.path.join(os.path.dirname(__file__), filename) + self.threadNumber = threadNumber + + def run(self): + print("\n"+str(self.threadNumber)+". menjalankan " + self.name ) + self.lock.acquire() + self.getWeight() + self.lock.release() + print("\n"+str(self.threadNumber)+". " + currentThread().getName() + " selesai") + + def getWeight(self): + with self.rlock: + print("mencari pokemon : " + self.pokemon) + apiurl='https://pokeapi.co/api/v2/pokemon/'+self.pokemon + response = requests.get(apiurl) + try: + html=response.json() + hasil = html["weight"] + print(self.pokemon+" ditemukan, pokemon ini memiliki berat "+ str(hasil)) + except: + print(self.pokemon+" tidak ditemukan") + hasil = "0" + self.createFile(hasil) + self.readFile() + + def readFile(self): + f = open(self.filelocation, "r") + print("Isi Filenya : "+f.read()) + self.semaphore.release() + + def createFile(self,isi): + print('membuat file baru "'+ self.filename +'"') + f = open(self.filelocation, "x") + f.write(str(isi)) + f.close() + + + def getFileLocation(self): + return self.filelocation+".txt" + + def getFileContent(self): + f = open(self.filelocation+".txt", "r") + return int(f.read()) + + + + + diff --git a/test_app.py b/test_app.py index 9556003..f322938 100644 --- a/test_app.py +++ b/test_app.py @@ -84,4 +84,19 @@ def test_02_hanif_1184058(self): def test_02_parhan_1184042(self): from Chapter02.Parhan1184042 import main response = main() - self.assertEqual(response, True) \ No newline at end of file + self.assertEqual(response, True) + + def test_03_WahyuKurniaSariDua1184001(self): + from Chapter02.WahyuKurniasariDua1184001 import WahyuKurniaSariSemaphoreDeleteFile, WahyuKurniaSariDua1184001 + delete = WahyuKurniaSariSemaphoreDeleteFile("Thread delete", 1,"pikachu") + main = WahyuKurniaSariDua1184001("Thread utama", 2,"pikachu", "pikachu") + delete.start() + main.start() + delete.join() + main.join() + self.assertGreaterEqual(main.getFileContent(),0 ) + + + + + \ No newline at end of file From 7ff8854bc7b05a40e0f03e0d02e90fab899e3189 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 25 Mar 2021 19:55:32 +0700 Subject: [PATCH 027/164] tugas03 --- .vscode/launch.json | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 17e15f2..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": "Python: Current File", - "type": "python", - "request": "launch", - "program": "${file}", - "console": "integratedTerminal" - } - ] -} \ No newline at end of file From 8895115489815d30fcd66b4f18de0950a74331a0 Mon Sep 17 00:00:00 2001 From: ravirahmatulfajri Date: Fri, 26 Mar 2021 01:31:52 +0700 Subject: [PATCH 028/164] Ravi 1184040 --- Chapter02/raviDua1184040.py | 2 +- test_app.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Chapter02/raviDua1184040.py b/Chapter02/raviDua1184040.py index d88b32b..96dbe37 100644 --- a/Chapter02/raviDua1184040.py +++ b/Chapter02/raviDua1184040.py @@ -27,7 +27,7 @@ def run(self): print("\n"+str(self.thread_number)+". ---> " + currentThread().getName() + "selesai") #threaddelete= raviSemaphoreDeleteFile Selesai (14) def readfile(self): - f = open(self.namafile, "r") #r = membuka file untuk dibaca (default). + f = open(self.namafile, "r") #r / read = membuka file untuk dibaca (default) f.read(2) #Metode read(n) berfungsi untuk membaca sebanyak n karakter print("menampilkan dua angka terakhir 3125: "+f.read()) # (12) diff --git a/test_app.py b/test_app.py index 4d75ae8..147ffac 100644 --- a/test_app.py +++ b/test_app.py @@ -79,7 +79,7 @@ def tearDown(self): # def test_02_hanif_1184058(self): # from Chapter02.Hanif1184058 import main # response = main() - # self.assertEqual(response, True) + # self.assertEqual(response, True) # # def test_02_parhan_1184042(self): # from Chapter02.Parhan1184042 import main From 32cd86ee1c715953f967169960f52ef2b64041f1 Mon Sep 17 00:00:00 2001 From: ravirahmatulfajri Date: Fri, 26 Mar 2021 02:18:37 +0700 Subject: [PATCH 029/164] Ravi 1184040 --- .gitignore | 3 +++ Chapter02/raviDua1184040.py | 2 +- test_app.py | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index e97c977..f5c5750 100644 --- a/.gitignore +++ b/.gitignore @@ -128,3 +128,6 @@ dmypy.json # Pyre type checker .pyre/ + +# +*.croot \ No newline at end of file diff --git a/Chapter02/raviDua1184040.py b/Chapter02/raviDua1184040.py index 96dbe37..9af5c20 100644 --- a/Chapter02/raviDua1184040.py +++ b/Chapter02/raviDua1184040.py @@ -27,7 +27,7 @@ def run(self): print("\n"+str(self.thread_number)+". ---> " + currentThread().getName() + "selesai") #threaddelete= raviSemaphoreDeleteFile Selesai (14) def readfile(self): - f = open(self.namafile, "r") #r / read = membuka file untuk dibaca (default) + f = open(self.namafile, "r") #r / read = membuka file untuk dibaca (default). f.read(2) #Metode read(n) berfungsi untuk membaca sebanyak n karakter print("menampilkan dua angka terakhir 3125: "+f.read()) # (12) diff --git a/test_app.py b/test_app.py index 147ffac..58d4856 100644 --- a/test_app.py +++ b/test_app.py @@ -79,7 +79,7 @@ def tearDown(self): # def test_02_hanif_1184058(self): # from Chapter02.Hanif1184058 import main # response = main() - # self.assertEqual(response, True) # + # self.assertEqual(response, True) # def test_02_parhan_1184042(self): # from Chapter02.Parhan1184042 import main From d3a6053cbf43ad857b2a2e7d7ea5d210c9edc7dc Mon Sep 17 00:00:00 2001 From: zanwar Date: Fri, 26 Mar 2021 02:44:39 +0700 Subject: [PATCH 030/164] Update Tugas3 DS --- Chapter02/ZanwarDua1184050.py | 91 +++++++++++++++++++++++++++++++++++ test_app.py | 62 ++++++++++++++++-------- 2 files changed, 133 insertions(+), 20 deletions(-) create mode 100644 Chapter02/ZanwarDua1184050.py diff --git a/Chapter02/ZanwarDua1184050.py b/Chapter02/ZanwarDua1184050.py new file mode 100644 index 0000000..fcfe3a6 --- /dev/null +++ b/Chapter02/ZanwarDua1184050.py @@ -0,0 +1,91 @@ +from threading import Thread,currentThread, Lock, RLock, Semaphore +import requests +import os + +semaphore = Semaphore(0) +hasilperhitungan=0 + +class zanwarSemaphoreRewriteFile (Thread): + def __init__(self,name,thread_number,filename): + Thread.__init__(self) + self.threadLock = Lock() + self.name = name + self.thread_number = thread_number + self.filename=os.path.join(os.path.dirname(__file__), filename) + self.semaphore = semaphore + + def run(self): + print("\n"+str(self.thread_number)+". ---> " + self.name + "start.") + print('semaphore acquire') + self.threadLock.acquire() + self.semaphore.acquire() + print('read file : '+self.filename) + self.readfile() + print('rewrite : '+self.filename) + self.rewritefile() + self.threadLock.release() + print("\n"+str(self.thread_number)+". ---> " + currentThread().getName() + "end") + + def readfile(self): + f = open(self.filename, "r") + print("File's Content is : \n "+f.read()) + + def rewritefile(self): + f = open(self.filename, "r") + fd = open(self.filename+'.txt', "w") + for line in f: + fd.write(line.replace('Angka', 'Nomor')) + fr = open(self.filename+'.txt', "r") + print(fr.read()) + + +class ZanwarDua1184050 (Thread): + def __init__(self, name,thread_number,a,b ,filename): + Thread.__init__(self) + self.threadLock = Lock() + self.semaphore = semaphore + self.rlock = RLock() + self.name = name + self.filename=os.path.join(os.path.dirname(__file__), filename) + self.thread_number = thread_number + self.a=a + self.b=b + + def run(self): + print("\n"+str(self.thread_number)+". ---> " + self.name + "start.") + self.threadLock.acquire() + print("main threadlock acquire") + self.count() + self.threadLock.release() + print("\n"+str(self.thread_number)+". ---> " + currentThread().getName() + "finish.") + + def apicount(self): + with self.rlock: + print('Inside rlock apipangkat, akses web service...') + apiurl='https://api.mathjs.org/v4/?expr=' + eq=str(self.a)+'*'+str(self.b) + response = requests.get(apiurl+eq) + html=response.content.decode(response.encoding) + hasil = int(html) + string = "Angka : " + i = 1 + while i <= hasil: + string = string+str(i) + i = i +1 + self.createfile(string) + x = open(self.filename, "r") + print(x.read()) + + def count(self): + with self.rlock: + self.apicount() + + def createfile(self,isi): + print('Create File : '+ self.filename) + f = open(self.filename, "w") + f.write(str(isi)) + f.close() + print('Create File > Semaphore release') + self.semaphore.release() + print('Semaphore released.') + \ No newline at end of file diff --git a/test_app.py b/test_app.py index 9556003..5d51860 100644 --- a/test_app.py +++ b/test_app.py @@ -61,27 +61,49 @@ def tearDown(self): # response = main() # self.assertEqual(response, True) - def test_02_alif_1184068(self): - from Chapter02.Alif1184068 import main - response = main() - self.assertEqual(response, True) + #def test_02_alif_1184068(self): + # from Chapter02.Alif1184068 import main + # response = main() + # self.assertEqual(response, True) - def test_02_iradwita_1184024(self): - from Chapter02.IraDwita1184024 import main - response = main() - self.assertEqual(response, True) + #def test_02_iradwita_1184024(self): + # from Chapter02.IraDwita1184024 import main + # response = main() + # self.assertEqual(response, True) - def test_02_bahar_1184002(self): - from Chapter02.baharandili1184002 import main - response = main() - self.assertEqual(response, True) + #def test_02_bahar_1184002(self): + # from Chapter02.baharandili1184002 import main + # response = main() + # self.assertEqual(response, True) - def test_02_hanif_1184058(self): - from Chapter02.Hanif1184058 import main - response = main() - self.assertEqual(response, True) + #def test_02_hanif_1184058(self): + # from Chapter02.Hanif1184058 import main + # response = main() + # self.assertEqual(response, True) - def test_02_parhan_1184042(self): - from Chapter02.Parhan1184042 import main - response = main() - self.assertEqual(response, True) \ No newline at end of file + #def test_02_parhan_1184042(self): + # from Chapter02.Parhan1184042 import main + # response = main() + # self.assertEqual(response, True) + + def readfile(self,filename): + f = open(filename, "r") + return str(f.read()) + + def test_03_zanwarDua1184050(self): + from Chapter02.ZanwarDua1184050 import ZanwarDua1184050,zanwarSemaphoreRewriteFile + threadrewrite= zanwarSemaphoreRewriteFile("Thread Rewrite File ", 1,'nilai') + threadutama = ZanwarDua1184050("Thread Utama ", 2,2,5,'nilai') + threadrewrite.start() + threadutama.start() + threadrewrite.join() + threadutama.join() + respon=self.readfile('./Chapter02/nilai.txt') + self.assertRegex(respon, "Nomor : 12345678910") + + + + + + + \ No newline at end of file From 7379266327a1bd6b153fc191890a0ed98a286570 Mon Sep 17 00:00:00 2001 From: ravirahmatulfajri Date: Fri, 26 Mar 2021 03:34:02 +0700 Subject: [PATCH 031/164] Ravi 1184040 --- .gitignore | 5 ++++- Chapter02/raviDua1184040.py | 2 +- test_app.py | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index f5c5750..7af0c7f 100644 --- a/.gitignore +++ b/.gitignore @@ -130,4 +130,7 @@ dmypy.json .pyre/ # -*.croot \ No newline at end of file +*.croot +ani.croot +anu.croot +ano.croot \ No newline at end of file diff --git a/Chapter02/raviDua1184040.py b/Chapter02/raviDua1184040.py index 9af5c20..2eb2ef7 100644 --- a/Chapter02/raviDua1184040.py +++ b/Chapter02/raviDua1184040.py @@ -71,7 +71,7 @@ def hitung(self): self.apipangkat() def createfile(self,isi): - print('membuat file baru : '+ self.namafile) #Selanjutnya ini (8) + print('membuat file baru : '+ self.namafile) #Selanjutnya yang ini (8) f = open(self.namafile, "w") #Membuka file untuk ditulis., Membuat file baru jika file belum tersedia atau menimpa isi file jika file sudah ada f.write(str(isi)) f.close() diff --git a/test_app.py b/test_app.py index 58d4856..147ffac 100644 --- a/test_app.py +++ b/test_app.py @@ -79,7 +79,7 @@ def tearDown(self): # def test_02_hanif_1184058(self): # from Chapter02.Hanif1184058 import main # response = main() - # self.assertEqual(response, True) + # self.assertEqual(response, True) # # def test_02_parhan_1184042(self): # from Chapter02.Parhan1184042 import main From 48f7f49411f6c8a272be35894199f9d1632fd171 Mon Sep 17 00:00:00 2001 From: zanwar Date: Fri, 26 Mar 2021 03:34:39 +0700 Subject: [PATCH 032/164] Update Tugas3 DS --- Chapter02/ZanwarDua1184050.py | 2 +- test_app.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Chapter02/ZanwarDua1184050.py b/Chapter02/ZanwarDua1184050.py index fcfe3a6..e8c1dc7 100644 --- a/Chapter02/ZanwarDua1184050.py +++ b/Chapter02/ZanwarDua1184050.py @@ -39,7 +39,7 @@ def rewritefile(self): print(fr.read()) -class ZanwarDua1184050 (Thread): +class zanwarDua1184050 (Thread): def __init__(self, name,thread_number,a,b ,filename): Thread.__init__(self) self.threadLock = Lock() diff --git a/test_app.py b/test_app.py index 5d51860..4be4465 100644 --- a/test_app.py +++ b/test_app.py @@ -91,9 +91,9 @@ def readfile(self,filename): return str(f.read()) def test_03_zanwarDua1184050(self): - from Chapter02.ZanwarDua1184050 import ZanwarDua1184050,zanwarSemaphoreRewriteFile + from Chapter02.ZanwarDua1184050 import zanwarDua1184050,zanwarSemaphoreRewriteFile threadrewrite= zanwarSemaphoreRewriteFile("Thread Rewrite File ", 1,'nilai') - threadutama = ZanwarDua1184050("Thread Utama ", 2,2,5,'nilai') + threadutama = zanwarDua1184050("Thread Utama ", 2,2,5,'nilai') threadrewrite.start() threadutama.start() threadrewrite.join() From f6d477a150475977c68fed70b7505e310bc6a596 Mon Sep 17 00:00:00 2001 From: zanwar Date: Fri, 26 Mar 2021 03:50:27 +0700 Subject: [PATCH 033/164] Update Tugas3 DS --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index f68adf4..55f9a52 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ +requests pytest-cov \ No newline at end of file From 7570f6b06291197f8fd739c1e74657f3d7fec14b Mon Sep 17 00:00:00 2001 From: ravirahmatulfajri Date: Fri, 26 Mar 2021 03:50:48 +0700 Subject: [PATCH 034/164] Ravi 1184040 --- .gitignore | 2 +- Chapter02/raviDua1184040.py | 2 +- test_app.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 7af0c7f..6d1244e 100644 --- a/.gitignore +++ b/.gitignore @@ -129,7 +129,7 @@ dmypy.json # Pyre type checker .pyre/ -# +# Croot *.croot ani.croot anu.croot diff --git a/Chapter02/raviDua1184040.py b/Chapter02/raviDua1184040.py index 2eb2ef7..8995d77 100644 --- a/Chapter02/raviDua1184040.py +++ b/Chapter02/raviDua1184040.py @@ -72,7 +72,7 @@ def hitung(self): def createfile(self,isi): print('membuat file baru : '+ self.namafile) #Selanjutnya yang ini (8) - f = open(self.namafile, "w") #Membuka file untuk ditulis., Membuat file baru jika file belum tersedia atau menimpa isi file jika file sudah ada + f = open(self.namafile, "w") #Membuka file untuk ditulis. Membuat file baru jika file belum tersedia atau menimpa isi file jika file sudah ada f.write(str(isi)) f.close() print('sudah membuat file baru, mau relese semaphore') #Lanjut (9) diff --git a/test_app.py b/test_app.py index 147ffac..58d4856 100644 --- a/test_app.py +++ b/test_app.py @@ -79,7 +79,7 @@ def tearDown(self): # def test_02_hanif_1184058(self): # from Chapter02.Hanif1184058 import main # response = main() - # self.assertEqual(response, True) # + # self.assertEqual(response, True) # def test_02_parhan_1184042(self): # from Chapter02.Parhan1184042 import main From d37594be50e2d6c3b33a3625bab94a52e42e6e6a Mon Sep 17 00:00:00 2001 From: ravirahmatulfajri Date: Fri, 26 Mar 2021 07:01:29 +0700 Subject: [PATCH 035/164] Ravi 1184040 --- Chapter02/raviDua1184040.py | 2 +- test_app.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Chapter02/raviDua1184040.py b/Chapter02/raviDua1184040.py index 8995d77..8139655 100644 --- a/Chapter02/raviDua1184040.py +++ b/Chapter02/raviDua1184040.py @@ -72,7 +72,7 @@ def hitung(self): def createfile(self,isi): print('membuat file baru : '+ self.namafile) #Selanjutnya yang ini (8) - f = open(self.namafile, "w") #Membuka file untuk ditulis. Membuat file baru jika file belum tersedia atau menimpa isi file jika file sudah ada + f = open(self.namafile, "w") #Membuka file untuk ditulis,. Membuat file baru jika file belum tersedia atau menimpa isi file jika file sudah ada f.write(str(isi)) f.close() print('sudah membuat file baru, mau relese semaphore') #Lanjut (9) diff --git a/test_app.py b/test_app.py index 58d4856..147ffac 100644 --- a/test_app.py +++ b/test_app.py @@ -79,7 +79,7 @@ def tearDown(self): # def test_02_hanif_1184058(self): # from Chapter02.Hanif1184058 import main # response = main() - # self.assertEqual(response, True) + # self.assertEqual(response, True) # # def test_02_parhan_1184042(self): # from Chapter02.Parhan1184042 import main From b27ddd57ff992a9fe33bba0635336db7c300f9a3 Mon Sep 17 00:00:00 2001 From: zanwar Date: Fri, 26 Mar 2021 09:59:28 +0700 Subject: [PATCH 036/164] update api --- Chapter02/ZanwarDua1184050.py | 21 +++++++++++---------- test_app.py | 8 ++++---- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/Chapter02/ZanwarDua1184050.py b/Chapter02/ZanwarDua1184050.py index e8c1dc7..2ef54d8 100644 --- a/Chapter02/ZanwarDua1184050.py +++ b/Chapter02/ZanwarDua1184050.py @@ -5,7 +5,7 @@ semaphore = Semaphore(0) hasilperhitungan=0 -class zanwarSemaphoreRewriteFile (Thread): +class zanwarRewrite (Thread): def __init__(self,name,thread_number,filename): Thread.__init__(self) self.threadLock = Lock() @@ -19,11 +19,11 @@ def run(self): print('semaphore acquire') self.threadLock.acquire() self.semaphore.acquire() - print('read file : '+self.filename) - self.readfile() print('rewrite : '+self.filename) self.rewritefile() self.threadLock.release() + print("Read setelah rewrite") + self.readfile() print("\n"+str(self.thread_number)+". ---> " + currentThread().getName() + "end") def readfile(self): @@ -34,7 +34,7 @@ def rewritefile(self): f = open(self.filename, "r") fd = open(self.filename+'.txt', "w") for line in f: - fd.write(line.replace('Angka', 'Nomor')) + fd.write(line.replace('Angka : ', '')) fr = open(self.filename+'.txt', "r") print(fr.read()) @@ -59,12 +59,13 @@ def run(self): self.threadLock.release() print("\n"+str(self.thread_number)+". ---> " + currentThread().getName() + "finish.") - def apicount(self): + def randomapi(self): with self.rlock: print('Inside rlock apipangkat, akses web service...') - apiurl='https://api.mathjs.org/v4/?expr=' - eq=str(self.a)+'*'+str(self.b) - response = requests.get(apiurl+eq) + apiurl='https://www.random.org/integers/?num=1&' + eq='min='+str(self.a)+'&max='+str(self.b) + form = '&col=1&base=10&format=plain&rnd=new' + response = requests.get(apiurl+eq+form) html=response.content.decode(response.encoding) hasil = int(html) string = "Angka : " @@ -78,14 +79,14 @@ def apicount(self): def count(self): with self.rlock: - self.apicount() + self.randomapi() def createfile(self,isi): print('Create File : '+ self.filename) f = open(self.filename, "w") f.write(str(isi)) f.close() - print('Create File > Semaphore release') + print('Create File') self.semaphore.release() print('Semaphore released.') \ No newline at end of file diff --git a/test_app.py b/test_app.py index 4be4465..717ad35 100644 --- a/test_app.py +++ b/test_app.py @@ -88,18 +88,18 @@ def tearDown(self): def readfile(self,filename): f = open(filename, "r") - return str(f.read()) + return int(f.read()) def test_03_zanwarDua1184050(self): - from Chapter02.ZanwarDua1184050 import zanwarDua1184050,zanwarSemaphoreRewriteFile - threadrewrite= zanwarSemaphoreRewriteFile("Thread Rewrite File ", 1,'nilai') + from Chapter02.ZanwarDua1184050 import zanwarDua1184050,zanwarRewrite + threadrewrite= zanwarRewrite("Thread Rewrite File ", 1,'nilai') threadutama = zanwarDua1184050("Thread Utama ", 2,2,5,'nilai') threadrewrite.start() threadutama.start() threadrewrite.join() threadutama.join() respon=self.readfile('./Chapter02/nilai.txt') - self.assertRegex(respon, "Nomor : 12345678910") + self.assertGreaterEqual(respon, 0) From c23ae6f26bbc31a37d980eec1d479921f0dd0211 Mon Sep 17 00:00:00 2001 From: ravirahmatulfajri Date: Fri, 26 Mar 2021 10:06:31 +0700 Subject: [PATCH 037/164] Tugas 3 --- .gitignore | 4 +- Chapter02/ani.croot | 1 - Chapter02/ano.croot | 1 - Chapter02/anu.croot | 1 - Chapter02/raviDua1184040.py | 97 ++++++++++++++++++++----------------- test_app.py | 76 ++++++++++++++--------------- 6 files changed, 92 insertions(+), 88 deletions(-) delete mode 100644 Chapter02/ani.croot delete mode 100644 Chapter02/ano.croot delete mode 100644 Chapter02/anu.croot diff --git a/.gitignore b/.gitignore index 6d1244e..073f3dc 100644 --- a/.gitignore +++ b/.gitignore @@ -133,4 +133,6 @@ dmypy.json *.croot ani.croot anu.croot -ano.croot \ No newline at end of file +ano.croot +nilai.html +nilai \ No newline at end of file diff --git a/Chapter02/ani.croot b/Chapter02/ani.croot deleted file mode 100644 index 26d3ca9..0000000 --- a/Chapter02/ani.croot +++ /dev/null @@ -1 +0,0 @@ -3125 \ No newline at end of file diff --git a/Chapter02/ano.croot b/Chapter02/ano.croot deleted file mode 100644 index 26d3ca9..0000000 --- a/Chapter02/ano.croot +++ /dev/null @@ -1 +0,0 @@ -3125 \ No newline at end of file diff --git a/Chapter02/anu.croot b/Chapter02/anu.croot deleted file mode 100644 index 26d3ca9..0000000 --- a/Chapter02/anu.croot +++ /dev/null @@ -1 +0,0 @@ -3125 \ No newline at end of file diff --git a/Chapter02/raviDua1184040.py b/Chapter02/raviDua1184040.py index 8139655..7dfbeb7 100644 --- a/Chapter02/raviDua1184040.py +++ b/Chapter02/raviDua1184040.py @@ -5,80 +5,87 @@ semaphore = Semaphore(0) hasilperhitungan=0 -class raviSemaphoreDeleteFile (Thread): - def __init__(self,name,thread_number,namafile): +class raviSemaphorewriteFile (Thread): + def __init__(self,name,threadId,nfile): Thread.__init__(self) self.threadLock = Lock() self.name = name - self.thread_number = thread_number - self.namafile=os.path.join(os.path.dirname(__file__), namafile) + self.threadId = threadId + self.nfile=os.path.join(os.path.dirname(__file__), nfile) self.semaphore = semaphore def run(self): - print("\n"+str(self.thread_number)+". ---> " + self.name + "jalan") #baris baru, yang pertama (1) jalan, method raviSemaphoreDeleteFile memanggil dari test_app.py - print('mau menjalankan semaphore acquire untuk baca dan delete file') #selanjutnya (2) yang dijalankan + print("\n"+str(self.threadId)+". ---> " + self.name + "Mulai ya") + print('mau menjalankan semaphore acquire untuk baca dan tulis, buat ulang file') self.threadLock.acquire() self.semaphore.acquire() - print('melakukan baca file : '+self.namafile) # (11) + print('baca file dong : '+self.nfile) self.readfile() - print('melakukan rename file : '+self.namafile) # (13.1) bersamaan dengan Thread utama selesai - self.renamefile() + print('Tulis dan buat ulang file dong : '+self.nfile) + self.writefile() self.threadLock.release() - print("\n"+str(self.thread_number)+". ---> " + currentThread().getName() + "selesai") #threaddelete= raviSemaphoreDeleteFile Selesai (14) - + print("\n"+str(self.threadId)+". ---> " + currentThread().getName() + "Finish") + def readfile(self): - f = open(self.namafile, "r") #r / read = membuka file untuk dibaca (default). - f.read(2) #Metode read(n) berfungsi untuk membaca sebanyak n karakter - print("menampilkan dua angka terakhir 3125: "+f.read()) # (12) - - def renamefile(self): - os.rename(self.namafile,self.namafile+('.croot')) + f = open(self.nfile, "r+") + #f.read(20) #Metode read(n) berfungsi untuk membaca sebanyak n karakter + print("Tampilin angkanya dong biar kita tau : \n "+f.read()) + + def writefile(self): + f = open(self.nfile, "r+") + fd = open(self.nfile+'.html', "w") + for line in f: + fd.write(line.replace('Angka', 'Nomor')) + fr = open(self.nfile+'.html', "r+") + print(fr.read()) -class raviDua1184040 (Thread): - def __init__(self, name,thread_number,a,b ,namafile): + +class raviDua1184040(Thread): + def __init__(self, name,threadId,ravi,rahmatul ,nfile): Thread.__init__(self) self.threadLock = Lock() self.semaphore = semaphore self.rlock = RLock() self.name = name - self.namafile=os.path.join(os.path.dirname(__file__), namafile) - self.thread_number = thread_number - self.a=a - self.b=b + self.nfile=os.path.join(os.path.dirname(__file__), nfile) + self.threadId = threadId + self.ravi=ravi + self.rahmatul=rahmatul def run(self): - print("\n"+str(self.thread_number)+". ---> " + self.name + "jalan") #Setelah itu (3) raviDua1184040 jalan + print("\n"+str(self.threadId)+". ---> " + self.name + "Mulai aja ya") self.threadLock.acquire() - print("threeadlock acquire utama") #terus (4) - self.hitung() + print("ini threeadlock acquire utama") + self.count() self.threadLock.release() - print("\n"+str(self.thread_number)+". ---> " + currentThread().getName() + "selesai") #Thread Utama Selesai (13.1) threadutama = raviDua1184040 + print("\n"+str(self.threadId)+". ---> " + currentThread().getName() + "Finish") - def apipangkat(self): + def apicount(self): with self.rlock: - print('didalam rlock apipangkat, akses web service...') #Lanjut (6) kesini - apiurl='https://api.mathjs.org/v4/?expr=' - eq=str(self.a)+'^'+str(self.b) + print('Inside rlock apipangkat, akses web service...') + apiurl=' http://api.mathjs.org/v4/?expr=2%2B3*sqrt(4)' + eq=str(self.ravi)+'*'+str(self.rahmatul) response = requests.get(apiurl+eq) html=response.content.decode(response.encoding) hasil = int(html) - print("hasil : "+str(hasil)) #ini (7) - self.createfile(hasil) + string = "Angka : " + i = 1 + while i <= hasil: + string = string+str(i) + i = i +1 + self.createfile(string) + x = open(self.nfile, "r+") + print(x.read()) - def hitung(self): + def count(self): with self.rlock: - print('rlock hitung') #Setelah itu (5) - self.apipangkat() + self.apicount() def createfile(self,isi): - print('membuat file baru : '+ self.namafile) #Selanjutnya yang ini (8) - f = open(self.namafile, "w") #Membuka file untuk ditulis,. Membuat file baru jika file belum tersedia atau menimpa isi file jika file sudah ada - f.write(str(isi)) + print('Membuat file baru nih : '+ self.nfile) + f = open(self.nfile, "w") + f.write(str(isi)) f.close() - print('sudah membuat file baru, mau relese semaphore') #Lanjut (9) + print('Sudah di buat file baru-nya nih, SIAP-Siap ya, selanjutnya mau relese semaphore') self.semaphore.release() - print('di dalam Semaphore release, semaphore sudah di release') #Setelah itu (10) - - - - + print('di dalam Semaphore release tadi, semaphore sudah di release') \ No newline at end of file diff --git a/test_app.py b/test_app.py index 147ffac..2f01d40 100644 --- a/test_app.py +++ b/test_app.py @@ -61,49 +61,47 @@ def tearDown(self): # response = main() # self.assertEqual(response, True) -# def test_02_alif_1184068(self): -# from Chapter02.Alif1184068 import main -# response = main() - # self.assertEqual(response, True) + #def test_02_alif_1184068(self): + # from Chapter02.Alif1184068 import main + # response = main() + # self.assertEqual(response, True) -# def test_02_iradwita_1184024(self): -# from Chapter02.IraDwita1184024 import main -# response = main() - # self.assertEqual(response, True) + #def test_02_iradwita_1184024(self): + # from Chapter02.IraDwita1184024 import main + # response = main() + # self.assertEqual(response, True) - # def test_02_bahar_1184002(self): -# from Chapter02.baharandili1184002 import main - # response = main() - # self.assertEqual(response, True) + #def test_02_bahar_1184002(self): + # from Chapter02.baharandili1184002 import main + # response = main() + # self.assertEqual(response, True) - # def test_02_hanif_1184058(self): - # from Chapter02.Hanif1184058 import main - # response = main() - # self.assertEqual(response, True) # + #def test_02_hanif_1184058(self): + # from Chapter02.Hanif1184058 import main + # response = main() + # self.assertEqual(response, True) - # def test_02_parhan_1184042(self): - # from Chapter02.Parhan1184042 import main - # response = main() - # self.assertEqual(response, True) - # + #def test_02_parhan_1184042(self): + # from Chapter02.Parhan1184042 import main + # response = main() + # self.assertEqual(response, True) def test_02_ravi_1184040(self): - from Chapter02.Ravi1184040 import main - response = main() - self.assertEqual(response, True) - - - def readfile(self,namafile): - f = open(namafile, "r") - f.read(2) - return int(f.read()) - - def test_03_raviDua1184040(self): - from Chapter02.raviDua1184040 import raviDua1184040,raviSemaphoreDeleteFile - threaddelete= raviSemaphoreDeleteFile("Thread Delete File ", 1,'anu') - threadutama = raviDua1184040("Thread Utama ", 2,5,5,'anu') - threaddelete.start() + from Chapter02.Ravi1184040 import main + response = main() + self.assertEqual(response, True) + + def readfile(self,nfile): + f = open(nfile, "r+") + #f.read(20) + return str(f.read()) + + def test_03_raviDua1184050(self): + from Chapter02.raviDua1184040 import raviDua1184040,raviSemaphorewriteFile + threadwrite= raviSemaphorewriteFile("Thread write File ", 1,'nilai') + threadutama = raviDua1184040("Thread Utama ", 2,2,5,'nilai') + threadwrite.start() threadutama.start() - threaddelete.join() + threadwrite.join() threadutama.join() - respon=self.readfile('./Chapter02/anu.croot') - self.assertGreaterEqual(respon, 0) \ No newline at end of file + respon=self.readfile('./Chapter02/nilai.html') + self.assertRegex(respon, "Nomor : 12345678910") \ No newline at end of file From 8b5074839f34b6fb749c0cc526f7c53142de10d0 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 26 Mar 2021 10:27:10 +0700 Subject: [PATCH 038/164] tugaswahyukurnia03 --- test_app.py | 1 - 1 file changed, 1 deletion(-) diff --git a/test_app.py b/test_app.py index f322938..edfe046 100644 --- a/test_app.py +++ b/test_app.py @@ -98,5 +98,4 @@ def test_03_WahyuKurniaSariDua1184001(self): - \ No newline at end of file From 6192256761dba29edfa998240421941c824eb0f6 Mon Sep 17 00:00:00 2001 From: ravirahmatulfajri Date: Fri, 26 Mar 2021 10:43:06 +0700 Subject: [PATCH 039/164] Tugas 3 --- Chapter02/raviDua1184040.py | 2 +- test_app.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Chapter02/raviDua1184040.py b/Chapter02/raviDua1184040.py index 7dfbeb7..2bb6f78 100644 --- a/Chapter02/raviDua1184040.py +++ b/Chapter02/raviDua1184040.py @@ -28,7 +28,7 @@ def run(self): def readfile(self): f = open(self.nfile, "r+") - #f.read(20) #Metode read(n) berfungsi untuk membaca sebanyak n karakter + ##f.read(20) #Metode read(n) berfungsi untuk membaca sebanyak n karakter print("Tampilin angkanya dong biar kita tau : \n "+f.read()) def writefile(self): diff --git a/test_app.py b/test_app.py index 4f0d40e..fbe2824 100644 --- a/test_app.py +++ b/test_app.py @@ -108,7 +108,7 @@ def test_03_raviDua1184050(self): # def readfile(self,filename): # f = open(filename, "r") -# return int(f.read()) +# return int(f.read()) # # def test_03_zanwarDua1184050(self): # from Chapter02.ZanwarDua1184050 import zanwarDua1184050,zanwarRewrite From b4f03cc10d9d1031df5766ae53496f2d352db834 Mon Sep 17 00:00:00 2001 From: ravirahmatulfajri Date: Fri, 26 Mar 2021 11:25:42 +0700 Subject: [PATCH 040/164] Tugas 3 --- Chapter02/raviDua1184040.py | 10 +++++----- test_app.py | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Chapter02/raviDua1184040.py b/Chapter02/raviDua1184040.py index 2bb6f78..66b9590 100644 --- a/Chapter02/raviDua1184040.py +++ b/Chapter02/raviDua1184040.py @@ -33,11 +33,11 @@ def readfile(self): def writefile(self): f = open(self.nfile, "r+") - fd = open(self.nfile+'.html', "w") + fc = open(self.nfile+'.html', "w") for line in f: - fd.write(line.replace('Angka', 'Nomor')) - fr = open(self.nfile+'.html', "r+") - print(fr.read()) + fc.write(line.replace('Angka', 'Nomor')) + ff = open(self.nfile+'.html', "r+") + print(ff.read()) class raviDua1184040(Thread): @@ -70,7 +70,7 @@ def apicount(self): hasil = int(html) string = "Angka : " i = 1 - while i <= hasil: + for i in range(1, 11): string = string+str(i) i = i +1 self.createfile(string) diff --git a/test_app.py b/test_app.py index fbe2824..e8d7928 100644 --- a/test_app.py +++ b/test_app.py @@ -85,10 +85,10 @@ def tearDown(self): # from Chapter02.Parhan1184042 import main # response = main() # self.assertEqual(response, True) - def test_02_ravi_1184040(self): - from Chapter02.Ravi1184040 import main - response = main() - self.assertEqual(response, True) + #def test_02_ravi_1184040(self): + # from Chapter02.Ravi1184040 import main + # response = main() + # self.assertEqual(response, True) def readfile(self,nfile): f = open(nfile, "r+") From 034da768244eececaf1767c6192070dfe4b1af62 Mon Sep 17 00:00:00 2001 From: ravirahmatulfajri Date: Fri, 26 Mar 2021 11:45:16 +0700 Subject: [PATCH 041/164] Tugas 3 --- Chapter02/raviDua1184040.py | 2 +- test_app.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Chapter02/raviDua1184040.py b/Chapter02/raviDua1184040.py index 66b9590..1c9868c 100644 --- a/Chapter02/raviDua1184040.py +++ b/Chapter02/raviDua1184040.py @@ -15,7 +15,7 @@ def __init__(self,name,threadId,nfile): self.semaphore = semaphore def run(self): - print("\n"+str(self.threadId)+". ---> " + self.name + "Mulai ya") + print("\n"+str(self.threadId)+". ---> " + self.name + "Mulai ya!") print('mau menjalankan semaphore acquire untuk baca dan tulis, buat ulang file') self.threadLock.acquire() self.semaphore.acquire() diff --git a/test_app.py b/test_app.py index 08a16f6..2002049 100644 --- a/test_app.py +++ b/test_app.py @@ -137,12 +137,12 @@ def test_03_raviDua1184050(self): # main.join() # self.assertGreaterEqual(main.getFileContent(),0 ) -def readfile(self,nfile): + def readfile(self,nfile): f = open(nfile, "r+") #f.read(20) return str(f.read()) -def test_03_raviDua1184050(self): + def test_03_raviDua1184040(self): from Chapter02.raviDua1184040 import raviDua1184040,raviSemaphorewriteFile threadwrite= raviSemaphorewriteFile("Thread write File ", 1,'nilai') threadutama = raviDua1184040("Thread Utama ", 2,2,5,'nilai') From b2e863baf45d38294dc331cee3ad416c3f699bae Mon Sep 17 00:00:00 2001 From: ravirahmatulfajri Date: Fri, 26 Mar 2021 12:05:14 +0700 Subject: [PATCH 042/164] Method buat sendiri --- Chapter02/raviDua1184040.py | 2 +- test_app.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Chapter02/raviDua1184040.py b/Chapter02/raviDua1184040.py index 1c9868c..66ae5ab 100644 --- a/Chapter02/raviDua1184040.py +++ b/Chapter02/raviDua1184040.py @@ -28,7 +28,7 @@ def run(self): def readfile(self): f = open(self.nfile, "r+") - ##f.read(20) #Metode read(n) berfungsi untuk membaca sebanyak n karakter + ##f.read(20) #Metode read(n) berfungsi untuk membaca sebanyak n karakter. print("Tampilin angkanya dong biar kita tau : \n "+f.read()) def writefile(self): diff --git a/test_app.py b/test_app.py index 2002049..2906fad 100644 --- a/test_app.py +++ b/test_app.py @@ -133,7 +133,7 @@ def test_03_raviDua1184050(self): # main = WahyuKurniaSariDua1184001("Thread utama", 2,"pikachu", "pikachu") # delete.start() # main.start() -# delete.join() +# delete.join() # # main.join() # self.assertGreaterEqual(main.getFileContent(),0 ) From 04ed8d449f4ff21f81ae92f2df65f09237901123 Mon Sep 17 00:00:00 2001 From: josua1111 Date: Fri, 26 Mar 2021 13:44:31 +0700 Subject: [PATCH 043/164] Tugas 3 Josuansef Pardede 1184091 --- Chapter02/JosuansefDua_1184091.py | 97 ++++++++++++++++++++++++++++++ test_app.py | 99 ++++++++++++++++--------------- 2 files changed, 148 insertions(+), 48 deletions(-) create mode 100644 Chapter02/JosuansefDua_1184091.py diff --git a/Chapter02/JosuansefDua_1184091.py b/Chapter02/JosuansefDua_1184091.py new file mode 100644 index 0000000..c44d621 --- /dev/null +++ b/Chapter02/JosuansefDua_1184091.py @@ -0,0 +1,97 @@ +from threading import Thread, currentThread, Lock, RLock, Semaphore +import requests + +import os +import glob +import json + +class josua1184091Arrangement (Thread): + files_list = glob.glob("*") +#Membuat satu set tipe ekstensi didalam folder untuk menghindari duplikasi file yang masuk +#menambahkan setiap tipe ekstensi ke satu set +for file in files_list: + extension = file.split(sep=".") + try: + extension_set.add(extension[1]) + except IndexError: + continue + +#print(extension_set) + +#Fungsi untuk membuat direktori untuk setiap ekstensi yang berbeda +def createDirs(): + for dir in extension_set: + try: + os.makedirs(dir+"_files") + except FileExistsError: + continue + +#Fungsi untuk memindahkan file file ke folder masing-masing berdasarkan ekstensinya +def arrange(): + for file in files_list: + fextension = file.split(sep=".") + try: + os.rename(file, fextension[1]+"_files/"+file) + except (OSError, IndexError): + continue + +#memanggil fungsinya +createDirs() +arrange() + + class josua1184091Api (Thread): + def __init__(self, nama,thread_number,filenya, bravo, delta): + Thread.__init__(self) + self.threadLock = Lock() + self.semaphore = semaphore + self.rlock = RLock() + self.nama = nama + self.filenya=os.path.join(os.path.dirname(__file__), filenya) + self.thread_number = thread_number + self.bravo=bravo + self.delta=delta + + def jalankan(self): + print("\n"+str(self.thread_number)+". ---> " + self.nama + "run") + self.threadLock.acquire() + + print("ini adalah threadlock aqcuire") + self.kalkulasi() + + self.threadLock.release() + + print("\n"+str(self.thread_number)+". ---> " + currentThread().getName() + "yoi beres") + + + + def fungsiapi(self): + with self.rlock: + + api_url='https://api.twitter.com/1.1/followers/list.json' + + print('Mengakses fungsi api web service dari twitter untuk mengambil view list follower yang ada pada username twitter saya josh0018 pada Rlock') + + eq=str(self.bravo)+'^'+str(self.delta) + response = requests.get(api_url+eq) + html=response.content.decode(response.encoding) + hasil = int(html) + print("result : "+str(result)) + self.createfile(result) + + def kalkulasi(self): + with self.rlock: + self.fungsiapi() + print('mengkalkulasi Rlock') + + def buatfile(self,konten): + print('buat file : '+ self.filenya) + f = open(self.filenya, "x") + f.write(str(konten)) + f.close() + print('sudah membuat file baru, mau relese semaphore') + self.semaphore.release() + print('di dalam Semaphore release, semaphore sudah di release') + + + + diff --git a/test_app.py b/test_app.py index 8107811..9bbc0c0 100644 --- a/test_app.py +++ b/test_app.py @@ -61,36 +61,32 @@ def tearDown(self): # from Chapter02.IrfanHernandez1184014 import main # response = main() # self.assertEqual(response, True) -<<<<<<< HEAD - - def test_02_josua_1184091(self): - from Chapter02.josua_1184091 import main - response = main() - self.assertEqual(response, True) -======= - def test_02_rolly_113040087(self): - from Chapter02.Rolly113040087 import main - response = main() - self.assertEqual(response, True) + + #def test_02_josua_1184091(self): + #from Chapter02.josua_1184091 import main + # response = main() + #self.assertEqual(response, True) + + # def test_02_rolly_113040087(self): + # from Chapter02.Rolly113040087 import main + # response = main() + # self.assertEqual(response, True) - def readfile(self,namafile): - f = open(namafile, "r") - return int(f.read()) + #def readfile(self,namafile): + # f = open(namafile, "r") + # return int(f.read()) - def test_03_rollyDua113040087(self): - from Chapter02.rollyDua113040087 import rollyDua113040087,rollySemaphoreDeleteFile - threaddelete= rollySemaphoreDeleteFile("Thread Delete File ", 1,'anu') - threadutama = rollyDua113040087("Thread Utama ", 2,5,5,'anu') - threaddelete.start() - threadutama.start() - threaddelete.join() - threadutama.join() - respon=self.readfile('./Chapter02/anu.croot') - self.assertGreaterEqual(respon, 0) + # def test_03_rollyDua113040087(self): + # from Chapter02.rollyDua113040087 import rollyDua113040087,rollySemaphoreDeleteFile + # threaddelete= rollySemaphoreDeleteFile("Thread Delete File ", 1,'anu') + # threadutama = rollyDua113040087("Thread Utama ", 2,5,5,'anu') + #threaddelete.start() + #threadutama.start() + #threaddelete.join() + #threadutama.join() + #respon=self.readfile('./Chapter02/anu.croot') + #self.assertGreaterEqual(respon, 0) - ->>>>>>> a6ae71262e263e401dde92eb13edffb6399aaf2c -======= #def test_02_alif_1184068(self): # from Chapter02.Alif1184068 import main @@ -121,29 +117,36 @@ def readfile(self,filename): f = open(filename, "r") return int(f.read()) - def test_03_zanwarDua1184050(self): - from Chapter02.ZanwarDua1184050 import zanwarDua1184050,zanwarRewrite - threadrewrite= zanwarRewrite("Thread Rewrite File ", 1,'nilai') - threadutama = zanwarDua1184050("Thread Utama ", 2,2,5,'nilai') - threadrewrite.start() + #def test_03_zanwarDua1184050(self): + #from Chapter02.ZanwarDua1184050 import zanwarDua1184050,zanwarRewrite + #threadrewrite= zanwarRewrite("Thread Rewrite File ", 1,'nilai') + #threadutama = zanwarDua1184050("Thread Utama ", 2,2,5,'nilai') + #threadrewrite.start() + #threadutama.start() + #threadrewrite.join() + # threadutama.join() + #respon=self.readfile('./Chapter02/nilai.txt') + #self.assertGreaterEqual(respon, 0) + + #def test_03_WahyuKurniaSariDua1184001(self): + #from Chapter02.WahyuKurniasariDua1184001 import WahyuKurniaSariSemaphoreDeleteFile, WahyuKurniaSariDua1184001 + #delete = WahyuKurniaSariSemaphoreDeleteFile("Thread delete", 1,"pikachu") + #main = WahyuKurniaSariDua1184001("Thread utama", 2,"pikachu", "pikachu") + #delete.start() + #main.start() + #delete.join() + #main.join() + # self.assertGreaterEqual(main.getFileContent(),0 ) + + def test_03_JosuaDua1184091(self): + from Chapter02.JosuansefDua_1184091 import josua1184091Arrangement,josua1184091Api + threadarrangement= josua1184091Api("Thread api file ", 1,'nilai') + threadutama = josua1184091Arrangement ("Thread Utama arrangement file ", 2,2,5,'arrangement') + threadarrangement.start() threadutama.start() - threadrewrite.join() + threadarrangement.join() threadutama.join() - respon=self.readfile('./Chapter02/nilai.txt') + respon=self.readfile('./Chapter02/arrangement.txt') self.assertGreaterEqual(respon, 0) - - def test_03_WahyuKurniaSariDua1184001(self): - from Chapter02.WahyuKurniasariDua1184001 import WahyuKurniaSariSemaphoreDeleteFile, WahyuKurniaSariDua1184001 - delete = WahyuKurniaSariSemaphoreDeleteFile("Thread delete", 1,"pikachu") - main = WahyuKurniaSariDua1184001("Thread utama", 2,"pikachu", "pikachu") - delete.start() - main.start() - delete.join() - main.join() - self.assertGreaterEqual(main.getFileContent(),0 ) - - - ->>>>>>> 60f18dd1952f6263522b91910916fe889e8e682f From f1f0c37bbd5ba7817ee6b4a3075daa236dae9e62 Mon Sep 17 00:00:00 2001 From: josua1111 Date: Fri, 26 Mar 2021 14:12:04 +0700 Subject: [PATCH 044/164] Tugas 3 Josuansef Pardede 1184091 --- Chapter02/JosuansefDua_1184091.py | 58 ++++++++++++++----------------- test_app.py | 4 +-- 2 files changed, 29 insertions(+), 33 deletions(-) diff --git a/Chapter02/JosuansefDua_1184091.py b/Chapter02/JosuansefDua_1184091.py index c44d621..109f1ae 100644 --- a/Chapter02/JosuansefDua_1184091.py +++ b/Chapter02/JosuansefDua_1184091.py @@ -2,43 +2,39 @@ import requests import os -import glob import json class josua1184091Arrangement (Thread): - files_list = glob.glob("*") -#Membuat satu set tipe ekstensi didalam folder untuk menghindari duplikasi file yang masuk -#menambahkan setiap tipe ekstensi ke satu set -for file in files_list: - extension = file.split(sep=".") - try: - extension_set.add(extension[1]) - except IndexError: - continue -#print(extension_set) - -#Fungsi untuk membuat direktori untuk setiap ekstensi yang berbeda -def createDirs(): - for dir in extension_set: - try: - os.makedirs(dir+"_files") - except FileExistsError: - continue + def __init__(self, nama, thread_number, filenya): + Thread.__init__(self) + self.threadLock = Lock() + self.nama = nama + self.thread_number = thread_number + self.filenya=os.path.join(os.path.dirname(__file__), filenya) + self.semaphore = semaphore -#Fungsi untuk memindahkan file file ke folder masing-masing berdasarkan ekstensinya -def arrange(): - for file in files_list: - fextension = file.split(sep=".") - try: - os.rename(file, fextension[1]+"_files/"+file) - except (OSError, IndexError): - continue + def jalankan(self): + print("\n"+str(self.thread_number)+". ---> " + self.nama + "run") + print('run semaphore yaitu untuk membuat dan menghapus file') + self.threadLock.acquire() + self.semaphore.acquire() + + print('buat file : '+self.filenya) + self.createfile() + + print('hapus file : '+self.filenya) + self.deletefile() + self.threadLock.release() + #print("\n"+str(self.thread_number)+". ---> " + currentThread().getName() + "selesai") -#memanggil fungsinya -createDirs() -arrange() - + def bacafile(self): + f = open(self.filenya, "r") + print("Josua1184091 : "+f.read()) + + def ubahnamafile(self): + os.rename(self.filenya,self.filenya+'.Josuainthehouse') + class josua1184091Api (Thread): def __init__(self, nama,thread_number,filenya, bravo, delta): Thread.__init__(self) diff --git a/test_app.py b/test_app.py index 9bbc0c0..3ed37c3 100644 --- a/test_app.py +++ b/test_app.py @@ -140,8 +140,8 @@ def readfile(self,filename): def test_03_JosuaDua1184091(self): from Chapter02.JosuansefDua_1184091 import josua1184091Arrangement,josua1184091Api - threadarrangement= josua1184091Api("Thread api file ", 1,'nilai') - threadutama = josua1184091Arrangement ("Thread Utama arrangement file ", 2,2,5,'arrangement') + threadarrangement= josua1184091Arrangement("Thread api file ", 1,'nilai') + threadutama = josua1184091Api("Thread Utama arrangement file ", 2,2,5,'arrangement') threadarrangement.start() threadutama.start() threadarrangement.join() From fdd8480926c004287a0feaafaa217d0880a2702a Mon Sep 17 00:00:00 2001 From: josua1111 Date: Fri, 26 Mar 2021 14:21:45 +0700 Subject: [PATCH 045/164] Tugas 3 Josuansef Pardede 1184091 --- Chapter02/JosuansefDua_1184091.py | 6 ++---- test_app.py | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/Chapter02/JosuansefDua_1184091.py b/Chapter02/JosuansefDua_1184091.py index 109f1ae..70fa5dc 100644 --- a/Chapter02/JosuansefDua_1184091.py +++ b/Chapter02/JosuansefDua_1184091.py @@ -1,8 +1,6 @@ from threading import Thread, currentThread, Lock, RLock, Semaphore import requests - import os -import json class josua1184091Arrangement (Thread): @@ -84,9 +82,9 @@ def buatfile(self,konten): f = open(self.filenya, "x") f.write(str(konten)) f.close() - print('sudah membuat file baru, mau relese semaphore') + print('buat file baru') self.semaphore.release() - print('di dalam Semaphore release, semaphore sudah di release') + print('semaphore sudah di release') diff --git a/test_app.py b/test_app.py index 3ed37c3..899a3f0 100644 --- a/test_app.py +++ b/test_app.py @@ -139,8 +139,8 @@ def readfile(self,filename): # self.assertGreaterEqual(main.getFileContent(),0 ) def test_03_JosuaDua1184091(self): - from Chapter02.JosuansefDua_1184091 import josua1184091Arrangement,josua1184091Api - threadarrangement= josua1184091Arrangement("Thread api file ", 1,'nilai') + from Chapter02.JosuansefDua_1184091 import josua1184091Arrangement, josua1184091Api + threadarrangement= josua1184091Arrangement("Thread api file ", 1,'arrangement') threadutama = josua1184091Api("Thread Utama arrangement file ", 2,2,5,'arrangement') threadarrangement.start() threadutama.start() From 5da7374c70b6d50e2f5376b3f1c01a727d1296b0 Mon Sep 17 00:00:00 2001 From: josua1111 Date: Fri, 26 Mar 2021 14:47:16 +0700 Subject: [PATCH 046/164] Tugas 3 Josuansef Pardede 1184091 --- Chapter02/JosuansefDua_1184091.py | 18 ++++++++++-------- test_app.py | 6 +++--- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/Chapter02/JosuansefDua_1184091.py b/Chapter02/JosuansefDua_1184091.py index 70fa5dc..6da9301 100644 --- a/Chapter02/JosuansefDua_1184091.py +++ b/Chapter02/JosuansefDua_1184091.py @@ -3,6 +3,9 @@ import os class josua1184091Arrangement (Thread): + +semaphore = Semaphore(0) +hasilperhitungan=0 def __init__(self, nama, thread_number, filenya): Thread.__init__(self) @@ -21,10 +24,10 @@ def jalankan(self): print('buat file : '+self.filenya) self.createfile() - print('hapus file : '+self.filenya) - self.deletefile() + print('ubah file : '+self.filenya) + self.renamefile() self.threadLock.release() - #print("\n"+str(self.thread_number)+". ---> " + currentThread().getName() + "selesai") + print("\n"+str(self.thread_number)+". ---> " + currentThread().getName() + "selesai") def bacafile(self): f = open(self.filenya, "r") @@ -34,7 +37,7 @@ def ubahnamafile(self): os.rename(self.filenya,self.filenya+'.Josuainthehouse') class josua1184091Api (Thread): - def __init__(self, nama,thread_number,filenya, bravo, delta): + def __init__(self, nama,thread_number, bravo, delta, filenya): Thread.__init__(self) self.threadLock = Lock() self.semaphore = semaphore @@ -60,10 +63,8 @@ def jalankan(self): def fungsiapi(self): with self.rlock: - - api_url='https://api.twitter.com/1.1/followers/list.json' - print('Mengakses fungsi api web service dari twitter untuk mengambil view list follower yang ada pada username twitter saya josh0018 pada Rlock') + api_url='https://api.twitter.com/1.1/followers/list.json' eq=str(self.bravo)+'^'+str(self.delta) response = requests.get(api_url+eq) @@ -74,8 +75,9 @@ def fungsiapi(self): def kalkulasi(self): with self.rlock: - self.fungsiapi() print('mengkalkulasi Rlock') + self.fungsiapi() + def buatfile(self,konten): print('buat file : '+ self.filenya) diff --git a/test_app.py b/test_app.py index 899a3f0..2dceb13 100644 --- a/test_app.py +++ b/test_app.py @@ -25,7 +25,7 @@ def tearDown(self): # response = multiprocessing_test.multiprocessing_test() # self.assertEqual(response, True) -<<<<<<< HEAD + # def test_02_kaisar_1184093(self): # from Chapter02.Kaisar1184093 import main # response = main() @@ -140,8 +140,8 @@ def readfile(self,filename): def test_03_JosuaDua1184091(self): from Chapter02.JosuansefDua_1184091 import josua1184091Arrangement, josua1184091Api - threadarrangement= josua1184091Arrangement("Thread api file ", 1,'arrangement') - threadutama = josua1184091Api("Thread Utama arrangement file ", 2,2,5,'arrangement') + threadarrangement= josua1184091Arrangement("Thread Utama arrangement file ", 1,'arrangement') + threadutama = josua1184091Api("Thread api file ", 2,2,5,'arrangement') threadarrangement.start() threadutama.start() threadarrangement.join() From 8a23a45cd3c9a321adebd2cbec0978e4294f9792 Mon Sep 17 00:00:00 2001 From: josua1111 Date: Fri, 26 Mar 2021 14:53:40 +0700 Subject: [PATCH 047/164] Tugas 3 Josuansef Pardede 1184091 --- Chapter02/JosuansefDua_1184091.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Chapter02/JosuansefDua_1184091.py b/Chapter02/JosuansefDua_1184091.py index 6da9301..141fa04 100644 --- a/Chapter02/JosuansefDua_1184091.py +++ b/Chapter02/JosuansefDua_1184091.py @@ -2,12 +2,12 @@ import requests import os -class josua1184091Arrangement (Thread): - + semaphore = Semaphore(0) hasilperhitungan=0 - def __init__(self, nama, thread_number, filenya): +class josua1184091Arrangement (Thread): + def __init__(self, nama, thread_number, filenya): Thread.__init__(self) self.threadLock = Lock() self.nama = nama From a2e95bdc1b89e85dcad6e7a7ed4ff96a6391b749 Mon Sep 17 00:00:00 2001 From: josua1111 Date: Fri, 26 Mar 2021 14:59:19 +0700 Subject: [PATCH 048/164] Tugas 3 Josuansef Pardede 1184091 --- Chapter02/JosuansefDua_1184091.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Chapter02/JosuansefDua_1184091.py b/Chapter02/JosuansefDua_1184091.py index 141fa04..384591e 100644 --- a/Chapter02/JosuansefDua_1184091.py +++ b/Chapter02/JosuansefDua_1184091.py @@ -15,7 +15,7 @@ def __init__(self, nama, thread_number, filenya): self.filenya=os.path.join(os.path.dirname(__file__), filenya) self.semaphore = semaphore - def jalankan(self): + def jalankan(self): print("\n"+str(self.thread_number)+". ---> " + self.nama + "run") print('run semaphore yaitu untuk membuat dan menghapus file') self.threadLock.acquire() @@ -36,7 +36,7 @@ def bacafile(self): def ubahnamafile(self): os.rename(self.filenya,self.filenya+'.Josuainthehouse') - class josua1184091Api (Thread): +class josua1184091Api (Thread): def __init__(self, nama,thread_number, bravo, delta, filenya): Thread.__init__(self) self.threadLock = Lock() @@ -69,7 +69,7 @@ def fungsiapi(self): eq=str(self.bravo)+'^'+str(self.delta) response = requests.get(api_url+eq) html=response.content.decode(response.encoding) - hasil = int(html) + result = int(html) print("result : "+str(result)) self.createfile(result) From 6473abe05cce9c4ca6fa88e47b0f4f72322d25e3 Mon Sep 17 00:00:00 2001 From: josua1111 Date: Fri, 26 Mar 2021 15:27:05 +0700 Subject: [PATCH 049/164] Tugas 3 Josuansef Pardede 1184091 --- Chapter02/JosuansefDua_1184091.py | 140 ++++++++++++++---------------- 1 file changed, 66 insertions(+), 74 deletions(-) diff --git a/Chapter02/JosuansefDua_1184091.py b/Chapter02/JosuansefDua_1184091.py index 384591e..9269cfb 100644 --- a/Chapter02/JosuansefDua_1184091.py +++ b/Chapter02/JosuansefDua_1184091.py @@ -4,90 +4,82 @@ semaphore = Semaphore(0) -hasilperhitungan=0 +hasilperhitungan = 0 + class josua1184091Arrangement (Thread): def __init__(self, nama, thread_number, filenya): - Thread.__init__(self) - self.threadLock = Lock() - self.nama = nama - self.thread_number = thread_number - self.filenya=os.path.join(os.path.dirname(__file__), filenya) - self.semaphore = semaphore + Thread.__init__(self) + self.threadLock = Lock() + self.nama = nama + self.thread_number = thread_number + self.filenya = os.path.join(os.path.dirname(__file__), filenya) + self.semaphore = semaphore def jalankan(self): - print("\n"+str(self.thread_number)+". ---> " + self.nama + "run") - print('run semaphore yaitu untuk membuat dan menghapus file') - self.threadLock.acquire() - self.semaphore.acquire() - - print('buat file : '+self.filenya) - self.createfile() - - print('ubah file : '+self.filenya) - self.renamefile() - self.threadLock.release() - print("\n"+str(self.thread_number)+". ---> " + currentThread().getName() + "selesai") + print("\n"+str(self.thread_number)+". ---> " + self.nama + "run") + print('run semaphore yaitu untuk membuat dan menghapus file') + self.threadLock.acquire() + self.semaphore.acquire() + print('buat file : '+self.filenya) + self.createfile() + print('ubah file : '+self.filenya) + self.renamefile() + self.threadLock.release() + print("\n"+str(self.thread_number)+". ---> " + + currentThread().getName() + "selesai") def bacafile(self): - f = open(self.filenya, "r") - print("Josua1184091 : "+f.read()) - + f = open(self.filenya, "r") + print("Josua1184091 : "+f.read()) + def ubahnamafile(self): - os.rename(self.filenya,self.filenya+'.Josuainthehouse') - + os.rename(self.filenya, self.filenya+'.Josuainthehouse') + + class josua1184091Api (Thread): - def __init__(self, nama,thread_number, bravo, delta, filenya): - Thread.__init__(self) - self.threadLock = Lock() - self.semaphore = semaphore - self.rlock = RLock() - self.nama = nama - self.filenya=os.path.join(os.path.dirname(__file__), filenya) - self.thread_number = thread_number - self.bravo=bravo - self.delta=delta - - def jalankan(self): - print("\n"+str(self.thread_number)+". ---> " + self.nama + "run") - self.threadLock.acquire() - - print("ini adalah threadlock aqcuire") - self.kalkulasi() - - self.threadLock.release() - - print("\n"+str(self.thread_number)+". ---> " + currentThread().getName() + "yoi beres") - - - - def fungsiapi(self): - with self.rlock: - print('Mengakses fungsi api web service dari twitter untuk mengambil view list follower yang ada pada username twitter saya josh0018 pada Rlock') - api_url='https://api.twitter.com/1.1/followers/list.json' - - eq=str(self.bravo)+'^'+str(self.delta) - response = requests.get(api_url+eq) - html=response.content.decode(response.encoding) - result = int(html) - print("result : "+str(result)) - self.createfile(result) + def __init__(self, nama, thread_number, bravo, delta, filenya): + Thread.__init__(self) + self.threadLock = Lock() + self.semaphore = semaphore + self.rlock = RLock() + self.nama = nama + self.filenya = os.path.join(os.path.dirname(__file__), filenya) + self.thread_number = thread_number + self.bravo = bravo + self.delta = delta - def kalkulasi(self): - with self.rlock: - print('mengkalkulasi Rlock') - self.fungsiapi() - - - def buatfile(self,konten): - print('buat file : '+ self.filenya) - f = open(self.filenya, "x") - f.write(str(konten)) - f.close() - print('buat file baru') - self.semaphore.release() - print('semaphore sudah di release') - + def jalankan(self): + print("\n"+str(self.thread_number)+". ---> " + self.nama + "run") + self.threadLock.acquire() + print("ini adalah threadlock aqcuire") + self.kalkulasi() + self.threadLock.release() + print("\n"+str(self.thread_number)+". ---> " + + currentThread().getName() + "yoi beres") + + def fungsiapi(self): + with self.rlock: + print('Mengakses fungsi api web service pada Rlock') + api_url = 'https://api.mathjs.org/v4/?expr=' + eq = str(self.bravo)+'^'+str(self.delta) + response = requests.get(api_url+eq) + html = response.content.decode(response.encoding) + result = int(html) + print("result : "+str(result)) + self.createfile(result) + def kalkulasi(self): + with self.rlock: + print('mengkalkulasi Rlock') + self.fungsiapi() + def buatfile(self, konten): + print('buat file : ' + self.filenya) + f = open(self.filenya, "x") + f.write(str(konten)) + f.close() + print('buat file baru') + self.semaphore.release() + print('semaphore sudah di release') From 2a1e9ad9f4134b51aa4609d19e04a456b09d5938 Mon Sep 17 00:00:00 2001 From: josua1111 Date: Fri, 26 Mar 2021 15:42:18 +0700 Subject: [PATCH 050/164] Tugas 3 Josuansef Pardede 1184091 --- test_app.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test_app.py b/test_app.py index 2dceb13..ea29e9a 100644 --- a/test_app.py +++ b/test_app.py @@ -140,13 +140,13 @@ def readfile(self,filename): def test_03_JosuaDua1184091(self): from Chapter02.JosuansefDua_1184091 import josua1184091Arrangement, josua1184091Api - threadarrangement= josua1184091Arrangement("Thread Utama arrangement file ", 1,'arrangement') + threadarrange= josua1184091Arrangement("Thread Utama arrangement file ", 1,'arrangement') threadutama = josua1184091Api("Thread api file ", 2,2,5,'arrangement') - threadarrangement.start() + threadarrange.start() threadutama.start() - threadarrangement.join() + threadarrange.join() threadutama.join() - respon=self.readfile('./Chapter02/arrangement.txt') + respon=self.readfile('./Chapter02/hasil.txt') self.assertGreaterEqual(respon, 0) From bada24b4036d71fc9e905990405332328c8d532c Mon Sep 17 00:00:00 2001 From: josua1111 Date: Fri, 26 Mar 2021 15:47:03 +0700 Subject: [PATCH 051/164] Tugas 3 Josuansef Pardede 1184091 --- Chapter02/hasil.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 Chapter02/hasil.txt diff --git a/Chapter02/hasil.txt b/Chapter02/hasil.txt new file mode 100644 index 0000000..e69de29 From 1b87f76aef469b3dca0e2a2d0138117c266f86a7 Mon Sep 17 00:00:00 2001 From: ravirahmatulfajri Date: Thu, 8 Apr 2021 22:15:44 +0700 Subject: [PATCH 052/164] Ravi 1184040 --- Chapter02/raviTiga1184040.py | 122 +++++++++++++++++++++++++++++++++++ test_app.py | 46 +++++++------ 2 files changed, 147 insertions(+), 21 deletions(-) create mode 100644 Chapter02/raviTiga1184040.py diff --git a/Chapter02/raviTiga1184040.py b/Chapter02/raviTiga1184040.py new file mode 100644 index 0000000..669be68 --- /dev/null +++ b/Chapter02/raviTiga1184040.py @@ -0,0 +1,122 @@ +from threading import Thread,currentThread, Lock, RLock, Event +import requests +import os + +items = [] +event = Event() +hasilperhitungan=0 + +class ravieventwriteFile (Thread): + def __init__(self,name,threadId,nomofile): + Thread.__init__(self) + self.threadLock = Lock() + self.name = name + self.threadId = threadId + self.nomofile=os.path.join(os.path.dirname(__file__), nomofile) + self.threadEvent = event + + def run(self): + a=0 + # while True: + print("\n"+str(self.threadId)+". ---> " + self.name + "Mulai ya!") + print('mau menjalankan event wait untuk baca dan tulis, buat ulang file') + self.threadLock.acquire() + # self.threadEvent.wait() + # while True: + # time.sleep(2) + print('Thread Utama raviTiga1184040 : menunggu event set dari ravieventwriteFile, status event.wait') + event.wait() #menunggu jika event=False / jika event=true maka event jalan + isinya=items.pop() + print(str(a)+'. raviTiga1184040: sudah di pop,tumpukan list sebanyak : '+str(len(items))+' isinya : '+str(isinya)) + a = a + 1 + print('raviTiga1184040 : event clear') + # logging.info('Consumer notify: {} popped by {}'.format(item, self.name)) + # event.clear() # set event=false + # items = items.pop() + # print('baca file dong : '+self.nomofile) + # self.readfile() + print('Tulis dan buat ulang file dong : '+self.nomofile) + # self.writefile() + # self.threadLock.release() + # self.event.clear() + print("\n"+str(self.threadId)+". ---> " + currentThread().getName() + "Finish") + # a=a+1 + # print('Konsumer : event clear') + self.threadLock.release() + self.threadEvent.clear() + + def readfile(self): + f = open(self.nomofile, "r+") + ##f.read(20) #Metode read(n) berfungsi untuk membaca sebanyak n karakter. + print("Tampilin angkanya dong biar kita tau : \n "+f.read()) + + def writefile(self): + f = open(self.nomofile, "r+") + fc = open(self.nomofile+'.html', "w") + for line in f: + fc.write(line.replace('Angka', 'Nomor')) + ff = open(self.nomofile+'.html', "r+") + print(ff.read()) + + +class raviTiga1184040(Thread): + def __init__(self, name,threadId,r,f ,nomofile): + Thread.__init__(self) + self.threadLock = Lock() + self.threadEvent = event + self.rlock = RLock() + self.name = name + self.nomofile=os.path.join(os.path.dirname(__file__), nomofile) + self.threadId = threadId + self.r=r + self.f=f + + def run(self): + print("\n"+str(self.threadId)+". ---> " + self.name + "Mulai aja ya") + self.threadLock.acquire() + # for i in range(2): + # item = (1, 10) + # items.append(item) + # event.set() + # event.clear() + print("ini threadlock acquire utama") + self.count() + self.threadLock.release() + print("\n"+str(self.threadId)+". ---> " + currentThread().getName() + "Finish") + + def apicount(self): + with self.rlock: + print('Dalam rlock apipangkat, akses web service...') + apiurl=' http://api.mathjs.org/v4/?expr=2%2B3*sqrt(4)' + eq=str(self.r)+'*'+str(self.f) + response = requests.get(apiurl+eq) + html=response.content.decode(response.encoding) + hasil = int(html) + string = " Angka : " + i = 1 + for i in range(1, 11): + isinya = (0, 10) + items.append(isinya) + string = string+str(i) + i = i +1 + self.createfile(string) + x = open(self.nomofile, "r+") + print(x.read()) + isinya = (0, 10) + items.append(isinya) + # self.event.set() + + + def count(self): + with self.rlock: + self.apicount() + + def createfile(self,isi): + print('Buat file baru ya di : '+ self.nomofile) + f = open(self.nomofile, "w") + f.write(str(isi)) + f.close() + print('Done pembuatan file baru, Bersiaplah, Selanjutnya nih kite mau set event') + self.threadEvent.set() + # self.event.clear() + print('di dalam event set tadi, event sudah di set ya') \ No newline at end of file diff --git a/test_app.py b/test_app.py index 2906fad..f6320ea 100644 --- a/test_app.py +++ b/test_app.py @@ -90,26 +90,26 @@ def tearDown(self): # response = main() # self.assertEqual(response, True) - def readfile(self,nfile): - f = open(nfile, "r+") - #f.read(20) - return str(f.read()) + # def readfile(self,nfile): + # f = open(nfile, "r+") + # #f.read(20) + # return str(f.read()) - def test_03_raviDua1184050(self): - from Chapter02.raviDua1184040 import raviDua1184040,raviSemaphorewriteFile - threadwrite= raviSemaphorewriteFile("Thread write File ", 1,'nilai') - threadutama = raviDua1184040("Thread Utama ", 2,2,5,'nilai') - threadwrite.start() - threadutama.start() - threadwrite.join() - threadutama.join() - respon=self.readfile('./Chapter02/nilai.html') - self.assertRegex(respon, "Nomor : 12345678910") + # def test_03_raviDua1184050(self): + # from Chapter02.raviDua1184040 import raviDua1184040,raviSemaphorewriteFile + # threadwrite= raviSemaphorewriteFile("Thread write File ", 1,'nilai') + # threadutama = raviDua1184040("Thread Utama ", 2,2,5,'nilai') + # threadwrite.start() + # threadutama.start() + # threadwrite.join() + # threadutama.join() + # respon=self.readfile('./Chapter02/nilai.html') + # self.assertRegex(respon, "Nomor : 12345678910") # def readfile(self,filename): # f = open(filename, "r") # return int(f.read()) # - + # def test_03_zanwarDua1184050(self): # from Chapter02.ZanwarDua1184050 import zanwarDua1184050,zanwarRewrite # threadrewrite= zanwarRewrite("Thread Rewrite File ", 1,'nilai') @@ -140,18 +140,22 @@ def test_03_raviDua1184050(self): def readfile(self,nfile): f = open(nfile, "r+") #f.read(20) - return str(f.read()) + return str(f.read()) + - def test_03_raviDua1184040(self): - from Chapter02.raviDua1184040 import raviDua1184040,raviSemaphorewriteFile - threadwrite= raviSemaphorewriteFile("Thread write File ", 1,'nilai') - threadutama = raviDua1184040("Thread Utama ", 2,2,5,'nilai') + def test_03_raviTiga1184040(self): + from Chapter02.raviTiga1184040 import raviTiga1184040,ravieventwriteFile + threadwrite = ravieventwriteFile("Thread write File ", 1,'nilai') + threadutama = raviTiga1184040("Thread Utama ", 2,2,5,'nilai') + # threadutama.start() threadwrite.start() threadutama.start() threadwrite.join() - threadutama.join() + # threadutama.join() respon=self.readfile('./Chapter02/nilai.html') self.assertRegex(respon, "Nomor : 12345678910") + # self.setUp() + From 16a4bdf1be9458c55b3ea4929761b532e93aa51a Mon Sep 17 00:00:00 2001 From: ravirahmatulfajri Date: Thu, 8 Apr 2021 22:58:50 +0700 Subject: [PATCH 053/164] Ravi 1184040 --- .gitignore | 4 +++- Chapter02/raviTiga1184040.py | 30 +++++++++++++++--------------- test_app.py | 31 ++++++++++++++++++++++++++----- 3 files changed, 44 insertions(+), 21 deletions(-) diff --git a/.gitignore b/.gitignore index 073f3dc..c8dcb12 100644 --- a/.gitignore +++ b/.gitignore @@ -135,4 +135,6 @@ ani.croot anu.croot ano.croot nilai.html -nilai \ No newline at end of file +nilai +value +value.txt \ No newline at end of file diff --git a/Chapter02/raviTiga1184040.py b/Chapter02/raviTiga1184040.py index 669be68..0a21c97 100644 --- a/Chapter02/raviTiga1184040.py +++ b/Chapter02/raviTiga1184040.py @@ -7,12 +7,12 @@ hasilperhitungan=0 class ravieventwriteFile (Thread): - def __init__(self,name,threadId,nomofile): + def __init__(self,name,threadId,nfile): Thread.__init__(self) self.threadLock = Lock() self.name = name self.threadId = threadId - self.nomofile=os.path.join(os.path.dirname(__file__), nomofile) + self.nfile=os.path.join(os.path.dirname(__file__), nfile) self.threadEvent = event def run(self): @@ -33,9 +33,9 @@ def run(self): # logging.info('Consumer notify: {} popped by {}'.format(item, self.name)) # event.clear() # set event=false # items = items.pop() - # print('baca file dong : '+self.nomofile) + # print('baca file dong : '+self.nfile) # self.readfile() - print('Tulis dan buat ulang file dong : '+self.nomofile) + print('Tulis dan buat ulang file dong : '+self.nfile) # self.writefile() # self.threadLock.release() # self.event.clear() @@ -46,27 +46,27 @@ def run(self): self.threadEvent.clear() def readfile(self): - f = open(self.nomofile, "r+") + f = open(self.nfile, "r+") ##f.read(20) #Metode read(n) berfungsi untuk membaca sebanyak n karakter. print("Tampilin angkanya dong biar kita tau : \n "+f.read()) def writefile(self): - f = open(self.nomofile, "r+") - fc = open(self.nomofile+'.html', "w") + f = open(self.nfile, "r+") + fc = open(self.nfile+'.html', "w") for line in f: fc.write(line.replace('Angka', 'Nomor')) - ff = open(self.nomofile+'.html', "r+") + ff = open(self.nfile+'.html', "r+") print(ff.read()) class raviTiga1184040(Thread): - def __init__(self, name,threadId,r,f ,nomofile): + def __init__(self, name,threadId,r,f ,nfile): Thread.__init__(self) self.threadLock = Lock() self.threadEvent = event self.rlock = RLock() self.name = name - self.nomofile=os.path.join(os.path.dirname(__file__), nomofile) + self.nfile=os.path.join(os.path.dirname(__file__), nfile) self.threadId = threadId self.r=r self.f=f @@ -95,14 +95,14 @@ def apicount(self): string = " Angka : " i = 1 for i in range(1, 11): - isinya = (0, 10) + isinya = (1, 11) items.append(isinya) string = string+str(i) i = i +1 self.createfile(string) - x = open(self.nomofile, "r+") + x = open(self.nfile, "r+") print(x.read()) - isinya = (0, 10) + isinya = (1, 11) items.append(isinya) # self.event.set() @@ -112,8 +112,8 @@ def count(self): self.apicount() def createfile(self,isi): - print('Buat file baru ya di : '+ self.nomofile) - f = open(self.nomofile, "w") + print('Buat file baru ya di : '+ self.nfile) + f = open(self.nfile, "w") f.write(str(isi)) f.close() print('Done pembuatan file baru, Bersiaplah, Selanjutnya nih kite mau set event') diff --git a/test_app.py b/test_app.py index f6320ea..a93fe1c 100644 --- a/test_app.py +++ b/test_app.py @@ -139,22 +139,43 @@ def tearDown(self): def readfile(self,nfile): f = open(nfile, "r+") + # f = open(nfile, "w") #f.read(20) return str(f.read()) def test_03_raviTiga1184040(self): from Chapter02.raviTiga1184040 import raviTiga1184040,ravieventwriteFile - threadwrite = ravieventwriteFile("Thread write File ", 1,'nilai') - threadutama = raviTiga1184040("Thread Utama ", 2,2,5,'nilai') + threadwrite = ravieventwriteFile("Thread write File ", 1,'value') + threadutama = raviTiga1184040("Thread Utama ", 2,2,5,'value') # threadutama.start() threadwrite.start() threadutama.start() threadwrite.join() - # threadutama.join() - respon=self.readfile('./Chapter02/nilai.html') - self.assertRegex(respon, "Nomor : 12345678910") + threadutama.join() + # respon=self.readfile('./Chapter02/value.html') + # self.assertRegex(respon, "Nomor : 12345678910") # self.setUp() + + # def readfile(self,nfile): + # f = open(nfile, "r+") + # # f = open(nfile, "w") + # #f.read(20) + # return str(f.read()) + + + # def test_03_raviDua1184040(self): + # from Chapter02.raviDua1184040 import raviDua1184040,raviSemaphorewriteFile + # threadwrite = raviSemaphorewriteFile("Thread write File ", 1,'nilai') + # threadutama = raviDua1184040("Thread Utama ", 2,2,5,'nilai') + # # threadutama.start() + # threadwrite.start() + # threadutama.start() + # threadwrite.join() + # threadutama.join() + # respon=self.readfile('./Chapter02/nilai.html') + # self.assertRegex(respon, "Nomor : 12345678910") + # # self.setUp() From 4f5262268dbfd871c39adfa9f89744b1519712e2 Mon Sep 17 00:00:00 2001 From: zanwar Date: Fri, 9 Apr 2021 00:58:30 +0700 Subject: [PATCH 054/164] update --- Chapter02/ZanwarTiga1184050.py | 89 ++++++++++++++++++++++++++++++++++ test_app.py | 30 ++++++------ 2 files changed, 104 insertions(+), 15 deletions(-) create mode 100644 Chapter02/ZanwarTiga1184050.py diff --git a/Chapter02/ZanwarTiga1184050.py b/Chapter02/ZanwarTiga1184050.py new file mode 100644 index 0000000..fe7abbb --- /dev/null +++ b/Chapter02/ZanwarTiga1184050.py @@ -0,0 +1,89 @@ +import threading +import requests +import os + +event = threading.Event() + +class zanwarRewrite (threading.Thread): + def __init__(self,name, thread_number, filename): + threading.Thread.__init__(self) + self.name = name + self.threadLock = threading.Lock() + self.thread_number = thread_number + self.filename=os.path.join(os.path.dirname(__file__), filename) + + def run(self): + print("\n"+str(self.thread_number)+". ---> " + self.name + "start.") + self.threadLock.acquire() + print('A: Pls give me some motivation :(') + print('B: Okay, pls wait~') + event.wait() + print('rewrite : '+self.filename) + self.readfile() + print("Read after rewrite") + self.rewritefile() + event.clear() + self.threadLock.release() + print("\n"+str(self.thread_number)+". ---> " + threading.currentThread().getName() + "end") + + def readfile(self): + f = open(self.filename, "r") + print("File's Content is : \n "+f.read()) + + def rewritefile(self): + f = open(self.filename, "r") + fd = open(self.filename+'.txt', "w") + for line in f: + fd.write(line.replace('Quotes', 'Kata Kata Bijak')) + fd.close() + fr = open(self.filename+'.txt', "r") + print(fr.read()) + fr.close() + + +class zanwarTiga1184050 (threading.Thread): + def __init__(self, name, thread_number, a ,filename): + threading.Thread.__init__(self) + self.threadLock = threading.Lock() + self.name = name + self.rlock = threading.RLock() + self.filename=os.path.join(os.path.dirname(__file__), filename) + self.thread_number = thread_number + self.a=a + + def run(self): + print("\n"+str(self.thread_number)+". ---> " + self.name + "start.") + self.count() + print("Event Set!") + event.set() + print("\n"+str(self.thread_number)+". ---> " + threading.currentThread().getName() + "finish.") + + def randomapi(self): + with self.rlock: + print('Inside rlock apipangkat, akses web service...') + apiurl='https://goquotes-api.herokuapp.com/api/v1/random?' + eq='count='+str(self.a) + response = requests.get(apiurl+eq) + html=response.json() + string = "Quotes : " + for i in range(len(html["quotes"])): + hasil = html["quotes"][i]["text"] + tulis = "\n"+str(i)+". " + string = string+tulis+str(hasil) + self.createfile(string) + x = open(self.filename, "r") + print(x.read()) + + def count(self): + with self.rlock: + self.randomapi() + + def createfile(self,isi): + print('Create File : '+ self.filename) + f = open(self.filename, "w") + f.write(str(isi)) + f.close() + + + + diff --git a/test_app.py b/test_app.py index fd469fc..b5876a9 100644 --- a/test_app.py +++ b/test_app.py @@ -88,28 +88,28 @@ def tearDown(self): def readfile(self,filename): f = open(filename, "r") - return int(f.read()) + return str(f.read()) - def test_03_zanwarDua1184050(self): - from Chapter02.ZanwarDua1184050 import zanwarDua1184050,zanwarRewrite - threadrewrite= zanwarRewrite("Thread Rewrite File ", 1,'nilai') - threadutama = zanwarDua1184050("Thread Utama ", 2,2,5,'nilai') + def test_03_zanwarTiga1184050(self): + from Chapter02.ZanwarTiga1184050 import zanwarTiga1184050, zanwarRewrite + threadrewrite= zanwarRewrite("Thread Rewrite File ",1 , 'nilai') + threadutama = zanwarTiga1184050("Thread Utama ", 2, 1, 'nilai') threadrewrite.start() threadutama.start() threadrewrite.join() threadutama.join() respon=self.readfile('./Chapter02/nilai.txt') - self.assertGreaterEqual(respon, 0) + self.assertNotRegex(respon, "Kosong") - def test_03_WahyuKurniaSariDua1184001(self): - from Chapter02.WahyuKurniasariDua1184001 import WahyuKurniaSariSemaphoreDeleteFile, WahyuKurniaSariDua1184001 - delete = WahyuKurniaSariSemaphoreDeleteFile("Thread delete", 1,"pikachu") - main = WahyuKurniaSariDua1184001("Thread utama", 2,"pikachu", "pikachu") - delete.start() - main.start() - delete.join() - main.join() - self.assertGreaterEqual(main.getFileContent(),0 ) +# def test_03_WahyuKurniaSariDua1184001(self): + # from Chapter02.WahyuKurniasariDua1184001 import WahyuKurniaSariSemaphoreDeleteFile, WahyuKurniaSariDua1184001 + # delete = WahyuKurniaSariSemaphoreDeleteFile("Thread delete", 1,"pikachu") + # main = WahyuKurniaSariDua1184001("Thread utama", 2,"pikachu", "pikachu") + # delete.start() + # main.start() + # delete.join() + # main.join() + #self.assertGreaterEqual(main.getFileContent(),0 ) From 101ef466b05a8de35b067c948d41dabc5f51a07e Mon Sep 17 00:00:00 2001 From: josua1111 Date: Fri, 9 Apr 2021 08:30:31 +0700 Subject: [PATCH 055/164] Josuansef Pardede 1184091 Tugas 4 DS --- Chapter02/JosuansefTiga1184091.py | 105 ++++++++++++++++++++++++++++++ Chapter02/josh123.txt | 0 test_app.py | 18 ++--- 3 files changed, 115 insertions(+), 8 deletions(-) create mode 100644 Chapter02/JosuansefTiga1184091.py create mode 100644 Chapter02/josh123.txt diff --git a/Chapter02/JosuansefTiga1184091.py b/Chapter02/JosuansefTiga1184091.py new file mode 100644 index 0000000..fd105bb --- /dev/null +++ b/Chapter02/JosuansefTiga1184091.py @@ -0,0 +1,105 @@ +# -*- coding: utf-8 -*- +""" +Created on Thu Apr 8 13:56:38 2021 + +@author: ASUS +""" + +import logging +import threading +import time + +LOG_FORMAT = '%(asctime)s %(threadName)-17s %(levelname)-8s %(message)s' +logging.basicConfig(level=logging.INFO, format=LOG_FORMAT) + +items = [] +condition = threading.Condition() + + +class josua1184091Write_Trier(threading.Thread): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + + + def trying(self): + + with condition: + f = open("josh123.txt", "w+") + for i in range(10): + f.write("hi are you okay number %d\r\n" % (i+1)) + + if len(items) == 0: + logging.info('no items to consume') + + condition.wait() + + items.pop() + logging.info('consumed 1 item') + + condition.notify() + + + def run(self): + for i in range(20): + time.sleep(2) + self.trying() + + +class josua1184091_Catcher(threading.Thread): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + def apiJosua(self): + print('Dalam apiJosua, akses webservice...') + apiurl='https://www.beanstream.com/api/v1' + eq=str(self.r)+'*'+str(self.f) + requests=str() + response = requests.get(apiurl) + html=response.content.decode(response.encoding) + hasil = int(html) + string = "hasil isinya = " + i = 1 + for i in range (1,10): + konten = (1,10) + items.append(konten) + string = string+str(i) + i = i + 1 + self.createfile(string) + x = open(self.nfile, "r+") + print(x.read()) + konten = (1,10) + items.append(konten) + + def catching(self): + + with condition: + + if len(items) == 10: + logging.info('items cathed {}. Stopped'.format(len(items))) + condition.wait() + + items.append(1) + logging.info('total items {}'.format(len(items))) + + condition.notify() + + def run(self): + for i in range(20): + time.sleep(1) + self.catching() + + +def main(): + josh_catcher = josua1184091_Catcher(name='Josh_Catcher') + josh_trier = josua1184091Write_Trier(name='Josh_Trier') + + josh_catcher.start() + josh_trier.start() + + josh_catcher.join() + josh_trier.join() + + +if __name__ == "__main__": + main() diff --git a/Chapter02/josh123.txt b/Chapter02/josh123.txt new file mode 100644 index 0000000..e69de29 diff --git a/test_app.py b/test_app.py index ea29e9a..477d574 100644 --- a/test_app.py +++ b/test_app.py @@ -138,15 +138,17 @@ def readfile(self,filename): #main.join() # self.assertGreaterEqual(main.getFileContent(),0 ) - def test_03_JosuaDua1184091(self): - from Chapter02.JosuansefDua_1184091 import josua1184091Arrangement, josua1184091Api - threadarrange= josua1184091Arrangement("Thread Utama arrangement file ", 1,'arrangement') - threadutama = josua1184091Api("Thread api file ", 2,2,5,'arrangement') - threadarrange.start() +def test_03_josuaTiga1184091(self): + from Chapter02.josuansefTiga1184091 import josua1184091_Catcher,josua1184091Write_Trier + threadwrite = josua1184091Write_Trier("Thread write File ", 1,'josua') + threadutama = josua1184091_Catcher("Thread Utama ", 2,2,5,'josua') + # threadutama.start() + threadwrite.start() threadutama.start() - threadarrange.join() + threadwrite.join() threadutama.join() - respon=self.readfile('./Chapter02/hasil.txt') - self.assertGreaterEqual(respon, 0) + respon=self.readfile('./Chapter02/josua1184091.txt') + self.assertRegex(respon, "Nomor : 18092001") + # self.setUp() From 4dccec5b4926e17b4209c73baa3cf9c06b79dc37 Mon Sep 17 00:00:00 2001 From: alif721 Date: Fri, 9 Apr 2021 08:52:35 +0700 Subject: [PATCH 056/164] tugas Alif --- Chapter02/alifTiga1184068.py | 80 ++++++++++++++++++++++++++++++++++++ test_app.py | 31 +++++++++----- 2 files changed, 101 insertions(+), 10 deletions(-) create mode 100644 Chapter02/alifTiga1184068.py diff --git a/Chapter02/alifTiga1184068.py b/Chapter02/alifTiga1184068.py new file mode 100644 index 0000000..bda3781 --- /dev/null +++ b/Chapter02/alifTiga1184068.py @@ -0,0 +1,80 @@ +from threading import Thread,currentThread, Lock, RLock, Event +import requests +import os + +event = Event() +hasilperhitungan=0 + +class alifEventDeleteFile (Thread): + def __init__(self,name,thread_number,namafile): + Thread.__init__(self) + self.threadLock = Lock() + self.name = name + self.thread_number = thread_number + self.namafile=os.path.join(os.path.dirname(__file__), namafile) + self.event = event + + def run(self): + print("\n"+str(self.thread_number)+". ---> " + self.name + "jalan") + print('class alifEventDeleteFile mau menjalankan event wait dilanjutkan clear untuk baca dan delete file') + self.event.wait() + self.threadLock.acquire() + print('melakukan baca file : '+self.namafile) + self.readfile() + print('melakukan rename file : '+self.namafile) + self.renamefile() + self.event.wait() + self.threadLock.release() + print("\n"+str(self.thread_number)+". ---> " + currentThread().getName() + "Baca file dan delete file selesai") + print ("menjalankan event clear") + self.event.clear() + + def readfile(self): + f = open(self.namafile, "r") + print("Isi Filenya : "+f.read()) + + def renamefile(self): + os.rename(self.namafile,self.namafile+'.txt') + +class alifTiga1184068 (Thread): + def __init__(self, name,thread_number,a,b ,namafile): + Thread.__init__(self) + self.threadLock = Lock() + self.event = event + self.rlock = RLock() + self.name = name + self.namafile=os.path.join(os.path.dirname(__file__), namafile) + self.thread_number = thread_number + self.a=a + self.b=b + + def run(self): + print("\n"+str(self.thread_number)+". ---> " + self.name + "jalan") + self.threadLock.acquire() + print("threeadlock acquire utama") + self.hitung() + self.event.set() + print('class alifTiga1184068 sudah selesai melakukan event set') + self.threadLock.release() + print("\n"+str(self.thread_number)+". ---> " + currentThread().getName() + "selesai") + + def apipangkat(self): + with self.rlock: + print('didalam rlock apipangkat, akses web service...') + apiurl='http://www.emsifa.com/api-wilayah-indonesia/api/provinces.json' + response = requests.get(apiurl) + html=response.json() + self.createfile(html) + + def hitung(self): + with self.rlock: + print('rlock hitung') + self.apipangkat() + + def createfile(self,isi): + print('membuat file baru : '+ self.namafile) + f = open(self.namafile, "x") + f.write(str(isi)) + f.close() + print('sudah membuat file baru, mau menjalankan event set') + diff --git a/test_app.py b/test_app.py index b5876a9..2ad89f4 100644 --- a/test_app.py +++ b/test_app.py @@ -90,16 +90,16 @@ def readfile(self,filename): f = open(filename, "r") return str(f.read()) - def test_03_zanwarTiga1184050(self): - from Chapter02.ZanwarTiga1184050 import zanwarTiga1184050, zanwarRewrite - threadrewrite= zanwarRewrite("Thread Rewrite File ",1 , 'nilai') - threadutama = zanwarTiga1184050("Thread Utama ", 2, 1, 'nilai') - threadrewrite.start() - threadutama.start() - threadrewrite.join() - threadutama.join() - respon=self.readfile('./Chapter02/nilai.txt') - self.assertNotRegex(respon, "Kosong") + # def test_03_zanwarTiga1184050(self): + # from Chapter02.ZanwarTiga1184050 import zanwarTiga1184050, zanwarRewrite + # threadrewrite= zanwarRewrite("Thread Rewrite File ",1 , 'nilai') + # threadutama = zanwarTiga1184050("Thread Utama ", 2, 1, 'nilai') + # threadrewrite.start() + # threadutama.start() + # threadrewrite.join() + # threadutama.join() + # respon=self.readfile('./Chapter02/nilai.txt') + # self.assertNotRegex(respon, "Kosong") # def test_03_WahyuKurniaSariDua1184001(self): # from Chapter02.WahyuKurniasariDua1184001 import WahyuKurniaSariSemaphoreDeleteFile, WahyuKurniaSariDua1184001 @@ -111,6 +111,17 @@ def test_03_zanwarTiga1184050(self): # main.join() #self.assertGreaterEqual(main.getFileContent(),0 ) + def test_03_alifTiga1184068(self): + from Chapter02.alifTiga1184068 import alifTiga1184068,alifEventDeleteFile + threadutama = alifTiga1184068("Thread Utama ", 2,5,5,'alip') + threaddelete= alifEventDeleteFile("Thread Delete File ", 1,'alip') + threaddelete.start() + threadutama.start() + threaddelete.join() + threadutama.join() + respon=self.readfile('./Chapter02/alip.txt') + self.assertNotRegex(respon, "kosong") + From 2290ab5ca8cef41f822befe537a254d709f75f5e Mon Sep 17 00:00:00 2001 From: FerdyBerlianoP Date: Fri, 9 Apr 2021 09:21:03 +0700 Subject: [PATCH 057/164] Tugas FerdyTiga2021 --- Chapter02/FerdyTiga1184112.py | 87 +++++++++++++++++++++++++++++++++++ test_app.py | 28 +++++++---- 2 files changed, 107 insertions(+), 8 deletions(-) create mode 100644 Chapter02/FerdyTiga1184112.py diff --git a/Chapter02/FerdyTiga1184112.py b/Chapter02/FerdyTiga1184112.py new file mode 100644 index 0000000..7a44fc4 --- /dev/null +++ b/Chapter02/FerdyTiga1184112.py @@ -0,0 +1,87 @@ +import threading +import requests +import os + +event = threading.Event() + +class FerdyEventGI(threading.Thread): + def __init__(self,name, thread_number, filename): + threading.Thread.__init__(self) + self.name = name + self.threadLock = threading.Lock() + self.thread_number = thread_number + self.filename = os.path.join(os.path.dirname(__file__), filename) + + def run(self): + print("\n"+str(self.thread_number)+". ---> " + self.name + "mulai.") + self.threadLock.acquire() + print('Cocktail 1(') + event.wait() + print('ubah : '+self.filename) + self.readfile() + print("pas udah diubah") + self.bikinfile() + event.clear() + self.threadLock.release() + print("\n"+str(self.thread_number)+". ---> " + threading.currentThread().getName() + "berhasil") + + def readfile(self): + f = open(self.filename, "r") + print("File's Content is : \n "+f.read()) + + def bikinfile(self): + f = open(self.filename, "r") + bikin = open(self.filename+'.txt', "w") + for line in f: + bikin.write(line.replace('strCategory', 'Jenis')) + bikin.close() + baru = open(self.filename+'.txt', "r") + print(baru.read()) + baru.close() + + +class FerdyGITiga1184112 (threading.Thread): + def __init__(self, name, thread_number ,filename): + threading.Thread.__init__(self) + self.threadLock = threading.Lock() + self.name = name + self.rlock = threading.RLock() + self.filename=os.path.join(os.path.dirname(__file__), filename) + self.thread_number = thread_number + + + def run(self): + print("\n"+str(self.thread_number)+". ---> " + self.name + "mulai.") + self.hasil() + print("Event") + event.set() + print("\n"+str(self.thread_number)+". ---> " + threading.currentThread().getName() + "selesai.") + + def apiwebservice(self): + with self.rlock: + print('Webservice nya') + apiurl='https://www.thecocktaildb.com/api/json/v1/1/list.php?c=list' + response = requests.get(apiurl) + html=response.json() + string = "" + for i in range(len(html["drinks"])): + cocokin = html["drinks"][i] + baru = "\n"+str(i)+". " + string = string+baru+str(cocokin) + self.createfile(string) + x = open(self.filename, "r") + print(x.read()) + + def hasil(self): + with self.rlock: + self.apiwebservice() + + def createfile(self,isi): + print('Create File : '+ self.filename) + f = open(self.filename, "w") + f.write(str(isi)) + f.close() + + + + diff --git a/test_app.py b/test_app.py index 2ad89f4..c13de50 100644 --- a/test_app.py +++ b/test_app.py @@ -111,16 +111,28 @@ def readfile(self,filename): # main.join() #self.assertGreaterEqual(main.getFileContent(),0 ) - def test_03_alifTiga1184068(self): - from Chapter02.alifTiga1184068 import alifTiga1184068,alifEventDeleteFile - threadutama = alifTiga1184068("Thread Utama ", 2,5,5,'alip') - threaddelete= alifEventDeleteFile("Thread Delete File ", 1,'alip') - threaddelete.start() + # def test_03_alifTiga1184068(self): + # from Chapter02.alifTiga1184068 import alifTiga1184068,alifEventDeleteFile + # threadutama = alifTiga1184068("Thread Utama ", 2,5,5,'alip') + # threaddelete= alifEventDeleteFile("Thread Delete File ", 1,'alip') + # threaddelete.start() + # threadutama.start() + # threaddelete.join() + # threadutama.join() + # respon=self.readfile('./Chapter02/alip.txt') + # self.assertNotRegex(respon, "kosong") + + + def test_03_FerdyTiga1184112(self): + from Chapter02.FerdyTiga1184112 import FerdyGITiga1184112,FerdyEventGI + threadrewrite= FerdyEventGI("Thread Lain ", 1,'minuman') + threadutama = FerdyGITiga1184112("Thread inti ", 2,'minuman') + threadrewrite.start() threadutama.start() - threaddelete.join() + threadrewrite.join() threadutama.join() - respon=self.readfile('./Chapter02/alip.txt') - self.assertNotRegex(respon, "kosong") + respon=self.readfile('./Chapter02/minuman.txt') + self.assertNotRegex(respon, "Gak Boleh Kosong") From e5990b6b75ee84dccc33022acca254b3828ff704 Mon Sep 17 00:00:00 2001 From: HanifWp Date: Fri, 9 Apr 2021 09:22:25 +0700 Subject: [PATCH 058/164] Tugas Hanif --- Chapter02/HanifDua1184058.py | 83 +++++++++++++++++++++++++++++++ Chapter02/ZanwarTiga1184050.py | 89 ++++++++++++++++++++++++++++++++++ nilai.txt | 0 test_app.py | 54 ++++++++++++--------- 4 files changed, 202 insertions(+), 24 deletions(-) create mode 100644 Chapter02/HanifDua1184058.py create mode 100644 Chapter02/ZanwarTiga1184050.py create mode 100644 nilai.txt diff --git a/Chapter02/HanifDua1184058.py b/Chapter02/HanifDua1184058.py new file mode 100644 index 0000000..9525aa5 --- /dev/null +++ b/Chapter02/HanifDua1184058.py @@ -0,0 +1,83 @@ +from threading import Thread,currentThread, Lock, RLock, Semaphore +import requests +import os +import shutil + +semaphore = Semaphore(0) +hasilperhitungan=0 + +class hanifCopy (Thread): + def __init__(self,name,thread_number,namafile): + Thread.__init__(self) + self.threadLock = Lock() + self.name = name + self.thread_number = thread_number + self.namafile=os.path.join(os.path.dirname(__file__), namafile) + self.semaphore = semaphore + + def run(self): + print("\n"+str(self.thread_number)+". ---> " + self.name + "mulai") + print('menjalankan semaphore acquire') + self.threadLock.acquire() + self.semaphore.acquire() + print('membaca file : '+self.namafile) + self.readfile() + print('menyalin file : '+self.namafile) + self.copyfile() + self.threadLock.release() + print("\n"+str(self.thread_number)+". ---> " + currentThread().getName() + "selesai") + + def readfile(self): + f = open(self.namafile, "r") + print("file : "+f.read()) + + def copyfile(self): + shutil.copy('.\Chapter02\provinsi.txt', '.\Chapter02') + +class hanifDua113040087 (Thread): + def __init__(self, name,thread_number,a,namafile): + Thread.__init__(self) + self.threadLock = Lock() + self.semaphore = semaphore + self.rlock = RLock() + self.name = name + self.namafile=os.path.join(os.path.dirname(__file__), namafile) + self.thread_number = thread_number + self.a=a + + def run(self): + print("\n"+str(self.thread_number)+". ---> " + self.name + "jalan") + self.threadLock.acquire() + print("threadlock acquire utama") + self.hitung() + self.threadLock.release() + print("\n"+str(self.thread_number)+". ---> " + currentThread().getName() + "selesai") + + def apitempat(self): + with self.rlock: + print('mengakses web service') + apiurl='https://dev.farizdotid.com/api/daerahindonesia/kota?id_provinsi=' + eq=str(self.a) + response = requests.get(apiurl+eq) + html=response.json() + hasil = html["nama"] + print("Nama Kabupaten : "+str(hasil)) + self.createfile(hasil) + + def hitung(self): + with self.rlock: + print('rlock hitung') + self.apitempat() + + def createfile(self,isi): + print('membuat file baru : '+ self.namafile) + f = open(self.namafile, "x") + f.write(str(isi)) + f.close() + print('me-release semaphore') + self.semaphore.release() + print('semaphore selesai di release') + + + + diff --git a/Chapter02/ZanwarTiga1184050.py b/Chapter02/ZanwarTiga1184050.py new file mode 100644 index 0000000..fe7abbb --- /dev/null +++ b/Chapter02/ZanwarTiga1184050.py @@ -0,0 +1,89 @@ +import threading +import requests +import os + +event = threading.Event() + +class zanwarRewrite (threading.Thread): + def __init__(self,name, thread_number, filename): + threading.Thread.__init__(self) + self.name = name + self.threadLock = threading.Lock() + self.thread_number = thread_number + self.filename=os.path.join(os.path.dirname(__file__), filename) + + def run(self): + print("\n"+str(self.thread_number)+". ---> " + self.name + "start.") + self.threadLock.acquire() + print('A: Pls give me some motivation :(') + print('B: Okay, pls wait~') + event.wait() + print('rewrite : '+self.filename) + self.readfile() + print("Read after rewrite") + self.rewritefile() + event.clear() + self.threadLock.release() + print("\n"+str(self.thread_number)+". ---> " + threading.currentThread().getName() + "end") + + def readfile(self): + f = open(self.filename, "r") + print("File's Content is : \n "+f.read()) + + def rewritefile(self): + f = open(self.filename, "r") + fd = open(self.filename+'.txt', "w") + for line in f: + fd.write(line.replace('Quotes', 'Kata Kata Bijak')) + fd.close() + fr = open(self.filename+'.txt', "r") + print(fr.read()) + fr.close() + + +class zanwarTiga1184050 (threading.Thread): + def __init__(self, name, thread_number, a ,filename): + threading.Thread.__init__(self) + self.threadLock = threading.Lock() + self.name = name + self.rlock = threading.RLock() + self.filename=os.path.join(os.path.dirname(__file__), filename) + self.thread_number = thread_number + self.a=a + + def run(self): + print("\n"+str(self.thread_number)+". ---> " + self.name + "start.") + self.count() + print("Event Set!") + event.set() + print("\n"+str(self.thread_number)+". ---> " + threading.currentThread().getName() + "finish.") + + def randomapi(self): + with self.rlock: + print('Inside rlock apipangkat, akses web service...') + apiurl='https://goquotes-api.herokuapp.com/api/v1/random?' + eq='count='+str(self.a) + response = requests.get(apiurl+eq) + html=response.json() + string = "Quotes : " + for i in range(len(html["quotes"])): + hasil = html["quotes"][i]["text"] + tulis = "\n"+str(i)+". " + string = string+tulis+str(hasil) + self.createfile(string) + x = open(self.filename, "r") + print(x.read()) + + def count(self): + with self.rlock: + self.randomapi() + + def createfile(self,isi): + print('Create File : '+ self.filename) + f = open(self.filename, "w") + f.write(str(isi)) + f.close() + + + + diff --git a/nilai.txt b/nilai.txt new file mode 100644 index 0000000..e69de29 diff --git a/test_app.py b/test_app.py index fd469fc..245c41a 100644 --- a/test_app.py +++ b/test_app.py @@ -88,30 +88,36 @@ def tearDown(self): def readfile(self,filename): f = open(filename, "r") - return int(f.read()) + return str(f.read()) - def test_03_zanwarDua1184050(self): - from Chapter02.ZanwarDua1184050 import zanwarDua1184050,zanwarRewrite - threadrewrite= zanwarRewrite("Thread Rewrite File ", 1,'nilai') - threadutama = zanwarDua1184050("Thread Utama ", 2,2,5,'nilai') - threadrewrite.start() + # def test_03_zanwarTiga1184050(self): + # from Chapter02.ZanwarTiga1184050 import zanwarTiga1184050, zanwarRewrite + # threadrewrite= zanwarRewrite("Thread Rewrite File ",1 , 'nilai') + # threadutama = zanwarTiga1184050("Thread Utama ", 2, 1, 'nilai') + # threadrewrite.start() + # threadutama.start() + # threadrewrite.join() + # threadutama.join() + # respon=self.readfile('./Chapter02/nilai.txt') + # self.assertNotRegex(respon, "Kosong") + +# def test_03_WahyuKurniaSariDua1184001(self): + # from Chapter02.WahyuKurniasariDua1184001 import WahyuKurniaSariSemaphoreDeleteFile, WahyuKurniaSariDua1184001 + # delete = WahyuKurniaSariSemaphoreDeleteFile("Thread delete", 1,"pikachu") + # main = WahyuKurniaSariDua1184001("Thread utama", 2,"pikachu", "pikachu") + # delete.start() + # main.start() + # delete.join() + # main.join() + #self.assertGreaterEqual(main.getFileContent(),0 ) + + def test_03_alifTiga1184068(self): + from Chapter02.alifTiga1184068 import alifTiga1184068,alifEventDeleteFile + threadutama = alifTiga1184068("Thread Utama ", 2,5,5,'alip') + threaddelete= alifEventDeleteFile("Thread Delete File ", 1,'alip') + threaddelete.start() threadutama.start() - threadrewrite.join() + threaddelete.join() threadutama.join() - respon=self.readfile('./Chapter02/nilai.txt') - self.assertGreaterEqual(respon, 0) - - def test_03_WahyuKurniaSariDua1184001(self): - from Chapter02.WahyuKurniasariDua1184001 import WahyuKurniaSariSemaphoreDeleteFile, WahyuKurniaSariDua1184001 - delete = WahyuKurniaSariSemaphoreDeleteFile("Thread delete", 1,"pikachu") - main = WahyuKurniaSariDua1184001("Thread utama", 2,"pikachu", "pikachu") - delete.start() - main.start() - delete.join() - main.join() - self.assertGreaterEqual(main.getFileContent(),0 ) - - - - - \ No newline at end of file + respon=self.readfile('./Chapter02/alip.txt') + self.assertNotRegex(respon, "kosong") From 79fa0654ed4f08d2faa4642c538572d4c2b0b2d1 Mon Sep 17 00:00:00 2001 From: HanifWp Date: Fri, 9 Apr 2021 09:44:27 +0700 Subject: [PATCH 059/164] Tugas Hanif --- Chapter02/HanifTiga1184058.py | 80 +++++++++++++++++++++++++++++++++++ test_app.py | 11 +++++ 2 files changed, 91 insertions(+) create mode 100644 Chapter02/HanifTiga1184058.py diff --git a/Chapter02/HanifTiga1184058.py b/Chapter02/HanifTiga1184058.py new file mode 100644 index 0000000..a11949f --- /dev/null +++ b/Chapter02/HanifTiga1184058.py @@ -0,0 +1,80 @@ +import threading +import requests +import os + +event = threading.Event() + +class hanifRename (threading.Thread): + def __init__(self,name, thread_number, filename): + threading.Thread.__init__(self) + self.name = name + self.threadLock = threading.Lock() + self.thread_number = thread_number + self.filename=os.path.join(os.path.dirname(__file__), filename) + + def run(self): + print("\n"+str(self.thread_number)+". ---> " + self.name + "start.") + self.threadLock.acquire() + print('Menunggu event') + event.wait() + print('Nama setelah rename: '+self.filename) + self.readfile() + print("Baca file setelah rename") + self.rewritefile() + event.clear() + self.threadLock.release() + print("\n"+str(self.thread_number)+". ---> " + threading.currentThread().getName() + "end") + + def readfile(self): + f = open(self.filename, "r") + print("File's Content is : \n "+f.read()) + f.close() + + def rewritefile(self): + os.rename(self.filename, self.filename+'.docx') + +class hanifTiga1184058 (threading.Thread): + def __init__(self, name, thread_number, a ,filename): + threading.Thread.__init__(self) + self.threadLock = threading.Lock() + self.name = name + self.rlock = threading.RLock() + self.filename=os.path.join(os.path.dirname(__file__), filename) + self.thread_number = thread_number + self.a=a + + def run(self): + print("\n"+str(self.thread_number)+". ---> " + self.name + "start.") + self.count() + print("Even set") + event.set() + print("\n"+str(self.thread_number)+". ---> " + threading.currentThread().getName() + "finish.") + + def randomapi(self): + with self.rlock: + print('akses web service...') + apiurl='https://pokeapi.co/api/v2/pokemon/ditto' + response = requests.get(apiurl) + html=response.json() + string = "ability :" + for i in range(len(html["abilities"])): + hasil = html["abilities"][i]["ability"]["name"] + tulis = "\n"+str(i)+". " + string = string+tulis+str(hasil) + self.createfile(string) + x = open(self.filename, "r") + print(x.read()) + + def count(self): + with self.rlock: + self.randomapi() + + def createfile(self,isi): + print('Create File : '+ self.filename) + f = open(self.filename, "w") + f.write(str(isi)) + f.close() + + + + diff --git a/test_app.py b/test_app.py index a677fcf..f803ec0 100644 --- a/test_app.py +++ b/test_app.py @@ -133,3 +133,14 @@ def test_03_FerdyTiga1184112(self): threadutama.join() respon=self.readfile('./Chapter02/minuman.txt') self.assertNotRegex(respon, "Gak Boleh Kosong") + + def test_03_hanifTiga1184058(self): + from Chapter02.HanifTiga1184058 import hanifTiga1184058, hanifRename + threadrename= hanifRename("Thread rename file ",1 , 'nilai') + threadutama = hanifTiga1184058("Thread utama ", 2, 1, 'nilai') + threadrename.start() + threadutama.start() + threadrename.join() + threadutama.join() + respon=self.readfile('./nilai.txt') + self.assertNotRegex(respon, "Kosong") \ No newline at end of file From 7206c198183096660d0021737b4fc79bd651d0ad Mon Sep 17 00:00:00 2001 From: ravirahmatulfajri Date: Fri, 9 Apr 2021 09:51:59 +0700 Subject: [PATCH 060/164] Ravi 1184040 --- Chapter02/raviTiga1184040.py | 83 ++++++++--------------- Chapter02/value.pdf | Bin 0 -> 20 bytes test_app.py | 128 +++++++++++++---------------------- 3 files changed, 76 insertions(+), 135 deletions(-) create mode 100644 Chapter02/value.pdf diff --git a/Chapter02/raviTiga1184040.py b/Chapter02/raviTiga1184040.py index 0a21c97..581e02e 100644 --- a/Chapter02/raviTiga1184040.py +++ b/Chapter02/raviTiga1184040.py @@ -6,7 +6,7 @@ event = Event() hasilperhitungan=0 -class ravieventwriteFile (Thread): +class raviMenulis (Thread): def __init__(self,name,threadId,nfile): Thread.__init__(self) self.threadLock = Lock() @@ -16,47 +16,33 @@ def __init__(self,name,threadId,nfile): self.threadEvent = event def run(self): - a=0 - # while True: - print("\n"+str(self.threadId)+". ---> " + self.name + "Mulai ya!") - print('mau menjalankan event wait untuk baca dan tulis, buat ulang file') + print("\n"+str(self.threadId)+". ---> " + self.name + "Go") self.threadLock.acquire() - # self.threadEvent.wait() - # while True: - # time.sleep(2) - print('Thread Utama raviTiga1184040 : menunggu event set dari ravieventwriteFile, status event.wait') - event.wait() #menunggu jika event=False / jika event=true maka event jalan - isinya=items.pop() - print(str(a)+'. raviTiga1184040: sudah di pop,tumpukan list sebanyak : '+str(len(items))+' isinya : '+str(isinya)) - a = a + 1 - print('raviTiga1184040 : event clear') - # logging.info('Consumer notify: {} popped by {}'.format(item, self.name)) - # event.clear() # set event=false - # items = items.pop() - # print('baca file dong : '+self.nfile) - # self.readfile() - print('Tulis dan buat ulang file dong : '+self.nfile) - # self.writefile() - # self.threadLock.release() - # self.event.clear() - print("\n"+str(self.threadId)+". ---> " + currentThread().getName() + "Finish") - # a=a+1 - # print('Konsumer : event clear') - self.threadLock.release() + print('Joni: Saya mau Belajar berhitung 1 sampai 10, Jono kamu bisa buatkan saya Angka dan Nomor nya?') + print('Jono: Bisa dong, tunggu sebentar') + event.wait() + print('Menulis : '+self.nfile) + self.readfile() + print('Baca file setala ditulis : '+self.nfile) + self.writefile() self.threadEvent.clear() - + self.threadLock.release() + print("\n"+str(self.threadId)+". ---> " + currentThread().getName() + "Finish") + def readfile(self): f = open(self.nfile, "r+") ##f.read(20) #Metode read(n) berfungsi untuk membaca sebanyak n karakter. - print("Tampilin angkanya dong biar kita tau : \n "+f.read()) + print("Ini angkanya, selamat belajar Joni : \n "+f.read()) def writefile(self): f = open(self.nfile, "r+") - fc = open(self.nfile+'.html', "w") + fd = open(self.nfile+'.pdf', "w") for line in f: - fc.write(line.replace('Angka', 'Nomor')) - ff = open(self.nfile+'.html', "r+") - print(ff.read()) + fd.write(line.replace('Ini Angkanya', 'dan Ini Nomor')) + fd.close() + fr = open(self.nfile+'.pdf', "r+") + print(fr.read()) + fr.close() class raviTiga1184040(Thread): @@ -72,22 +58,16 @@ def __init__(self, name,threadId,r,f ,nfile): self.f=f def run(self): - print("\n"+str(self.threadId)+". ---> " + self.name + "Mulai aja ya") - self.threadLock.acquire() - # for i in range(2): - # item = (1, 10) - # items.append(item) - # event.set() - # event.clear() - print("ini threadlock acquire utama") + print("\n"+str(self.threadId)+". ---> " + self.name + "Mulai") self.count() - self.threadLock.release() - print("\n"+str(self.threadId)+". ---> " + currentThread().getName() + "Finish") + print("Event di Set!") + event.set() + print("\n"+str(self.threadId)+". ---> " + currentThread().getName() + "finish.") - def apicount(self): + def Api(self): with self.rlock: - print('Dalam rlock apipangkat, akses web service...') - apiurl=' http://api.mathjs.org/v4/?expr=2%2B3*sqrt(4)' + print('Di dalam rlock APIpangkat, akses web service...') + apiurl=' https://api.mathjs.org/v4/?expr=4%2B2*6-8' eq=str(self.r)+'*'+str(self.f) response = requests.get(apiurl+eq) html=response.content.decode(response.encoding) @@ -104,19 +84,14 @@ def apicount(self): print(x.read()) isinya = (1, 11) items.append(isinya) - # self.event.set() def count(self): with self.rlock: - self.apicount() + self.Api() def createfile(self,isi): - print('Buat file baru ya di : '+ self.nfile) + print('Create File : '+ self.nfile) f = open(self.nfile, "w") f.write(str(isi)) - f.close() - print('Done pembuatan file baru, Bersiaplah, Selanjutnya nih kite mau set event') - self.threadEvent.set() - # self.event.clear() - print('di dalam event set tadi, event sudah di set ya') \ No newline at end of file + f.close() \ No newline at end of file diff --git a/Chapter02/value.pdf b/Chapter02/value.pdf new file mode 100644 index 0000000000000000000000000000000000000000..9081fb70d22a5b4018c773547ef896ada783da4a GIT binary patch literal 20 bcmY#z%uCNsRIpMoG%_|ZH8Z!cG&BGJHS7et literal 0 HcmV?d00001 diff --git a/test_app.py b/test_app.py index a93fe1c..00afe91 100644 --- a/test_app.py +++ b/test_app.py @@ -85,100 +85,66 @@ def tearDown(self): # from Chapter02.Parhan1184042 import main # response = main() # self.assertEqual(response, True) - #def test_02_ravi_1184040(self): - # from Chapter02.Ravi1184040 import main - # response = main() - # self.assertEqual(response, True) - # def readfile(self,nfile): - # f = open(nfile, "r+") - # #f.read(20) + # def readfile(self,filename): + # f = open(filename, "r") # return str(f.read()) - # def test_03_raviDua1184050(self): - # from Chapter02.raviDua1184040 import raviDua1184040,raviSemaphorewriteFile - # threadwrite= raviSemaphorewriteFile("Thread write File ", 1,'nilai') - # threadutama = raviDua1184040("Thread Utama ", 2,2,5,'nilai') - # threadwrite.start() + # def test_03_zanwarTiga1184050(self): + # from Chapter02.ZanwarTiga1184050 import zanwarTiga1184050, zanwarRewrite + # threadrewrite= zanwarRewrite("Thread Rewrite File ",1 , 'nilai') + # threadutama = zanwarTiga1184050("Thread Utama ", 2, 1, 'nilai') + # threadrewrite.start() # threadutama.start() - # threadwrite.join() + # threadrewrite.join() # threadutama.join() - # respon=self.readfile('./Chapter02/nilai.html') - # self.assertRegex(respon, "Nomor : 12345678910") - -# def readfile(self,filename): -# f = open(filename, "r") -# return int(f.read()) # - -# def test_03_zanwarDua1184050(self): -# from Chapter02.ZanwarDua1184050 import zanwarDua1184050,zanwarRewrite -# threadrewrite= zanwarRewrite("Thread Rewrite File ", 1,'nilai') -# threadutama = zanwarDua1184050("Thread Utama ", 2,2,5,'nilai') -# threadrewrite.start() -# threadutama.start() -# threadrewrite.join() -# threadutama.join() -# respon=self.readfile('./Chapter02/nilai.txt') -# self.assertGreaterEqual(respon, 0) - - - - - - + # respon=self.readfile('./Chapter02/nilai.txt') + # self.assertNotRegex(respon, "Kosong") # def test_03_WahyuKurniaSariDua1184001(self): -# from Chapter02.WahyuKurniasariDua1184001 import WahyuKurniaSariSemaphoreDeleteFile, WahyuKurniaSariDua1184001 -# delete = WahyuKurniaSariSemaphoreDeleteFile("Thread delete", 1,"pikachu") -# main = WahyuKurniaSariDua1184001("Thread utama", 2,"pikachu", "pikachu") -# delete.start() -# main.start() -# delete.join() # -# main.join() -# self.assertGreaterEqual(main.getFileContent(),0 ) + # from Chapter02.WahyuKurniasariDua1184001 import WahyuKurniaSariSemaphoreDeleteFile, WahyuKurniaSariDua1184001 + # delete = WahyuKurniaSariSemaphoreDeleteFile("Thread delete", 1,"pikachu") + # main = WahyuKurniaSariDua1184001("Thread utama", 2,"pikachu", "pikachu") + # delete.start() + # main.start() + # delete.join() + # main.join() + #self.assertGreaterEqual(main.getFileContent(),0 ) + + # def test_03_alifTiga1184068(self): + # from Chapter02.alifTiga1184068 import alifTiga1184068,alifEventDeleteFile + # threadutama = alifTiga1184068("Thread Utama ", 2,5,5,'alip') + # threaddelete= alifEventDeleteFile("Thread Delete File ", 1,'alip') + # threaddelete.start() + # threadutama.start() + # threaddelete.join() + # threadutama.join() + # respon=self.readfile('./Chapter02/alip.txt') + # self.assertNotRegex(respon, "kosong") + + + # def test_03_FerdyTiga1184112(self): + # from Chapter02.FerdyTiga1184112 import FerdyGITiga1184112,FerdyEventGI + # threadrewrite= FerdyEventGI("Thread Lain ", 1,'minuman') + # threadutama = FerdyGITiga1184112("Thread inti ", 2,'minuman') + # threadrewrite.start() + # threadutama.start() + # threadrewrite.join() + # threadutama.join() + # respon=self.readfile('./Chapter02/minuman.txt') + # self.assertNotRegex(respon, "Gak Boleh Kosong") def readfile(self,nfile): f = open(nfile, "r+") - # f = open(nfile, "w") - #f.read(20) - return str(f.read()) - + return str(f.read()) def test_03_raviTiga1184040(self): - from Chapter02.raviTiga1184040 import raviTiga1184040,ravieventwriteFile - threadwrite = ravieventwriteFile("Thread write File ", 1,'value') - threadutama = raviTiga1184040("Thread Utama ", 2,2,5,'value') - # threadutama.start() + from Chapter02.raviTiga1184040 import raviTiga1184040, raviMenulis + threadwrite = raviMenulis ("Thread Pro ",1 , 'value') + threadutama = raviTiga1184040("Thread Utama ", 2,2,5, 'value') threadwrite.start() threadutama.start() threadwrite.join() threadutama.join() - # respon=self.readfile('./Chapter02/value.html') - # self.assertRegex(respon, "Nomor : 12345678910") - # self.setUp() - - # def readfile(self,nfile): - # f = open(nfile, "r+") - # # f = open(nfile, "w") - # #f.read(20) - # return str(f.read()) - - - # def test_03_raviDua1184040(self): - # from Chapter02.raviDua1184040 import raviDua1184040,raviSemaphorewriteFile - # threadwrite = raviSemaphorewriteFile("Thread write File ", 1,'nilai') - # threadutama = raviDua1184040("Thread Utama ", 2,2,5,'nilai') - # # threadutama.start() - # threadwrite.start() - # threadutama.start() - # threadwrite.join() - # threadutama.join() - # respon=self.readfile('./Chapter02/nilai.html') - # self.assertRegex(respon, "Nomor : 12345678910") - # # self.setUp() - - - - - - + respon=self.readfile('./Chapter02/value.pdf') + self.assertNotRegex(respon, "Nomor : 12345678910") \ No newline at end of file From b468d1885e28c4477fe0e804dd6a70e952bef0e5 Mon Sep 17 00:00:00 2001 From: ravirahmatulfajri Date: Fri, 9 Apr 2021 09:59:15 +0700 Subject: [PATCH 061/164] Ravi 1184040 --- Chapter02/raviTiga1184040.py | 1 + test_app.py | 1 + 2 files changed, 2 insertions(+) diff --git a/Chapter02/raviTiga1184040.py b/Chapter02/raviTiga1184040.py index 581e02e..a2f16d4 100644 --- a/Chapter02/raviTiga1184040.py +++ b/Chapter02/raviTiga1184040.py @@ -34,6 +34,7 @@ def readfile(self): ##f.read(20) #Metode read(n) berfungsi untuk membaca sebanyak n karakter. print("Ini angkanya, selamat belajar Joni : \n "+f.read()) + def writefile(self): f = open(self.nfile, "r+") fd = open(self.nfile+'.pdf', "w") diff --git a/test_app.py b/test_app.py index 00afe91..f29ec2f 100644 --- a/test_app.py +++ b/test_app.py @@ -138,6 +138,7 @@ def readfile(self,nfile): f = open(nfile, "r+") return str(f.read()) + def test_03_raviTiga1184040(self): from Chapter02.raviTiga1184040 import raviTiga1184040, raviMenulis threadwrite = raviMenulis ("Thread Pro ",1 , 'value') From 3f4185e937fb777973805d8a99869a6b0ce3ec77 Mon Sep 17 00:00:00 2001 From: ravirahmatulfajri Date: Fri, 9 Apr 2021 10:08:06 +0700 Subject: [PATCH 062/164] Ravi 1184040 --- Chapter02/raviTiga1184040.py | 1 + test_app.py | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Chapter02/raviTiga1184040.py b/Chapter02/raviTiga1184040.py index a2f16d4..90b031f 100644 --- a/Chapter02/raviTiga1184040.py +++ b/Chapter02/raviTiga1184040.py @@ -6,6 +6,7 @@ event = Event() hasilperhitungan=0 + class raviMenulis (Thread): def __init__(self,name,threadId,nfile): Thread.__init__(self) diff --git a/test_app.py b/test_app.py index f29ec2f..81e5afc 100644 --- a/test_app.py +++ b/test_app.py @@ -133,12 +133,21 @@ def tearDown(self): # threadutama.join() # respon=self.readfile('./Chapter02/minuman.txt') # self.assertNotRegex(respon, "Gak Boleh Kosong") - + + # def test_03_hanifTiga1184058(self): + # from Chapter02.HanifTiga1184058 import hanifTiga1184058, hanifRename + # threadrename= hanifRename("Thread rename file ",1 , 'nilai') + # threadutama = hanifTiga1184058("Thread utama ", 2, 1, 'nilai') + # threadrename.start() + # threadutama.start() + # threadrename.join() + # threadutama.join() + # respon=self.readfile('./nilai.txt') + # self.assertNotRegex(respon, "Kosong") def readfile(self,nfile): f = open(nfile, "r+") return str(f.read()) - def test_03_raviTiga1184040(self): from Chapter02.raviTiga1184040 import raviTiga1184040, raviMenulis threadwrite = raviMenulis ("Thread Pro ",1 , 'value') From fe2751f3a135a865a397d1d329de7e1c1d7239c9 Mon Sep 17 00:00:00 2001 From: ravirahmatulfajri Date: Fri, 9 Apr 2021 10:08:55 +0700 Subject: [PATCH 063/164] Ravi 1184040 --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index c8dcb12..343afd8 100644 --- a/.gitignore +++ b/.gitignore @@ -137,4 +137,6 @@ ano.croot nilai.html nilai value -value.txt \ No newline at end of file +value.txt +value +value.pdf \ No newline at end of file From e52fb1137c6c41c982a94f1c96e4a3e507007e9d Mon Sep 17 00:00:00 2001 From: ravirahmatulfajri Date: Fri, 9 Apr 2021 10:21:23 +0700 Subject: [PATCH 064/164] Ravi 1184040 --- Chapter02/raviTiga1184040.py | 1 - test_app.py | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/Chapter02/raviTiga1184040.py b/Chapter02/raviTiga1184040.py index 90b031f..7fe18d5 100644 --- a/Chapter02/raviTiga1184040.py +++ b/Chapter02/raviTiga1184040.py @@ -86,7 +86,6 @@ def Api(self): print(x.read()) isinya = (1, 11) items.append(isinya) - def count(self): with self.rlock: diff --git a/test_app.py b/test_app.py index 81e5afc..2a72206 100644 --- a/test_app.py +++ b/test_app.py @@ -148,6 +148,7 @@ def readfile(self,nfile): f = open(nfile, "r+") return str(f.read()) + def test_03_raviTiga1184040(self): from Chapter02.raviTiga1184040 import raviTiga1184040, raviMenulis threadwrite = raviMenulis ("Thread Pro ",1 , 'value') From 64bec0f3434350532be3c0492b54772cbb3499ef Mon Sep 17 00:00:00 2001 From: idafatriniputri Date: Fri, 9 Apr 2021 10:30:55 +0700 Subject: [PATCH 065/164] Ida Fatrini Tugas 4 --- Chapter02/IdaTiga1184113.py | 84 +++++++++++++++++++++++++++++++++++++ Chapter02/idanilai.txt | 19 +++++++++ test_app.py | 49 ++++++++++++++-------- 3 files changed, 134 insertions(+), 18 deletions(-) create mode 100644 Chapter02/IdaTiga1184113.py create mode 100644 Chapter02/idanilai.txt diff --git a/Chapter02/IdaTiga1184113.py b/Chapter02/IdaTiga1184113.py new file mode 100644 index 0000000..91d7be7 --- /dev/null +++ b/Chapter02/IdaTiga1184113.py @@ -0,0 +1,84 @@ +import logging +import threading +import time + +LOG_FORMAT = '%(asctime)s %(threadName)-17s %(levelname)-8s %(message)s' +logging.basicConfig(level=logging.INFO, format=LOG_FORMAT) + +items = [] +condition = threading.Condition() + + +class ida1184113_Catcher (threading.Thread): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + + + def trying(self): + + with condition: + f = open("idanilai.txt", "w+") + for i in range(10): + f.write("how are you? %d\r\n" % (i+1)) + + if len(items) == 0: + logging.info('no items to consume') + + condition.wait() + + items.pop() + logging.info('consumed 1 item') + + condition.notify() + + + def run(self): + for i in range(20): + time.sleep(2) + self.trying() + + +class ida1184113Write_Trier(threading.Thread): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + def apiIda(self): + print('Dalam apiIda, akses webservice...') + apiurl='https://api.instagram.com/v1/tags/{tag-name}/media/recent' + eq=str(self.r)+'*'+str(self.f) + requests=str() + response = requests.get(apiurl) + html=response.content.decode(response.encoding) + hasil = int(html) + string = "hasil isinya = " + i = 1 + for i in range (1,10): + konten = (1,10) + items.append(konten) + string = string+str(i) + i = i + 1 + self.createfile(string) + x = open(self.nfile, "r+") + print(x.read()) + konten = (1,10) + items.append(konten) + + def catching(self): + + with condition: + + if len(items) == 10: + logging.info('items cathed {}. Stopped'.format(len(items))) + condition.wait() + + items.append(1) + logging.info('total items {}'.format(len(items))) + + condition.notify() + + def run(self): + for i in range(20): + time.sleep(0.5) + self.catching() + \ No newline at end of file diff --git a/Chapter02/idanilai.txt b/Chapter02/idanilai.txt new file mode 100644 index 0000000..f6c1b22 --- /dev/null +++ b/Chapter02/idanilai.txt @@ -0,0 +1,19 @@ +how are you? + +how are you? 2 + +how are you? 3 + +how are you? 4 + +how are you? 5 + +how are you? 6 + +how are you? 7 + +how are you? 8 + +how are you? 9 + +how are you? 10 \ No newline at end of file diff --git a/test_app.py b/test_app.py index f803ec0..37e4dfc 100644 --- a/test_app.py +++ b/test_app.py @@ -123,24 +123,37 @@ def readfile(self,filename): # self.assertNotRegex(respon, "kosong") - def test_03_FerdyTiga1184112(self): - from Chapter02.FerdyTiga1184112 import FerdyGITiga1184112,FerdyEventGI - threadrewrite= FerdyEventGI("Thread Lain ", 1,'minuman') - threadutama = FerdyGITiga1184112("Thread inti ", 2,'minuman') - threadrewrite.start() - threadutama.start() - threadrewrite.join() - threadutama.join() - respon=self.readfile('./Chapter02/minuman.txt') - self.assertNotRegex(respon, "Gak Boleh Kosong") + # def test_03_FerdyTiga1184112(self): + # from Chapter02.FerdyTiga1184112 import FerdyGITiga1184112,FerdyEventGI + # threadrewrite= FerdyEventGI("Thread Lain ", 1,'minuman') + # threadutama = FerdyGITiga1184112("Thread inti ", 2,'minuman') + # threadrewrite.start() + # threadutama.start() + # threadrewrite.join() + # threadutama.join() + # respon=self.readfile('./Chapter02/minuman.txt') + # self.assertNotRegex(respon, "Gak Boleh Kosong") - def test_03_hanifTiga1184058(self): - from Chapter02.HanifTiga1184058 import hanifTiga1184058, hanifRename - threadrename= hanifRename("Thread rename file ",1 , 'nilai') - threadutama = hanifTiga1184058("Thread utama ", 2, 1, 'nilai') - threadrename.start() + # def test_03_hanifTiga1184058(self): + # from Chapter02.HanifTiga1184058 import hanifTiga1184058, hanifRename + # threadrename= hanifRename("Thread rename file ",1 , 'nilai') + # threadutama = hanifTiga1184058("Thread utama ", 2, 1, 'nilai') + # threadrename.start() + # threadutama.start() + # threadrename.join() + # threadutama.join() + # respon=self.readfile('./nilai.txt') + # self.assertNotRegex(respon, "Kosong") + + def test_03_idaTiga1184113(self): + from Chapter02.idaTiga1184113 import ida1184113_Catcher,ida1184113Write_Trier + threadwrite = ida1184113Write_Trier("Thread write File ", 1,'ida') + threadutama = ida1184113_Catcher("Thread Utama ", 2,2,5,'ida') + # threadutama.start() + threadwrite.start() threadutama.start() - threadrename.join() + threadwrite.join() threadutama.join() - respon=self.readfile('./nilai.txt') - self.assertNotRegex(respon, "Kosong") \ No newline at end of file + respon=self.readfile('./Chapter02/idanilai.txt') + self.assertRegex(respon, "Nomor : 14102000") + # self.setUp() \ No newline at end of file From 15cf947ef3516a220af353aacd71c84536c045cd Mon Sep 17 00:00:00 2001 From: ravirahmatulfajri Date: Fri, 9 Apr 2021 10:34:59 +0700 Subject: [PATCH 066/164] Ravi 1184040 --- Chapter02/raviTiga1184040.py | 5 +-- test_app.py | 77 +++++++++++++++++++++--------------- 2 files changed, 48 insertions(+), 34 deletions(-) diff --git a/Chapter02/raviTiga1184040.py b/Chapter02/raviTiga1184040.py index 7fe18d5..a1862ab 100644 --- a/Chapter02/raviTiga1184040.py +++ b/Chapter02/raviTiga1184040.py @@ -1,12 +1,11 @@ from threading import Thread,currentThread, Lock, RLock, Event import requests import os - +# items = [] event = Event() hasilperhitungan=0 - class raviMenulis (Thread): def __init__(self,name,threadId,nfile): Thread.__init__(self) @@ -35,7 +34,6 @@ def readfile(self): ##f.read(20) #Metode read(n) berfungsi untuk membaca sebanyak n karakter. print("Ini angkanya, selamat belajar Joni : \n "+f.read()) - def writefile(self): f = open(self.nfile, "r+") fd = open(self.nfile+'.pdf', "w") @@ -86,6 +84,7 @@ def Api(self): print(x.read()) isinya = (1, 11) items.append(isinya) + def count(self): with self.rlock: diff --git a/test_app.py b/test_app.py index e522492..6759a6b 100644 --- a/test_app.py +++ b/test_app.py @@ -86,15 +86,15 @@ def tearDown(self): # response = main() # self.assertEqual(response, True) -<<<<<<< HEAD + # def readfile(self,filename): # f = open(filename, "r") # return str(f.read()) -======= - def readfile(self,filename): - f = open(filename, "r") - return str(f.read()) ->>>>>>> 3aa81716bb58a3e7685425efe1259762e524b6aa + + # def readfile(self,filename): + # f = open(filename, "r") + # return str(f.read()) + # def test_03_zanwarTiga1184050(self): # from Chapter02.ZanwarTiga1184050 import zanwarTiga1184050, zanwarRewrite @@ -129,7 +129,7 @@ def readfile(self,filename): # self.assertNotRegex(respon, "kosong") -<<<<<<< HEAD + # def test_03_FerdyTiga1184112(self): # from Chapter02.FerdyTiga1184112 import FerdyGITiga1184112,FerdyEventGI # threadrewrite= FerdyEventGI("Thread Lain ", 1,'minuman') @@ -151,41 +151,56 @@ def readfile(self,filename): # threadutama.join() # respon=self.readfile('./nilai.txt') # self.assertNotRegex(respon, "Kosong") + # def readfile(self,nfile): + # f = open(nfile, "r+") + # return str(f.read()) + + + # def test_03_raviTiga1184040(self): + # from Chapter02.raviTiga1184040 import raviTiga1184040, raviMenulis + # threadwrite = raviMenulis ("Thread Pro ",1 , 'value') + # threadutama = raviTiga1184040("Thread Utama ", 2,2,5, 'value') + # threadwrite.start() + + # def test_03_FerdyTiga1184112(self): + # from Chapter02.FerdyTiga1184112 import FerdyGITiga1184112,FerdyEventGI + # threadrewrite= FerdyEventGI("Thread Lain ", 1,'minuman') + # threadutama = FerdyGITiga1184112("Thread inti ", 2,'minuman') + # threadrewrite.start() + + # threadutama.start() + # threadwrite.join() + # threadutama.join() + + # respon=self.readfile('./Chapter02/value.pdf') + # self.assertNotRegex(respon, "Nomor : 12345678910") + + # respon=self.readfile('./Chapter02/minuman.txt') + # self.assertNotRegex(respon, "Gak Boleh Kosong") + + # def test_03_hanifTiga1184058(self): + # from Chapter02.HanifTiga1184058 import hanifTiga1184058, hanifRename + # threadrename= hanifRename("Thread rename file ",1 , 'nilai') + # threadutama = hanifTiga1184058("Thread utama ", 2, 1, 'nilai') + # threadrename.start() + # threadutama.start() + # threadrename.join() + # threadutama.join() + # respon=self.readfile('./nilai.txt') + # self.assertNotRegex(respon, "Kosong") + def readfile(self,nfile): f = open(nfile, "r+") return str(f.read()) - def test_03_raviTiga1184040(self): from Chapter02.raviTiga1184040 import raviTiga1184040, raviMenulis threadwrite = raviMenulis ("Thread Pro ",1 , 'value') threadutama = raviTiga1184040("Thread Utama ", 2,2,5, 'value') threadwrite.start() -======= - def test_03_FerdyTiga1184112(self): - from Chapter02.FerdyTiga1184112 import FerdyGITiga1184112,FerdyEventGI - threadrewrite= FerdyEventGI("Thread Lain ", 1,'minuman') - threadutama = FerdyGITiga1184112("Thread inti ", 2,'minuman') - threadrewrite.start() ->>>>>>> 3aa81716bb58a3e7685425efe1259762e524b6aa threadutama.start() threadwrite.join() threadutama.join() -<<<<<<< HEAD respon=self.readfile('./Chapter02/value.pdf') self.assertNotRegex(respon, "Nomor : 12345678910") -======= - respon=self.readfile('./Chapter02/minuman.txt') - self.assertNotRegex(respon, "Gak Boleh Kosong") - - def test_03_hanifTiga1184058(self): - from Chapter02.HanifTiga1184058 import hanifTiga1184058, hanifRename - threadrename= hanifRename("Thread rename file ",1 , 'nilai') - threadutama = hanifTiga1184058("Thread utama ", 2, 1, 'nilai') - threadrename.start() - threadutama.start() - threadrename.join() - threadutama.join() - respon=self.readfile('./nilai.txt') - self.assertNotRegex(respon, "Kosong") ->>>>>>> 3aa81716bb58a3e7685425efe1259762e524b6aa + From b66504acda60f991a1abb3d41fc123a9d3097d94 Mon Sep 17 00:00:00 2001 From: ravirahmatulfajri Date: Fri, 9 Apr 2021 10:38:14 +0700 Subject: [PATCH 067/164] Ravi 1184040 --- Chapter02/raviTiga1184040.py | 2 +- test_app.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Chapter02/raviTiga1184040.py b/Chapter02/raviTiga1184040.py index a1862ab..581e02e 100644 --- a/Chapter02/raviTiga1184040.py +++ b/Chapter02/raviTiga1184040.py @@ -1,7 +1,7 @@ from threading import Thread,currentThread, Lock, RLock, Event import requests import os -# + items = [] event = Event() hasilperhitungan=0 diff --git a/test_app.py b/test_app.py index 6759a6b..a303499 100644 --- a/test_app.py +++ b/test_app.py @@ -188,7 +188,7 @@ def tearDown(self): # threadutama.join() # respon=self.readfile('./nilai.txt') # self.assertNotRegex(respon, "Kosong") - + # def readfile(self,nfile): f = open(nfile, "r+") return str(f.read()) From 3f81d32429d4f29c4be7a3699117646ea1741a97 Mon Sep 17 00:00:00 2001 From: parhanhambali Date: Fri, 9 Apr 2021 10:45:44 +0700 Subject: [PATCH 068/164] Parhan Hambali 1184042 --- Chapter02/parhanTiga1184042.py | 80 ++++++++++++++++++++++++++++++++++ test_app.py | 28 ++++++++---- 2 files changed, 99 insertions(+), 9 deletions(-) create mode 100644 Chapter02/parhanTiga1184042.py diff --git a/Chapter02/parhanTiga1184042.py b/Chapter02/parhanTiga1184042.py new file mode 100644 index 0000000..8cfd98f --- /dev/null +++ b/Chapter02/parhanTiga1184042.py @@ -0,0 +1,80 @@ +from threading import Thread,currentThread, Lock, RLock, Event +import requests +import os + +event = Event() +hasilperhitungan=0 + +class parhanEventDeleteFile (Thread): + def __init__(self,name,thread_number,namafile): + Thread.__init__(self) + self.threadLock = Lock() + self.name = name + self.thread_number = thread_number + self.namafile=os.path.join(os.path.dirname(__file__), namafile) + self.event = event + + def run(self): + print("\n"+str(self.thread_number)+". ---> " + self.name + "jalan") + print('class parhanEventDeleteFile mau menjalankan event wait dilanjutkan clear untuk baca dan delete file') + self.event.wait() + self.threadLock.acquire() + print('melakukan baca file : '+self.namafile) + self.readfile() + print('melakukan rename file : '+self.namafile) + self.renamefile() + self.event.wait() + self.threadLock.release() + print("\n"+str(self.thread_number)+". ---> " + currentThread().getName() + "Baca file dan delete file selesai") + print ("menjalankan event clear") + self.event.clear() + + def readfile(self): + f = open(self.namafile, "r") + print("Isi Filenya : "+f.read()) + + def renamefile(self): + os.rename(self.namafile,self.namafile+'.txt') + +class parhanTiga1184042 (Thread): + def __init__(self, name,thread_number,a,b ,namafile): + Thread.__init__(self) + self.threadLock = Lock() + self.event = event + self.rlock = RLock() + self.name = name + self.namafile=os.path.join(os.path.dirname(__file__), namafile) + self.thread_number = thread_number + self.a=a + self.b=b + + def run(self): + print("\n"+str(self.thread_number)+". ---> " + self.name + "jalan") + self.threadLock.acquire() + print("threeadlock acquire utama") + self.hitung() + self.event.set() + print('class parhanTiga1184042 sudah selesai melakukan event set') + self.threadLock.release() + print("\n"+str(self.thread_number)+". ---> " + currentThread().getName() + "selesai") + + def apicorona(self): + with self.rlock: + print('didalam rlock apicorona, akses web service...') + apiurl='https://api.kawalcorona.com/indonesia' + response = requests.get(apiurl) + html=response.json() + self.createfile(html) + + def hitung(self): + with self.rlock: + print('rlock hitung') + self.apicorona() + + def createfile(self,isi): + print('membuat file baru : '+ self.namafile) + f = open(self.namafile, "x") + f.write(str(isi)) + f.close() + print('sudah membuat file baru, mau menjalankan event set') + diff --git a/test_app.py b/test_app.py index a303499..2b303e0 100644 --- a/test_app.py +++ b/test_app.py @@ -193,14 +193,24 @@ def readfile(self,nfile): f = open(nfile, "r+") return str(f.read()) - def test_03_raviTiga1184040(self): - from Chapter02.raviTiga1184040 import raviTiga1184040, raviMenulis - threadwrite = raviMenulis ("Thread Pro ",1 , 'value') - threadutama = raviTiga1184040("Thread Utama ", 2,2,5, 'value') - threadwrite.start() + # def test_03_raviTiga1184040(self): + # from Chapter02.raviTiga1184040 import raviTiga1184040, raviMenulis + # threadwrite = raviMenulis ("Thread Pro ",1 , 'value') + # threadutama = raviTiga1184040("Thread Utama ", 2,2,5, 'value') + # threadwrite.start() + # threadutama.start() + # threadwrite.join() + # threadutama.join() + # respon=self.readfile('./Chapter02/value.pdf') + # self.assertNotRegex(respon, "Nomor : 12345678910") + + def test_03_parhanTiga1184042(self): + from Chapter02.parhanTiga1184042 import parhanTiga1184042,parhanEventDeleteFile + threadutama = parhanTiga1184042("Thread Utama ", 2,5,5,'parhan') + threaddelete= parhanEventDeleteFile("Thread Delete File ", 1,'parhan') + threaddelete.start() threadutama.start() - threadwrite.join() + threaddelete.join() threadutama.join() - respon=self.readfile('./Chapter02/value.pdf') - self.assertNotRegex(respon, "Nomor : 12345678910") - + respon=self.readfile('./Chapter02/parhan.txt') + self.assertNotRegex(respon, "kosong") \ No newline at end of file From 814ccd726251a545ce263bd7ead17e6fd17f4281 Mon Sep 17 00:00:00 2001 From: Okky Yudistira Date: Fri, 9 Apr 2021 11:08:00 +0700 Subject: [PATCH 069/164] Tugas 5 Okky1184087 --- Chapter02/okkyTiga1184087.py | 119 +++++++++++++++++++++++++++++++++++ test_app.py | 13 +++- 2 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 Chapter02/okkyTiga1184087.py diff --git a/Chapter02/okkyTiga1184087.py b/Chapter02/okkyTiga1184087.py new file mode 100644 index 0000000..c8db1be --- /dev/null +++ b/Chapter02/okkyTiga1184087.py @@ -0,0 +1,119 @@ +# -*- coding: utf-8 -*- +""" +Created on Fri Apr 9 08:34:57 2021 + +@author: Okky Yudistira +""" +import threading +import time +import os +import condition +import logging +import items +from flask import request, jsonify +import sqlite3 + + +class okky1184087Write_Trier(threading.Thread): + def __init__(self,name, thread_number, filename): + threading.Thread.__init__(self) + self.name = name + self.threadLock = threading.Lock() + self.thread_number = thread_number + self.filename=os.path.join(os.path.dirname(__file__), filename) + + def start_server(): + # starting server + print("starting the server...") + # do some startup work + time.sleep(2) + + def server(b): + start_server() + b.wait() + print("Server is ready.") + + def client(b): + print("waiting for server getting ready...") + b.wait() + print("sending request to server...") + + if __name__=='__main__': + b = threading.Barrier(2, timeout=5) + s = threading.Thread(target=server, args=(b,)) + s.start() + c = threading.Thread(target=client, args=(b,)) + # client thread + c.start() + s.join() + c.join() + print("Done") + + def trying(self): + with condition: + f = open("okky.txt", "w+") + for i in range(10): + f.write("hi are you okay number %d\r\n" % (i+1)) + + if len(items) == 0: + logging.info('no items to consume') + + condition.wait() + items.pop() + logging.info('consumed 1 item') + + condition.notify() + + def run(self): + for i in range(20): + time.sleep(2) + self.trying() + +class okky1184087(threading.Thread): + def __init__(self, name, thread_number, a ,filename): + threading.Thread.__init__(self) + self.threadLock = threading.Lock() + self.name = name + self.rlock = threading.RLock() + self.filename=os.path.join(os.path.dirname(__file__), filename) + self.thread_number = thread_number + self.a=a + + + def api_filter(): + query_parameters = request.args + id = query_parameters.get('id') + published = query_parameters.get('published') + author = query_parameters.get('author') + + query = "SELECT * FROM books WHERE" + to_filter = [] + + if id: + query += ' id=? AND' + to_filter.append(id) + + if published: + query += ' published=? AND' + to_filter.append(published) + + if author: + query += ' author=? AND' + to_filter.append(author) + + if not (id or published or author): + + return page_not_found(404) + + query = query[:-4] + ';' + conn = sqlite3.connect('books.db') + conn.row_factory = dict_factory + cur = conn.cursor() + results = cur.execute(query, to_filter).fetchall() + return jsonify(results) + + def createfile(self,isi): + print('Create File : '+ self.filename) + f = open(self.filename, "w") + f.write(str(isi)) + f.close() \ No newline at end of file diff --git a/test_app.py b/test_app.py index 2b303e0..092b291 100644 --- a/test_app.py +++ b/test_app.py @@ -213,4 +213,15 @@ def test_03_parhanTiga1184042(self): threaddelete.join() threadutama.join() respon=self.readfile('./Chapter02/parhan.txt') - self.assertNotRegex(respon, "kosong") \ No newline at end of file + self.assertNotRegex(respon, "kosong") + + def test_03_okkyTiga1184087(self): + from chapter02.okkyTiga1184087 import okky1184087Write_Trier, okky1184087 + threadwrite = okky1184087Write_Trier ("Thread satu ",1 , 'okky1') + threadutama = okky1184087("Thread dua ", 2,2, 'okky2') + threadwrite.start() + threadutama.start() + threadwrite.join() + threadutama.join() + respon=self.readfile('./Chapter02/value.pdf') + self.assertNotRegex(respon, "Nomor : 12345678910") \ No newline at end of file From 72cc20c2b85312dfd65b4fd5de5cd6b5601a4105 Mon Sep 17 00:00:00 2001 From: hernandez2804 <56632278+hernandez2804@users.noreply.github.com> Date: Fri, 9 Apr 2021 11:34:16 +0700 Subject: [PATCH 070/164] Update test_app.py --- test_app.py | 69 ++++++++++++++++++++++++++--------------------------- 1 file changed, 34 insertions(+), 35 deletions(-) diff --git a/test_app.py b/test_app.py index cae63b3..60e1d3c 100644 --- a/test_app.py +++ b/test_app.py @@ -61,34 +61,32 @@ def tearDown(self): # response = main() # self.assertEqual(response, True) -<<<<<<< HEAD - def test_02_alif_1184068(self): - from Chapter02.Alif1184068 import main - response = main() - self.assertEqual(response, True) -<<<<<<< HEAD - - def test_02_iradwita_1184024(self): - from Chapter02.IraDwita1184024 import main - response = main() - self.assertEqual(response, True) + + # def test_02_alif_1184068(self): + # from Chapter02.Alif1184068 import main + # response = main() + # self.assertEqual(response, True) + + # def test_02_iradwita_1184024(self): + # from Chapter02.IraDwita1184024 import main + # response = main() + # self.assertEqual(response, True) - def test_02_bahar_1184002(self): - from Chapter02.baharandili1184002 import main - response = main() - self.assertEqual(response, True) - - def test_02_hanif_1184058(self): - from Chapter02.Hanif1184058 import main - response = main() - self.assertEqual(response, True) + # def test_02_bahar_1184002(self): + # from Chapter02.baharandili1184002 import main + # response = main() + # self.assertEqual(response, True) + + # def test_02_hanif_1184058(self): + # from Chapter02.Hanif1184058 import main + # response = main() + # self.assertEqual(response, True) - def test_02_parhan_1184042(self): - from Chapter02.Parhan1184042 import main - response = main() - self.assertEqual(response, True) -======= -======= + # def test_02_parhan_1184042(self): + # from Chapter02.Parhan1184042 import main + # response = main() + # self.assertEqual(response, True) + #def test_02_alif_1184068(self): # from Chapter02.Alif1184068 import main # response = main() @@ -108,7 +106,7 @@ def test_02_parhan_1184042(self): # from Chapter02.Hanif1184058 import main # response = main() # self.assertEqual(response, True) ->>>>>>> 48ca87266fc537948d7e48a77c9ffa47bed5cfc4 + #def test_02_parhan_1184042(self): # from Chapter02.Parhan1184042 import main @@ -233,14 +231,14 @@ def readfile(self,nfile): # respon=self.readfile('./Chapter02/value.pdf') # self.assertNotRegex(respon, "Nomor : 12345678910") - def test_03_parhanTiga1184042(self): - from Chapter02.parhanTiga1184042 import parhanTiga1184042,parhanEventDeleteFile - threadutama = parhanTiga1184042("Thread Utama ", 2,5,5,'parhan') - threaddelete= parhanEventDeleteFile("Thread Delete File ", 1,'parhan') - threaddelete.start() - threadutama.start() - threaddelete.join() - threadutama.join() + # def test_03_parhanTiga1184042(self): + # from Chapter02.parhanTiga1184042 import parhanTiga1184042,parhanEventDeleteFile + # threadutama = parhanTiga1184042("Thread Utama ", 2,5,5,'parhan') + # threaddelete= parhanEventDeleteFile("Thread Delete File ", 1,'parhan') + # threaddelete.start() + # threadutama.start() + # threaddelete.join() + # threadutama.join() def test_03_IrfanHernadezTiga1184014(self): from Chapter02.IrfanHernandezTiga1184014 import NandezEvent,NandezEvent1184014 @@ -254,3 +252,4 @@ def test_03_IrfanHernadezTiga1184014(self): self.assertNotRegex(respon, "marimas") + From a17ac7ee4155193e017190626a3605cb100b0201 Mon Sep 17 00:00:00 2001 From: zanwar Date: Wed, 14 Apr 2021 23:00:52 +0700 Subject: [PATCH 071/164] update --- Chapter02/ZanwarTiga1184050.py | 7 +- test_app.py | 133 ++++++++++++++++++++++++++++----- 2 files changed, 119 insertions(+), 21 deletions(-) diff --git a/Chapter02/ZanwarTiga1184050.py b/Chapter02/ZanwarTiga1184050.py index fe7abbb..1ea2d52 100644 --- a/Chapter02/ZanwarTiga1184050.py +++ b/Chapter02/ZanwarTiga1184050.py @@ -61,13 +61,12 @@ def run(self): def randomapi(self): with self.rlock: print('Inside rlock apipangkat, akses web service...') - apiurl='https://goquotes-api.herokuapp.com/api/v1/random?' - eq='count='+str(self.a) - response = requests.get(apiurl+eq) + apiurl='https://digimon-api.herokuapp.com/api/digimon' + response = requests.get(apiurl) html=response.json() string = "Quotes : " for i in range(len(html["quotes"])): - hasil = html["quotes"][i]["text"] + hasil = html[i]["name"] tulis = "\n"+str(i)+". " string = string+tulis+str(hasil) self.createfile(string) diff --git a/test_app.py b/test_app.py index b5876a9..2b303e0 100644 --- a/test_app.py +++ b/test_app.py @@ -86,20 +86,26 @@ def tearDown(self): # response = main() # self.assertEqual(response, True) - def readfile(self,filename): - f = open(filename, "r") - return str(f.read()) + + # def readfile(self,filename): + # f = open(filename, "r") + # return str(f.read()) + + # def readfile(self,filename): + # f = open(filename, "r") + # return str(f.read()) + - def test_03_zanwarTiga1184050(self): - from Chapter02.ZanwarTiga1184050 import zanwarTiga1184050, zanwarRewrite - threadrewrite= zanwarRewrite("Thread Rewrite File ",1 , 'nilai') - threadutama = zanwarTiga1184050("Thread Utama ", 2, 1, 'nilai') - threadrewrite.start() - threadutama.start() - threadrewrite.join() - threadutama.join() - respon=self.readfile('./Chapter02/nilai.txt') - self.assertNotRegex(respon, "Kosong") + # def test_03_zanwarTiga1184050(self): + # from Chapter02.ZanwarTiga1184050 import zanwarTiga1184050, zanwarRewrite + # threadrewrite= zanwarRewrite("Thread Rewrite File ",1 , 'nilai') + # threadutama = zanwarTiga1184050("Thread Utama ", 2, 1, 'nilai') + # threadrewrite.start() + # threadutama.start() + # threadrewrite.join() + # threadutama.join() + # respon=self.readfile('./Chapter02/nilai.txt') + # self.assertNotRegex(respon, "Kosong") # def test_03_WahyuKurniaSariDua1184001(self): # from Chapter02.WahyuKurniasariDua1184001 import WahyuKurniaSariSemaphoreDeleteFile, WahyuKurniaSariDua1184001 @@ -111,7 +117,100 @@ def test_03_zanwarTiga1184050(self): # main.join() #self.assertGreaterEqual(main.getFileContent(),0 ) - - - - \ No newline at end of file + # def test_03_alifTiga1184068(self): + # from Chapter02.alifTiga1184068 import alifTiga1184068,alifEventDeleteFile + # threadutama = alifTiga1184068("Thread Utama ", 2,5,5,'alip') + # threaddelete= alifEventDeleteFile("Thread Delete File ", 1,'alip') + # threaddelete.start() + # threadutama.start() + # threaddelete.join() + # threadutama.join() + # respon=self.readfile('./Chapter02/alip.txt') + # self.assertNotRegex(respon, "kosong") + + + + # def test_03_FerdyTiga1184112(self): + # from Chapter02.FerdyTiga1184112 import FerdyGITiga1184112,FerdyEventGI + # threadrewrite= FerdyEventGI("Thread Lain ", 1,'minuman') + # threadutama = FerdyGITiga1184112("Thread inti ", 2,'minuman') + # threadrewrite.start() + # threadutama.start() + # threadrewrite.join() + # threadutama.join() + # respon=self.readfile('./Chapter02/minuman.txt') + # self.assertNotRegex(respon, "Gak Boleh Kosong") + + # def test_03_hanifTiga1184058(self): + # from Chapter02.HanifTiga1184058 import hanifTiga1184058, hanifRename + # threadrename= hanifRename("Thread rename file ",1 , 'nilai') + # threadutama = hanifTiga1184058("Thread utama ", 2, 1, 'nilai') + # threadrename.start() + # threadutama.start() + # threadrename.join() + # threadutama.join() + # respon=self.readfile('./nilai.txt') + # self.assertNotRegex(respon, "Kosong") + # def readfile(self,nfile): + # f = open(nfile, "r+") + # return str(f.read()) + + + # def test_03_raviTiga1184040(self): + # from Chapter02.raviTiga1184040 import raviTiga1184040, raviMenulis + # threadwrite = raviMenulis ("Thread Pro ",1 , 'value') + # threadutama = raviTiga1184040("Thread Utama ", 2,2,5, 'value') + # threadwrite.start() + + # def test_03_FerdyTiga1184112(self): + # from Chapter02.FerdyTiga1184112 import FerdyGITiga1184112,FerdyEventGI + # threadrewrite= FerdyEventGI("Thread Lain ", 1,'minuman') + # threadutama = FerdyGITiga1184112("Thread inti ", 2,'minuman') + # threadrewrite.start() + + # threadutama.start() + # threadwrite.join() + # threadutama.join() + + # respon=self.readfile('./Chapter02/value.pdf') + # self.assertNotRegex(respon, "Nomor : 12345678910") + + # respon=self.readfile('./Chapter02/minuman.txt') + # self.assertNotRegex(respon, "Gak Boleh Kosong") + + # def test_03_hanifTiga1184058(self): + # from Chapter02.HanifTiga1184058 import hanifTiga1184058, hanifRename + # threadrename= hanifRename("Thread rename file ",1 , 'nilai') + # threadutama = hanifTiga1184058("Thread utama ", 2, 1, 'nilai') + # threadrename.start() + # threadutama.start() + # threadrename.join() + # threadutama.join() + # respon=self.readfile('./nilai.txt') + # self.assertNotRegex(respon, "Kosong") + # + def readfile(self,nfile): + f = open(nfile, "r+") + return str(f.read()) + + # def test_03_raviTiga1184040(self): + # from Chapter02.raviTiga1184040 import raviTiga1184040, raviMenulis + # threadwrite = raviMenulis ("Thread Pro ",1 , 'value') + # threadutama = raviTiga1184040("Thread Utama ", 2,2,5, 'value') + # threadwrite.start() + # threadutama.start() + # threadwrite.join() + # threadutama.join() + # respon=self.readfile('./Chapter02/value.pdf') + # self.assertNotRegex(respon, "Nomor : 12345678910") + + def test_03_parhanTiga1184042(self): + from Chapter02.parhanTiga1184042 import parhanTiga1184042,parhanEventDeleteFile + threadutama = parhanTiga1184042("Thread Utama ", 2,5,5,'parhan') + threaddelete= parhanEventDeleteFile("Thread Delete File ", 1,'parhan') + threaddelete.start() + threadutama.start() + threaddelete.join() + threadutama.join() + respon=self.readfile('./Chapter02/parhan.txt') + self.assertNotRegex(respon, "kosong") \ No newline at end of file From 65a642b18efbfeda03507586be90e712d1c187ac Mon Sep 17 00:00:00 2001 From: zanwar Date: Thu, 15 Apr 2021 01:14:14 +0700 Subject: [PATCH 072/164] update tugas --- Chapter02/ZanwarEnam1184050.py | 76 +++++++++++++++++++++++++++++++++ Chapter02/ZanwarTiga1184050.py | 12 +++--- Chapter02/value.pdf | Bin 20 -> 0 bytes nilai.txt | 0 test_app.py | 25 ++++++----- 5 files changed, 96 insertions(+), 17 deletions(-) create mode 100644 Chapter02/ZanwarEnam1184050.py delete mode 100644 Chapter02/value.pdf delete mode 100644 nilai.txt diff --git a/Chapter02/ZanwarEnam1184050.py b/Chapter02/ZanwarEnam1184050.py new file mode 100644 index 0000000..5622e6e --- /dev/null +++ b/Chapter02/ZanwarEnam1184050.py @@ -0,0 +1,76 @@ +from threading import Barrier, Thread +import os +import requests +from time import ctime, sleep + +#akan menentukan berapa thread yang akan di tahan untuk diijinkan selesai eksekusi, tengan penanda wait() +# intinya tentukan jumlah thread dan gunakaan wait() +num_runners = 3 +finish_line = Barrier(num_runners) +#runners = ['Hermawan', 'Dadang', 'Asep'] +file = "za" +filename = os.path.join(os.path.dirname(__file__), file) + +def randomapi(): + apiurl='https://goquotes-api.herokuapp.com/api/v1/random?' + eq='count='+str(num_runners) + response = requests.get(apiurl+eq) + html=response.json() + string = "Quotes : " + for i in range(len(html["quotes"])): + hasil = html["quotes"][i]["text"] + tulis = "\n"+str(i)+". " + string = string+tulis+str(hasil) + createfile(string) + +def read(): + x = open(filename+'2.txt', "r") + print(x.read()) + x.close() + +def createfile(isi): + for i in range(num_runners): + print('Create File : '+file+str(i)+'.txt') + f = open(filename+str(i)+".txt", "w") + f.write(str(isi)) + sleep(2) + finish_line.wait() + print('Read File:'+file+str(i)+'.txt') + x = open(filename+str(i)+".txt", "r") + print(x.read()) + x.close() + print('Create & Read reached the barrier at: %s \n' % (ctime())) + sleep(2) + finish_line.wait() + f.close() + +def runner(): + randomapi() + sleep(2) + print('Remove 0 reached the barrier at: %s \n' % (ctime())) + finish_line.wait() + print('hapus file pertama!') + os.remove(filename+'0.txt') + sleep(2) + print('Remove 1 reached the barrier at: %s \n' % (ctime())) + finish_line.wait() + print('hapus file kedua!') + os.remove(filename+'1.txt') + print('Baca File za2.txt') + read() + +### In[]: + +def main(): + threads = []#buat list kosong namanya threads + print('START!!!!') + for i in range(num_runners):#lakukan perulangan sebanyak 3 kali adalah jumlah pelari + threads.append(Thread(target=runner))#menyimpan objek thread ke dalam variable list threads + threads[-1].start()#mengambil list thread paling belakang + for thread in threads: + thread.join() + print('Over!') + return True + +#if __name__ == "__main__": +# main() \ No newline at end of file diff --git a/Chapter02/ZanwarTiga1184050.py b/Chapter02/ZanwarTiga1184050.py index 1ea2d52..b80f119 100644 --- a/Chapter02/ZanwarTiga1184050.py +++ b/Chapter02/ZanwarTiga1184050.py @@ -61,12 +61,13 @@ def run(self): def randomapi(self): with self.rlock: print('Inside rlock apipangkat, akses web service...') - apiurl='https://digimon-api.herokuapp.com/api/digimon' - response = requests.get(apiurl) + apiurl='https://goquotes-api.herokuapp.com/api/v1/random?' + eq='count='+str(self.a) + response = requests.get(apiurl+eq) html=response.json() string = "Quotes : " for i in range(len(html["quotes"])): - hasil = html[i]["name"] + hasil = html["quotes"][i]["text"] tulis = "\n"+str(i)+". " string = string+tulis+str(hasil) self.createfile(string) @@ -82,7 +83,4 @@ def createfile(self,isi): f = open(self.filename, "w") f.write(str(isi)) f.close() - - - - + \ No newline at end of file diff --git a/Chapter02/value.pdf b/Chapter02/value.pdf deleted file mode 100644 index 9081fb70d22a5b4018c773547ef896ada783da4a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 20 bcmY#z%uCNsRIpMoG%_|ZH8Z!cG&BGJHS7et diff --git a/nilai.txt b/nilai.txt deleted file mode 100644 index e69de29..0000000 diff --git a/test_app.py b/test_app.py index 2b303e0..3e2b50f 100644 --- a/test_app.py +++ b/test_app.py @@ -204,13 +204,18 @@ def readfile(self,nfile): # respon=self.readfile('./Chapter02/value.pdf') # self.assertNotRegex(respon, "Nomor : 12345678910") - def test_03_parhanTiga1184042(self): - from Chapter02.parhanTiga1184042 import parhanTiga1184042,parhanEventDeleteFile - threadutama = parhanTiga1184042("Thread Utama ", 2,5,5,'parhan') - threaddelete= parhanEventDeleteFile("Thread Delete File ", 1,'parhan') - threaddelete.start() - threadutama.start() - threaddelete.join() - threadutama.join() - respon=self.readfile('./Chapter02/parhan.txt') - self.assertNotRegex(respon, "kosong") \ No newline at end of file + #def test_03_parhanTiga1184042(self): + # from Chapter02.parhanTiga1184042 import parhanTiga1184042,parhanEventDeleteFile + # threadutama = parhanTiga1184042("Thread Utama ", 2,5,5,'parhan') + # threaddelete= parhanEventDeleteFile("Thread Delete File ", 1,'parhan') + #threaddelete.start() + #threadutama.start() + #threaddelete.join() + #threadutama.join() + #respon=self.readfile('./Chapter02/parhan.txt') + #self.assertNotRegex(respon, "kosong") + + def test_06_zanwar_1184050(self): + from Chapter02.ZanwarEnam1184050 import main + response = main() + self.assertEqual(response, True) From eea95d5edeb0cbc6fd82f2784cd222b23b3bddec Mon Sep 17 00:00:00 2001 From: zanwar Date: Thu, 15 Apr 2021 10:54:13 +0700 Subject: [PATCH 073/164] update var --- Chapter02/ZanwarEnam1184050.py | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/Chapter02/ZanwarEnam1184050.py b/Chapter02/ZanwarEnam1184050.py index 5622e6e..a6f0f24 100644 --- a/Chapter02/ZanwarEnam1184050.py +++ b/Chapter02/ZanwarEnam1184050.py @@ -3,17 +3,14 @@ import requests from time import ctime, sleep -#akan menentukan berapa thread yang akan di tahan untuk diijinkan selesai eksekusi, tengan penanda wait() -# intinya tentukan jumlah thread dan gunakaan wait() -num_runners = 3 -finish_line = Barrier(num_runners) -#runners = ['Hermawan', 'Dadang', 'Asep'] +kali = 3 +barr = Barrier(kali) file = "za" filename = os.path.join(os.path.dirname(__file__), file) def randomapi(): apiurl='https://goquotes-api.herokuapp.com/api/v1/random?' - eq='count='+str(num_runners) + eq='count='+str(kali) response = requests.get(apiurl+eq) html=response.json() string = "Quotes : " @@ -29,31 +26,31 @@ def read(): x.close() def createfile(isi): - for i in range(num_runners): + for i in range(kali): print('Create File : '+file+str(i)+'.txt') f = open(filename+str(i)+".txt", "w") f.write(str(isi)) sleep(2) - finish_line.wait() + barr.wait() print('Read File:'+file+str(i)+'.txt') x = open(filename+str(i)+".txt", "r") print(x.read()) x.close() print('Create & Read reached the barrier at: %s \n' % (ctime())) sleep(2) - finish_line.wait() + barr.wait() f.close() -def runner(): +def run(): randomapi() sleep(2) print('Remove 0 reached the barrier at: %s \n' % (ctime())) - finish_line.wait() + barr.wait() print('hapus file pertama!') os.remove(filename+'0.txt') sleep(2) print('Remove 1 reached the barrier at: %s \n' % (ctime())) - finish_line.wait() + barr.wait() print('hapus file kedua!') os.remove(filename+'1.txt') print('Baca File za2.txt') @@ -62,11 +59,11 @@ def runner(): ### In[]: def main(): - threads = []#buat list kosong namanya threads + threads = [] print('START!!!!') - for i in range(num_runners):#lakukan perulangan sebanyak 3 kali adalah jumlah pelari - threads.append(Thread(target=runner))#menyimpan objek thread ke dalam variable list threads - threads[-1].start()#mengambil list thread paling belakang + for i in range(kali): + threads.append(Thread(target=run)) + threads[-1].start() for thread in threads: thread.join() print('Over!') From 5f38dc3c3d89134bc2b667681d7603093e4ba95b Mon Sep 17 00:00:00 2001 From: zanwar Date: Thu, 15 Apr 2021 11:39:18 +0700 Subject: [PATCH 074/164] update fungsi --- Chapter02/ZanwarEnam1184050.py | 36 ++++++++++------------------------ 1 file changed, 10 insertions(+), 26 deletions(-) diff --git a/Chapter02/ZanwarEnam1184050.py b/Chapter02/ZanwarEnam1184050.py index a6f0f24..a45f1c7 100644 --- a/Chapter02/ZanwarEnam1184050.py +++ b/Chapter02/ZanwarEnam1184050.py @@ -3,7 +3,7 @@ import requests from time import ctime, sleep -kali = 3 +kali = 1 barr = Barrier(kali) file = "za" filename = os.path.join(os.path.dirname(__file__), file) @@ -20,47 +20,31 @@ def randomapi(): string = string+tulis+str(hasil) createfile(string) -def read(): - x = open(filename+'2.txt', "r") - print(x.read()) - x.close() - def createfile(isi): - for i in range(kali): - print('Create File : '+file+str(i)+'.txt') + for i in range(3): + print('Create File : '+file+str(i)+'.txt \n') f = open(filename+str(i)+".txt", "w") f.write(str(isi)) - sleep(2) - barr.wait() - print('Read File:'+file+str(i)+'.txt') + f.close() + print('Read File: '+file+str(i)+'.txt') x = open(filename+str(i)+".txt", "r") - print(x.read()) + print(x.read()+'\n') x.close() - print('Create & Read reached the barrier at: %s \n' % (ctime())) + print('Create & Read '+file+str(i)+' reached the barrier at: %s \n' % (ctime())) sleep(2) barr.wait() - f.close() - + def run(): randomapi() sleep(2) - print('Remove 0 reached the barrier at: %s \n' % (ctime())) - barr.wait() - print('hapus file pertama!') - os.remove(filename+'0.txt') - sleep(2) - print('Remove 1 reached the barrier at: %s \n' % (ctime())) barr.wait() - print('hapus file kedua!') - os.remove(filename+'1.txt') - print('Baca File za2.txt') - read() + print('All reached the barrier at: %s \n' % (ctime())) ### In[]: def main(): threads = [] - print('START!!!!') + print('START!') for i in range(kali): threads.append(Thread(target=run)) threads[-1].start() From 429e1ae810a127e6062e16c62c705a0414c067db Mon Sep 17 00:00:00 2001 From: FerdyBerlianoP Date: Thu, 15 Apr 2021 14:49:22 +0700 Subject: [PATCH 075/164] Tugas6 Ferdy Berliano Putra 1184112 --- Chapter02/FerdyEnam1184112.py | 52 +++++++++++++++++++++++++++++++++++ test_app.py | 25 ++++++++++------- 2 files changed, 67 insertions(+), 10 deletions(-) create mode 100644 Chapter02/FerdyEnam1184112.py diff --git a/Chapter02/FerdyEnam1184112.py b/Chapter02/FerdyEnam1184112.py new file mode 100644 index 0000000..0a16e8a --- /dev/null +++ b/Chapter02/FerdyEnam1184112.py @@ -0,0 +1,52 @@ +from threading import Barrier, Thread +import requests +from time import ctime, sleep + +nomor = 1 +finish = Barrier(nomor) +yuhu = [] + + + +def webservice(): + apiurl='https://www.thecocktaildb.com/api/json/v1/1/list.php?c=list' + response = requests.get(apiurl) + html=response.json() + for i in range(len(html["drinks"])): + cocokin = html["drinks"][i] + yuhu.append(cocokin) + + +def bacafile(): + f = open("barrier.txt", "r") + print("isi file setelah di pop: \n" +f.read()) + +def utama(): + webservice() + sleep(2) + name = yuhu.pop() + print('%s reached the barrier at: %s \n' % (name, ctime())) + finish.wait() + print('buat file baru namanya: barrier.txt \n') + f = open("barrier.txt","w") + f.write(str(yuhu)) + f.close() + bacafile() + + +def main (): + hiya=[] + print("\n Barrier Mulai \n") + for i in range(nomor): + hiya.append(Thread(target=utama)) + hiya[-1].start() + for thread in hiya: + thread.join() + print("finish") + return True + + + +#if __name__ == "__main__": +# main() + diff --git a/test_app.py b/test_app.py index 2b303e0..80019c7 100644 --- a/test_app.py +++ b/test_app.py @@ -204,13 +204,18 @@ def readfile(self,nfile): # respon=self.readfile('./Chapter02/value.pdf') # self.assertNotRegex(respon, "Nomor : 12345678910") - def test_03_parhanTiga1184042(self): - from Chapter02.parhanTiga1184042 import parhanTiga1184042,parhanEventDeleteFile - threadutama = parhanTiga1184042("Thread Utama ", 2,5,5,'parhan') - threaddelete= parhanEventDeleteFile("Thread Delete File ", 1,'parhan') - threaddelete.start() - threadutama.start() - threaddelete.join() - threadutama.join() - respon=self.readfile('./Chapter02/parhan.txt') - self.assertNotRegex(respon, "kosong") \ No newline at end of file + # def test_03_parhanTiga1184042(self): + # from Chapter02.parhanTiga1184042 import parhanTiga1184042,parhanEventDeleteFile + # threadutama = parhanTiga1184042("Thread Utama ", 2,5,5,'parhan') + # threaddelete= parhanEventDeleteFile("Thread Delete File ", 1,'parhan') + # threaddelete.start() + # threadutama.start() + # threaddelete.join() + # threadutama.join() + # respon=self.readfile('./Chapter02/parhan.txt') + # self.assertNotRegex(respon, "kosong") + + def test_06_Ferdy_1184112(self): + from Chapter02.FerdyEnam1184112 import main + response = main() + self.assertEqual(response, True) \ No newline at end of file From 1977655ceddaa66b0d1be02c95b98217f6ada9de Mon Sep 17 00:00:00 2001 From: zanwar Date: Thu, 15 Apr 2021 15:07:05 +0700 Subject: [PATCH 076/164] update --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 343afd8..1344c17 100644 --- a/.gitignore +++ b/.gitignore @@ -136,6 +136,7 @@ anu.croot ano.croot nilai.html nilai +nilai.txt value value.txt value From 708b6724573f659c9a84701c88a2bb0aedb15c19 Mon Sep 17 00:00:00 2001 From: alif721 Date: Thu, 15 Apr 2021 16:08:25 +0700 Subject: [PATCH 077/164] Tugas 6 Alif --- Chapter02/AlifEnam1184068.py | 57 ++++++++++++++++++++++++++++++++++++ test_app.py | 17 +++++++---- 2 files changed, 68 insertions(+), 6 deletions(-) create mode 100644 Chapter02/AlifEnam1184068.py diff --git a/Chapter02/AlifEnam1184068.py b/Chapter02/AlifEnam1184068.py new file mode 100644 index 0000000..fd54328 --- /dev/null +++ b/Chapter02/AlifEnam1184068.py @@ -0,0 +1,57 @@ +from threading import Barrier, Thread +import os +import requests +from time import ctime, sleep + +angka = 1 +b = Barrier(angka) +file = "alif" +file2 = "alifbaru" +filename = os.path.join(os.path.dirname(__file__), file) +filename2 = os.path.join(os.path.dirname(__file__), file2) + +def getapi(): + apiurl='http://www.emsifa.com/api-wilayah-indonesia/api/provinces.json' + response = requests.get(apiurl) + html=response.json() + handlingfile(html) + +def handlingfile(isi): + print('Yoo filenya dibuat dulu ya : '+file+'.txt \n') + f = open(filename+".txt", "w") + print('Filenya udah dibuat nih \n') + f.write(str(isi)) + f.close() + print('Isi filenya apaan yaa: '+file+'.txt') + x = open(filename+".txt", "r") + print(x.read()+'\n') + x.close() + print('coba ganti nama filenya dong \n') + print('Rename File menjadi: '+file2+'.txt \n') + os.rename(filename+'.txt', filename2+'.txt') + sleep(2) + b.wait() + print('File:'+file+'.txt'+' telah berhasil di Rename \n') + sleep(2) + b.wait() + print('Create, Read, and delete file: '+file+' mencapai barrier pada waktu: %s \n' % (ctime())) + +def run(): + getapi() + sleep(2) + b.wait() + print('Semua mencapai barrier pada waktu: %s \n' % (ctime())) + +def main(): + threads = [] + print('Gasskeun! Semoga berhasil') + for i in range(angka): + threads.append(Thread(target=run)) + threads[-1].start() + for thread in threads: + thread.join() + print('Yeaayy berhasil berhasil! Horeee!') + return True + +#if __name__ == "__main__": +# main() \ No newline at end of file diff --git a/test_app.py b/test_app.py index a406638..4925953 100644 --- a/test_app.py +++ b/test_app.py @@ -215,13 +215,18 @@ def readfile(self,nfile): # respon=self.readfile('./Chapter02/parhan.txt') # self.assertNotRegex(respon, "kosong") - def test_06_Ferdy_1184112(self): - from Chapter02.FerdyEnam1184112 import main - response = main() - self.assertEqual(response, True) + # def test_06_Ferdy_1184112(self): + # from Chapter02.FerdyEnam1184112 import main + # response = main() + # self.assertEqual(response, True) - def test_06_zanwar_1184050(self): - from Chapter02.ZanwarEnam1184050 import main + # def test_06_zanwar_1184050(self): + # from Chapter02.ZanwarEnam1184050 import main + # response = main() + # self.assertEqual(response, True) + + def test_06_alif_1184068(self): + from Chapter02.AlifEnam1184068 import main response = main() self.assertEqual(response, True) From 92bd8d94f36b8369fffb13d7238dcfd17b720bf0 Mon Sep 17 00:00:00 2001 From: parhanhambali Date: Thu, 15 Apr 2021 16:46:22 +0700 Subject: [PATCH 078/164] 1184042 Parhan Hambali --- Chapter02/ParhanEnam1184042.py | 55 ++++++++++++++++++++++++++++++++++ test_app.py | 13 ++++---- 2 files changed, 63 insertions(+), 5 deletions(-) create mode 100644 Chapter02/ParhanEnam1184042.py diff --git a/Chapter02/ParhanEnam1184042.py b/Chapter02/ParhanEnam1184042.py new file mode 100644 index 0000000..54a28ef --- /dev/null +++ b/Chapter02/ParhanEnam1184042.py @@ -0,0 +1,55 @@ +from threading import Barrier, Thread +import os +import requests +from time import ctime, sleep + +angka = 1 +b = Barrier(angka) +file = "parhan" +filename = os.path.join(os.path.dirname(__file__), file) + +def apiwebservice(): + apiurl='https://api.kawalcorona.com/indonesia' + response = requests.get(apiurl) + html=response.json() + manajemenfile(html) + +def manajemenfile(isi): + print('buat file terlebih dahulu : '+file+'.txt \n') + f = open(filename+".txt", "w") + print('File telah berhasil dibuat \n') + f.write(str(isi)) + f.close() + print('Isi file tersebut adalah: '+file+'.txt') + x = open(filename+".txt", "r") + print(x.read()+'\n') + x.close() + print('coba hapus file \n') + print('Hapus File: '+file+'.txt \n') + os.remove(filename+'.txt') + sleep(2) + b.wait() + print('File:'+file+'.txt'+' telah berhasil di Hapus \n') + sleep(2) + b.wait() + print('Create, Read, and delete file: '+file+' mencapai barrier pada waktu: %s \n' % (ctime())) + +def run(): + apiwebservice() + sleep(2) + b.wait() + print('Semua mencapai barrier pada waktu: %s \n' % (ctime())) + +def main(): + threads = [] + print('Semoga berhasil') + for i in range(angka): + threads.append(Thread(target=run)) + threads[-1].start() + for thread in threads: + thread.join() + print('Success') + return True + +# if __name__ == "__main__": +# main() \ No newline at end of file diff --git a/test_app.py b/test_app.py index 4925953..ad69315 100644 --- a/test_app.py +++ b/test_app.py @@ -225,9 +225,12 @@ def readfile(self,nfile): # response = main() # self.assertEqual(response, True) - def test_06_alif_1184068(self): - from Chapter02.AlifEnam1184068 import main + #def test_06_alif_1184068(self): + # from Chapter02.AlifEnam1184068 import main + # response = main() + # self.assertEqual(response, True) + + def test_06_parhan_1184042(self): + from Chapter02.ParhanEnam1184042 import main response = main() - self.assertEqual(response, True) - - + self.assertEqual(response, True) \ No newline at end of file From ea7ac3827391b7c7e73e2483c96ba127e99d72ea Mon Sep 17 00:00:00 2001 From: HanifWp Date: Thu, 15 Apr 2021 21:42:07 +0700 Subject: [PATCH 079/164] Tugas 6 Hanif --- Chapter02/HanifEnam1184058.py | 57 +++++++++++++++++++++++++++++++++++ test_app.py | 9 ++++-- 2 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 Chapter02/HanifEnam1184058.py diff --git a/Chapter02/HanifEnam1184058.py b/Chapter02/HanifEnam1184058.py new file mode 100644 index 0000000..b2aeef4 --- /dev/null +++ b/Chapter02/HanifEnam1184058.py @@ -0,0 +1,57 @@ +from threading import Barrier, Thread +import os +import requests +from time import ctime, sleep + +bar = Barrier(1) +file = "pokemon" +filename = os.path.join(os.path.dirname(__file__), file) + +def createfile(isi): + print('Buat file : '+file+'.txt \n') + f = open(filename+".txt", "w") + f.write(str(isi)) + f.close() + print('Membaca file: '+file+'.txt \n') + x = open(filename+".txt", "r") + print(x.read()+'\n') + x.close() + print("Copy file ke direktori luar") + copyfile() + print('Membuat, membaca dan copy '+file+' menggapai barrier dalam: %s \n' % (ctime())) + sleep(2) + bar.wait() + +def copyfile(): + with open ("F:\\Kuliah\\Semester 6\\Sistem Tersebar\\Python-Parallel-Programming-Cookbook-Second-Edition\\Chapter02\\pokemon.txt", "rb") as read: + with open ("F:\\Kuliah\\Semester 6\\Sistem Tersebar\\Python-Parallel-Programming-Cookbook-Second-Edition\\pokemon_copy.txt", "wb") as filetobecopied: + filetobecopied.write(read.read()) + +def randomapi(): + print('akses web service...') + apiurl='https://pokeapi.co/api/v2/pokemon/ditto' + response = requests.get(apiurl) + html=response.json() + string = "ability :" + for i in range(len(html["abilities"])): + hasil = html["abilities"][i]["ability"]["name"] + tulis = "\n"+str(i)+". " + string = string+tulis+str(hasil) + createfile(string) + +def run(): + randomapi() + sleep(2) + bar.wait() + print('All reached the barrier at: %s \n' % (ctime())) + +def main(): + threads = [] + print('\nBismillah berkah Ramadhan \n') + for i in range(1): + threads.append(Thread(target=run)) + threads[-1].start() + for thread in threads: + thread.join() + print('Alhamdulillah bisa') + return True diff --git a/test_app.py b/test_app.py index ad69315..b49f989 100644 --- a/test_app.py +++ b/test_app.py @@ -230,7 +230,12 @@ def readfile(self,nfile): # response = main() # self.assertEqual(response, True) - def test_06_parhan_1184042(self): - from Chapter02.ParhanEnam1184042 import main + #def test_06_parhan_1184042(self): + # from Chapter02.ParhanEnam1184042 import main + # response = main() + # self.assertEqual(response, True) + + def test_06_hanif_1184058(self): + from Chapter02.HanifEnam1184058 import main response = main() self.assertEqual(response, True) \ No newline at end of file From cd9064e5b27e677531799687ad9641f03260714d Mon Sep 17 00:00:00 2001 From: idafatriniputri Date: Thu, 15 Apr 2021 22:48:54 +0700 Subject: [PATCH 080/164] Tugas Enam Ida 1184113 --- Chapter02/IdaEnam1184113.py | 57 +++++++++++++++++++++++++++++++++++++ test_app.py | 9 ++++-- 2 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 Chapter02/IdaEnam1184113.py diff --git a/Chapter02/IdaEnam1184113.py b/Chapter02/IdaEnam1184113.py new file mode 100644 index 0000000..a24cc3b --- /dev/null +++ b/Chapter02/IdaEnam1184113.py @@ -0,0 +1,57 @@ +from threading import Barrier, Thread +from time import ctime, sleep +import requests + +jumlah = 3 +shield = Barrier(jumlah) +runners = [] +filename = "luffy.txt" + +def api(): + url = "https://api.jikan.moe/v3/search/anime?q=One%20Piece" + response = requests.get(url) + html=response.json() + string = "Anime: " + for i in range(len(html)): + hasil = html["results"][i]["title"] + data = str(hasil) + ent = "\n"+str(i)+". " + string = string+ent+data + runners.append(data) + createfile(string) + +def read(): + x = open(filename, "r") + print(x.read()) + +def createfile(isi): + f = open(filename, "w") + f.write(str(isi)) + f.close() + +def runner(): + api() + sleep(2) + shield.wait() + name = runners.pop() + sleep(2) + print('%s sudah mencaapai barier pada: %s \n' % (name, ctime())) + shield.wait() + print('Create dan Read File sudah mencaapai barier pada: %s \n' % (ctime())) + read() + shield.wait() + + +def main(): + threads = [] + print('Mulai!') + for i in range(jumlah): + threads.append(Thread(target=runner)) + threads[-1].start() + for thread in threads: + thread.join() + print('Selesai!') + return True + +#if __name__ == "__main__": +# main() diff --git a/test_app.py b/test_app.py index ad69315..47b2e89 100644 --- a/test_app.py +++ b/test_app.py @@ -230,7 +230,12 @@ def readfile(self,nfile): # response = main() # self.assertEqual(response, True) - def test_06_parhan_1184042(self): - from Chapter02.ParhanEnam1184042 import main + # def test_06_parhan_1184042(self): + # from Chapter02.ParhanEnam1184042 import main + # response = main() + # self.assertEqual(response, True) + + def test_06_ida_1184113(self): + from Chapter02.IdaEnam1184113 import main response = main() self.assertEqual(response, True) \ No newline at end of file From dad9e844b9868b575ef8c2256635479c51ba66cb Mon Sep 17 00:00:00 2001 From: hernandez2804 <56632278+hernandez2804@users.noreply.github.com> Date: Thu, 15 Apr 2021 23:16:40 +0700 Subject: [PATCH 081/164] Tugas 6 update --- Chapter02/FerdyEnam1184112.py | 4 -- Chapter02/IrfanHernandezEnam1184014.py | 53 ++++++++++++++++++++++++++ test_app.py | 14 ++++--- 3 files changed, 62 insertions(+), 9 deletions(-) create mode 100644 Chapter02/IrfanHernandezEnam1184014.py diff --git a/Chapter02/FerdyEnam1184112.py b/Chapter02/FerdyEnam1184112.py index 0a16e8a..825f557 100644 --- a/Chapter02/FerdyEnam1184112.py +++ b/Chapter02/FerdyEnam1184112.py @@ -6,8 +6,6 @@ finish = Barrier(nomor) yuhu = [] - - def webservice(): apiurl='https://www.thecocktaildb.com/api/json/v1/1/list.php?c=list' response = requests.get(apiurl) @@ -16,7 +14,6 @@ def webservice(): cocokin = html["drinks"][i] yuhu.append(cocokin) - def bacafile(): f = open("barrier.txt", "r") print("isi file setelah di pop: \n" +f.read()) @@ -33,7 +30,6 @@ def utama(): f.close() bacafile() - def main (): hiya=[] print("\n Barrier Mulai \n") diff --git a/Chapter02/IrfanHernandezEnam1184014.py b/Chapter02/IrfanHernandezEnam1184014.py new file mode 100644 index 0000000..b58b819 --- /dev/null +++ b/Chapter02/IrfanHernandezEnam1184014.py @@ -0,0 +1,53 @@ +from threading import Barrier, Thread +import requests +import os +from time import ctime, sleep + +total = 1 +nama_minuman = Barrier(total) +file = "Miramas" +filename=os.path.join(os.path.dirname(__file__), file) + +def api(): + apiurl='https://www.thecocktaildb.com/api/json/v1/1/search.php?s=margarita' + response = requests.get(apiurl) + html=response.json() + string="minuman : " + for i in range(len(html["drinks"])): + hasil = html["drinks"][i]["strDrink"] + tulis = "\n"+str(i)+". " + string = string+tulis+str(hasil) + createfile(string) + x = open(filename, "r") + print(x.read()) + +def createfile(isi): + print('Create File : '+ filename) + f = open(filename, "w") + f.write(str(isi)) + f.close() + +def readfile(): + f = open(filename, "r") + print("Isi Dari File ini : \n "+f.read()) + f.close() + +def start(): + api() + sleep(4) + readfile() + print('api dan readfile freached the barrier at: %s \n' % (ctime())) + nama_minuman.wait() + + +def main(): + threads = [] + print('Minuman Yang tersedia') + for i in range(total): + threads.append(Thread(target=start)) + threads[-1].start() + for thread in threads: + thread.join() + print('Telah Muncul') + return True + diff --git a/test_app.py b/test_app.py index 438653d..d8b2ca7 100644 --- a/test_app.py +++ b/test_app.py @@ -1,4 +1,3 @@ - import unittest @@ -231,7 +230,12 @@ def readfile(self,nfile): # response = main() # self.assertEqual(response, True) - def test_06_parhan_1184042(self): - from Chapter02.ParhanEnam1184042 import main - response = main() - self.assertEqual(response, True) \ No newline at end of file + #def test_06_parhan_1184042(self): + # from Chapter02.ParhanEnam1184042 import main + # response = main() + # self.assertEqual(response, True) + + def test_06_nandez_1184014(self): + from Chapter02.IrfanHernandezEnam1184014 import main + response = main() + self.assertEqual(response, True) \ No newline at end of file From 7e0ad4d97e6f7953dda5515a8e6744265df599ee Mon Sep 17 00:00:00 2001 From: Okky Yudistira Date: Thu, 15 Apr 2021 23:41:11 +0700 Subject: [PATCH 082/164] Tugas 6 1184087 Okky Yudistira --- Chapter02/parhan.txt | 1 + test_app.py | 46 ++++++++++++++++++++++---------------------- 2 files changed, 24 insertions(+), 23 deletions(-) create mode 100644 Chapter02/parhan.txt diff --git a/Chapter02/parhan.txt b/Chapter02/parhan.txt new file mode 100644 index 0000000..522c15c --- /dev/null +++ b/Chapter02/parhan.txt @@ -0,0 +1 @@ +[{'name': 'Indonesia', 'positif': '1,589,359', 'sembuh': '1,438,254', 'meninggal': '43,073', 'dirawat': '108,032'}] \ No newline at end of file diff --git a/test_app.py b/test_app.py index 7b7d19b..396808d 100644 --- a/test_app.py +++ b/test_app.py @@ -204,29 +204,29 @@ def readfile(self,nfile): # respon=self.readfile('./Chapter02/value.pdf') # self.assertNotRegex(respon, "Nomor : 12345678910") -<<<<<<< HEAD - def test_03_parhanTiga1184042(self): - from Chapter02.parhanTiga1184042 import parhanTiga1184042,parhanEventDeleteFile - threadutama = parhanTiga1184042("Thread Utama ", 2,5,5,'parhan') - threaddelete= parhanEventDeleteFile("Thread Delete File ", 1,'parhan') - threaddelete.start() - threadutama.start() - threaddelete.join() - threadutama.join() - respon=self.readfile('./Chapter02/parhan.txt') - self.assertNotRegex(respon, "kosong") - - def test_03_okkyTiga1184087(self): - from chapter02.okkyTiga1184087 import okky1184087Write_Trier, okky1184087 - threadwrite = okky1184087Write_Trier ("Thread satu ",1 , 'okky1') - threadutama = okky1184087("Thread dua ", 2,2, 'okky2') - threadwrite.start() - threadutama.start() - threadwrite.join() - threadutama.join() - respon=self.readfile('./Chapter02/value.pdf') - self.assertNotRegex(respon, "Nomor : 12345678910") -======= + +# def test_03_parhanTiga1184042(self): +# from Chapter02.parhanTiga1184042 import parhanTiga1184042,parhanEventDeleteFile +# threadutama = parhanTiga1184042("Thread Utama ", 2,5,5,'parhan') +# threaddelete= parhanEventDeleteFile("Thread Delete File ", 1,'parhan') +# threaddelete.start() +# threadutama.start() +# threaddelete.join() +# threadutama.join() +# respon=self.readfile('./Chapter02/parhan.txt') +# self.assertNotRegex(respon, "kosong") +# +# def test_03_okkyTiga1184087(self): +# from chapter02.okkyTiga1184087 import okky1184087Write_Trier, okky1184087 +# threadwrite = okky1184087Write_Trier ("Thread satu ",1 , 'okky1') +# threadutama = okky1184087("Thread dua ", 2,2, 'okky2') +# threadwrite.start() +# threadutama.start() +# threadwrite.join() +# threadutama.join() +# respon=self.readfile('./Chapter02/value.pdf') +# self.assertNotRegex(respon, "Nomor : 12345678910") + # def test_03_parhanTiga1184042(self): # from Chapter02.parhanTiga1184042 import parhanTiga1184042,parhanEventDeleteFile # threadutama = parhanTiga1184042("Thread Utama ", 2,5,5,'parhan') From 68ac457a6132e871ec5e40d753284a4313c754de Mon Sep 17 00:00:00 2001 From: Okky Yudistira Date: Thu, 15 Apr 2021 23:43:02 +0700 Subject: [PATCH 083/164] Tugas 6 1184087 Okky Yudistira --- Chapter02/parhan.txt | 1 - 1 file changed, 1 deletion(-) delete mode 100644 Chapter02/parhan.txt diff --git a/Chapter02/parhan.txt b/Chapter02/parhan.txt deleted file mode 100644 index 522c15c..0000000 --- a/Chapter02/parhan.txt +++ /dev/null @@ -1 +0,0 @@ -[{'name': 'Indonesia', 'positif': '1,589,359', 'sembuh': '1,438,254', 'meninggal': '43,073', 'dirawat': '108,032'}] \ No newline at end of file From 3b1863329defd203c84541b7226d228198f08fe5 Mon Sep 17 00:00:00 2001 From: IraDwita Date: Fri, 16 Apr 2021 00:30:55 +0700 Subject: [PATCH 084/164] TugasIraaaa --- Chapter02/IraEnam1184024.py | 58 +++++++++++++++++++++++++++++++++++++ test_app.py | 9 ++++-- 2 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 Chapter02/IraEnam1184024.py diff --git a/Chapter02/IraEnam1184024.py b/Chapter02/IraEnam1184024.py new file mode 100644 index 0000000..4c15031 --- /dev/null +++ b/Chapter02/IraEnam1184024.py @@ -0,0 +1,58 @@ +from threading import Barrier, Thread +from time import ctime, sleep +import requests +import os + +jumlah = 1 +shield = Barrier(jumlah) +filename = "iraa.txt" +filename2 = "iranew.txt" + +def getapi(): + apiurl='https://api.thecatapi.com/v1/images/search' + response = requests.get(apiurl) + html=response.json() + createfile(html) + +def createfile(isi): + f = open(filename, "w") + f.write(str(isi)) + f.close() + +def read(): + x = open(filename, "r") + print(x.read()) + +def renamefile(): + os.rename(filename, filename2) + print('file sudah direname') + +def deletefile(): + os.remove(filename2) + print('File sudah dihapus') + +def runner(): + getapi() + sleep(2) + shield.wait() + sleep(2) + print('udah mencapai barrier nih : %s \n' % (ctime())) + shield.wait() + print('Semua mencapai barrier pada waktunya nih: %s \n' % (ctime())) + read() + shield.wait() + + +def main(): + threads = [] + print('Start!') + for i in range(jumlah): + threads.append(Thread(target=runner)) + threads[-1].start() + for thread in threads: + thread.join() + print('Finish!') + return True + +#if __name__ == "__main__": +# main() \ No newline at end of file diff --git a/test_app.py b/test_app.py index ad69315..7636584 100644 --- a/test_app.py +++ b/test_app.py @@ -230,7 +230,12 @@ def readfile(self,nfile): # response = main() # self.assertEqual(response, True) - def test_06_parhan_1184042(self): - from Chapter02.ParhanEnam1184042 import main + # def test_06_parhan_1184042(self): + #from Chapter02.ParhanEnam1184042 import main + #response = main() + #self.assertEqual(response, True) + + def test_06_ira_1184024(self): + from Chapter02.IraEnam1184024 import main response = main() self.assertEqual(response, True) \ No newline at end of file From 22e4aa40a90f42c1575aec5d40f0c6db14532424 Mon Sep 17 00:00:00 2001 From: Anisarosalina Date: Fri, 16 Apr 2021 01:08:01 +0700 Subject: [PATCH 085/164] Tugas6_1184016_anisa --- Chapter02/AnisaRosalinaEnam1184016.py | 54 +++++++++++++++++++++++++++ test_app.py | 15 ++++---- 2 files changed, 62 insertions(+), 7 deletions(-) create mode 100644 Chapter02/AnisaRosalinaEnam1184016.py diff --git a/Chapter02/AnisaRosalinaEnam1184016.py b/Chapter02/AnisaRosalinaEnam1184016.py new file mode 100644 index 0000000..7a4167b --- /dev/null +++ b/Chapter02/AnisaRosalinaEnam1184016.py @@ -0,0 +1,54 @@ +from threading import Barrier, Thread +import requests +import os +from time import ctime, sleep + +total = 1 +brr = Barrier(total) +file = "Miramas" +filename=os.path.join(os.path.dirname(file), file) + +def api(): + apiurl='https://www.thecocktaildb.com/api/json/v1/1/search.php?s=margarita' + response = requests.get(apiurl) + html=response.json() + string="minuman : " + for i in range(len(html["drinks"])): + hasil = html["drinks"][i]["strDrink"] + tulis = "\n"+str(i)+". " + string = string+tulis+str(hasil) + createfile(string) + + +def createfile(isi): + print('Create File : '+ filename) + f = open(filename+".txt", "w") + f.write(str(isi)) + f.close() + a = open(filename+".txt", "r") + print("Isi Dari File ini : \n "+a.read()) + a.close() + b = open(filename+".txt", "a") + b.write("\ndiatas adalah minuman yang tersedia") + b.close() + c = open(filename+".txt", "r") + print("Perubahan Isi Dari File ini : \n "+c.read()) + c.close() + +def start(): + api() + sleep(4) + brr.wait() + print('API and readfile reached the barrier at: %s \n' % (ctime())) + + +def main(): + threads = [] + print('Minuman Yang tersedia') + for i in range(total): + threads.append(Thread(target=start)) + threads[-1].start() + for thread in threads: + thread.join() + print('Telah Muncul') + return True diff --git a/test_app.py b/test_app.py index 11b0212..9cacec5 100644 --- a/test_app.py +++ b/test_app.py @@ -230,12 +230,13 @@ def readfile(self,nfile): # response = main() # self.assertEqual(response, True) - def test_06_parhan_1184042(self): - from Chapter02.ParhanEnam1184042 import main - response = main() - self.assertEqual(response, True) + #def test_06_parhan_1184042(self): + # from Chapter02.ParhanEnam1184042 import main + # response = main() + # self.assertEqual(response, True) - def test_02_anisa_1184016(self): - from Chapter02.Anisa1184016 import main + def test_06_anisa_1184016(self): + from Chapter02.AnisaRosalinaEnam1184016 import main response = main() - self.assertEqual(response, True) \ No newline at end of file + self.assertEqual(response, True) + \ No newline at end of file From 2fafa9025f593a749fe3c812543826b78b260c20 Mon Sep 17 00:00:00 2001 From: josua1111 Date: Fri, 16 Apr 2021 01:38:55 +0700 Subject: [PATCH 086/164] Josuansef Pardede 1184091 Tugas 6 DS Barrier.py --- Chapter02/JosuansefEnam_1184091.py | 67 ++++++++++++++++++++++++++++++ test_app.py | 31 ++++++++------ 2 files changed, 85 insertions(+), 13 deletions(-) create mode 100644 Chapter02/JosuansefEnam_1184091.py diff --git a/Chapter02/JosuansefEnam_1184091.py b/Chapter02/JosuansefEnam_1184091.py new file mode 100644 index 0000000..3b28ec9 --- /dev/null +++ b/Chapter02/JosuansefEnam_1184091.py @@ -0,0 +1,67 @@ +# -*- coding: utf-8 -*- +""" +Created on Thu Apr 15 12:31:12 2021 + +@author: Josuansef Pardede (1184091) +""" +from threading import Barrier, Thread +import os +import requests +from time import ctime, sleep + +jenis_file = 1 +batas = Barrier(jenis_file) +file = "movie_2020_" +filename = os.path.join(os.path.dirname(__file__), file) + +def ApiJosuansef1184091(): + url = "https://movie-database-imdb-alternative.p.rapidapi.com/" + + querystring = {"s":"Avengers Endgame","page":"1","r":"json"} + + headers = { + 'x-rapidapi-key': "03ea4d51b5mshde64ddab3687a71p1fb88fjsn3c194b2ea8bc", + 'x-rapidapi-host': "movie-database-imdb-alternative.p.rapidapi.com" + } + + response = requests.request("GET", url, headers=headers, params=querystring) + html=response.json() + print(response.text) + Josuansef1184091_CreateAppendFile(html) + +def Josuansef1184091_CreateAppendFile(konten): + for i in range(2): + print('Create File : '+file+str(i)+'.txt \n') + f = open(filename+str(i)+".txt", "w+") + f.write(str(konten)) + f.close() + + print('Append File: '+file+str(i)+'.txt') + a = open(filename+str(i)+".txt", "a+") + a.write(" => Film Terbaik Sepanjang Masa setelah 'Titanic' %d\r\n") + a.close() + print('Create & Append '+file+str(i)+' reached the barrier at: %s \n' % (ctime())) + sleep(2) + batas.wait() + +def run(): + ApiJosuansef1184091() + sleep(2) + batas.wait() + print('All reached the barrier at: %s \n' % (ctime())) + +### In[]: + +def main(): + threads = [] + print('MULAI LAH, APA LAGI YEKAN!') + for i in range(jenis_file): + threads.append(Thread(target=run)) + threads[-1].start() + for thread in threads: + thread.join() + print('UDAH UDAH! UDAH SELESAI GUYS!') + return True + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/test_app.py b/test_app.py index 738c8e9..1169b45 100644 --- a/test_app.py +++ b/test_app.py @@ -212,17 +212,17 @@ def tearDown(self): #self.assertNotRegex(respon, "Kosong") #>>>>>>> 3aa81716bb58a3e7685425efe1259762e524b6aa -def test_03_josuaTiga1184091(self): - from Chapter02.josuansefTiga1184091 import josua1184091_Catcher,josua1184091Write_Trier - threadwrite = josua1184091Write_Trier("Thread write File ", 1,'josua') - threadutama = josua1184091_Catcher("Thread Utama ", 2,2,5,'josua') +#def test_03_josuaTiga1184091(self): + # from Chapter02.josuansefTiga1184091 import josua1184091_Catcher,josua1184091Write_Trier + # threadwrite = josua1184091Write_Trier("Thread write File ", 1,'josua') + # threadutama = josua1184091_Catcher("Thread Utama ", 2,2,5,'josua') # threadutama.start() - threadwrite.start() - threadutama.start() - threadwrite.join() - threadutama.join() - respon=self.readfile('./Chapter02/josua1184091.txt') - self.assertRegex(respon, "Nomor : 18092001") + # threadwrite.start() + # threadutama.start() + # threadwrite.join() + # threadutama.join() + #respon=self.readfile('./Chapter02/josua1184091.txt') + #self.assertRegex(respon, "Nomor : 18092001") # self.setUp() ======= @@ -326,8 +326,13 @@ def readfile(self,nfile): # response = main() # self.assertEqual(response, True) - def test_06_parhan_1184042(self): - from Chapter02.ParhanEnam1184042 import main + #def test_06_parhan_1184042(self): + # from Chapter02.ParhanEnam1184042 import main + # response = main() + # self.assertEqual(response, True) + + def test_06_josuansef_1184091(self): + from Chapter02.JosuansefEnam_1184091 import main response = main() self.assertEqual(response, True) ->>>>>>> 05681a40c1f1600886af7de701d3a93641396e74 + From 02dc91506ae8a181825221cedd0972d1d6e05f8d Mon Sep 17 00:00:00 2001 From: josua1111 Date: Fri, 16 Apr 2021 02:24:56 +0700 Subject: [PATCH 087/164] Josuansef Pardede 1184091 Tugas Barrier DS --- Chapter02/JosuansefEnam_1184091.py | 26 +++++++++++++------------- test_app.py | 13 +++---------- 2 files changed, 16 insertions(+), 23 deletions(-) diff --git a/Chapter02/JosuansefEnam_1184091.py b/Chapter02/JosuansefEnam_1184091.py index 3b28ec9..ea496b6 100644 --- a/Chapter02/JosuansefEnam_1184091.py +++ b/Chapter02/JosuansefEnam_1184091.py @@ -14,20 +14,20 @@ file = "movie_2020_" filename = os.path.join(os.path.dirname(__file__), file) -def ApiJosuansef1184091(): - url = "https://movie-database-imdb-alternative.p.rapidapi.com/" - querystring = {"s":"Avengers Endgame","page":"1","r":"json"} +def ApiJosuansef1184091(): + url = "https://movie-database-imdb-alternative.p.rapidapi.com/" + querystring = {"s":"Avengers Endgame","page":"1","r":"json"} - headers = { - 'x-rapidapi-key': "03ea4d51b5mshde64ddab3687a71p1fb88fjsn3c194b2ea8bc", - 'x-rapidapi-host': "movie-database-imdb-alternative.p.rapidapi.com" - } + headers = { + 'x-rapidapi-key': "03ea4d51b5mshde64ddab3687a71p1fb88fjsn3c194b2ea8bc", + 'x-rapidapi-host': "movie-database-imdb-alternative.p.rapidapi.com" + } - response = requests.request("GET", url, headers=headers, params=querystring) - html=response.json() - print(response.text) - Josuansef1184091_CreateAppendFile(html) + response = requests.request("GET", url, headers=headers, params=querystring) + html=response.json() + print(response.text) + Josuansef1184091_CreateAppendFile(html) def Josuansef1184091_CreateAppendFile(konten): for i in range(2): @@ -63,5 +63,5 @@ def main(): print('UDAH UDAH! UDAH SELESAI GUYS!') return True -if __name__ == "__main__": - main() \ No newline at end of file +#if __name__ == "__main__": +# main() \ No newline at end of file diff --git a/test_app.py b/test_app.py index 1169b45..c81a26c 100644 --- a/test_app.py +++ b/test_app.py @@ -25,10 +25,6 @@ def tearDown(self): # response = multiprocessing_test.multiprocessing_test() # self.assertEqual(response, True) -<<<<<<< HEAD - -======= ->>>>>>> 05681a40c1f1600886af7de701d3a93641396e74 # def test_02_kaisar_1184093(self): # from Chapter02.Kaisar1184093 import main # response = main() @@ -125,8 +121,7 @@ def tearDown(self): # f = open(filename, "r") # return str(f.read()) - -<<<<<<< HEAD + #def test_03_zanwarDua1184050(self): #from Chapter02.ZanwarDua1184050 import zanwarDua1184050,zanwarRewrite #threadrewrite= zanwarRewrite("Thread Rewrite File ", 1,'nilai') @@ -180,8 +175,6 @@ def tearDown(self): # respon=self.readfile('./Chapter02/alip.txt') # self.assertNotRegex(respon, "kosong") - -<<<<<<< HEAD #def test_03_FerdyTiga1184112(self): # from Chapter02.FerdyTiga1184112 import FerdyGITiga1184112,FerdyEventGI # threadrewrite= FerdyEventGI("Thread Lain ", 1,'minuman') @@ -224,7 +217,7 @@ def tearDown(self): #respon=self.readfile('./Chapter02/josua1184091.txt') #self.assertRegex(respon, "Nomor : 18092001") # self.setUp() -======= + # def test_03_FerdyTiga1184112(self): # from Chapter02.FerdyTiga1184112 import FerdyGITiga1184112,FerdyEventGI @@ -333,6 +326,6 @@ def readfile(self,nfile): def test_06_josuansef_1184091(self): from Chapter02.JosuansefEnam_1184091 import main - response = main() + response = main() self.assertEqual(response, True) From 857ac08e49660ed1f8cf09d77103393b07ce266b Mon Sep 17 00:00:00 2001 From: baharandili Date: Fri, 16 Apr 2021 05:32:09 +0700 Subject: [PATCH 088/164] revisi tgs bahar --- Chapter02/baharenam1184002.py | 55 +++++++++++++++++++++++++++++++++++ test_app.py | 9 ++++-- 2 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 Chapter02/baharenam1184002.py diff --git a/Chapter02/baharenam1184002.py b/Chapter02/baharenam1184002.py new file mode 100644 index 0000000..64bcff3 --- /dev/null +++ b/Chapter02/baharenam1184002.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- +""" +Created on Thu Apr 15 18:20:47 2021 + +@author: HP +""" + +from threading import Barrier, Thread +import os +import requests +from time import ctime, sleep + +jika = 1 +br = Barrier(jika) +file = "list film" +filename = os.path.join(os.path.dirname(__file__), file) + +def webapi(): + apiurl='https://bioskop-api-zahirr.herokuapp.com/api/now-playing' + response = requests.get(apiurl) + html=response.json() + buatfile(html) + +def buatfile(isi): + for i in range(1): + print('buat file dulu gan, namanya : '+file+'.txt \n') + f = open("Film.txt", "w") + print('File sudah berhasil dibuat gan \n') + f.write(str(isi)) + f.close() + f = open("Film.txt", "r") + print("ini adalah isi filenya gan: \n" +f.read()) + print('Create, Read this file: '+file+' mencapai barrier pada waktu: %s \n' % (ctime())) + +def jalan(): + webapi() + sleep(2) + br.wait() + print('All reached the barrier at: %s \n' % (ctime())) + +### In[]: + +def main(): + threads = [] + print('Bentar Gann') + for i in range(jika): + threads.append(Thread(target=jalan)) + threads[-1].start() + for thread in threads: + thread.join() + print('Over!') + return True + +#if __name__ == "__main__": +# main() \ No newline at end of file diff --git a/test_app.py b/test_app.py index ad69315..3cb92e4 100644 --- a/test_app.py +++ b/test_app.py @@ -230,7 +230,12 @@ def readfile(self,nfile): # response = main() # self.assertEqual(response, True) - def test_06_parhan_1184042(self): - from Chapter02.ParhanEnam1184042 import main + # def test_06_parhan_1184042(self): + # from Chapter02.ParhanEnam1184042 import main + # response = main() + # self.assertEqual(response, True) + + def test_06_bahar_1184002(self): + from Chapter02.baharenam1184002 import main response = main() self.assertEqual(response, True) \ No newline at end of file From d7ea8c1755b7f8b90cab926864b310d21e52b485 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 16 Apr 2021 05:58:05 +0700 Subject: [PATCH 089/164] WahyuKurniaSariEnam1184001 --- Chapter02/WahyuKurniaSariEnam1184001.py | 43 +++++++++++++++++++++++++ test_app.py | 11 ++++++- 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 Chapter02/WahyuKurniaSariEnam1184001.py diff --git a/Chapter02/WahyuKurniaSariEnam1184001.py b/Chapter02/WahyuKurniaSariEnam1184001.py new file mode 100644 index 0000000..39f8e5b --- /dev/null +++ b/Chapter02/WahyuKurniaSariEnam1184001.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +""" +Created on Fri Apr 16 05:28:16 2021 + +@author: NITRO 5 ACER +""" + +import threading +import time +import random +import requests + +br=threading.Barrier(2) + +def webservices(): + apiurl = 'https://pokeapi.co/api/v2/pokemon/pikachu' + response = requests.get(apiurl) + html = response.json() + print(html["weight"]) + + +def run(): + webservices() + br.wait() + +def main(): + + threads = [] + + for i in range(4): + thread = threading.Thread(target=run) + thread.start() + threads.append(thread) + + for t in threads: + t.join() + return True + + + + + + \ No newline at end of file diff --git a/test_app.py b/test_app.py index ad69315..4db2abc 100644 --- a/test_app.py +++ b/test_app.py @@ -233,4 +233,13 @@ def readfile(self,nfile): def test_06_parhan_1184042(self): from Chapter02.ParhanEnam1184042 import main response = main() - self.assertEqual(response, True) \ No newline at end of file + self.assertEqual(response, True) + + def test_06_WahyuKurniaSari_1184001(self): + from Chapter02.WahyuKurniaSariEnam1184001 import main + result=main() + self.assertEqual(result, True) + + + + From a639184f741b50865102ef1ddee2c0e36a6a0d72 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 16 Apr 2021 06:16:04 +0700 Subject: [PATCH 090/164] WahyuKurniaSariEnam1184001 --- test_app.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test_app.py b/test_app.py index 4db2abc..bb63cbb 100644 --- a/test_app.py +++ b/test_app.py @@ -230,10 +230,10 @@ def readfile(self,nfile): # response = main() # self.assertEqual(response, True) - def test_06_parhan_1184042(self): - from Chapter02.ParhanEnam1184042 import main - response = main() - self.assertEqual(response, True) + #def test_06_parhan_1184042(self): + #from Chapter02.ParhanEnam1184042 import main + #response = main() + #self.assertEqual(response, True) def test_06_WahyuKurniaSari_1184001(self): from Chapter02.WahyuKurniaSariEnam1184001 import main From e14b22013c3473ce2057736270e45382dff25025 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 16 Apr 2021 06:51:35 +0700 Subject: [PATCH 091/164] WahyuKurniaSariEnam1184001 --- test_app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_app.py b/test_app.py index bb63cbb..6e551c5 100644 --- a/test_app.py +++ b/test_app.py @@ -240,6 +240,6 @@ def test_06_WahyuKurniaSari_1184001(self): result=main() self.assertEqual(result, True) - + From 82ebb8c573522f740954c10c8b22721e37441b76 Mon Sep 17 00:00:00 2001 From: baharandili Date: Fri, 16 Apr 2021 08:03:48 +0700 Subject: [PATCH 092/164] upadate --- Chapter02/WahyuKurniaSariEnam1184001.py | 43 +++++++++++++++++++++++++ test_app.py | 9 +++++- 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 Chapter02/WahyuKurniaSariEnam1184001.py diff --git a/Chapter02/WahyuKurniaSariEnam1184001.py b/Chapter02/WahyuKurniaSariEnam1184001.py new file mode 100644 index 0000000..39f8e5b --- /dev/null +++ b/Chapter02/WahyuKurniaSariEnam1184001.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +""" +Created on Fri Apr 16 05:28:16 2021 + +@author: NITRO 5 ACER +""" + +import threading +import time +import random +import requests + +br=threading.Barrier(2) + +def webservices(): + apiurl = 'https://pokeapi.co/api/v2/pokemon/pikachu' + response = requests.get(apiurl) + html = response.json() + print(html["weight"]) + + +def run(): + webservices() + br.wait() + +def main(): + + threads = [] + + for i in range(4): + thread = threading.Thread(target=run) + thread.start() + threads.append(thread) + + for t in threads: + t.join() + return True + + + + + + \ No newline at end of file diff --git a/test_app.py b/test_app.py index 121efe3..daf890a 100644 --- a/test_app.py +++ b/test_app.py @@ -247,7 +247,14 @@ def readfile(self,nfile): # response = main() # self.assertEqual(response, True) +<<<<<<< HEAD def test_06_bahar_1184002(self): from Chapter02.baharenam1184002 import main response = main() - self.assertEqual(response, True) \ No newline at end of file + self.assertEqual(response, True) +======= + def test_06_WahyuKurniaSari_1184001(self): + from Chapter02.WahyuKurniaSariEnam1184001 import main + result=main() + self.assertEqual(result, True) +>>>>>>> d44e0b07775ddf642cd4fa0af63714f34d54f927 From 5456a98698dcbd0206fc2f14692cc3b7c5eee9a3 Mon Sep 17 00:00:00 2001 From: josua1111 Date: Fri, 16 Apr 2021 08:14:42 +0700 Subject: [PATCH 093/164] Josuansef Pardede 1184091 Tugas 6 Sistem Tersebar Barrier --- test_app.py | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/test_app.py b/test_app.py index ac60d2f..a079123 100644 --- a/test_app.py +++ b/test_app.py @@ -320,17 +320,11 @@ def readfile(self,nfile): # self.assertEqual(response, True) #def test_06_parhan_1184042(self): -<<<<<<< HEAD + # from Chapter02.ParhanEnam1184042 import main # response = main() - # self.assertEqual(response, True) - - def test_06_josuansef_1184091(self): - from Chapter02.JosuansefEnam_1184091 import main - response = main() - self.assertEqual(response, True) + # self.assertEqual(response, True) -======= # from Chapter02.ParhanEnam1184042 import main # response = main() # self.assertEqual(response, True) @@ -340,8 +334,12 @@ def test_06_josuansef_1184091(self): # response = main() # self.assertEqual(response, True) - def test_06_WahyuKurniaSari_1184001(self): - from Chapter02.WahyuKurniaSariEnam1184001 import main - result=main() - self.assertEqual(result, True) ->>>>>>> d44e0b07775ddf642cd4fa0af63714f34d54f927 + #def test_06_WahyuKurniaSari_1184001(self): + # from Chapter02.WahyuKurniaSariEnam1184001 import main + # result=main() + # self.assertEqual(result, True) + + def test_06_josuansef_1184091(self): + from Chapter02.JosuansefEnam_1184091 import main + response = main() + self.assertEqual(response, True) From b04f23df579a87ac959a85d156b77a864c2ae98f Mon Sep 17 00:00:00 2001 From: rizaluardi Date: Fri, 16 Apr 2021 08:23:20 +0700 Subject: [PATCH 094/164] update konflik rizaluardi 1184102 --- Chapter02/RizaluardiEnam1184102.py | 54 ++++++++++++++++++++++++++++++ test_app.py | 13 ++++--- 2 files changed, 63 insertions(+), 4 deletions(-) create mode 100644 Chapter02/RizaluardiEnam1184102.py diff --git a/Chapter02/RizaluardiEnam1184102.py b/Chapter02/RizaluardiEnam1184102.py new file mode 100644 index 0000000..e2fe3d4 --- /dev/null +++ b/Chapter02/RizaluardiEnam1184102.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +""" +Created on Wed Apr 14 13:48:09 2021 + +@author: Rizaluardi +""" +from threading import Barrier, Thread +import os +import requests +from time import ctime, sleep + +kpos = 5 +bar = Barrier(kpos) +file = "list kodepos" +filename = os.path.join(os.path.dirname(file), file) + +def webapiservice(): + apiurl=' https://kodepos-2d475.firebaseio.com/list_propinsi.json?print=pretty' + response = requests.get(apiurl) + html=response.json() + buatkodepos(html) + +def buatkodepos(isi): + for i in range(1): + print('Sebentar sedang membuat file bernama : '+file+'.txt \n') + k = open("Kodepos.txt", "w") + print('Oke file telah dibuat \n') + k.write(str(isi)) + k.close() + k = open("Kodepos.txt", "r") + print("Berikut adalah data kodeposnya : \n" +k.read()) + print('Create, Read this file: '+file+' telah mencapai barrier pada waktu: %s \n' % (ctime())) + +def eksekusi(): + webapiservice() + sleep(2) + bar.wait() + print('All reached the barrier at: %s \n' % (ctime())) + +### In[]: + +def main(): + threads = [] + print('Tunggu sejenak') + for i in range(kpos): + threads.append(Thread(target=eksekusi)) + threads[-1].start() + for thread in threads: + thread.join() + print('Over!') + return True + +#if __name__ == "__main__": +# main() \ No newline at end of file diff --git a/test_app.py b/test_app.py index 9640251..9cfcd22 100644 --- a/test_app.py +++ b/test_app.py @@ -240,7 +240,12 @@ def readfile(self,nfile): # response = main() # self.assertEqual(response, True) - def test_06_WahyuKurniaSari_1184001(self): - from Chapter02.WahyuKurniaSariEnam1184001 import main - result=main() - self.assertEqual(result, True) + #def test_06_WahyuKurniaSari_1184001(self): + # from Chapter02.WahyuKurniaSariEnam1184001 import main + # result=main() + # self.assertEqual(result, True) + + def test_06_rizaluardi_1184102(self): + from Chapter02.RizaluardiEnam1184102 import main + response = main() + self.assertEqual(response, True) From 2b12e7a87b99907efa5a3b1d15ccc28d022a78c4 Mon Sep 17 00:00:00 2001 From: hernandez2804 <56632278+hernandez2804@users.noreply.github.com> Date: Fri, 16 Apr 2021 08:47:21 +0700 Subject: [PATCH 095/164] Update --- test_app.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/test_app.py b/test_app.py index d8b2ca7..bc2ee92 100644 --- a/test_app.py +++ b/test_app.py @@ -234,8 +234,13 @@ def readfile(self,nfile): # from Chapter02.ParhanEnam1184042 import main # response = main() # self.assertEqual(response, True) - - def test_06_nandez_1184014(self): - from Chapter02.IrfanHernandezEnam1184014 import main - response = main() - self.assertEqual(response, True) \ No newline at end of file + + # def test_06_hanif_1184058(self): + # from Chapter02.HanifEnam1184058 import main + # response = main() + # self.assertEqual(response, True) + + def test_06_WahyuKurniaSari_1184001(self): + from Chapter02.WahyuKurniaSariEnam1184001 import main + result=main() + self.assertEqual(result, True) \ No newline at end of file From e06ebe7d473f897b023b03ec9c73ef79c1b5e58a Mon Sep 17 00:00:00 2001 From: Anisarosalina Date: Fri, 16 Apr 2021 08:47:42 +0700 Subject: [PATCH 096/164] Tugas6Anisa --- test_app.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test_app.py b/test_app.py index 9cacec5..93cf1d8 100644 --- a/test_app.py +++ b/test_app.py @@ -235,6 +235,11 @@ def readfile(self,nfile): # response = main() # self.assertEqual(response, True) + #def test_06_WahyuKurniaSari_1184001(self): + # from Chapter02.WahyuKurniaSariEnam1184001 import main + # result=main() + # self.assertEqual(result, True) + def test_06_anisa_1184016(self): from Chapter02.AnisaRosalinaEnam1184016 import main response = main() From 488edf41d01c2103d1c658b68786d73d0b39a6a3 Mon Sep 17 00:00:00 2001 From: hernandez2804 <56632278+hernandez2804@users.noreply.github.com> Date: Fri, 16 Apr 2021 08:54:42 +0700 Subject: [PATCH 097/164] update Tugas 6 Hernandez --- test_app.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/test_app.py b/test_app.py index 34699a4..6a50a43 100644 --- a/test_app.py +++ b/test_app.py @@ -240,11 +240,13 @@ def readfile(self,nfile): # response = main() # self.assertEqual(response, True) - def test_06_WahyuKurniaSari_1184001(self): - from Chapter02.WahyuKurniaSariEnam1184001 import main - result=main() -<<<<<<< HEAD - self.assertEqual(result, True) -======= - self.assertEqual(result, True) ->>>>>>> d44e0b07775ddf642cd4fa0af63714f34d54f927 + #def test_06_WahyuKurniaSari_1184001(self): + # from Chapter02.WahyuKurniaSariEnam1184001 import main + # result=main() + # self.assertEqual(result, True) + + def test_06_nandez_1184014(self): + from Chapter02.IrfanHernandezEnam1184014 import main + response = main() + self.assertEqual(response, True) + From d2243a17946249cd14af821456504c5ec72c7a10 Mon Sep 17 00:00:00 2001 From: hernandez2804 <56632278+hernandez2804@users.noreply.github.com> Date: Fri, 16 Apr 2021 09:09:16 +0700 Subject: [PATCH 098/164] update Tugas 6 Nandez --- Chapter02/IrfanHernandezTiga1184014.py | 82 -------------------------- 1 file changed, 82 deletions(-) delete mode 100644 Chapter02/IrfanHernandezTiga1184014.py diff --git a/Chapter02/IrfanHernandezTiga1184014.py b/Chapter02/IrfanHernandezTiga1184014.py deleted file mode 100644 index 65d06d2..0000000 --- a/Chapter02/IrfanHernandezTiga1184014.py +++ /dev/null @@ -1,82 +0,0 @@ -import threading -import requests -import os - -event = threading.Event() - -class NandezEvent (threading.Thread): - def __init__(self,name, thread_number, filename): - threading.Thread.__init__(self) - self.name = name - self.threadLock = threading.Lock() - self.thread_number = thread_number - self.filename=os.path.join(os.path.dirname(__file__), filename) - - def run(self): - print("\n"+str(self.thread_number)+". ---> " + self.name + "start.") - self.threadLock.acquire() - print('Tampilkan Minuman:(') - event.wait() - print('rewrite : '+self.filename) - self.readfile() - print("Read after rewrite") - self.rewritefile() - event.clear() - self.threadLock.release() - print("\n"+str(self.thread_number)+". ---> " + threading.currentThread().getName() + "end") - - def readfile(self): - f = open(self.filename, "r") - print("Isi Dari File ini : \n "+f.read()) - - def rewritefile(self): - f = open(self.filename, "r") - fd = open(self.filename+'.txt', "w") - for line in f: - fd.write(line.replace('Minuman', 'Nama Minuman')) - fd.close() - fr = open(self.filename+'.txt', "r") - print(fr.read()) - fr.close() - - -class NandezEvent1184014 (threading.Thread): - def __init__(self, name, thread_number,filename): - threading.Thread.__init__(self) - self.threadLock = threading.Lock() - self.name = name - self.rlock = threading.RLock() - self.filename=os.path.join(os.path.dirname(__file__), filename) - self.thread_number = thread_number - - def run(self): - print("\n"+str(self.thread_number)+". ---> " + self.name + "start.") - self.count() - print("Event Set!") - event.set() - print("\n"+str(self.thread_number)+". ---> " + threading.currentThread().getName() + "finish.") - - def randomapi(self): - with self.rlock: - print('Inside rlock apipangkat, akses web service...') - apiurl='https://www.thecocktaildb.com/api/json/v1/1/search.php?s=margarita' - response = requests.get(apiurl) - html=response.json() - string = "Minuman" - for i in range(len(html["drinks"])): - hasil = html["drinks"][1]["strDrink"] - tulis = "\n"+str(i)+". " - string = string+tulis+str(hasil) - self.createfile(string) - x = open(self.filename, "r") - print(x.read()) - - def count(self): - with self.rlock: - self.randomapi() - - def createfile(self,isi): - print('Create File : '+ self.filename) - f = open(self.filename, "w") - f.write(str(isi)) - f.close() \ No newline at end of file From 767201133e513c4bde59756f8723b9cc61716311 Mon Sep 17 00:00:00 2001 From: hernandez2804 <56632278+hernandez2804@users.noreply.github.com> Date: Fri, 16 Apr 2021 10:00:12 +0700 Subject: [PATCH 099/164] Update konflik tugas 6 Nandez 1184014 --- test_app.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/test_app.py b/test_app.py index 35dbb55..72577d5 100644 --- a/test_app.py +++ b/test_app.py @@ -256,7 +256,12 @@ def readfile(self,nfile): #result=main() #self.assertEqual(result, True) - def test_06_ira_1184024(self): - from Chapter02.IraEnam1184024 import main - response = main() - self.assertEqual(response, True) \ No newline at end of file + #def test_06_ira_1184024(self): + # from Chapter02.IraEnam1184024 import main + # response = main() + # self.assertEqual(response, True) + + def test_06_nandez_1184014(self): + from Chapter02.IrfanHernandezEnam1184014 import main + response = main() + self.assertEqual(response, True) \ No newline at end of file From 8c5c968dc690fa4cdcd8ad73615ff8ba9fb4f0b0 Mon Sep 17 00:00:00 2001 From: josua1111 Date: Fri, 16 Apr 2021 10:03:16 +0700 Subject: [PATCH 100/164] Josuansef Pardede 1184091 Tugas 6 Sistem Tersebar --- test_app.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/test_app.py b/test_app.py index 4debd77..64c3a24 100644 --- a/test_app.py +++ b/test_app.py @@ -346,21 +346,21 @@ def readfile(self,nfile): # self.assertEqual(response, True) #def test_06_WahyuKurniaSari_1184001(self): -<<<<<<< HEAD + # from Chapter02.WahyuKurniaSariEnam1184001 import main # result=main() # self.assertEqual(result, True) - def test_06_josuansef_1184091(self): - from Chapter02.JosuansefEnam_1184091 import main - response = main() -======= #from Chapter02.WahyuKurniaSariEnam1184001 import main #result=main() #self.assertEqual(result, True) - def test_06_ira_1184024(self): - from Chapter02.IraEnam1184024 import main - response = main() ->>>>>>> 09bf0a2a99f37d5012fc10a65857d5ee400f6400 - self.assertEqual(response, True) + # def test_06_ira_1184024(self): + # from Chapter02.IraEnam1184024 import main + # response = main() +#>>>>>>> 09bf0a2a99f37d5012fc10a65857d5ee400f6400 + # self.assertEqual(response, True) + + def test_06_josuansef_1184091(self): + from Chapter02.JosuansefEnam_1184091 import main + response = main() From 07976225eea93cbe9393dc633c65545fc5058857 Mon Sep 17 00:00:00 2001 From: Anisarosalina Date: Fri, 16 Apr 2021 10:11:45 +0700 Subject: [PATCH 101/164] Updatekonflik --- Miramas.txt | 8 ++++++++ test_app.py | 9 +++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 Miramas.txt diff --git a/Miramas.txt b/Miramas.txt new file mode 100644 index 0000000..6b77282 --- /dev/null +++ b/Miramas.txt @@ -0,0 +1,8 @@ +minuman : +0. Margarita +1. Blue Margarita +2. Tommy's Margarita +3. Whitecap Margarita +4. Strawberry Margarita +5. Smashed Watermelon Margarita +diatas adalah minuman yang tersedia \ No newline at end of file diff --git a/test_app.py b/test_app.py index 18b2699..5bd3c83 100644 --- a/test_app.py +++ b/test_app.py @@ -256,7 +256,12 @@ def readfile(self,nfile): #result=main() #self.assertEqual(result, True) - def test_06_ira_1184024(self): - from Chapter02.IraEnam1184024 import main + #def test_06_ira_1184024(self): + # from Chapter02.IraEnam1184024 import main + # response = main() + # self.assertEqual(response, True) + + def test_06_anisa_1184016(self): + from Chapter02.AnisaRosalinaEnam1184016 import main response = main() self.assertEqual(response, True) From ecd13721daeab53e02f0c37278516a891552d2fe Mon Sep 17 00:00:00 2001 From: hernandez2804 <56632278+hernandez2804@users.noreply.github.com> Date: Fri, 16 Apr 2021 10:23:37 +0700 Subject: [PATCH 102/164] update --- Chapter02/FerdyEnam1184112.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Chapter02/FerdyEnam1184112.py b/Chapter02/FerdyEnam1184112.py index 825f557..9dbdb82 100644 --- a/Chapter02/FerdyEnam1184112.py +++ b/Chapter02/FerdyEnam1184112.py @@ -44,5 +44,4 @@ def main (): #if __name__ == "__main__": -# main() - +# main() \ No newline at end of file From 1096c40f6996be54b08517fd8555da09396a622e Mon Sep 17 00:00:00 2001 From: baharandili Date: Fri, 16 Apr 2021 10:26:43 +0700 Subject: [PATCH 103/164] update --- test_app.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test_app.py b/test_app.py index 21d2f4b..b60531f 100644 --- a/test_app.py +++ b/test_app.py @@ -267,7 +267,7 @@ def readfile(self,nfile): #def test_06_WahyuKurniaSari_1184001(self): -<<<<<<< HEAD + #from Chapter02.WahyuKurniaSariEnam1184001 import main #result=main() #self.assertEqual(result, True) @@ -281,7 +281,7 @@ def test_06_bahar_1184002(self): from Chapter02.baharenam1184002 import main response = main() self.assertEqual(response, True) -======= + # from Chapter02.WahyuKurniaSariEnam1184001 import main # result=main() @@ -292,8 +292,8 @@ def test_06_bahar_1184002(self): # response = main() # self.assertEqual(response, True) - def test_06_rizaluardi_1184102(self): - from Chapter02.RizaluardiEnam1184102 import main - result=main() - self.assertEqual(result, True) ->>>>>>> a25ed61c5ea41968e9719e1dc0ad4174cb91c1b0 + # def test_06_rizaluardi_1184102(self): + # from Chapter02.RizaluardiEnam1184102 import main + # result=main() + # self.assertEqual(result, True) + From 81e50fbf86081d4bfdbcdce3c51bd9a02dd08721 Mon Sep 17 00:00:00 2001 From: baharandili Date: Fri, 16 Apr 2021 10:29:22 +0700 Subject: [PATCH 104/164] update --- test_app.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/test_app.py b/test_app.py index b60531f..68726d8 100644 --- a/test_app.py +++ b/test_app.py @@ -277,11 +277,6 @@ def readfile(self,nfile): # response = main() # self.assertEqual(response, True) - def test_06_bahar_1184002(self): - from Chapter02.baharenam1184002 import main - response = main() - self.assertEqual(response, True) - # from Chapter02.WahyuKurniaSariEnam1184001 import main # result=main() @@ -297,3 +292,7 @@ def test_06_bahar_1184002(self): # result=main() # self.assertEqual(result, True) + def test_06_bahar_1184002(self): + from Chapter02.baharenam1184002 import main + response = main() + self.assertEqual(response, True) \ No newline at end of file From 5b45d793e3481f3281e98299c5c79c0695bc80db Mon Sep 17 00:00:00 2001 From: hernandez2804 <56632278+hernandez2804@users.noreply.github.com> Date: Fri, 16 Apr 2021 10:29:53 +0700 Subject: [PATCH 105/164] Update Konfik Irfan Hernandez Tugas 6 --- Kodepos.txt | 1 + test_app.py | 13 +++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 Kodepos.txt diff --git a/Kodepos.txt b/Kodepos.txt new file mode 100644 index 0000000..671ae71 --- /dev/null +++ b/Kodepos.txt @@ -0,0 +1 @@ +{'p1': 'Bali', 'p10': 'Jawa Tengah', 'p11': 'Jawa Timur', 'p12': 'Kalimantan Barat', 'p13': 'Kalimantan Selatan', 'p14': 'Kalimantan Tengah', 'p15': 'Kalimantan Timur', 'p16': 'Kalimantan Utara', 'p17': 'Kepulauan Riau', 'p18': 'Lampung', 'p19': 'Maluku', 'p2': 'Bangka Belitung', 'p20': 'Maluku Utara', 'p21': 'Nanggroe Aceh Darussalam', 'p22': 'Nusa Tenggara Barat', 'p23': 'Nusa Tenggara Timur', 'p24': 'Papua', 'p25': 'Papua Barat', 'p26': 'Riau', 'p27': 'Sulawesi Barat', 'p28': 'Sulawesi Selatan', 'p29': 'Sulawesi Tengah', 'p3': 'Banten', 'p30': 'Sulawesi Tenggara', 'p31': 'Sulawesi Utara', 'p32': 'Sumatera Barat', 'p33': 'Sumatera Selatan', 'p34': 'Sumatera Utara', 'p4': 'Bengkulu', 'p5': 'DI Yogyakarta', 'p6': 'DKI Jakarta', 'p7': 'Gorontalo', 'p8': 'Jambi', 'p9': 'Jawa Barat'} \ No newline at end of file diff --git a/test_app.py b/test_app.py index 3c27418..907e320 100644 --- a/test_app.py +++ b/test_app.py @@ -262,7 +262,12 @@ def readfile(self,nfile): # response = main() # self.assertEqual(response, True) - def test_06_rizaluardi_1184102(self): - from Chapter02.RizaluardiEnam1184102 import main - result=main() - self.assertEqual(result, True) \ No newline at end of file + #def test_06_rizaluardi_1184102(self): + # from Chapter02.RizaluardiEnam1184102 import main + # result=main() + # self.assertEqual(result, True) + + def test_06_nandez_1184014(self): + from Chapter02.IrfanHernandezEnam1184014 import main + response = main() + self.assertEqual(response, True) \ No newline at end of file From 51e67e49d5c119e489084fabc345b688cdbc173a Mon Sep 17 00:00:00 2001 From: hernandez2804 <56632278+hernandez2804@users.noreply.github.com> Date: Fri, 16 Apr 2021 10:31:42 +0700 Subject: [PATCH 106/164] Update Konflik 1184014 Irfan Hernandez --- Kodepos.txt | 1 - 1 file changed, 1 deletion(-) delete mode 100644 Kodepos.txt diff --git a/Kodepos.txt b/Kodepos.txt deleted file mode 100644 index 671ae71..0000000 --- a/Kodepos.txt +++ /dev/null @@ -1 +0,0 @@ -{'p1': 'Bali', 'p10': 'Jawa Tengah', 'p11': 'Jawa Timur', 'p12': 'Kalimantan Barat', 'p13': 'Kalimantan Selatan', 'p14': 'Kalimantan Tengah', 'p15': 'Kalimantan Timur', 'p16': 'Kalimantan Utara', 'p17': 'Kepulauan Riau', 'p18': 'Lampung', 'p19': 'Maluku', 'p2': 'Bangka Belitung', 'p20': 'Maluku Utara', 'p21': 'Nanggroe Aceh Darussalam', 'p22': 'Nusa Tenggara Barat', 'p23': 'Nusa Tenggara Timur', 'p24': 'Papua', 'p25': 'Papua Barat', 'p26': 'Riau', 'p27': 'Sulawesi Barat', 'p28': 'Sulawesi Selatan', 'p29': 'Sulawesi Tengah', 'p3': 'Banten', 'p30': 'Sulawesi Tenggara', 'p31': 'Sulawesi Utara', 'p32': 'Sumatera Barat', 'p33': 'Sumatera Selatan', 'p34': 'Sumatera Utara', 'p4': 'Bengkulu', 'p5': 'DI Yogyakarta', 'p6': 'DKI Jakarta', 'p7': 'Gorontalo', 'p8': 'Jambi', 'p9': 'Jawa Barat'} \ No newline at end of file From 2c6237346812e8e4ee64e5d95f1d601c9e81b626 Mon Sep 17 00:00:00 2001 From: ariyo21 Date: Fri, 16 Apr 2021 10:35:00 +0700 Subject: [PATCH 107/164] Update konflik Ariyo 1184056 --- Chapter02/AriyoEnam1184056.py | 62 +++++++++++++++++++++++++++++++++++ test_app.py | 13 +++++--- 2 files changed, 71 insertions(+), 4 deletions(-) create mode 100644 Chapter02/AriyoEnam1184056.py diff --git a/Chapter02/AriyoEnam1184056.py b/Chapter02/AriyoEnam1184056.py new file mode 100644 index 0000000..b178d5b --- /dev/null +++ b/Chapter02/AriyoEnam1184056.py @@ -0,0 +1,62 @@ +from threading import Barrier, Thread +import requests +from time import ctime, sleep + +num_list = 1 +list_cocktail = Barrier(num_list) +file = [] +filename = "list_cocktail.txt" + +def api(): + apiurl ='https://www.thecocktaildb.com/api/json/v1/1/list.php?a=list' + response = requests.get(apiurl) + html=response.json() + string ="list: " + for i in range(len(html)): + hasil =html["drinks"] + tulis = "\n"+str(i)+". " + string = string+tulis+str(hasil) + createfile(string) + x = open(filename, "r") + print(x.read()) + + + +def createfile(isi): + f = open(filename, "w") + f.write(str(isi)) + f.close() + +def read(): + x = open(filename, "r") + print(x.read()) + x.close() + +def start(): + api() + sleep(2) + list_cocktail.wait() + sleep(2) + print(' ini barrier nya : %s \n' % (ctime())) + list_cocktail.wait() + print('Create dan Read File Barrier: %s \n' % (ctime())) + read() + list_cocktail.wait() + +def main(): + threads = [] + print('Ayo Mulai') + for i in range(num_list): + threads.append(Thread(target=start)) + threads[-1].start() + for thread in threads: + thread.join() + print('Udah Selasi') + return True + +#if __name__ == "__main__": +# main() + + + + diff --git a/test_app.py b/test_app.py index 3c27418..93b2aeb 100644 --- a/test_app.py +++ b/test_app.py @@ -262,7 +262,12 @@ def readfile(self,nfile): # response = main() # self.assertEqual(response, True) - def test_06_rizaluardi_1184102(self): - from Chapter02.RizaluardiEnam1184102 import main - result=main() - self.assertEqual(result, True) \ No newline at end of file + #def test_06_rizaluardi_1184102(self): + # from Chapter02.RizaluardiEnam1184102 import main + # result=main() + # self.assertEqual(result, True) + + def test_06_ariyo_1184056(self): + from Chapter02.AriyoEnam1184056 import main + response = main() + self.assertEqual(response, True) \ No newline at end of file From d628d3fb86f6b12a96eee74209c19026237879c6 Mon Sep 17 00:00:00 2001 From: ravirahmatulfajri Date: Fri, 16 Apr 2021 10:41:28 +0700 Subject: [PATCH 108/164] Ravi 1184040 --- .gitignore | 3 +- Chapter02/raviEnam1184040.py | 57 ++++++++++++++++++++++++++++++++++++ test_app.py | 9 ++++-- 3 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 Chapter02/raviEnam1184040.py diff --git a/.gitignore b/.gitignore index 1344c17..4506a92 100644 --- a/.gitignore +++ b/.gitignore @@ -140,4 +140,5 @@ nilai.txt value value.txt value -value.pdf \ No newline at end of file +value.pdf +newravi.docx \ No newline at end of file diff --git a/Chapter02/raviEnam1184040.py b/Chapter02/raviEnam1184040.py new file mode 100644 index 0000000..a518071 --- /dev/null +++ b/Chapter02/raviEnam1184040.py @@ -0,0 +1,57 @@ +from threading import Barrier, Thread +import os +import requests +from time import ctime, sleep + +no = 1 +b = Barrier(no) +r1 = "ravi" +r2 = "newravi" +filename = os.path.join(os.path.dirname(__file__), r1) +filename2 = os.path.join(os.path.dirname(__file__), r2) + +def API(): + apiurl='http://www.emsifa.com/api-wilayah-indonesia/api/regencies/13.json' + response = requests.get(apiurl) + html=response.json() + cfile(html) + +def cfile(isi): + print('File dibuat : '+r1+'.docx \n') + f = open(filename+".docx", "w") + print('File dibuat sudah \n') + f.write(str(isi)) + f.close() + print('Ini isinya: '+r1+'.docx') + x = open(filename+".docx", "r") + print(x.read()+'\n') + x.close() + print('Ganti nama \n') + print('menjadi: '+r2+'.docx \n') + os.rename(filename+'.docx', filename2+'.docx') + sleep(2) + b.wait() + print('File:'+r1+'.docx'+' berhasil di ganti \n') + sleep(2) + b.wait() + print('Create, Read, and delete r1: '+r1+' barrier waktu: %s \n' % (ctime())) + +def run(): + API() + sleep(2) + b.wait() + print('Semua mencapai barrier pada waktu: %s \n' % (ctime())) + +def main(): + threads = [] + print('goodluck') + for i in range(no): + threads.append(Thread(target=run)) + threads[-1].start() + for thread in threads: + thread.join() + print('done') + return True + +#if __name__ == "__main__": +# main() \ No newline at end of file diff --git a/test_app.py b/test_app.py index 907e320..a51d56b 100644 --- a/test_app.py +++ b/test_app.py @@ -267,7 +267,12 @@ def readfile(self,nfile): # result=main() # self.assertEqual(result, True) - def test_06_nandez_1184014(self): - from Chapter02.IrfanHernandezEnam1184014 import main + # def test_06_nandez_1184014(self): + # from Chapter02.IrfanHernandezEnam1184014 import main + # response = main() + # self.assertEqual(response, True) + + def test_06_ravi_1184040(self): + from Chapter02.raviEnam1184040 import main response = main() self.assertEqual(response, True) \ No newline at end of file From fd5b53f9852ae39a48bf15fb0de3aab27f95b045 Mon Sep 17 00:00:00 2001 From: baharandili Date: Fri, 16 Apr 2021 10:47:58 +0700 Subject: [PATCH 109/164] update --- test_app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_app.py b/test_app.py index 604cb6d..1bb080b 100644 --- a/test_app.py +++ b/test_app.py @@ -315,7 +315,7 @@ def readfile(self,nfile): # response = main() # self.assertEqual(response, True) - def test_06_bahar_1184002(self): + def test_06_bahar_1184002(self): from Chapter02.baharenam1184002 import main response = main() self.assertEqual(response, True) From b457735583b53353d2053c49c95bd243926e3d2d Mon Sep 17 00:00:00 2001 From: Anisarosalina Date: Fri, 16 Apr 2021 10:53:29 +0700 Subject: [PATCH 110/164] update --- Chapter02/AnisaRosalinaEnam1184016.py | 8 +++----- test_app.py | 10 ++++++++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Chapter02/AnisaRosalinaEnam1184016.py b/Chapter02/AnisaRosalinaEnam1184016.py index 7a4167b..9829825 100644 --- a/Chapter02/AnisaRosalinaEnam1184016.py +++ b/Chapter02/AnisaRosalinaEnam1184016.py @@ -29,17 +29,15 @@ def createfile(isi): print("Isi Dari File ini : \n "+a.read()) a.close() b = open(filename+".txt", "a") - b.write("\ndiatas adalah minuman yang tersedia") + b.write("diatas adalah minuman yang tersedia") + print("Tambah Isi Dari File ini : \n "+b.read()) b.close() - c = open(filename+".txt", "r") - print("Perubahan Isi Dari File ini : \n "+c.read()) - c.close() def start(): api() sleep(4) brr.wait() - print('API and readfile reached the barrier at: %s \n' % (ctime())) + print('api dan readfile freached the barrier at: %s \n' % (ctime())) def main(): diff --git a/test_app.py b/test_app.py index 1bb080b..6756663 100644 --- a/test_app.py +++ b/test_app.py @@ -315,7 +315,13 @@ def readfile(self,nfile): # response = main() # self.assertEqual(response, True) - def test_06_bahar_1184002(self): - from Chapter02.baharenam1184002 import main + #def test_06_bahar_1184002(self): + # from Chapter02.baharenam1184002 import main + # response = main() + # self.assertEqual(response, True) + + def test_06_anisa_1184016(self): + from Chapter02.AnisaRosalinaEnam1184016 import main response = main() self.assertEqual(response, True) + From 5ceb1ae9480e185e9841989be5623de03f48a677 Mon Sep 17 00:00:00 2001 From: ravirahmatulfajri Date: Fri, 16 Apr 2021 10:58:47 +0700 Subject: [PATCH 111/164] Ravi 1184040 --- test_app.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/test_app.py b/test_app.py index b0826e2..9153b27 100644 --- a/test_app.py +++ b/test_app.py @@ -298,21 +298,17 @@ def readfile(self,nfile): # result=main() # self.assertEqual(result, True) -<<<<<<< HEAD -======= ->>>>>>> 9c6e187ae3fde20a3dda815b486585cb7377a560 # def test_06_nandez_1184014(self): # from Chapter02.IrfanHernandezEnam1184014 import main # response = main() # self.assertEqual(response, True) -<<<<<<< HEAD + def test_06_ravi_1184040(self): from Chapter02.raviEnam1184040 import main response = main() self.assertEqual(response, True) -======= #def test_06_nandez_1184014(self): # from Chapter02.IrfanHernandezEnam1184014 import main @@ -324,8 +320,8 @@ def test_06_ravi_1184040(self): # response = main() # self.assertEqual(response, True) - def test_06_bahar_1184002(self): - from Chapter02.baharenam1184002 import main - response = main() - self.assertEqual(response, True) ->>>>>>> 9c6e187ae3fde20a3dda815b486585cb7377a560 + # def test_06_bahar_1184002(self): + # from Chapter02.baharenam1184002 import main + # response = main() + # self.assertEqual(response, True) + From 7c1b53ccbc457b9a69d16938c7be14d5a8e45703 Mon Sep 17 00:00:00 2001 From: Anisarosalina Date: Fri, 16 Apr 2021 10:58:49 +0700 Subject: [PATCH 112/164] update --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 1344c17..413378f 100644 --- a/.gitignore +++ b/.gitignore @@ -140,4 +140,6 @@ nilai.txt value value.txt value -value.pdf \ No newline at end of file +value.pdf +miramas.txt +file.txt \ No newline at end of file From b219e61bf5527c390680ab17d2ed99e03b74b91a Mon Sep 17 00:00:00 2001 From: idafatriniputri Date: Fri, 16 Apr 2021 11:00:17 +0700 Subject: [PATCH 113/164] Tugas Enam Ida 1184113 --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 1344c17..df1b11a 100644 --- a/.gitignore +++ b/.gitignore @@ -140,4 +140,6 @@ nilai.txt value value.txt value -value.pdf \ No newline at end of file +value.pdf + +luffy.txt \ No newline at end of file From cfcf3d8ad50835aecb89ace61b786b8bdd864c15 Mon Sep 17 00:00:00 2001 From: Anisarosalina Date: Fri, 16 Apr 2021 11:04:34 +0700 Subject: [PATCH 114/164] update konflik --- test_app.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/test_app.py b/test_app.py index 9153b27..20c700c 100644 --- a/test_app.py +++ b/test_app.py @@ -305,10 +305,10 @@ def readfile(self,nfile): # self.assertEqual(response, True) - def test_06_ravi_1184040(self): - from Chapter02.raviEnam1184040 import main - response = main() - self.assertEqual(response, True) + # def test_06_ravi_1184040(self): + # from Chapter02.raviEnam1184040 import main + # response = main() + # self.assertEqual(response, True) #def test_06_nandez_1184014(self): # from Chapter02.IrfanHernandezEnam1184014 import main @@ -325,3 +325,8 @@ def test_06_ravi_1184040(self): # response = main() # self.assertEqual(response, True) + def test_06_anisa_1184016(self): + from Chapter02.AnisaRosalinaEnam1184016 import main + response = main() + self.assertEqual(response, True) + \ No newline at end of file From 1de3ca3dad662dd14b1ce067db621b7dc1aa077a Mon Sep 17 00:00:00 2001 From: idafatriniputri Date: Fri, 16 Apr 2021 11:11:20 +0700 Subject: [PATCH 115/164] Tugas Enam Ida 1184113 --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 43fa246..83cebb0 100644 --- a/.gitignore +++ b/.gitignore @@ -141,7 +141,6 @@ value value.txt value value.pdf -<<<<<<< HEAD luffy.txt From 97bd74fe044054513066e64b1bcfc183cbcd5731 Mon Sep 17 00:00:00 2001 From: Okky Yudistira Date: Fri, 16 Apr 2021 11:11:47 +0700 Subject: [PATCH 116/164] Perbaikan tugas 6 Okky yang tadi --- Chapter02/okkyTiga1184087.py | 119 ----------------------------------- 1 file changed, 119 deletions(-) delete mode 100644 Chapter02/okkyTiga1184087.py diff --git a/Chapter02/okkyTiga1184087.py b/Chapter02/okkyTiga1184087.py deleted file mode 100644 index c8db1be..0000000 --- a/Chapter02/okkyTiga1184087.py +++ /dev/null @@ -1,119 +0,0 @@ -# -*- coding: utf-8 -*- -""" -Created on Fri Apr 9 08:34:57 2021 - -@author: Okky Yudistira -""" -import threading -import time -import os -import condition -import logging -import items -from flask import request, jsonify -import sqlite3 - - -class okky1184087Write_Trier(threading.Thread): - def __init__(self,name, thread_number, filename): - threading.Thread.__init__(self) - self.name = name - self.threadLock = threading.Lock() - self.thread_number = thread_number - self.filename=os.path.join(os.path.dirname(__file__), filename) - - def start_server(): - # starting server - print("starting the server...") - # do some startup work - time.sleep(2) - - def server(b): - start_server() - b.wait() - print("Server is ready.") - - def client(b): - print("waiting for server getting ready...") - b.wait() - print("sending request to server...") - - if __name__=='__main__': - b = threading.Barrier(2, timeout=5) - s = threading.Thread(target=server, args=(b,)) - s.start() - c = threading.Thread(target=client, args=(b,)) - # client thread - c.start() - s.join() - c.join() - print("Done") - - def trying(self): - with condition: - f = open("okky.txt", "w+") - for i in range(10): - f.write("hi are you okay number %d\r\n" % (i+1)) - - if len(items) == 0: - logging.info('no items to consume') - - condition.wait() - items.pop() - logging.info('consumed 1 item') - - condition.notify() - - def run(self): - for i in range(20): - time.sleep(2) - self.trying() - -class okky1184087(threading.Thread): - def __init__(self, name, thread_number, a ,filename): - threading.Thread.__init__(self) - self.threadLock = threading.Lock() - self.name = name - self.rlock = threading.RLock() - self.filename=os.path.join(os.path.dirname(__file__), filename) - self.thread_number = thread_number - self.a=a - - - def api_filter(): - query_parameters = request.args - id = query_parameters.get('id') - published = query_parameters.get('published') - author = query_parameters.get('author') - - query = "SELECT * FROM books WHERE" - to_filter = [] - - if id: - query += ' id=? AND' - to_filter.append(id) - - if published: - query += ' published=? AND' - to_filter.append(published) - - if author: - query += ' author=? AND' - to_filter.append(author) - - if not (id or published or author): - - return page_not_found(404) - - query = query[:-4] + ';' - conn = sqlite3.connect('books.db') - conn.row_factory = dict_factory - cur = conn.cursor() - results = cur.execute(query, to_filter).fetchall() - return jsonify(results) - - def createfile(self,isi): - print('Create File : '+ self.filename) - f = open(self.filename, "w") - f.write(str(isi)) - f.close() \ No newline at end of file From c9955f84c2bf2a7409c1685e20bdaf7825521ab5 Mon Sep 17 00:00:00 2001 From: Anisarosalina Date: Fri, 16 Apr 2021 11:13:20 +0700 Subject: [PATCH 117/164] update konflik --- .gitignore | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index c1c1042..9084936 100644 --- a/.gitignore +++ b/.gitignore @@ -141,9 +141,6 @@ value value.txt value value.pdf -<<<<<<< HEAD -miramas.txt -file.txt -======= newravi.docx ->>>>>>> 053c7fd69c430b43a9756844987e50795a0d78f3 +Miramas.txt +file.txt \ No newline at end of file From d5d2a2a0a562553cf22053a8800958a8cba8c864 Mon Sep 17 00:00:00 2001 From: Anisarosalina Date: Fri, 16 Apr 2021 11:19:31 +0700 Subject: [PATCH 118/164] update konflik --- .gitignore | 2 ++ test_app.py | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 9084936..fc1a46a 100644 --- a/.gitignore +++ b/.gitignore @@ -142,5 +142,7 @@ value.txt value value.pdf newravi.docx +movie_2020_0 +movie_2020_1 Miramas.txt file.txt \ No newline at end of file diff --git a/test_app.py b/test_app.py index 20c700c..4235e2e 100644 --- a/test_app.py +++ b/test_app.py @@ -324,9 +324,15 @@ def readfile(self,nfile): # from Chapter02.baharenam1184002 import main # response = main() # self.assertEqual(response, True) - + + # def test_06_josuansef_1184091(self): + # from Chapter02.JosuansefEnam_1184091 import main + # response = main() + # self.assertEqual(response, True) + def test_06_anisa_1184016(self): from Chapter02.AnisaRosalinaEnam1184016 import main response = main() self.assertEqual(response, True) - \ No newline at end of file + + \ No newline at end of file From 96a9eb49d185b3ebb5aecfd440e8468d4b9bbdfa Mon Sep 17 00:00:00 2001 From: Anisarosalina Date: Fri, 16 Apr 2021 11:23:03 +0700 Subject: [PATCH 119/164] update konflik --- Chapter02/JosuansefEnam_1184091.py | 74 ++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 Chapter02/JosuansefEnam_1184091.py diff --git a/Chapter02/JosuansefEnam_1184091.py b/Chapter02/JosuansefEnam_1184091.py new file mode 100644 index 0000000..47b9de0 --- /dev/null +++ b/Chapter02/JosuansefEnam_1184091.py @@ -0,0 +1,74 @@ +# -*- coding: utf-8 -*- +""" +Created on Fri Apr 16 11:21:11 2021 + +@author: asus +""" + +# -*- coding: utf-8 -*- +""" +Created on Thu Apr 15 12:31:12 2021 + +@author: Josuansef Pardede (1184091) +""" +from threading import Barrier, Thread +import os +import requests +from time import ctime, sleep + +jenis_file = 1 +batas = Barrier(jenis_file) +file = "movie_2020_" +filename = os.path.join(os.path.dirname(__file__), file) + + +def ApiJosuansef1184091(): + url = "https://movie-database-imdb-alternative.p.rapidapi.com/" + querystring = {"s":"Avengers Endgame","page":"1","r":"json"} + + headers = { + 'x-rapidapi-key': "03ea4d51b5mshde64ddab3687a71p1fb88fjsn3c194b2ea8bc", + 'x-rapidapi-host': "movie-database-imdb-alternative.p.rapidapi.com" + } + + response = requests.request("GET", url, headers=headers, params=querystring) + html=response.json() + print(response.text) + Josuansef1184091_CreateAppendFile(html) + +def Josuansef1184091_CreateAppendFile(konten): + for i in range(2): + print('Create File : '+file+str(i)+'.txt \n') + f = open(filename+str(i)+".txt", "w+") + f.write(str(konten)) + f.close() + + print('Append File: '+file+str(i)+'.txt') + a = open(filename+str(i)+".txt", "a+") + a.write(" => Film Terbaik Sepanjang Masa setelah 'Titanic' %d\r\n") + a.close() + print('Create & Append '+file+str(i)+' reached the barrier at: %s \n' % (ctime())) + sleep(2) + batas.wait() + +def run(): + ApiJosuansef1184091() + sleep(2) + batas.wait() + print('All reached the barrier at: %s \n' % (ctime())) + +### In[]: + +def main(): + threads = [] + print('MULAI LAH, APA LAGI YEKAN!') + for i in range(jenis_file): + threads.append(Thread(target=run)) + threads[-1].start() + for thread in threads: + thread.join() + print('UDAH UDAH! UDAH SELESAI GUYS!') + return True + +#if __name__ == "__main__": + #main() \ No newline at end of file From 3ffd7e6e0f62ee0ce4be104160d4d4ab9eec6a04 Mon Sep 17 00:00:00 2001 From: idafatriniputri Date: Fri, 16 Apr 2021 11:30:39 +0700 Subject: [PATCH 120/164] Tugas Enam Ida 1184113 --- Chapter02/IdaEnam1184113.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Chapter02/IdaEnam1184113.py b/Chapter02/IdaEnam1184113.py index a24cc3b..7d5a07c 100644 --- a/Chapter02/IdaEnam1184113.py +++ b/Chapter02/IdaEnam1184113.py @@ -6,7 +6,7 @@ shield = Barrier(jumlah) runners = [] filename = "luffy.txt" - +#api ida def api(): url = "https://api.jikan.moe/v3/search/anime?q=One%20Piece" response = requests.get(url) From e118e8a8ff1fcd553be3f882980ae9b1783e2584 Mon Sep 17 00:00:00 2001 From: Okky Yudistira Date: Fri, 16 Apr 2021 11:38:18 +0700 Subject: [PATCH 121/164] Perbaikan Okky 1184087 --- test_app.py | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/test_app.py b/test_app.py index b19e136..7061136 100644 --- a/test_app.py +++ b/test_app.py @@ -283,9 +283,9 @@ def readfile(self,nfile): # response = main() # self.assertEqual(response, True) -<<<<<<< HEAD + #def test_06_WahyuKurniaSari_1184001(self): -======= + # def test_06_WahyuKurniaSari_1184001(self): # from Chapter02.WahyuKurniaSariEnam1184001 import main @@ -305,18 +305,11 @@ def readfile(self,nfile): # self.assertEqual(response, True) ->>>>>>> 053c7fd69c430b43a9756844987e50795a0d78f3 + # from Chapter02.WahyuKurniaSariEnam1184001 import main # result=main() # self.assertEqual(result, True) -<<<<<<< HEAD - - def test_06_Okky_1184087(self): - from Chapter02.OkkyEnam1184087 import main - response = main() - self.assertEqual(response, True) -======= #def test_06_ira_1184024(self): # from Chapter02.IraEnam1184024 import main # response = main() @@ -360,10 +353,10 @@ def test_06_Okky_1184087(self): # response = main() # self.assertEqual(response, True) - def test_06_josuansef_1184091(self): - from Chapter02.JosuansefEnam_1184091 import main - response = main() - self.assertEqual(response, True) + #def test_06_josuansef_1184091(self): + # from Chapter02.JosuansefEnam_1184091 import main + # response = main() + # self.assertEqual(response, True) def test_06_Okky_1184087(self): from Chapter02.OkkyEnam1184087 import main From 7f4e32ae28818f3694b46bc45e63ba7b38d62d49 Mon Sep 17 00:00:00 2001 From: zanwar Date: Tue, 20 Apr 2021 14:42:43 +0700 Subject: [PATCH 122/164] tugas 7 zanwar --- Chapter02/ZanwarTujuh1184050.py | 100 ++++++++++++ test_app.py | 276 ++------------------------------ 2 files changed, 117 insertions(+), 259 deletions(-) create mode 100644 Chapter02/ZanwarTujuh1184050.py diff --git a/Chapter02/ZanwarTujuh1184050.py b/Chapter02/ZanwarTujuh1184050.py new file mode 100644 index 0000000..42b0a45 --- /dev/null +++ b/Chapter02/ZanwarTujuh1184050.py @@ -0,0 +1,100 @@ +import threading +import requests +from queue import Queue +import os + +event = threading.Event() +queue = Queue() + +class zanwarRewrite (threading.Thread): + def __init__(self, name, thread_number, filename): + threading.Thread.__init__(self) + self.name = name + self.threadLock = threading.Lock() + self.thread_number = thread_number + self.filename=os.path.join(os.path.dirname(__file__), filename) + + def run(self): + print("\n"+str(self.thread_number)+". ---> " + self.name + "start.") + self.threadLock.acquire() + print('A: Pls give me some motivation :(') + print('B: Okay, pls wait~') + event.wait() + print('rewrite : '+self.filename) + self.readfile() + print("Read after rewrite") + self.rewritefile() + event.clear() + self.threadLock.release() + print("\n"+str(self.thread_number)+". ---> " + threading.currentThread().getName() + "end") + + def readfile(self): + tulis = queue.get() + while tulis > 0: + f = open(self.filename, "r") + baca = f.readlines() + print('\n'+str(tulis)+' Tulis Readed from queue by %s' % ( self.name)) + print(baca[tulis]) + f.close() + tulis = tulis - 1 + queue.task_done() + + def rewritefile(self): + f = open(self.filename, "r") + fd = open(self.filename+'.txt', "w") + for line in f: + fd.write(line.replace('Quotes', 'Kata Kata Bijak')) + fd.close() + fr = open(self.filename+'.txt', "r") + print(fr.read()) + fr.close() + + +class zanwarTiga1184050 (threading.Thread): + def __init__(self, name, thread_number, a ,filename): + threading.Thread.__init__(self) + self.threadLock = threading.Lock() + self.name = name + self.rlock = threading.RLock() + self.filename=os.path.join(os.path.dirname(__file__), filename) + self.thread_number = thread_number + self.a=a + + def run(self): + print("\n"+str(self.thread_number)+". ---> " + self.name + "start.") + self.count() + print("Event Set!") + event.set() + print("\n"+str(self.thread_number)+". ---> " + threading.currentThread().getName() + "finish.") + + def randomapi(self): + with self.rlock: + print('Akses web service...') + apiurl='https://goquotes-api.herokuapp.com/api/v1/random?' + eq='count='+str(self.a) + response = requests.get(apiurl+eq) + html=response.json() + string = "Quotes : " + global x + x = self.a + for i in range(len(html["quotes"])): + hasil = html["quotes"][i]["text"] + tulis = "\n"+str(i)+". " + string = string+tulis+str(hasil) + queue.put(x) + print('%d Writed from queue by %s' % (x, self.name)) + x = x-1 + self.createfile(string) + # x = open(self.filename, "r") + # print(x.read()) + + def count(self): + with self.rlock: + self.randomapi() + + def createfile(self,isi): + print('Create File : '+ self.filename) + f = open(self.filename, "w") + f.write(str(isi)) + f.close() + \ No newline at end of file diff --git a/test_app.py b/test_app.py index c5b1c29..68498d5 100644 --- a/test_app.py +++ b/test_app.py @@ -34,78 +34,24 @@ def tearDown(self): # from Chapter02.Rizaluardi1184102 import main # response = main() # self.assertEqual(response, True) - - # def test_02_zanwar_1184050(self): - # from Chapter02.Zanwar1184050 import main - # response = main() - # self.assertEqual(response, True) - - #def test_02_ferdy_1184112(self): - # from Chapter02.Ferdy1184112 import main - # response = main() - # self.assertEqual(response, True) - - #def test_02_ida_1184113(self): - # from Chapter02.Ida1184113 import main - # response = main() - # self.assertEqual(response, True) - - #def test_02_okky_1184087(self): - # from Chapter02.okky1184087 import main - # response = main() - # self.assertEqual(response, True) - - #def test_02_Nandez_1184014(self): - # from Chapter02.IrfanHernandez1184014 import main - # response = main() - # self.assertEqual(response, True) - - #def test_02_alif_1184068(self): - # from Chapter02.Alif1184068 import main - # response = main() - # self.assertEqual(response, True) - #def test_02_iradwita_1184024(self): - # from Chapter02.IraDwita1184024 import main - # response = main() - # self.assertEqual(response, True) - - #def test_02_bahar_1184002(self): - # from Chapter02.baharandili1184002 import main - # response = main() - # self.assertEqual(response, True) - - #def test_02_hanif_1184058(self): - # from Chapter02.Hanif1184058 import main - # response = main() - # self.assertEqual(response, True) - - #def test_02_parhan_1184042(self): - # from Chapter02.Parhan1184042 import main - # response = main() - # self.assertEqual(response, True) - - - # def readfile(self,filename): - # f = open(filename, "r") - # return str(f.read()) - - # def readfile(self,filename): - # f = open(filename, "r") - # return str(f.read()) + def readfile(self,filename): + f = open(filename, "r") + return str(f.read()) + f.close() - # def test_03_zanwarTiga1184050(self): - # from Chapter02.ZanwarTiga1184050 import zanwarTiga1184050, zanwarRewrite - # threadrewrite= zanwarRewrite("Thread Rewrite File ",1 , 'nilai') - # threadutama = zanwarTiga1184050("Thread Utama ", 2, 1, 'nilai') - # threadrewrite.start() - # threadutama.start() - # threadrewrite.join() - # threadutama.join() - # respon=self.readfile('./Chapter02/nilai.txt') - # self.assertNotRegex(respon, "Kosong") + def test_03_zanwarTiga1184050(self): + from Chapter02.ZanwarTujuh1184050 import zanwarTiga1184050, zanwarRewrite + thread1 = zanwarRewrite("Thread Rewrite File ",1 , 'nilai') + thread2 = zanwarTiga1184050("Thread Utama ", 2, 10, 'nilai') + thread2.start() + thread1.start() + thread2.join() + thread1.join() + respon=self.readfile('./Chapter02/nilai.txt') + self.assertNotRegex(respon, "Kosong") # def test_03_WahyuKurniaSariDua1184001(self): # from Chapter02.WahyuKurniasariDua1184001 import WahyuKurniaSariSemaphoreDeleteFile, WahyuKurniaSariDua1184001 @@ -117,17 +63,6 @@ def tearDown(self): # main.join() #self.assertGreaterEqual(main.getFileContent(),0 ) - # def test_03_alifTiga1184068(self): - # from Chapter02.alifTiga1184068 import alifTiga1184068,alifEventDeleteFile - # threadutama = alifTiga1184068("Thread Utama ", 2,5,5,'alip') - # threaddelete= alifEventDeleteFile("Thread Delete File ", 1,'alip') - # threaddelete.start() - # threadutama.start() - # threaddelete.join() - # threadutama.join() - # respon=self.readfile('./Chapter02/alip.txt') - # self.assertNotRegex(respon, "kosong") - # def test_03_FerdyTiga1184112(self): @@ -140,192 +75,15 @@ def tearDown(self): # threadutama.join() # respon=self.readfile('./Chapter02/minuman.txt') # self.assertNotRegex(respon, "Gak Boleh Kosong") - - # def test_03_hanifTiga1184058(self): - # from Chapter02.HanifTiga1184058 import hanifTiga1184058, hanifRename - # threadrename= hanifRename("Thread rename file ",1 , 'nilai') - # threadutama = hanifTiga1184058("Thread utama ", 2, 1, 'nilai') - # threadrename.start() - # threadutama.start() - # threadrename.join() - # threadutama.join() - # respon=self.readfile('./nilai.txt') - # self.assertNotRegex(respon, "Kosong") - # def readfile(self,nfile): - # f = open(nfile, "r+") - # return str(f.read()) - - - # def test_03_raviTiga1184040(self): - # from Chapter02.raviTiga1184040 import raviTiga1184040, raviMenulis - # threadwrite = raviMenulis ("Thread Pro ",1 , 'value') - # threadutama = raviTiga1184040("Thread Utama ", 2,2,5, 'value') - # threadwrite.start() - - # def test_03_FerdyTiga1184112(self): - # from Chapter02.FerdyTiga1184112 import FerdyGITiga1184112,FerdyEventGI - # threadrewrite= FerdyEventGI("Thread Lain ", 1,'minuman') - # threadutama = FerdyGITiga1184112("Thread inti ", 2,'minuman') - # threadrewrite.start() - - # threadutama.start() - # threadwrite.join() - # threadutama.join() - - # respon=self.readfile('./Chapter02/value.pdf') - # self.assertNotRegex(respon, "Nomor : 12345678910") - - # respon=self.readfile('./Chapter02/minuman.txt') - # self.assertNotRegex(respon, "Gak Boleh Kosong") - - # def test_03_hanifTiga1184058(self): - # from Chapter02.HanifTiga1184058 import hanifTiga1184058, hanifRename - # threadrename= hanifRename("Thread rename file ",1 , 'nilai') - # threadutama = hanifTiga1184058("Thread utama ", 2, 1, 'nilai') - # threadrename.start() - # threadutama.start() - # threadrename.join() - # threadutama.join() - # respon=self.readfile('./nilai.txt') - # self.assertNotRegex(respon, "Kosong") - # - def readfile(self,nfile): - f = open(nfile, "r+") - return str(f.read()) - - # def test_03_raviTiga1184040(self): - # from Chapter02.raviTiga1184040 import raviTiga1184040, raviMenulis - # threadwrite = raviMenulis ("Thread Pro ",1 , 'value') - # threadutama = raviTiga1184040("Thread Utama ", 2,2,5, 'value') - # threadwrite.start() - # threadutama.start() - # threadwrite.join() - # threadutama.join() - # respon=self.readfile('./Chapter02/value.pdf') - # self.assertNotRegex(respon, "Nomor : 12345678910") - - # def test_03_parhanTiga1184042(self): - # from Chapter02.parhanTiga1184042 import parhanTiga1184042,parhanEventDeleteFile - # threadutama = parhanTiga1184042("Thread Utama ", 2,5,5,'parhan') - # threaddelete= parhanEventDeleteFile("Thread Delete File ", 1,'parhan') - # threaddelete.start() - # threadutama.start() - # threaddelete.join() - # threadutama.join() - # respon=self.readfile('./Chapter02/parhan.txt') - # self.assertNotRegex(respon, "kosong") # def test_06_Ferdy_1184112(self): # from Chapter02.FerdyEnam1184112 import main # response = main() # self.assertEqual(response, True) - # def test_06_zanwar_1184050(self): - # from Chapter02.ZanwarEnam1184050 import main - # response = main() - # self.assertEqual(response, True) - - #def test_06_alif_1184068(self): - # from Chapter02.AlifEnam1184068 import main - # response = main() - # self.assertEqual(response, True) - - - - # def test_06_parhan_1184042(self): - # from Chapter02.ParhanEnam1184042 import main - # response = main() - # self.assertEqual(response, True) - - - # def test_06_parhan_1184042(self): - #from Chapter02.ParhanEnam1184042 import main - #response = main() - #self.assertEqual(response, True) - - #def test_06_ira_1184024(self): - #from Chapter02.IraEnam1184024 import main - #response = main() - #self.assertEqual(response, True) - - - #def test_06_parhan_1184042(self): - # from Chapter02.ParhanEnam1184042 import main - # response = main() - # self.assertEqual(response, True) - - # def test_06_hanif_1184058(self): - # from Chapter02.HanifEnam1184058 import main - # response = main() - # self.assertEqual(response, True) - - - # def test_06_WahyuKurniaSari_1184001(self): - # from Chapter02.WahyuKurniaSariEnam1184001 import main - # result=main() - # self.assertEqual(result, True) - - - #def test_06_WahyuKurniaSari_1184001(self): - - #from Chapter02.WahyuKurniaSariEnam1184001 import main - #result=main() - #self.assertEqual(result, True) - - # def test_06_ira_1184024(self): - # from Chapter02.IraEnam1184024 import main - # response = main() - # self.assertEqual(response, True) - - - # from Chapter02.WahyuKurniaSariEnam1184001 import main - # result=main() - # self.assertEqual(result, True) - - #def test_06_ira_1184024(self): - # from Chapter02.IraEnam1184024 import main - # response = main() - # self.assertEqual(response, True) - - - # def test_06_rizaluardi_1184102(self): - # from Chapter02.RizaluardiEnam1184102 import main - # result=main() - # self.assertEqual(result, True) - - #def test_06_rizaluardi_1184102(self): - # from Chapter02.RizaluardiEnam1184102 import main - # result=main() - # self.assertEqual(result, True) - - - # def test_06_nandez_1184014(self): - # from Chapter02.IrfanHernandezEnam1184014 import main + # def test_06_josuansef_1184091(self): + # from Chapter02.JosuansefEnam_1184091 import main # response = main() # self.assertEqual(response, True) - - - # def test_06_ravi_1184040(self): - # from Chapter02.raviEnam1184040 import main - # response = main() - # self.assertEqual(response, True) - - #def test_06_nandez_1184014(self): - # from Chapter02.IrfanHernandezEnam1184014 import main - # response = main() - # self.assertEqual(response, True) - # def test_06_ariyo_1184056(self): - # from Chapter02.AriyoEnam1184056 import main - # response = main() - # self.assertEqual(response, True) - - # def test_06_bahar_1184002(self): - # from Chapter02.baharenam1184002 import main - # response = main() - # self.assertEqual(response, True) - - def test_06_josuansef_1184091(self): - from Chapter02.JosuansefEnam_1184091 import main - response = main() - self.assertEqual(response, True) \ No newline at end of file + \ No newline at end of file From c5eec7a129beba3ed4917e42c53046ea3345faca Mon Sep 17 00:00:00 2001 From: zanwar Date: Tue, 20 Apr 2021 14:49:52 +0700 Subject: [PATCH 123/164] tugas 7 zanwar --- Chapter02/ZanwarTujuh1184050.py | 2 +- test_app.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Chapter02/ZanwarTujuh1184050.py b/Chapter02/ZanwarTujuh1184050.py index 42b0a45..de23afc 100644 --- a/Chapter02/ZanwarTujuh1184050.py +++ b/Chapter02/ZanwarTujuh1184050.py @@ -50,7 +50,7 @@ def rewritefile(self): fr.close() -class zanwarTiga1184050 (threading.Thread): +class zanwarTujuh1184050 (threading.Thread): def __init__(self, name, thread_number, a ,filename): threading.Thread.__init__(self) self.threadLock = threading.Lock() diff --git a/test_app.py b/test_app.py index 68498d5..4625f05 100644 --- a/test_app.py +++ b/test_app.py @@ -42,10 +42,10 @@ def readfile(self,filename): f.close() - def test_03_zanwarTiga1184050(self): - from Chapter02.ZanwarTujuh1184050 import zanwarTiga1184050, zanwarRewrite + def test_07_zanwarTujuh1184050(self): + from Chapter02.ZanwarTujuh1184050 import zanwarTujuh1184050, zanwarRewrite thread1 = zanwarRewrite("Thread Rewrite File ",1 , 'nilai') - thread2 = zanwarTiga1184050("Thread Utama ", 2, 10, 'nilai') + thread2 = zanwarTujuh1184050("Thread Utama ", 2, 5, 'nilai') thread2.start() thread1.start() thread2.join() From 1a99dcd385e9aaa6f19e7047179271e28bea0756 Mon Sep 17 00:00:00 2001 From: FerdyBerlianoP Date: Tue, 20 Apr 2021 21:41:42 +0700 Subject: [PATCH 124/164] Tugas 7 Ferdy 1184112 --- test_app.py | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/test_app.py b/test_app.py index 4625f05..be5ef75 100644 --- a/test_app.py +++ b/test_app.py @@ -42,16 +42,16 @@ def readfile(self,filename): f.close() - def test_07_zanwarTujuh1184050(self): - from Chapter02.ZanwarTujuh1184050 import zanwarTujuh1184050, zanwarRewrite - thread1 = zanwarRewrite("Thread Rewrite File ",1 , 'nilai') - thread2 = zanwarTujuh1184050("Thread Utama ", 2, 5, 'nilai') - thread2.start() - thread1.start() - thread2.join() - thread1.join() - respon=self.readfile('./Chapter02/nilai.txt') - self.assertNotRegex(respon, "Kosong") + # def test_07_zanwarTujuh1184050(self): + # from Chapter02.ZanwarTujuh1184050 import zanwarTujuh1184050, zanwarRewrite + # thread1 = zanwarRewrite("Thread Rewrite File ",1 , 'nilai') + # thread2 = zanwarTujuh1184050("Thread Utama ", 2, 5, 'nilai') + # thread2.start() + # thread1.start() + # thread2.join() + # thread1.join() + # respon=self.readfile('./Chapter02/nilai.txt') + # self.assertNotRegex(respon, "Kosong") # def test_03_WahyuKurniaSariDua1184001(self): # from Chapter02.WahyuKurniasariDua1184001 import WahyuKurniaSariSemaphoreDeleteFile, WahyuKurniaSariDua1184001 @@ -85,5 +85,22 @@ def test_07_zanwarTujuh1184050(self): # from Chapter02.JosuansefEnam_1184091 import main # response = main() # self.assertEqual(response, True) + + def readfile(self,filename): + f = open(filename, "r") + return str(f.read()) + + + + def test_03_FerdyEvent1184112(self): + from Chapter02.FerdyTujuh1184112 import FerdyQueue,Ferdy + threadrewrite= FerdyQueue("Thread Lain ",'queue') + threadutama = Ferdy("Thread inti",'queue') + threadrewrite.start() + threadutama.start() + threadrewrite.join() + threadutama.join() + respon=self.readfile('./Chapter02/queue.txt') + self.assertNotRegex(respon, "Gak Boleh Kosong") \ No newline at end of file From d3967ae327973ca01bb0727d97a915e5f5529207 Mon Sep 17 00:00:00 2001 From: FerdyBerlianoP Date: Tue, 20 Apr 2021 23:00:29 +0700 Subject: [PATCH 125/164] Tugas Tujuh Ferdy 1184112 --- Chapter02/FerdyTujuh1184112.py | 90 ++++++++++++++++++++++++++++++++++ test_app.py | 14 +++--- 2 files changed, 97 insertions(+), 7 deletions(-) create mode 100644 Chapter02/FerdyTujuh1184112.py diff --git a/Chapter02/FerdyTujuh1184112.py b/Chapter02/FerdyTujuh1184112.py new file mode 100644 index 0000000..3d18037 --- /dev/null +++ b/Chapter02/FerdyTujuh1184112.py @@ -0,0 +1,90 @@ +import threading +import requests +import os +from queue import Queue + +queue = Queue() +event = threading.Event() + +class FerdyQueue(threading.Thread): + def __init__(self,name, filename): + threading.Thread.__init__(self) + self.name = name + self.threadLock = threading.Lock() + self.filename = os.path.join(os.path.dirname(__file__), filename) + + def run(self): + print("\n"+ self.name + "mulai.") + self.threadLock.acquire() + print('Cocktail 1') + event.wait() + print('ubah : '+self.filename) + self.readfile() + print("pas udah diubah") + self.bikinfile() + event.clear() + self.threadLock.release() + print("\n" + threading.currentThread().getName() + "berhasil") + + def readfile(self): + f = open(self.filename, "r") + print("File's Content is : \n "+f.read()) + + def bikinfile(self): + f = open(self.filename, "r") + bikin = open(self.filename+'.txt', "w") + for line in f: + bikin.write(line.replace('strCategory', 'Jenis')) + bikin.close() + baru = open(self.filename+'.txt', "r") + print(baru.read()) + baru.close() + + +class Ferdy (threading.Thread): + def __init__(self, name, filename): + threading.Thread.__init__(self) + self.threadLock = threading.Lock() + self.name = name + self.rlock = threading.RLock() + self.filename=os.path.join(os.path.dirname(__file__), filename) + + + def run(self): + print("\n"+ self.name + "mulai.") + self.hasil() + cb = queue.get() + print("\n queuenya") + print(cb) + queue.task_done() + event.set() + print("\n" + threading.currentThread().getName() + "selesai.") + + def apiwebservice(self): + with self.rlock: + print('Webservice nya') + apiurl='https://www.thecocktaildb.com/api/json/v1/1/list.php?c=list' + response = requests.get(apiurl) + html=response.json() + string = "" + for i in range(len(html["drinks"])): + cocokin = html["drinks"][i] + baru = "\n"+str(i)+". " + string = string+baru+str(cocokin) + queue.put(string) + self.createfile(string) + + + def hasil(self): + with self.rlock: + self.apiwebservice() + + def createfile(self,isi): + print('Create File : '+ self.filename) + f = open(self.filename, "w") + f.write(str(isi)) + f.close() + + + + diff --git a/test_app.py b/test_app.py index be5ef75..27c7b02 100644 --- a/test_app.py +++ b/test_app.py @@ -94,13 +94,13 @@ def readfile(self,filename): def test_03_FerdyEvent1184112(self): from Chapter02.FerdyTujuh1184112 import FerdyQueue,Ferdy - threadrewrite= FerdyQueue("Thread Lain ",'queue') - threadutama = Ferdy("Thread inti",'queue') - threadrewrite.start() - threadutama.start() - threadrewrite.join() - threadutama.join() - respon=self.readfile('./Chapter02/queue.txt') + threadjuga= FerdyQueue("Thread Lain ",'queue') + threadaja = Ferdy("Thread inti",'queue') + threadjuga.start() + threadaja.start() + threadjuga.join() + threadaja.join() + respon=self.readfile('./Chapter02/queue') self.assertNotRegex(respon, "Gak Boleh Kosong") \ No newline at end of file From d368e2c6ca3a6c5030d63729fce32818855733d1 Mon Sep 17 00:00:00 2001 From: alif721 Date: Wed, 21 Apr 2021 14:54:48 +0700 Subject: [PATCH 126/164] Tugas 7 Alif --- Chapter02/AlifTujuh1184068.py | 87 +++++++++++++++++++++++++++++++++++ test_app.py | 30 ++++++++---- 2 files changed, 107 insertions(+), 10 deletions(-) create mode 100644 Chapter02/AlifTujuh1184068.py diff --git a/Chapter02/AlifTujuh1184068.py b/Chapter02/AlifTujuh1184068.py new file mode 100644 index 0000000..c269944 --- /dev/null +++ b/Chapter02/AlifTujuh1184068.py @@ -0,0 +1,87 @@ +from threading import Thread,currentThread, Lock, RLock, Event +import requests +import os +from queue import Queue + +queue = Queue() +event = Event() + +class alifHandlingFile (Thread): + def __init__(self,name,thread_number,namafile): + Thread.__init__(self) + self.threadLock = Lock() + self.name = name + self.thread_number = thread_number + self.namafile=os.path.join(os.path.dirname(__file__), namafile) + self.event = event + + def run(self): + print("\n"+str(self.thread_number)+". ---> " + self.name + "jalan") + print('class alifHandlingFile mau menjalankan event wait dilanjutkan clear untuk baca dan rename file') + self.event.wait() + self.threadLock.acquire() + print('melakukan baca file : '+self.namafile) + self.readfile() + print('melakukan rename file : '+self.namafile) + self.renamefile() + self.event.wait() + self.threadLock.release() + print("\n"+str(self.thread_number)+". ---> " + currentThread().getName() + "Baca file dan delete file selesai") + print ("menjalankan event clear") + self.event.clear() + + def readfile(self): + q=queue.get() + f = open(self.namafile, "r") + print("Isi Filenya apaan yaa : "+f.read()) + print("Sudah selesai baca isi file nya nih, jalanin queue task done \n") + queue.task_done() + + def renamefile(self): + print('coba ganti nama filenya dong \n') + os.rename(self.namafile,self.namafile+'.txt') + print("nama file telah diganti \n") + +class alifTujuh1184068 (Thread): + def __init__(self, name,thread_number,a,b ,namafile): + Thread.__init__(self) + self.threadLock = Lock() + self.event = event + self.rlock = RLock() + self.name = name + self.namafile=os.path.join(os.path.dirname(__file__), namafile) + self.thread_number = thread_number + self.a=a + self.b=b + + def run(self): + print("\n"+str(self.thread_number)+". ---> " + self.name + "jalan") + self.threadLock.acquire() + print("threeadlock acquire utama") + self.hitung() + self.event.set() + print('class alifTujuh1184068 sudah selesai melakukan event set') + self.threadLock.release() + print("\n"+str(self.thread_number)+". ---> " + currentThread().getName() + "selesai") + + def getapi(self): + with self.rlock: + print('didalam rlock apipangkat, akses web service...') + apiurl='http://www.emsifa.com/api-wilayah-indonesia/api/provinces.json' + response = requests.get(apiurl) + html=response.json() + queue.put(html) + self.createfile(html) + + def hitung(self): + with self.rlock: + print('rlock hitung') + self.getapi() + + def createfile(self,isi): + print('membuat file baru : '+ self.namafile) + f = open(self.namafile, "x") + f.write(str(isi)) + f.close() + print('sudah membuat file baru, mau menjalankan event set') + diff --git a/test_app.py b/test_app.py index 27c7b02..617b126 100644 --- a/test_app.py +++ b/test_app.py @@ -92,15 +92,25 @@ def readfile(self,filename): - def test_03_FerdyEvent1184112(self): - from Chapter02.FerdyTujuh1184112 import FerdyQueue,Ferdy - threadjuga= FerdyQueue("Thread Lain ",'queue') - threadaja = Ferdy("Thread inti",'queue') - threadjuga.start() - threadaja.start() - threadjuga.join() - threadaja.join() - respon=self.readfile('./Chapter02/queue') - self.assertNotRegex(respon, "Gak Boleh Kosong") + # def test_03_FerdyEvent1184112(self): + # from Chapter02.FerdyTujuh1184112 import FerdyQueue,Ferdy + # threadjuga= FerdyQueue("Thread Lain ",'queue') + # threadaja = Ferdy("Thread inti",'queue') + # threadjuga.start() + # threadaja.start() + # threadjuga.join() + # threadaja.join() + # respon=self.readfile('./Chapter02/queue') + # self.assertNotRegex(respon, "Gak Boleh Kosong") + def test_07_alifTujuh1184068(self): + from Chapter02.AlifTujuh1184068 import alifTujuh1184068,alifHandlingFile + threadutama = alifTujuh1184068("Thread Utama ", 2,5,5,'alip') + threadhandling= alifHandlingFile("Thread handling File ", 1,'alip') + threadhandling.start() + threadutama.start() + threadhandling.join() + threadutama.join() + respon=self.readfile('./Chapter02/alip.txt') + self.assertNotRegex(respon, "kosong") \ No newline at end of file From 9c53611b04c6056d3392832cbc65cb9c28021461 Mon Sep 17 00:00:00 2001 From: hernandez2804 <56632278+hernandez2804@users.noreply.github.com> Date: Wed, 21 Apr 2021 15:20:10 +0700 Subject: [PATCH 127/164] Tugas 7 --- Chapter02/IrfanHernandezTujuh1184014.py | 58 +++++++++++++++++++++++++ test_app.py | 35 ++++++++------- 2 files changed, 78 insertions(+), 15 deletions(-) create mode 100644 Chapter02/IrfanHernandezTujuh1184014.py diff --git a/Chapter02/IrfanHernandezTujuh1184014.py b/Chapter02/IrfanHernandezTujuh1184014.py new file mode 100644 index 0000000..148dd99 --- /dev/null +++ b/Chapter02/IrfanHernandezTujuh1184014.py @@ -0,0 +1,58 @@ +from threading import Thread +import os +import requests +from queue import Queue + +queue = Queue() +drink = [] + +apiurl='https://www.thecocktaildb.com/api/json/v1/1/search.php?s=margarita' +response = requests.get(apiurl) +html=response.json() + + +class IrfanPut(Thread): + def __init__(self, name, thread_number, filename): + Thread.__init__(self) + self.name = name + self.thread_number = thread_number + self.filename = os.path.join(os.path.dirname(__file__), filename) + + def margaritaapi(self): + string = "Drinks :" + for i in range(len(html["drinks"])): + hasil = html["drinks"][i]["strDrink"] + angka = "\n"+str(i)+". " + string = string+angka+hasil + drink.append(hasil) + queue.put(drink) + print(str(i)+'. Margarita %s Appended from queue by %s' % (hasil, self.name)) + self.fileresult(string) + + def fileresult(self, isi): + f = open(self.filename+".txt", "w") + f.write(isi) + f.close() + + def readfile(self): + read = queue.get() + r = len(read) + while r > 0: + f = open(self.filename+".txt", "r") + baca = f.readlines() + print('\n'+str(r)+' Tulis Readed from queue by %s' % ( self.name)) + print(baca[r]) + f.close() + r = r - 1 + queue.task_done() + + def run(self): + print("Start Queue!") + self.margaritaapi() + self.readfile() + print("Queue Finish!") + + + + + diff --git a/test_app.py b/test_app.py index 27c7b02..05f63a3 100644 --- a/test_app.py +++ b/test_app.py @@ -86,21 +86,26 @@ def readfile(self,filename): # response = main() # self.assertEqual(response, True) - def readfile(self,filename): - f = open(filename, "r") - return str(f.read()) - - +# def test_03_FerdyEvent1184112(self): +# from Chapter02.FerdyTujuh1184112 import FerdyQueue,Ferdy +# threadjuga= FerdyQueue("Thread Lain ",'queue') +# threadaja = Ferdy("Thread inti",'queue') +# threadjuga.start() +# threadaja.start() +# threadjuga.join() +# threadaja.join() +# respon=self.readfile('./Chapter02/queue') +# self.assertNotRegex(respon, "Gak Boleh Kosong") + + def test_07_HernandezTujuh1184014(self): + from Chapter02.IrfanHernandezTujuh1184014 import IrfanPut + thread1 = IrfanPut("Thread Put", 1, "miramas") + thread1.start() + thread1.join() + respon=self.readfile('./Chapter02/miramas.txt') + self.assertNotRegex(respon, "Kosong") + - def test_03_FerdyEvent1184112(self): - from Chapter02.FerdyTujuh1184112 import FerdyQueue,Ferdy - threadjuga= FerdyQueue("Thread Lain ",'queue') - threadaja = Ferdy("Thread inti",'queue') - threadjuga.start() - threadaja.start() - threadjuga.join() - threadaja.join() - respon=self.readfile('./Chapter02/queue') - self.assertNotRegex(respon, "Gak Boleh Kosong") + \ No newline at end of file From 32fb070775993992c146a12036d41516b337912f Mon Sep 17 00:00:00 2001 From: Anisarosalina Date: Wed, 21 Apr 2021 16:35:06 +0700 Subject: [PATCH 128/164] update --- Chapter02/AnisaRosalinaEnam1184016.py | 52 --------------------------- Miramas.txt | 8 ----- test_app.py | 44 +++++++++++------------ 3 files changed, 22 insertions(+), 82 deletions(-) delete mode 100644 Chapter02/AnisaRosalinaEnam1184016.py delete mode 100644 Miramas.txt diff --git a/Chapter02/AnisaRosalinaEnam1184016.py b/Chapter02/AnisaRosalinaEnam1184016.py deleted file mode 100644 index 9829825..0000000 --- a/Chapter02/AnisaRosalinaEnam1184016.py +++ /dev/null @@ -1,52 +0,0 @@ -from threading import Barrier, Thread -import requests -import os -from time import ctime, sleep - -total = 1 -brr = Barrier(total) -file = "Miramas" -filename=os.path.join(os.path.dirname(file), file) - -def api(): - apiurl='https://www.thecocktaildb.com/api/json/v1/1/search.php?s=margarita' - response = requests.get(apiurl) - html=response.json() - string="minuman : " - for i in range(len(html["drinks"])): - hasil = html["drinks"][i]["strDrink"] - tulis = "\n"+str(i)+". " - string = string+tulis+str(hasil) - createfile(string) - - -def createfile(isi): - print('Create File : '+ filename) - f = open(filename+".txt", "w") - f.write(str(isi)) - f.close() - a = open(filename+".txt", "r") - print("Isi Dari File ini : \n "+a.read()) - a.close() - b = open(filename+".txt", "a") - b.write("diatas adalah minuman yang tersedia") - print("Tambah Isi Dari File ini : \n "+b.read()) - b.close() - -def start(): - api() - sleep(4) - brr.wait() - print('api dan readfile freached the barrier at: %s \n' % (ctime())) - - -def main(): - threads = [] - print('Minuman Yang tersedia') - for i in range(total): - threads.append(Thread(target=start)) - threads[-1].start() - for thread in threads: - thread.join() - print('Telah Muncul') - return True diff --git a/Miramas.txt b/Miramas.txt deleted file mode 100644 index 6b77282..0000000 --- a/Miramas.txt +++ /dev/null @@ -1,8 +0,0 @@ -minuman : -0. Margarita -1. Blue Margarita -2. Tommy's Margarita -3. Whitecap Margarita -4. Strawberry Margarita -5. Smashed Watermelon Margarita -diatas adalah minuman yang tersedia \ No newline at end of file diff --git a/test_app.py b/test_app.py index 84c7391..79502fc 100644 --- a/test_app.py +++ b/test_app.py @@ -97,31 +97,31 @@ def readfile(self,filename): # respon=self.readfile('./Chapter02/queue') # self.assertNotRegex(respon, "Gak Boleh Kosong") - # def test_07_HernandezTujuh1184014(self): - # from Chapter02.IrfanHernandezTujuh1184014 import IrfanPut - # thread1 = IrfanPut("Thread Put", 1, "miramas") - # thread1.start() - # thread1.join() - # respon=self.readfile('./Chapter02/miramas.txt') - # self.assertNotRegex(respon, "Kosong") +# def test_07_HernandezTujuh1184014(self): +# from Chapter02.IrfanHernandezTujuh1184014 import IrfanPut +# thread1 = IrfanPut("Thread Put", 1, "miramas") +# thread1.start() +# thread1.join() +# respon=self.readfile('./Chapter02/miramas.txt') +# self.assertNotRegex(respon, "Kosong") +# +# +# def test_07_alifTujuh1184068(self): +# from Chapter02.AlifTujuh1184068 import alifTujuh1184068,alifHandlingFile +# threadutama = alifTujuh1184068("Thread Utama ", 2,5,5,'alip') +# threadhandling= alifHandlingFile("Thread handling File ", 1,'alip') +# threadhandling.start() +# threadutama.start() +# threadhandling.join() +# threadutama.join() +# respon=self.readfile('./Chapter02/alip.txt') +# self.assertNotRegex(respon, "kosong") +# - - # def test_07_alifTujuh1184068(self): - # from Chapter02.AlifTujuh1184068 import alifTujuh1184068,alifHandlingFile - # threadutama = alifTujuh1184068("Thread Utama ", 2,5,5,'alip') - # threadhandling= alifHandlingFile("Thread handling File ", 1,'alip') - # threadhandling.start() - # threadutama.start() - # threadhandling.join() - # threadutama.join() - # respon=self.readfile('./Chapter02/alip.txt') - # self.assertNotRegex(respon, "kosong") - - def test_07_AnisaTujuh1184016(self): + def test_07_AnisaTujuh1184016(self): from Chapter02.AnisaRosalinaTujuh1184016 import Anisa thread1 = Anisa("Thread Put", 1, "Cocktile") thread1.start() thread1.join() respon=self.readfile('./Chapter02/Cocktile.txt') - self.assertNotRegex(respon, "Kosong") - \ No newline at end of file + self.assertNotRegex(respon, "Kosong") \ No newline at end of file From cbf59d79f8d8469ce82c5bcbf745d9c7374d4de6 Mon Sep 17 00:00:00 2001 From: HanifWp Date: Wed, 21 Apr 2021 18:05:06 +0700 Subject: [PATCH 129/164] Tugas 7 Hanif 1184058 --- Chapter02/HanifTujuh1184058.py | 83 ++++++++++++++++++++++++++++++++++ test_app.py | 47 +++++++++++-------- 2 files changed, 112 insertions(+), 18 deletions(-) create mode 100644 Chapter02/HanifTujuh1184058.py diff --git a/Chapter02/HanifTujuh1184058.py b/Chapter02/HanifTujuh1184058.py new file mode 100644 index 0000000..094efe3 --- /dev/null +++ b/Chapter02/HanifTujuh1184058.py @@ -0,0 +1,83 @@ +import threading +import requests +from queue import Queue +import os + +event = threading.Event() +queue = Queue() + +class HanifCopy (threading.Thread): + def __init__(self, name, thread_number, filename): + threading.Thread.__init__(self) + self.name = name + self.threadLock = threading.Lock() + self.thread_number = thread_number + self.filename=os.path.join(os.path.dirname(__file__), filename) + + def run(self): + print("\n"+str(self.thread_number)+". ---> " + self.name + "start.") + self.threadLock.acquire() + event.wait() + print('Copy file : '+self.filename) + self.readfile() + print("Read file") + self.copyfile() + event.clear() + self.threadLock.release() + print("\n"+str(self.thread_number)+". ---> " + threading.currentThread().getName() + "end") + + def readfile(self): + f = open(self.filename, "r") + print("Isi file : "+f.read()) + + def copyfile(self): + queue.get() + with open ("F:\\Kuliah\\Semester 6\\Sistem Tersebar\\Python-Parallel-Programming-Cookbook-Second-Edition\\Chapter02\\pokemon.txt", "rb") as read: + with open ("F:\\Kuliah\\Semester 6\\Sistem Tersebar\\Python-Parallel-Programming-Cookbook-Second-Edition\\pokemon.txt", "wb") as filetobecopied: + filetobecopied.write(read.read()) + queue.task_done() + + +class HanifTujuh1184058 (threading.Thread): + def __init__(self, name, thread_number, a ,filename): + threading.Thread.__init__(self) + self.threadLock = threading.Lock() + self.name = name + self.rlock = threading.RLock() + self.filename=os.path.join(os.path.dirname(__file__), filename) + self.thread_number = thread_number + self.a=a + + def run(self): + print("\n"+str(self.thread_number)+". ---> " + self.name + "start.") + self.count() + event.set() + print("\n"+str(self.thread_number)+". ---> " + threading.currentThread().getName() + "finish.") + + def getapi(self): + with self.rlock: + print('Akses web service') + apiurl='https://pokeapi.co/api/v2/pokemon/ditto' + response = requests.get(apiurl) + html=response.json() + string = "ability :" + global x + x = self.a + for i in range(len(html["abilities"])): + hasil = html["abilities"][i]["ability"]["name"] + tulis = "\n"+str(i)+". " + string = string+tulis+str(hasil) + queue.put(x) + print('%d Writed from queue by %s' % (x, self.name)) + x = x-1 + self.createfile(string) + + def count(self): + with self.rlock: + self.getapi() + + def createfile(self,isi): + print('Create File : '+ self.filename) + f = open(self.filename, "w") + f.write(str(isi)) + f.close() \ No newline at end of file diff --git a/test_app.py b/test_app.py index 3c8fb97..3c26deb 100644 --- a/test_app.py +++ b/test_app.py @@ -97,23 +97,34 @@ def readfile(self,filename): # respon=self.readfile('./Chapter02/queue') # self.assertNotRegex(respon, "Gak Boleh Kosong") - def test_07_HernandezTujuh1184014(self): - from Chapter02.IrfanHernandezTujuh1184014 import IrfanPut - thread1 = IrfanPut("Thread Put", 1, "miramas") - thread1.start() - thread1.join() - respon=self.readfile('./Chapter02/miramas.txt') - self.assertNotRegex(respon, "Kosong") +# def test_07_HernandezTujuh1184014(self): +# from Chapter02.IrfanHernandezTujuh1184014 import IrfanPut +# thread1 = IrfanPut("Thread Put", 1, "miramas") +# thread1.start() +# thread1.join() +# respon=self.readfile('./Chapter02/miramas.txt') +# self.assertNotRegex(respon, "Kosong") +# +# +# def test_07_alifTujuh1184068(self): +# from Chapter02.AlifTujuh1184068 import alifTujuh1184068,alifHandlingFile +# threadutama = alifTujuh1184068("Thread Utama ", 2,5,5,'alip') +# threadhandling= alifHandlingFile("Thread handling File ", 1,'alip') +# threadhandling.start() +# threadutama.start() +# threadhandling.join() +# threadutama.join() +# respon=self.readfile('./Chapter02/alip.txt') +# self.assertNotRegex(respon, "kosong") - - def test_07_alifTujuh1184068(self): - from Chapter02.AlifTujuh1184068 import alifTujuh1184068,alifHandlingFile - threadutama = alifTujuh1184068("Thread Utama ", 2,5,5,'alip') - threadhandling= alifHandlingFile("Thread handling File ", 1,'alip') - threadhandling.start() - threadutama.start() - threadhandling.join() - threadutama.join() - respon=self.readfile('./Chapter02/alip.txt') - self.assertNotRegex(respon, "kosong") + def test_07_hanifTujuh1184058(self): + from Chapter02.HanifTujuh1184058 import HanifTujuh1184058, HanifCopy + thread1 = HanifCopy("Thread Copy File ",1 , 'pokemon.txt') + thread2 = HanifTujuh1184058("Thread Utama ", 2, 5, 'pokemon.txt') + thread2.start() + thread1.start() + thread2.join() + thread1.join() + respon=self.readfile('./Chapter02/pokemon.txt') + self.assertNotRegex(respon, "Kosong") \ No newline at end of file From 8b08312e6c2ff82353cdff9783bdc463712806b0 Mon Sep 17 00:00:00 2001 From: Anisarosalina Date: Wed, 21 Apr 2021 18:34:40 +0700 Subject: [PATCH 130/164] update eror --- .gitignore | 8 +------- Chapter02/JosuansefEnam_1184091.py | 10 ---------- 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index 0fe663c..3963586 100644 --- a/.gitignore +++ b/.gitignore @@ -143,10 +143,4 @@ value value.pdf newravi.docx movie_2020_0 -<<<<<<< HEAD -movie_2020_1 -Miramas.txt -file.txt -======= -movie_2020_1 ->>>>>>> 648734b0ad2623db5ac8aa2105e3b9d38d2252c4 +movie_2020_1 \ No newline at end of file diff --git a/Chapter02/JosuansefEnam_1184091.py b/Chapter02/JosuansefEnam_1184091.py index bb838db..4dfe326 100644 --- a/Chapter02/JosuansefEnam_1184091.py +++ b/Chapter02/JosuansefEnam_1184091.py @@ -1,15 +1,5 @@ # -*- coding: utf-8 -*- """ -<<<<<<< HEAD -Created on Fri Apr 16 11:21:11 2021 - -@author: asus -""" - -# -*- coding: utf-8 -*- -""" -======= ->>>>>>> 648734b0ad2623db5ac8aa2105e3b9d38d2252c4 Created on Thu Apr 15 12:31:12 2021 @author: Josuansef Pardede (1184091) From 72e3cdd405373f91a06e23372411a511479fb824 Mon Sep 17 00:00:00 2001 From: ravirahmatulfajri Date: Wed, 21 Apr 2021 19:50:45 +0700 Subject: [PATCH 131/164] 1184040 Ravi --- .gitignore | 3 +- Chapter02/ravi.txt | 1 + Chapter02/raviTujuh1184040.py | 87 +++++++++++++++++++++++++++++++++++ test_app.py | 33 ++++++++----- 4 files changed, 112 insertions(+), 12 deletions(-) create mode 100644 Chapter02/ravi.txt create mode 100644 Chapter02/raviTujuh1184040.py diff --git a/.gitignore b/.gitignore index 3963586..1c2116e 100644 --- a/.gitignore +++ b/.gitignore @@ -143,4 +143,5 @@ value value.pdf newravi.docx movie_2020_0 -movie_2020_1 \ No newline at end of file +movie_2020_1 +ravi.txt \ No newline at end of file diff --git a/Chapter02/ravi.txt b/Chapter02/ravi.txt new file mode 100644 index 0000000..5e7c2db --- /dev/null +++ b/Chapter02/ravi.txt @@ -0,0 +1 @@ +[{'id': '1301', 'province_id': '13', 'name': 'KABUPATEN KEPULAUAN MENTAWAI'}, {'id': '1302', 'province_id': '13', 'name': 'KABUPATEN PESISIR SELATAN'}, {'id': '1303', 'province_id': '13', 'name': 'KABUPATEN SOLOK'}, {'id': '1304', 'province_id': '13', 'name': 'KABUPATEN SIJUNJUNG'}, {'id': '1305', 'province_id': '13', 'name': 'KABUPATEN TANAH DATAR'}, {'id': '1306', 'province_id': '13', 'name': 'KABUPATEN PADANG PARIAMAN'}, {'id': '1307', 'province_id': '13', 'name': 'KABUPATEN AGAM'}, {'id': '1308', 'province_id': '13', 'name': 'KABUPATEN LIMA PULUH KOTA'}, {'id': '1309', 'province_id': '13', 'name': 'KABUPATEN PASAMAN'}, {'id': '1310', 'province_id': '13', 'name': 'KABUPATEN SOLOK SELATAN'}, {'id': '1311', 'province_id': '13', 'name': 'KABUPATEN DHARMASRAYA'}, {'id': '1312', 'province_id': '13', 'name': 'KABUPATEN PASAMAN BARAT'}, {'id': '1371', 'province_id': '13', 'name': 'KOTA PADANG'}, {'id': '1372', 'province_id': '13', 'name': 'KOTA SOLOK'}, {'id': '1373', 'province_id': '13', 'name': 'KOTA SAWAH LUNTO'}, {'id': '1374', 'province_id': '13', 'name': 'KOTA PADANG PANJANG'}, {'id': '1375', 'province_id': '13', 'name': 'KOTA BUKITTINGGI'}, {'id': '1376', 'province_id': '13', 'name': 'KOTA PAYAKUMBUH'}, {'id': '1377', 'province_id': '13', 'name': 'KOTA PARIAMAN'}] \ No newline at end of file diff --git a/Chapter02/raviTujuh1184040.py b/Chapter02/raviTujuh1184040.py new file mode 100644 index 0000000..dce3fda --- /dev/null +++ b/Chapter02/raviTujuh1184040.py @@ -0,0 +1,87 @@ +from threading import Thread,currentThread, Lock, RLock, Event +import requests +import os +from queue import Queue + +queue = Queue() +event = Event() + +class raviMenulis (Thread): + def __init__(self,name,thread_number,namafile): + Thread.__init__(self) + self.threadLock = Lock() + self.name = name + self.thread_number = thread_number + self.namafile=os.path.join(os.path.dirname(__file__), namafile) + self.event = event + + def run(self): + print("\n"+str(self.thread_number)+". ---> " + self.name + "GO!!") + print('class raviMenulis mau menjalankan event wait, setelah itu clear untuk baca dan rename file') + self.event.wait() + self.threadLock.acquire() + print('Action read file : '+self.namafile) + self.readfile() + print('Action rename file : '+self.namafile) + self.unamofile() + self.event.wait() + self.threadLock.release() + print("\n"+str(self.thread_number)+". ---> " + currentThread().getName() + "Baca dan delete file done") + print ("menjalankan event clear") + self.event.clear() + + def readfile(self): + q=queue.get() + f = open(self.namafile, "r") + print("Isi Filenya: "+f.read()) + print("Done!!, jalanin queue task done \n") + queue.task_done() + + def unamofile(self): + print('Ganti Nama File \n') + os.rename(self.namafile,self.namafile+'.txt') + print("nama file diganti ya \n") + +class raviTujuh1184040 (Thread): + def __init__(self, name,thread_number,r,f ,namafile): + Thread.__init__(self) + self.threadLock = Lock() + self.event = event + self.rlock = RLock() + self.name = name + self.namafile=os.path.join(os.path.dirname(__file__), namafile) + self.thread_number = thread_number + self.r=r + self.f=f + + def run(self): + print("\n"+str(self.thread_number)+". ---> " + self.name + "GO!!") + self.threadLock.acquire() + print("threeadlock acquire utama") + self.hitung() + self.event.set() + print('class raviTujuh1184068 selesai untuk event set') + self.threadLock.release() + print("\n"+str(self.thread_number)+". ---> " + currentThread().getName() + "selesai") + + def Aapi(self): + with self.rlock: + print('didalam rlock apipangkat, akses web service...') + apiurl='http://www.emsifa.com/api-wilayah-indonesia/api/regencies/13.json' + response = requests.get(apiurl) + html=response.json() + queue.put(html) + self.createfile(html) + + def hitung(self): + with self.rlock: + print('rlock hitung') + self.Aapi() + + def createfile(self,isi): + print('Buat file baru : '+ self.namafile) + f = open(self.namafile, "x") + f.write(str(isi)) + f.close() + print('file baru sudah dibuat, mau menjalankan event set') + diff --git a/test_app.py b/test_app.py index 3c26deb..dc05715 100644 --- a/test_app.py +++ b/test_app.py @@ -117,14 +117,25 @@ def readfile(self,filename): # respon=self.readfile('./Chapter02/alip.txt') # self.assertNotRegex(respon, "kosong") - def test_07_hanifTujuh1184058(self): - from Chapter02.HanifTujuh1184058 import HanifTujuh1184058, HanifCopy - thread1 = HanifCopy("Thread Copy File ",1 , 'pokemon.txt') - thread2 = HanifTujuh1184058("Thread Utama ", 2, 5, 'pokemon.txt') - thread2.start() - thread1.start() - thread2.join() - thread1.join() - respon=self.readfile('./Chapter02/pokemon.txt') - self.assertNotRegex(respon, "Kosong") - \ No newline at end of file + # def test_07_hanifTujuh1184058(self): + # from Chapter02.HanifTujuh1184058 import HanifTujuh1184058, HanifCopy + # thread1 = HanifCopy("Thread Copy File ",1 , 'pokemon.txt') + # thread2 = HanifTujuh1184058("Thread Utama ", 2, 5, 'pokemon.txt') + # thread2.start() + # thread1.start() + # thread2.join() + # thread1.join() + # respon=self.readfile('./Chapter02/pokemon.txt') + # self.assertNotRegex(respon, "Kosong") + + + def test_07_raviTujuh1184040(self): + from Chapter02.raviTujuh1184040 import raviTujuh1184040,raviMenulis + threadutama = raviTujuh1184040("Thread Utama ", 2,5,5,'ravi') + threadravi2= raviMenulis("Thread raviMenulis File ", 1,'ravi') + threadravi2.start() + threadutama.start() + threadravi2.join() + threadutama.join() + respon=self.readfile('./Chapter02/ravi.txt') + self.assertNotRegex(respon, "kosong") \ No newline at end of file From 109482c8f0a400126dbcd5a4fa1a3562866e73e3 Mon Sep 17 00:00:00 2001 From: Okky Yudistira Date: Wed, 21 Apr 2021 21:05:50 +0700 Subject: [PATCH 132/164] Tugas 7 Okky Yudistira 1184087 --- Chapter02/OkkyEnam1184087.py | 62 ------------------------------------ 1 file changed, 62 deletions(-) delete mode 100644 Chapter02/OkkyEnam1184087.py diff --git a/Chapter02/OkkyEnam1184087.py b/Chapter02/OkkyEnam1184087.py deleted file mode 100644 index 8360f65..0000000 --- a/Chapter02/OkkyEnam1184087.py +++ /dev/null @@ -1,62 +0,0 @@ -# -*- coding: utf-8 -*- -""" -Created on Thu Apr 15 15:11:37 2021 - -@author: Okky Yudistira -""" -from threading import Barrier, Thread -import os -import requests -from time import ctime, sleep - -number = 1 -br = Barrier(number) -fl1 = "Random user" -fln1 = os.path.join(os.path.dirname(__file__), fl1) - - -def api(): - apiurl='https://randomuser.me/api' - response = requests.get(apiurl) - html= response.json() - manajemen(html) - -def manajemen(isi): - print('buat file terlebih dahulu : '+fl1+'.txt \n') - f = open(fln1+".txt", "w") - print('File telah berhasil dibuat bruh\n') - f.write(str(isi)) - f.close() - print('Isi file tersebut adalah: '+fl1+'.txt') - x = open(fln1+".txt", "r") - print(x.read()+'\n') - x.close() - print('coba Hapus file \n') - print('Menghapus File: '+fl1+'.txt \n') - os.remove(fln1+'.txt') - sleep(1) - br.wait() - print('File:'+fl1+'.txt'+' ini telah berhasil di Hapus \n') - sleep(1) - br.wait() - print('Create, Read, and delete file: '+fl1+' mencapai barrier pada waktu: %s \n' % (ctime())) - -def run(): - api() - sleep(1) - br.wait() - print('All reached the barrier at: %s \n' % (ctime())) - -def main(): - threads = [] - print('Mulai Mas!') - for i in range(number): - threads.append(Thread(target=run)) - threads[-1].start() - for thread in threads: - thread.join() - print('Berakhir') - return True - -#if __name__ == "__main__": -# main() \ No newline at end of file From 2e5a5f7e258878468396c75bb02f3646963e43f0 Mon Sep 17 00:00:00 2001 From: josua1111 Date: Wed, 21 Apr 2021 22:10:10 +0700 Subject: [PATCH 133/164] Tugas 7 Josuansef Pardede 1184091 DS --- Chapter02/JosuansefTujuh_1184091.py | 104 ++++++++++++++++++++++++++++ test_app.py | 29 +++++--- 2 files changed, 124 insertions(+), 9 deletions(-) create mode 100644 Chapter02/JosuansefTujuh_1184091.py diff --git a/Chapter02/JosuansefTujuh_1184091.py b/Chapter02/JosuansefTujuh_1184091.py new file mode 100644 index 0000000..25596ff --- /dev/null +++ b/Chapter02/JosuansefTujuh_1184091.py @@ -0,0 +1,104 @@ +""" +Created on Tue Apr 20 16:06:43 2021 + +@author: Josuansef Pardede (1184091) +""" +from threading import Thread, currentThread, Lock, RLock, Event +from queue import Queue +import time +import os +import requests + +queue = Queue() +event = Event() + +class Josuansef1184091Tujuh_Producer(Thread): + + def __init__(self, name,thread_number, alpha, beta, filenya): + Thread.__init__(self) + self.threadLock = Lock() + self.event = event + self.rlock = RLock() + self.name = name + self.alpha=alpha + self.beta=beta + self.filenya=os.path.join(os.path.dirname(__file__), filenya) + self.thread_number = thread_number + + def run(self): + + print("\n"+str(self.thread_number)+". ---> " + self.name + "jalan") + self.threadLock.acquire() + print("threeadlock acquire utama") + self.hitung() + self.event.set() + print('class Josuansef1184091Tujuh_Producer sudah selesai melakukan event set') + self.threadLock.release() + print("\n"+str(self.thread_number)+". ---> " + currentThread().getName() + "done") + + def ApiJosuansef(self): + url = "https://movie-database-imdb-alternative.p.rapidapi.com/" + querystring = {"s":"Avengers Endgame","page":"1","r":"json"} + + headers = { + 'x-rapidapi-key': "03ea4d51b5mshde64ddab3687a71p1fb88fjsn3c194b2ea8bc", + 'x-rapidapi-host': "movie-database-imdb-alternative.p.rapidapi.com" + } + + response = requests.request("GET", url, headers=headers, params=querystring) + html=response.json() + queue.put(html) + self.createfile(html) + + def hitung(self): + with self.rlock: + print('rlock hitung') + self.ApiJosuansef() + + def createfile(self, konten): + print('membuat file baru : '+ self.filenya) + f = open(self.filenya, "x") + f.write(str(konten)) + f.close() + print('File sudah dibuat, selanjutnya, mau eksekusi event set') + + +class Josuansef1184091Tujuh_Consumer(Thread): + + def __init__(self,name,thread_number,filenya): + Thread.__init__(self) + self.threadLock = Lock() + self.name = name + self.thread_number = thread_number + self.filenya=os.path.join(os.path.dirname(__file__), filenya) + self.event = event + + def run(self): + while True: + item = self.queue.get() + print('Consumer notify : %d popped from queue by %s'\ + % (item, self.name)) + self.queue.task_done() + + print("\n"+str(self.thread_number)+". ---> " + self.name + "jalan") + print('class Josuansef1184091Tujuh_Consumer eksekusi event.wait lalu clear. Jalankan fungsi Read File') + self.event.wait() + self.threadLock.acquire() + print('read file : '+self.filenya) + self.readfile() + print('append file : '+self.filenya) + self.appendfile() + self.event.wait() + self.threadLock.release() + print("\n"+str(self.thread_number)+". ---> " + currentThread().getName() + "Read dan Append file Done") + print ("eksekusi event clear") + self.event.clear() + + def readfile(self): + q=queue.get() + f = open(self.filenya, "r+") + print("Isi Filenya apaan yaa : "+f.read()) + print("Sudah selesai baca isi file nya nih, jalanin queue task done \n") + queue.task_done() + + diff --git a/test_app.py b/test_app.py index dc05715..8d78ca2 100644 --- a/test_app.py +++ b/test_app.py @@ -129,13 +129,24 @@ def readfile(self,filename): # self.assertNotRegex(respon, "Kosong") - def test_07_raviTujuh1184040(self): - from Chapter02.raviTujuh1184040 import raviTujuh1184040,raviMenulis - threadutama = raviTujuh1184040("Thread Utama ", 2,5,5,'ravi') - threadravi2= raviMenulis("Thread raviMenulis File ", 1,'ravi') - threadravi2.start() - threadutama.start() - threadravi2.join() - threadutama.join() - respon=self.readfile('./Chapter02/ravi.txt') + #def test_07_raviTujuh1184040(self): + # from Chapter02.raviTujuh1184040 import raviTujuh1184040,raviMenulis + # threadutama = raviTujuh1184040("Thread Utama ", 2,5,5,'ravi') + # threadravi2= raviMenulis("Thread raviMenulis File ", 1,'ravi') + #threadravi2.start() + #threadutama.start() + #threadravi2.join() + #threadutama.join() + #respon=self.readfile('./Chapter02/ravi.txt') + #elf.assertNotRegex(respon, "kosong") + + def test_07_josuanseftujuh1184091(self): + from Chapter02.JosuansefTujuh_1184091 import Josuansef1184091Tujuh_Producer,Josuansef1184091Tujuh_Consumer + threadjosuaproducer = Josuansef1184091Tujuh_Producer("Thread Utama ", 2,5,5,'josuansef') + threadjosuaconsumer= Josuansef1184091Tujuh_Consumer("Thread read File ", 1,'josuansef') + threadjosuaconsumer.start() + threadjosuaproducer.start() + threadjosuaconsumer.join() + threadjosuaproducer.join() + respon=self.readfile('./Chapter02/josuansef.txt') self.assertNotRegex(respon, "kosong") \ No newline at end of file From f39716ff91b70a2b2129e46e8dd9398d1ccb0943 Mon Sep 17 00:00:00 2001 From: IraDwita Date: Wed, 21 Apr 2021 23:01:38 +0700 Subject: [PATCH 134/164] Tugas7Iraaaa --- Chapter02/IraTujuh1184024.py | 91 ++++++++++++++++++++++++++++++++++++ Chapter02/ira | 1 + Chapter02/ira.txt | 1 + test_app.py | 26 ++++++++--- 4 files changed, 112 insertions(+), 7 deletions(-) create mode 100644 Chapter02/IraTujuh1184024.py create mode 100644 Chapter02/ira create mode 100644 Chapter02/ira.txt diff --git a/Chapter02/IraTujuh1184024.py b/Chapter02/IraTujuh1184024.py new file mode 100644 index 0000000..55fe74a --- /dev/null +++ b/Chapter02/IraTujuh1184024.py @@ -0,0 +1,91 @@ +from threading import Thread,currentThread, Lock, RLock, Event +import requests +import os +from queue import Queue + +queue = Queue() +event = Event() + +class iraRemoveFile (Thread): + def __init__(self,name,thread_number,namafile): + Thread.__init__(self) + self.threadLock = Lock() + self.name = name + self.thread_number = thread_number + self.namafile=os.path.join(os.path.dirname(__file__), namafile) + self.event = event + + def run(self): + print("\n"+str(self.thread_number)+". ---> " + self.name + "jalan") + print('class iraRemoveFile ingin menjalankan event') + self.event.wait() + self.threadLock.acquire() + print('membaca file : '+self.namafile) + self.readfile() + print('rename file : '+self.namafile) + self.renamefile() + self.event.wait() + self.threadLock.release() + print("\n"+str(self.thread_number)+". ---> " + currentThread().getName() + "membaca file dan menghapus file telah selesai") + print ("menjalankan event selesai") + self.event.clear() + + def readfile(self): + q=queue.get() + f = open(self.namafile, "r") + print("isi file : "+f.read()) + print("Selesai membaca file, jalanin queue task done \n") + queue.task_done() + + def renamefile(self): + print('mengganti nama file \n') + os.rename(self.namafile,self.namafile+'.txt') + print("nama file sudah diganti \n") + + def removefile(self): + print('menghapus atau meremove file \n') + os.remove(self.namafile+'.txt') + print("file sudah diremove \n") + +class iraTujuh1184024 (Thread): + def __init__(self, name,thread_number,a,b ,namafile): + Thread.__init__(self) + self.threadLock = Lock() + self.event = event + self.rlock = RLock() + self.name = name + self.namafile=os.path.join(os.path.dirname(__file__), namafile) + self.thread_number = thread_number + self.a=a + self.b=b + + def run(self): + print("\n"+str(self.thread_number)+". ---> " + self.name + "jalan") + self.threadLock.acquire() + print("threeadlock acquire utama") + self.hitung() + self.event.set() + print('class iraTujuh1184024 sudah selesai melakukan event set') + self.threadLock.release() + print("\n"+str(self.thread_number)+". ---> " + currentThread().getName() + "selesai") + + def getapi(self): + with self.rlock: + print('akses web service...') + apiurl='https://api.thecatapi.com/v1/images/search' + response = requests.get(apiurl) + html=response.json() + queue.put(html) + self.createfile(html) + + def hitung(self): + with self.rlock: + self.getapi() + + def createfile(self,isi): + print('membuat file baru : '+ self.namafile) + f = open(self.namafile, "x") + f.write(str(isi)) + f.close() + print('sudah membuat file baru, mau menjalankan event set') + diff --git a/Chapter02/ira b/Chapter02/ira new file mode 100644 index 0000000..aa91386 --- /dev/null +++ b/Chapter02/ira @@ -0,0 +1 @@ +[{'breeds': [], 'id': '3sm', 'url': 'https://cdn2.thecatapi.com/images/3sm.jpg', 'width': 480, 'height': 320}] \ No newline at end of file diff --git a/Chapter02/ira.txt b/Chapter02/ira.txt new file mode 100644 index 0000000..f1936a1 --- /dev/null +++ b/Chapter02/ira.txt @@ -0,0 +1 @@ +[{'breeds': [], 'categories': [{'id': 1, 'name': 'hats'}], 'id': '37a', 'url': 'https://cdn2.thecatapi.com/images/37a.gif', 'width': 500, 'height': 375}] \ No newline at end of file diff --git a/test_app.py b/test_app.py index dc05715..fecb774 100644 --- a/test_app.py +++ b/test_app.py @@ -129,13 +129,25 @@ def readfile(self,filename): # self.assertNotRegex(respon, "Kosong") - def test_07_raviTujuh1184040(self): - from Chapter02.raviTujuh1184040 import raviTujuh1184040,raviMenulis - threadutama = raviTujuh1184040("Thread Utama ", 2,5,5,'ravi') - threadravi2= raviMenulis("Thread raviMenulis File ", 1,'ravi') - threadravi2.start() + # def test_07_raviTujuh1184040(self): + # from Chapter02.raviTujuh1184040 import raviTujuh1184040,raviMenulis + # threadutama = raviTujuh1184040("Thread Utama ", 2,5,5,'ravi') + # threadravi2= raviMenulis("Thread raviMenulis File ", 1,'ravi') + # threadravi2.start() + # threadutama.start() + # threadravi2.join() + # threadutama.join() + # respon=self.readfile('./Chapter02/ravi.txt') + # self.assertNotRegex(respon, "kosong") + + + def test_07_IraTujuh1184024(self): + from Chapter02.IraTujuh1184024 import iraRemoveFile,iraTujuh1184024 + threadutama = iraTujuh1184024("Thread Utama ", 2,5,5,'ira') + threadremove= iraRemoveFile("Thread Remove File ", 1,'ira') + threadremove.start() threadutama.start() - threadravi2.join() + threadremove.join() threadutama.join() - respon=self.readfile('./Chapter02/ravi.txt') + respon=self.readfile('./Chapter02/ira.txt') self.assertNotRegex(respon, "kosong") \ No newline at end of file From 9bf1523ca4b6bc707eec752f07ed9cfd310117b6 Mon Sep 17 00:00:00 2001 From: idafatriniputri Date: Wed, 21 Apr 2021 23:24:52 +0700 Subject: [PATCH 135/164] Tugas Tujuh Ida 1184113 --- Chapter02/IdaTujuh1184113.py | 93 ++++++++++++++++++++++++++++++++++++ Chapter02/ida.txt | 6 +++ test_app.py | 30 ++++++++---- 3 files changed, 119 insertions(+), 10 deletions(-) create mode 100644 Chapter02/IdaTujuh1184113.py create mode 100644 Chapter02/ida.txt diff --git a/Chapter02/IdaTujuh1184113.py b/Chapter02/IdaTujuh1184113.py new file mode 100644 index 0000000..5dbd4c4 --- /dev/null +++ b/Chapter02/IdaTujuh1184113.py @@ -0,0 +1,93 @@ +from threading import Thread,currentThread, Lock, RLock, Event +import requests +import os +from queue import Queue + +queue = Queue() +event = Event() + +class Director (Thread): + def __init__(self,name,thread_number,idafile): + Thread.__init__(self) + self.threadLock = Lock() + self.name = name + self.thread_number = thread_number + self.idafile=os.path.join(os.path.dirname(__file__), idafile) + self.event = event + + def run(self): + print("\n"+str(self.thread_number)+". ---> " + self.name + "jalan") + print('class Director mau menjalankan event wait dilanjutkan clear untuk baca dan rename file') + self.event.wait() + self.threadLock.acquire() + print('read file kamu: '+self.idafile) + self.readfile() + print('rename file kamu: '+self.idafile) + self.renamefile() + self.event.wait() + self.threadLock.release() + print("\n"+str(self.thread_number)+". ---> " + currentThread().getName() + "Baca file dan delete file selesai") + print ("menjalankan event clear") + self.event.clear() + + def readfile(self): + ida=queue.get() + f = open(self.idafile, "r") + print("Isi Filenya apa hayo : "+f.read()) + print("Sudah selesai baca isi file nya yaw, jalanin queue task done \n") + queue.task_done() + + def renamefile(self): + print('coba ganti nama filenya dulu dong \n') + os.rename(self.idafile,self.idafile+'.txt') + print("nama file udah diganti yaww \n") + +class idaTujuh1184113 (Thread): + def __init__(self, name,thread_number,a,b ,idafile): + Thread.__init__(self) + self.threadLock = Lock() + self.event = event + self.rlock = RLock() + self.name = name + self.idafile=os.path.join(os.path.dirname(__file__), idafile) + self.thread_number = thread_number + self.a=a + self.b=b + + def run(self): + print("\n"+str(self.thread_number)+". ---> " + self.name + "jalan") + self.threadLock.acquire() + print("threeadlock acquire utama") + self.hitung() + self.event.set() + print('class idaTujuh1184113 sudah selesai melakukan event set') + self.threadLock.release() + print("\n"+str(self.thread_number)+". ---> " + currentThread().getName() + "selesai") + + def getapi(self): + with self.rlock: + print('akses web service...') + apiurl = "https://api.jikan.moe/v3/search/anime?q=One%20Piece" + response = requests.get(apiurl) + html=response.json() + string = "Anime: " + for i in range(len(html)): + hasil = html["results"][i]["title"] + data = str(hasil) + ent = "\n"+str(i)+". " + string = string+ent+data + queue.put(string) + self.createfile(string) + + def hitung(self): + with self.rlock: + print('rlock hitung') + self.getapi() + + def createfile(self,isi): + print('file baru kamu: '+ self.idafile) + f = open(self.idafile, "x") + f.write(str(isi)) + f.close() + print('sudah membuat file baru, mau menjalankan event set') + diff --git a/Chapter02/ida.txt b/Chapter02/ida.txt new file mode 100644 index 0000000..9a4b06b --- /dev/null +++ b/Chapter02/ida.txt @@ -0,0 +1,6 @@ +Anime: +0. One Piece +1. One Piece Movie 1 +2. One Piece Film: Gold +3. One Piece Film: Z +4. One Piece 3D: Mugiwara Chase \ No newline at end of file diff --git a/test_app.py b/test_app.py index 8c40d19..4c8c3d1 100644 --- a/test_app.py +++ b/test_app.py @@ -337,14 +337,24 @@ def readfile(self,nfile): # respon=self.readfile('./Chapter02/ravi.txt') # self.assertNotRegex(respon, "kosong") - def test_07_OkkyTujuh1184087(self): - from Chapter02.OkkyTujuh1184087 import Person,okky - t1 = Person("Thread Utama ", 1,'okky.txt') - t2 = okky("Thread kedua File ", 2,5,'okky.txt') - t2.start() - t1.start() - t2.join() - t1.join() - respon=self.readfile('./Chapter02/okky.txt') - self.assertNotRegex(respon, "kosong") + # def test_07_OkkyTujuh1184087(self): + # from Chapter02.OkkyTujuh1184087 import Person,okky + # t1 = Person("Thread Utama ", 1,'okky.txt') + # t2 = okky("Thread kedua File ", 2,5,'okky.txt') + # t2.start() + # t1.start() + # t2.join() + # t1.join() + # respon=self.readfile('./Chapter02/okky.txt') + # self.assertNotRegex(respon, "kosong") + def test_07_idaTujuh1184113(self): + from Chapter02.IdaTujuh1184113 import idaTujuh1184113,Director + threadutama = idaTujuh1184113("Thread Utama ", 2,5,5,'ida') + threaddirector= Director("Thread Director ", 1,'ida') + threaddirector.start() + threadutama.start() + threaddirector.join() + threadutama.join() + respon=self.readfile('./Chapter02/ida.txt') + self.assertNotRegex(respon, "kosong") \ No newline at end of file From ef4b042c2460505aa28b84f65e606df12af60d3a Mon Sep 17 00:00:00 2001 From: ariyo21 Date: Thu, 22 Apr 2021 00:21:52 +0700 Subject: [PATCH 136/164] TugasAriyoTujuh1184056 --- Chapter02/AriyoTujuh1184056.py | 71 ++++++++++++++++++++++++++++++++++ test_app.py | 16 ++++++-- 2 files changed, 83 insertions(+), 4 deletions(-) create mode 100644 Chapter02/AriyoTujuh1184056.py diff --git a/Chapter02/AriyoTujuh1184056.py b/Chapter02/AriyoTujuh1184056.py new file mode 100644 index 0000000..0252721 --- /dev/null +++ b/Chapter02/AriyoTujuh1184056.py @@ -0,0 +1,71 @@ +from threading import Thread +from queue import Queue +import os +import requests + +queue = Queue() +ayo = [] +apiurl ='https://www.thecocktaildb.com/api/json/v1/1/list.php?a=list' +response = requests.get(apiurl) +html=response.json() + +class ayomaju(Thread): + def __init__(self, namathread, filename): + Thread.__init__(self) + self.filename = os.path.join(os.path.dirname(__file__), filename) + self.namathread = namathread + + def mainapi(self): + string = "minuman:" + for i in range(len(html["drinks"])): + sini = html["drinks"][i]["strAlcoholic"] + nomor = "\n"+str(i)+". " + string = string + nomor + sini + ayo.append(sini) + queue.put(ayo) + print(str(i)+". %s yg di append" % (sini)) + self.createfile(string) + self.mundur() + + def run(self): + print("Kita mulai queunya") + self.mainapi() + print("queue selesai") + + def createfile(self, isi): + f = open(self.filename, "w") + f.write(str(isi)) + f.close() + + def read(self): + x = open(self.filename, "r") + print(x.read()) + x.close() + + def mundur(self): + ayomundur = queue.get() + dur = len(ayomundur) + while dur > 0: + print("hasil pop") + dur = dur -1 + self.read() + queue.task_done() + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test_app.py b/test_app.py index 07c8ac1..4128d4a 100644 --- a/test_app.py +++ b/test_app.py @@ -360,10 +360,18 @@ def readfile(self,nfile): # respon=self.readfile('./Chapter02/ravi.txt') # self.assertNotRegex(respon, "kosong") - def test_07_AnisaTujuh1184016(self): - from Chapter02.AnisaRosalinaTujuh1184016 import Anisa - thread1 = Anisa("Thread Put", 1, "Cocktile") + # def test_07_AnisaTujuh1184016(self): + # from Chapter02.AnisaRosalinaTujuh1184016 import Anisa + # thread1 = Anisa("Thread Put", 1, "Cocktile") + # thread1.start() + # thread1.join() + # respon=self.readfile('./Chapter02/Cocktile.txt') + # self.assertNotRegex(respon, "Kosong") + + def test_07_AriyoTujuh1184056(self): + from Chapter02.AriyoTujuh1184056 import ayomaju + thread1 = ayomaju("Thread Put", "AriyoTujuh") thread1.start() thread1.join() - respon=self.readfile('./Chapter02/Cocktile.txt') + respon=self.readfile('./Chapter02/AriyoTujuh') self.assertNotRegex(respon, "Kosong") From 051a92e53184098bbc63985ea4d1a276a39ac40b Mon Sep 17 00:00:00 2001 From: IraDwita Date: Thu, 22 Apr 2021 00:34:50 +0700 Subject: [PATCH 137/164] Tugaske7Ira --- test_app.py | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/test_app.py b/test_app.py index 3d6e104..c29ba7f 100644 --- a/test_app.py +++ b/test_app.py @@ -337,7 +337,6 @@ def readfile(self,nfile): # respon=self.readfile('./Chapter02/ravi.txt') # self.assertNotRegex(respon, "kosong") -#<<<<<<< HEAD # def test_07_OkkyTujuh1184087(self): # from Chapter02.OkkyTujuh1184087 import Person,okky # t1 = Person("Thread Utama ", 1,'okky.txt') @@ -359,31 +358,6 @@ def readfile(self,nfile): # threadutama.join() # respon=self.readfile('./Chapter02/ravi.txt') # self.assertNotRegex(respon, "kosong") - -# ======= -# def test_07_OkkyTujuh1184087(self): -# from Chapter02.OkkyTujuh1184087 import Person,okky -# t1 = Person("Thread Utama ", 1,'okky.txt') -# t2 = okky("Thread kedua File ", 2,5,'okky.txt') -# t2.start() -# t1.start() -# t2.join() -# t1.join() -# respon=self.readfile('./Chapter02/okky.txt') -# self.assertNotRegex(respon, "kosong") - -# >>>>>>> 84d9529186324afd0455a455998e7a21370cbe71 - -# # def test_07_raviTujuh1184040(self): -# # from Chapter02.raviTujuh1184040 import raviTujuh1184040,raviMenulis -# # threadutama = raviTujuh1184040("Thread Utama ", 2,5,5,'ravi') -# # threadravi2= raviMenulis("Thread raviMenulis File ", 1,'ravi') -# # threadravi2.start() -# # threadutama.start() -# # threadravi2.join() -# # threadutama.join() -# # respon=self.readfile('./Chapter02/ravi.txt') -# # self.assertNotRegex(respon, "kosong") # def test_07_AnisaTujuh1184016(self): # from Chapter02.AnisaRosalinaTujuh1184016 import Anisa From 944b3a4a14568439b88dd5ce6c8e1a1227e562d6 Mon Sep 17 00:00:00 2001 From: baharandili Date: Thu, 22 Apr 2021 08:19:40 +0700 Subject: [PATCH 138/164] tugas7bahar --- Chapter02/bahartujuh1184002.py | 89 ++++++++++++++++++++++++++++++++++ test_app.py | 25 +++++++--- 2 files changed, 107 insertions(+), 7 deletions(-) create mode 100644 Chapter02/bahartujuh1184002.py diff --git a/Chapter02/bahartujuh1184002.py b/Chapter02/bahartujuh1184002.py new file mode 100644 index 0000000..f0a3c3c --- /dev/null +++ b/Chapter02/bahartujuh1184002.py @@ -0,0 +1,89 @@ +import threading +import requests +import os +from queue import Queue + +queue = Queue() +event = threading.Event() + +class BaharQue(threading.Thread): + def __init__(self,name, filename): + threading.Thread.__init__(self) + self.name = name + self.threadLock = threading.Lock() + self.filename = os.path.join(os.path.dirname(__file__), filename) + + def run(self): + print("\n"+ self.name + "mulai.") + self.threadLock.acquire() + print('kodepos') + event.wait() + print('ubah : '+self.filename) + self.baca() + print("kode sudah diubah") + self.buat() + event.clear() + self.threadLock.release() + print("\n" + threading.currentThread().getName() + "berhasil") + + def baca(self): + f = open(self.filename, "r") + print("isi file : \n "+f.read()) + + def buat(self): + f = open(self.filename, "r") + bikin = open(self.filename+'.txt', "w") + for line in f: + bikin.write(line.replace('kodepos', 'kelurahan')) + bikin.close() + new = open(self.filename+'.txt', "r") + print(new.read()) + new.close() + + +class Bahartujuh1184002 (threading.Thread): + def __init__(self, name, filename): + threading.Thread.__init__(self) + self.threadLock = threading.Lock() + self.name = name + self.rlock = threading.RLock() + self.filename=os.path.join(os.path.dirname(__file__), filename) + + + def run(self): + print("\n"+ self.name + " mulai.") + self.main() + cb = queue.get() + print("\n queuenya") + print(cb) + queue.task_done() + event.set() + print("\n" + threading.currentThread().getName() + "selesai.") + + def webapi(self): + with self.rlock: + print('Webservice nya') + apiurl='https://nbc.vanmason.web.id/service/kodepos/42173' + response = requests.get(apiurl) + html=response.json() + string = "" + for i in range(len(html["kodepos"])): + baru = html["kodepos"][i]["kelurahan"] + new = "\n"+str(i)+". " + string = string+new+str(baru) + queue.put(string) + self.createfile(string) + + + def main(self): + with self.rlock: + self.webapi() + + def createfile(self,isi): + print('Create File : '+ self.filename) + f = open(self.filename, "w") + f.write(str(isi)) + f.close() + + + diff --git a/test_app.py b/test_app.py index 07c8ac1..f2e936b 100644 --- a/test_app.py +++ b/test_app.py @@ -360,10 +360,21 @@ def readfile(self,nfile): # respon=self.readfile('./Chapter02/ravi.txt') # self.assertNotRegex(respon, "kosong") - def test_07_AnisaTujuh1184016(self): - from Chapter02.AnisaRosalinaTujuh1184016 import Anisa - thread1 = Anisa("Thread Put", 1, "Cocktile") - thread1.start() - thread1.join() - respon=self.readfile('./Chapter02/Cocktile.txt') - self.assertNotRegex(respon, "Kosong") + # def test_07_AnisaTujuh1184016(self): + # from Chapter02.AnisaRosalinaTujuh1184016 import Anisa + # thread1 = Anisa("Thread Put", 1, "Cocktile") + # thread1.start() + # thread1.join() + # respon=self.readfile('./Chapter02/Cocktile.txt') + # self.assertNotRegex(respon, "Kosong") + + def test_07_bahartujuh1184002(self): + from Chapter02.bahartujuh1184002 import BaharQue,Bahartujuh1184002 + ti= BaharQue("Thread 1 ",'kodepos') + tl = Bahartujuh1184002("Thread 2",'kodepos') + ti.start() + tl.start() + ti.join() + tl.join() + respon=self.readfile('./Chapter02/kodepos') + self.assertNotRegex(respon, "Gak Boleh Kosong") \ No newline at end of file From 3386e9a1836db2c78101e8fe6328889b2d91c309 Mon Sep 17 00:00:00 2001 From: parhanhambali Date: Thu, 22 Apr 2021 09:22:48 +0700 Subject: [PATCH 139/164] Tugas 7 Parhan Hambali 1184042 --- Chapter02/ParhanTujuh1184042.py | 87 +++++++++++++++++++++++++++++++++ test_app.py | 31 ++++++++---- 2 files changed, 108 insertions(+), 10 deletions(-) create mode 100644 Chapter02/ParhanTujuh1184042.py diff --git a/Chapter02/ParhanTujuh1184042.py b/Chapter02/ParhanTujuh1184042.py new file mode 100644 index 0000000..aa19666 --- /dev/null +++ b/Chapter02/ParhanTujuh1184042.py @@ -0,0 +1,87 @@ +from threading import Thread,currentThread, Lock, RLock, Event +import requests +import os +from queue import Queue + +queue = Queue() +event = Event() + +class parhanmanajemenFile (Thread): + def __init__(self,name,thread_number,namafile): + Thread.__init__(self) + self.threadLock = Lock() + self.name = name + self.thread_number = thread_number + self.namafile=os.path.join(os.path.dirname(__file__), namafile) + self.event = event + + def run(self): + print("\n"+str(self.thread_number)+". ---> " + self.name + "jalan") + print('pada class parhanmanajemenFile jalankan event wait lalu clear untuk read dan rename file') + self.event.wait() + self.threadLock.acquire() + print('membaca file : '+self.namafile) + self.readfile() + print('merename file : '+self.namafile) + self.event.wait() + self.renamefile() + self.threadLock.release() + print("\n"+str(self.thread_number)+". ---> " + currentThread().getName() + "Baca file dan delete file selesai") + print ("jalankan event clear") + self.event.clear() + + def readfile(self): + q=queue.get() + f = open(self.namafile, "r") + print("isi file yang di read : "+f.read()) + print("setelah baca file, jalankan queue task done \n") + queue.task_done() + + def renamefile(self): + print('ganti nama file \n') + os.rename(self.namafile,self.namafile+'.txt') + print("nama file telah diganti \n") + +class parhanTujuh1184042 (Thread): + def __init__(self, name,thread_number,a,b ,namafile): + Thread.__init__(self) + self.threadLock = Lock() + self.event = event + self.rlock = RLock() + self.name = name + self.namafile=os.path.join(os.path.dirname(__file__), namafile) + self.thread_number = thread_number + self.a=a + self.b=b + + def run(self): + print("\n"+str(self.thread_number)+". ---> " + self.name + "jalan") + self.threadLock.acquire() + print("threeadlock acquire utama") + self.jumlah() + self.event.set() + print('class parhanTujuh1184042 selesai melakukan event set') + self.threadLock.release() + print("\n"+str(self.thread_number)+". ---> " + currentThread().getName() + "selesai") + + def apiservice(self): + with self.rlock: + print('didalam rlock apiservice, akses web service...') + apiurl='https://gempa-api-zhirrr.vercel.app/api/gempa' + response = requests.get(apiurl) + z=response.json() + queue.put(z) + self.createfile(z) + + def jumlah(self): + with self.rlock: + print('rlock jumlah') + self.apiservice() + + def createfile(self,isi): + print('buat file baru : '+ self.namafile) + f = open(self.namafile, "x") + f.write(str(isi)) + f.close() + print('sudah buat file baru, jalankan event set') + diff --git a/test_app.py b/test_app.py index b2f77d4..574b6c9 100644 --- a/test_app.py +++ b/test_app.py @@ -378,13 +378,24 @@ def readfile(self,nfile): # respon=self.readfile('./Chapter02/AriyoTujuh') # self.assertNotRegex(respon, "Kosong") - def test_07_bahartujuh1184002(self): - from Chapter02.bahartujuh1184002 import BaharQue,Bahartujuh1184002 - ti= BaharQue("Thread 1 ",'kodepos') - tl = Bahartujuh1184002("Thread 2",'kodepos') - ti.start() - tl.start() - ti.join() - tl.join() - respon=self.readfile('./Chapter02/kodepos') - self.assertNotRegex(respon, "Gak Boleh Kosong") \ No newline at end of file + # def test_07_bahartujuh1184002(self): + # from Chapter02.bahartujuh1184002 import BaharQue,Bahartujuh1184002 + # ti= BaharQue("Thread 1 ",'kodepos') + # tl = Bahartujuh1184002("Thread 2",'kodepos') + # ti.start() + # tl.start() + # ti.join() + # tl.join() + # respon=self.readfile('./Chapter02/kodepos') + # self.assertNotRegex(respon, "Gak Boleh Kosong") + + def test_07_parhanTujuh1184042(self): + from Chapter02.ParhanTujuh1184042 import parhanTujuh1184042,parhanmanajemenFile + threadutama = parhanTujuh1184042("Thread Utama ", 2,5,5,'apigempa') + threadmanajemen= parhanmanajemenFile("Thread manajemen File ", 1,'apigempa') + threadmanajemen.start() + threadutama.start() + threadmanajemen.join() + threadutama.join() + respon=self.readfile('./Chapter02/apigempa.txt') + self.assertNotRegex(respon, "kosong") \ No newline at end of file From 282f76fea390e99dac817cc84bc9da53c64c3dde Mon Sep 17 00:00:00 2001 From: idafatriniputri Date: Thu, 22 Apr 2021 11:01:55 +0700 Subject: [PATCH 140/164] Update Tugas Tujuh Ida 1184113 --- .gitignore | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index b3a980d..adb0256 100644 --- a/.gitignore +++ b/.gitignore @@ -144,8 +144,6 @@ value.pdf newravi.docx movie_2020_0 movie_2020_1 -<<<<<<< HEAD + luffy.txt -======= -ravi.txt ->>>>>>> 9a78c5a855f07c2d601c0c5f1c13f24ee43fc343 +ravi.txt \ No newline at end of file From 19e4e5f0636bc2e0a4aefe734d99959b0e5ee33c Mon Sep 17 00:00:00 2001 From: josua1111 Date: Thu, 22 Apr 2021 11:50:45 +0700 Subject: [PATCH 141/164] update josuansef pardede 1184091 tugas 7 --- Chapter02/JosuansefTujuh_1184091.py | 16 ++++++++-------- Chapter02/josuanseff | 1 - 2 files changed, 8 insertions(+), 9 deletions(-) delete mode 100644 Chapter02/josuanseff diff --git a/Chapter02/JosuansefTujuh_1184091.py b/Chapter02/JosuansefTujuh_1184091.py index 71454bb..d3b2a33 100644 --- a/Chapter02/JosuansefTujuh_1184091.py +++ b/Chapter02/JosuansefTujuh_1184091.py @@ -60,30 +60,30 @@ def run(self): print("\n"+str(self.thread_number)+". ---> " + self.name + "jalan") self.threadLock.acquire() print("threeadlock acquire utama") - self.hitung() + self.count() self.event.set() print('class Josuansef1184091Tujuh_Producer sudah selesai melakukan event set') self.threadLock.release() print("\n"+str(self.thread_number)+". ---> " + currentThread().getName() + "done") - - def apijj(self): + + def apijosua(self): with self.rlock: - print('didalam rlock apiservice, akses web service...') + print('akses webservices api seperti berikut') url='https://api-lk21.herokuapp.com/comingsoon' response = requests.get(url) html=response.json() queue.put(html) self.createfile(html) - def hitung(self): + def count(self): with self.rlock: - print('rlock hitung') - self.apijj() + print('rlock count') + self.apijosua() def createfile(self, konten): print('membuat file baru : '+ self.filenya) f = open(self.filenya, "x") f.write(str(konten)) f.close() - print('File sudah dibuat, selanjutnya, mau eksekusi event set') + print('File telah di create, lalu eksekusi event set') diff --git a/Chapter02/josuanseff b/Chapter02/josuanseff deleted file mode 100644 index b2de42d..0000000 --- a/Chapter02/josuanseff +++ /dev/null @@ -1 +0,0 @@ -{'result': [{'title': ' Tom Clancy’s Without Remorse (2021)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2021/03/s9VFcru4oAurVVK49jmpB35vVhZ-170x255.jpg', 'genre': ['Action', ' Coming Soon', ' Thriller'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=e-rw2cxFVLg', 'watch': 'https://lk21online.online/nonton-tom-clancys-without-remorse-2021-subtitle-indonesia/'}, {'title': ' Avatar 2 (2021)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/04/krOMOEjDpw3Mf2EuJb9OgmqD6ft-170x255.jpg', 'genre': ['Action', ' Adventure', ' Coming Soon', ' Sci-Fi'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=Tnj9E5I3DkM', 'watch': 'https://lk21online.online/avatar-2-2021/'}, {'title': ' Eternals (2021)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/04/uRc0RTpUszMFakhXouZzK1clLsb-170x255.jpg', 'genre': ['Action', ' Adventure', ' Coming Soon', ' Fantasy', ' Sci-Fi'], 'rating': '', 'duration': '', 'quality': 'HD', 'watch': 'https://lk21online.online/eternals-2021/'}, {'title': ' The Batman (2021)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/04/mi2oVlgujK5HYcujdXyKZkt4SpU-170x255.jpg', 'genre': ['Action', ' Coming Soon', ' Crime', ' Drama', ' Mystery'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=391277390', 'watch': 'https://lk21online.online/the-batman-2021/'}, {'title': ' Coming 2 America (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/Coming-2-America-2020-170x255.jpg', 'genre': ['Comedy', ' Coming Soon'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=gYYylfwQu-s', 'watch': 'https://lk21online.online/coming-2-america-2020/'}, {'title': ' Peter Rabbit 2: The Runaway (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/cycDz68DtTjJrDJ1fV8EBq2Xdpb-170x255.jpg', 'genre': ['Adventure', ' Animation', ' Comedy', ' Coming Soon', ' Australia'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=PWBcqCz7l_c', 'watch': 'https://lk21online.online/peter-rabbit-2-the-runaway-2020/'}, {'title': ' Morbius (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/i4v4Ew7SxJSGDFCVAINtKwieEzS-170x255.jpg', 'genre': ['Action', ' Adventure', ' Coming Soon', ' Drama'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=jLMBLuGJTsA', 'watch': 'https://lk21online.online/morbius-2020/'}, {'title': ' Jungle Cruise (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/bEFFj0KKtOIYbydhcxJSDq0hzg7-170x255.jpg', 'genre': ['Action', ' Adventure', ' Comedy', ' Coming Soon'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=Zsnp3WMX3AE', 'watch': 'https://lk21online.online/jungle-cruise-2020/'}, {'title': ' Ghostbusters: Afterlife (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/fMyCgXLYehlbiQPlcu7nG98GFZU-170x255.jpg', 'genre': ['Action', ' Comedy', ' Coming Soon', ' Drama'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=BGq1chBbc30', 'watch': 'https://lk21online.online/ghostbusters-afterlife-2020/'}, {'title': ' Minions: The Rise of Gru (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/wNDfjpamXnNOtPW2DVJoDDvfz54-170x255.jpg', 'genre': ['Adventure', ' Animation', ' Comedy', ' Coming Soon', ' France', ' Japan'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=54yAKyNkK7w', 'watch': 'https://lk21online.online/minions-the-rise-of-gru-2020/'}, {'title': ' Free Guy (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/1fdLUHWXhPlTSV6rBxhc3rsXHw-170x255.jpg', 'genre': ['Action', ' Adventure', ' Comedy', ' Coming Soon'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=X2m-08cOAbc', 'watch': 'https://lk21online.online/free-guy-2020/'}, {'title': ' In the Heights (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/uyX4XtWpp7cywg1DE7cdvNHsEAt-170x255.jpg', 'genre': ['Coming Soon', ' Drama', ' Music'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=U0CL-ZSuCrQ', 'watch': 'https://lk21online.online/in-the-heights-2020/'}, {'title': ' Top Gun: Maverick (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/i0FHyNF9VvQTXOi4yKnZJ1zql1-170x255.jpg', 'genre': ['Action', ' Coming Soon', ' Drama'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=qSqVVswa420', 'watch': 'https://lk21online.online/top-gun-maverick-2020/'}, {'title': ' Antlers (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/tNule8bZ3PPU4uDHe1aAkOMu34W-170x255.jpg', 'genre': ['Coming Soon', ' Horror', ' Misteri'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=IEM5HW7q5dY', 'watch': 'https://lk21online.online/antlers-2020/'}, {'title': ' The Woman in the Window (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/gUnMWEtz07x5ZeNT7dOZpvDK8Hb-170x255.jpg', 'genre': ['Coming Soon', ' Crime', ' Drama', ' Misteri'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=J0hTmzISOlQ', 'watch': 'https://lk21online.online/the-woman-in-the-window-2020/'}, {'title': ' Fast & Furious 9 (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/01/8Qfp5l4lqqz961EOyW3yPrjXBjQ-170x255.jpg', 'genre': ['Action', ' Adventure', ' Coming Soon', ' Crime'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=B_5mSXIDb5s', 'watch': 'https://lk21online.online/fast-furious-9-2020/'}, {'title': ' No Time to Die (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2019/12/vd6w8M7ixwPHmiVauphyGVjkflA-170x255.jpg', 'genre': ['Adventure', ' Coming Soon', ' Crime', ' Thriller', ' United Kingdom'], 'rating': '', 'duration': ' null min', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=NQkO0Shirl8', 'watch': 'https://lk21online.online/no-time-to-die-2020/'}, {'title': ' The Conjuring 3 (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2019/12/7PKHmdFhC1umtsVT2fzIR3TmCzb-170x255.jpg', 'genre': ['Coming Soon', ' Horror', ' Misteri', ' Thriller'], 'rating': '', 'duration': ' null min', 'quality': 'HD', 'watch': 'https://lk21online.online/the-conjuring-3-2020/'}, {'title': ' Black Widow (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2019/12/sRhaJ6D3x6gQB0swrV0UDqMwHJu-170x255.jpg', 'genre': ['Action', ' Adventure', ' Coming Soon', ' Sci-Fi', ' Hungary', ' Norway', ' United Kingdom'], 'rating': '', 'duration': ' null min', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=RxAtuMu_ph4', 'watch': 'https://lk21online.online/black-widow-2020/'}, {'title': ' Habibie & Ainun 3 (2019)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2019/10/wdGAxdAtyjFuI4UgYebXJgiHHvi-170x255.jpg', 'genre': ['Coming Soon', ' Drama', ' Movie', ' Romance'], 'rating': '', 'duration': ' null min', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=CIP0esJ6MMs', 'watch': 'https://lk21online.online/habibie-ainun-3-2019/'}, {'title': ' The Art of Racing in the Rain (2019)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2019/08/Akx5MjXFj5KCz9QM6wWShOjN3oS-170x255.jpg', 'genre': ['Comedy', ' Coming Soon', ' Drama'], 'rating': ' 9', 'duration': ' 123 min', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=Dp2ufFO4QGg', 'watch': 'https://lk21online.online/the-art-of-racing-in-the-rain-2019/'}], 'page': 1} \ No newline at end of file From 980d6bed5b88fc37efeca757aba7dccc9bed0706 Mon Sep 17 00:00:00 2001 From: josua1111 Date: Thu, 22 Apr 2021 11:55:04 +0700 Subject: [PATCH 142/164] Josuansef Pardede 1184091 update tugas 7 --- Chapter02/josuanseff | 1 + 1 file changed, 1 insertion(+) create mode 100644 Chapter02/josuanseff diff --git a/Chapter02/josuanseff b/Chapter02/josuanseff new file mode 100644 index 0000000..b2de42d --- /dev/null +++ b/Chapter02/josuanseff @@ -0,0 +1 @@ +{'result': [{'title': ' Tom Clancy’s Without Remorse (2021)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2021/03/s9VFcru4oAurVVK49jmpB35vVhZ-170x255.jpg', 'genre': ['Action', ' Coming Soon', ' Thriller'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=e-rw2cxFVLg', 'watch': 'https://lk21online.online/nonton-tom-clancys-without-remorse-2021-subtitle-indonesia/'}, {'title': ' Avatar 2 (2021)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/04/krOMOEjDpw3Mf2EuJb9OgmqD6ft-170x255.jpg', 'genre': ['Action', ' Adventure', ' Coming Soon', ' Sci-Fi'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=Tnj9E5I3DkM', 'watch': 'https://lk21online.online/avatar-2-2021/'}, {'title': ' Eternals (2021)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/04/uRc0RTpUszMFakhXouZzK1clLsb-170x255.jpg', 'genre': ['Action', ' Adventure', ' Coming Soon', ' Fantasy', ' Sci-Fi'], 'rating': '', 'duration': '', 'quality': 'HD', 'watch': 'https://lk21online.online/eternals-2021/'}, {'title': ' The Batman (2021)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/04/mi2oVlgujK5HYcujdXyKZkt4SpU-170x255.jpg', 'genre': ['Action', ' Coming Soon', ' Crime', ' Drama', ' Mystery'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=391277390', 'watch': 'https://lk21online.online/the-batman-2021/'}, {'title': ' Coming 2 America (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/Coming-2-America-2020-170x255.jpg', 'genre': ['Comedy', ' Coming Soon'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=gYYylfwQu-s', 'watch': 'https://lk21online.online/coming-2-america-2020/'}, {'title': ' Peter Rabbit 2: The Runaway (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/cycDz68DtTjJrDJ1fV8EBq2Xdpb-170x255.jpg', 'genre': ['Adventure', ' Animation', ' Comedy', ' Coming Soon', ' Australia'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=PWBcqCz7l_c', 'watch': 'https://lk21online.online/peter-rabbit-2-the-runaway-2020/'}, {'title': ' Morbius (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/i4v4Ew7SxJSGDFCVAINtKwieEzS-170x255.jpg', 'genre': ['Action', ' Adventure', ' Coming Soon', ' Drama'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=jLMBLuGJTsA', 'watch': 'https://lk21online.online/morbius-2020/'}, {'title': ' Jungle Cruise (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/bEFFj0KKtOIYbydhcxJSDq0hzg7-170x255.jpg', 'genre': ['Action', ' Adventure', ' Comedy', ' Coming Soon'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=Zsnp3WMX3AE', 'watch': 'https://lk21online.online/jungle-cruise-2020/'}, {'title': ' Ghostbusters: Afterlife (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/fMyCgXLYehlbiQPlcu7nG98GFZU-170x255.jpg', 'genre': ['Action', ' Comedy', ' Coming Soon', ' Drama'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=BGq1chBbc30', 'watch': 'https://lk21online.online/ghostbusters-afterlife-2020/'}, {'title': ' Minions: The Rise of Gru (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/wNDfjpamXnNOtPW2DVJoDDvfz54-170x255.jpg', 'genre': ['Adventure', ' Animation', ' Comedy', ' Coming Soon', ' France', ' Japan'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=54yAKyNkK7w', 'watch': 'https://lk21online.online/minions-the-rise-of-gru-2020/'}, {'title': ' Free Guy (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/1fdLUHWXhPlTSV6rBxhc3rsXHw-170x255.jpg', 'genre': ['Action', ' Adventure', ' Comedy', ' Coming Soon'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=X2m-08cOAbc', 'watch': 'https://lk21online.online/free-guy-2020/'}, {'title': ' In the Heights (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/uyX4XtWpp7cywg1DE7cdvNHsEAt-170x255.jpg', 'genre': ['Coming Soon', ' Drama', ' Music'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=U0CL-ZSuCrQ', 'watch': 'https://lk21online.online/in-the-heights-2020/'}, {'title': ' Top Gun: Maverick (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/i0FHyNF9VvQTXOi4yKnZJ1zql1-170x255.jpg', 'genre': ['Action', ' Coming Soon', ' Drama'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=qSqVVswa420', 'watch': 'https://lk21online.online/top-gun-maverick-2020/'}, {'title': ' Antlers (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/tNule8bZ3PPU4uDHe1aAkOMu34W-170x255.jpg', 'genre': ['Coming Soon', ' Horror', ' Misteri'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=IEM5HW7q5dY', 'watch': 'https://lk21online.online/antlers-2020/'}, {'title': ' The Woman in the Window (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/gUnMWEtz07x5ZeNT7dOZpvDK8Hb-170x255.jpg', 'genre': ['Coming Soon', ' Crime', ' Drama', ' Misteri'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=J0hTmzISOlQ', 'watch': 'https://lk21online.online/the-woman-in-the-window-2020/'}, {'title': ' Fast & Furious 9 (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/01/8Qfp5l4lqqz961EOyW3yPrjXBjQ-170x255.jpg', 'genre': ['Action', ' Adventure', ' Coming Soon', ' Crime'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=B_5mSXIDb5s', 'watch': 'https://lk21online.online/fast-furious-9-2020/'}, {'title': ' No Time to Die (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2019/12/vd6w8M7ixwPHmiVauphyGVjkflA-170x255.jpg', 'genre': ['Adventure', ' Coming Soon', ' Crime', ' Thriller', ' United Kingdom'], 'rating': '', 'duration': ' null min', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=NQkO0Shirl8', 'watch': 'https://lk21online.online/no-time-to-die-2020/'}, {'title': ' The Conjuring 3 (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2019/12/7PKHmdFhC1umtsVT2fzIR3TmCzb-170x255.jpg', 'genre': ['Coming Soon', ' Horror', ' Misteri', ' Thriller'], 'rating': '', 'duration': ' null min', 'quality': 'HD', 'watch': 'https://lk21online.online/the-conjuring-3-2020/'}, {'title': ' Black Widow (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2019/12/sRhaJ6D3x6gQB0swrV0UDqMwHJu-170x255.jpg', 'genre': ['Action', ' Adventure', ' Coming Soon', ' Sci-Fi', ' Hungary', ' Norway', ' United Kingdom'], 'rating': '', 'duration': ' null min', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=RxAtuMu_ph4', 'watch': 'https://lk21online.online/black-widow-2020/'}, {'title': ' Habibie & Ainun 3 (2019)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2019/10/wdGAxdAtyjFuI4UgYebXJgiHHvi-170x255.jpg', 'genre': ['Coming Soon', ' Drama', ' Movie', ' Romance'], 'rating': '', 'duration': ' null min', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=CIP0esJ6MMs', 'watch': 'https://lk21online.online/habibie-ainun-3-2019/'}, {'title': ' The Art of Racing in the Rain (2019)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2019/08/Akx5MjXFj5KCz9QM6wWShOjN3oS-170x255.jpg', 'genre': ['Comedy', ' Coming Soon', ' Drama'], 'rating': ' 9', 'duration': ' 123 min', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=Dp2ufFO4QGg', 'watch': 'https://lk21online.online/the-art-of-racing-in-the-rain-2019/'}], 'page': 1} \ No newline at end of file From 658c964744458c576b2ef0625fa98274441621f7 Mon Sep 17 00:00:00 2001 From: josua1111 Date: Thu, 22 Apr 2021 12:11:28 +0700 Subject: [PATCH 143/164] update Josuansef Pardede 1184091 update tugas 7 --- Chapter02/josuanseff | 1 - Chapter02/josuanseff.txt | 1 - 2 files changed, 2 deletions(-) delete mode 100644 Chapter02/josuanseff delete mode 100644 Chapter02/josuanseff.txt diff --git a/Chapter02/josuanseff b/Chapter02/josuanseff deleted file mode 100644 index b2de42d..0000000 --- a/Chapter02/josuanseff +++ /dev/null @@ -1 +0,0 @@ -{'result': [{'title': ' Tom Clancy’s Without Remorse (2021)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2021/03/s9VFcru4oAurVVK49jmpB35vVhZ-170x255.jpg', 'genre': ['Action', ' Coming Soon', ' Thriller'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=e-rw2cxFVLg', 'watch': 'https://lk21online.online/nonton-tom-clancys-without-remorse-2021-subtitle-indonesia/'}, {'title': ' Avatar 2 (2021)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/04/krOMOEjDpw3Mf2EuJb9OgmqD6ft-170x255.jpg', 'genre': ['Action', ' Adventure', ' Coming Soon', ' Sci-Fi'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=Tnj9E5I3DkM', 'watch': 'https://lk21online.online/avatar-2-2021/'}, {'title': ' Eternals (2021)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/04/uRc0RTpUszMFakhXouZzK1clLsb-170x255.jpg', 'genre': ['Action', ' Adventure', ' Coming Soon', ' Fantasy', ' Sci-Fi'], 'rating': '', 'duration': '', 'quality': 'HD', 'watch': 'https://lk21online.online/eternals-2021/'}, {'title': ' The Batman (2021)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/04/mi2oVlgujK5HYcujdXyKZkt4SpU-170x255.jpg', 'genre': ['Action', ' Coming Soon', ' Crime', ' Drama', ' Mystery'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=391277390', 'watch': 'https://lk21online.online/the-batman-2021/'}, {'title': ' Coming 2 America (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/Coming-2-America-2020-170x255.jpg', 'genre': ['Comedy', ' Coming Soon'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=gYYylfwQu-s', 'watch': 'https://lk21online.online/coming-2-america-2020/'}, {'title': ' Peter Rabbit 2: The Runaway (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/cycDz68DtTjJrDJ1fV8EBq2Xdpb-170x255.jpg', 'genre': ['Adventure', ' Animation', ' Comedy', ' Coming Soon', ' Australia'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=PWBcqCz7l_c', 'watch': 'https://lk21online.online/peter-rabbit-2-the-runaway-2020/'}, {'title': ' Morbius (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/i4v4Ew7SxJSGDFCVAINtKwieEzS-170x255.jpg', 'genre': ['Action', ' Adventure', ' Coming Soon', ' Drama'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=jLMBLuGJTsA', 'watch': 'https://lk21online.online/morbius-2020/'}, {'title': ' Jungle Cruise (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/bEFFj0KKtOIYbydhcxJSDq0hzg7-170x255.jpg', 'genre': ['Action', ' Adventure', ' Comedy', ' Coming Soon'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=Zsnp3WMX3AE', 'watch': 'https://lk21online.online/jungle-cruise-2020/'}, {'title': ' Ghostbusters: Afterlife (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/fMyCgXLYehlbiQPlcu7nG98GFZU-170x255.jpg', 'genre': ['Action', ' Comedy', ' Coming Soon', ' Drama'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=BGq1chBbc30', 'watch': 'https://lk21online.online/ghostbusters-afterlife-2020/'}, {'title': ' Minions: The Rise of Gru (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/wNDfjpamXnNOtPW2DVJoDDvfz54-170x255.jpg', 'genre': ['Adventure', ' Animation', ' Comedy', ' Coming Soon', ' France', ' Japan'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=54yAKyNkK7w', 'watch': 'https://lk21online.online/minions-the-rise-of-gru-2020/'}, {'title': ' Free Guy (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/1fdLUHWXhPlTSV6rBxhc3rsXHw-170x255.jpg', 'genre': ['Action', ' Adventure', ' Comedy', ' Coming Soon'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=X2m-08cOAbc', 'watch': 'https://lk21online.online/free-guy-2020/'}, {'title': ' In the Heights (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/uyX4XtWpp7cywg1DE7cdvNHsEAt-170x255.jpg', 'genre': ['Coming Soon', ' Drama', ' Music'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=U0CL-ZSuCrQ', 'watch': 'https://lk21online.online/in-the-heights-2020/'}, {'title': ' Top Gun: Maverick (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/i0FHyNF9VvQTXOi4yKnZJ1zql1-170x255.jpg', 'genre': ['Action', ' Coming Soon', ' Drama'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=qSqVVswa420', 'watch': 'https://lk21online.online/top-gun-maverick-2020/'}, {'title': ' Antlers (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/tNule8bZ3PPU4uDHe1aAkOMu34W-170x255.jpg', 'genre': ['Coming Soon', ' Horror', ' Misteri'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=IEM5HW7q5dY', 'watch': 'https://lk21online.online/antlers-2020/'}, {'title': ' The Woman in the Window (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/gUnMWEtz07x5ZeNT7dOZpvDK8Hb-170x255.jpg', 'genre': ['Coming Soon', ' Crime', ' Drama', ' Misteri'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=J0hTmzISOlQ', 'watch': 'https://lk21online.online/the-woman-in-the-window-2020/'}, {'title': ' Fast & Furious 9 (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/01/8Qfp5l4lqqz961EOyW3yPrjXBjQ-170x255.jpg', 'genre': ['Action', ' Adventure', ' Coming Soon', ' Crime'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=B_5mSXIDb5s', 'watch': 'https://lk21online.online/fast-furious-9-2020/'}, {'title': ' No Time to Die (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2019/12/vd6w8M7ixwPHmiVauphyGVjkflA-170x255.jpg', 'genre': ['Adventure', ' Coming Soon', ' Crime', ' Thriller', ' United Kingdom'], 'rating': '', 'duration': ' null min', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=NQkO0Shirl8', 'watch': 'https://lk21online.online/no-time-to-die-2020/'}, {'title': ' The Conjuring 3 (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2019/12/7PKHmdFhC1umtsVT2fzIR3TmCzb-170x255.jpg', 'genre': ['Coming Soon', ' Horror', ' Misteri', ' Thriller'], 'rating': '', 'duration': ' null min', 'quality': 'HD', 'watch': 'https://lk21online.online/the-conjuring-3-2020/'}, {'title': ' Black Widow (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2019/12/sRhaJ6D3x6gQB0swrV0UDqMwHJu-170x255.jpg', 'genre': ['Action', ' Adventure', ' Coming Soon', ' Sci-Fi', ' Hungary', ' Norway', ' United Kingdom'], 'rating': '', 'duration': ' null min', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=RxAtuMu_ph4', 'watch': 'https://lk21online.online/black-widow-2020/'}, {'title': ' Habibie & Ainun 3 (2019)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2019/10/wdGAxdAtyjFuI4UgYebXJgiHHvi-170x255.jpg', 'genre': ['Coming Soon', ' Drama', ' Movie', ' Romance'], 'rating': '', 'duration': ' null min', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=CIP0esJ6MMs', 'watch': 'https://lk21online.online/habibie-ainun-3-2019/'}, {'title': ' The Art of Racing in the Rain (2019)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2019/08/Akx5MjXFj5KCz9QM6wWShOjN3oS-170x255.jpg', 'genre': ['Comedy', ' Coming Soon', ' Drama'], 'rating': ' 9', 'duration': ' 123 min', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=Dp2ufFO4QGg', 'watch': 'https://lk21online.online/the-art-of-racing-in-the-rain-2019/'}], 'page': 1} \ No newline at end of file diff --git a/Chapter02/josuanseff.txt b/Chapter02/josuanseff.txt deleted file mode 100644 index b2de42d..0000000 --- a/Chapter02/josuanseff.txt +++ /dev/null @@ -1 +0,0 @@ -{'result': [{'title': ' Tom Clancy’s Without Remorse (2021)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2021/03/s9VFcru4oAurVVK49jmpB35vVhZ-170x255.jpg', 'genre': ['Action', ' Coming Soon', ' Thriller'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=e-rw2cxFVLg', 'watch': 'https://lk21online.online/nonton-tom-clancys-without-remorse-2021-subtitle-indonesia/'}, {'title': ' Avatar 2 (2021)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/04/krOMOEjDpw3Mf2EuJb9OgmqD6ft-170x255.jpg', 'genre': ['Action', ' Adventure', ' Coming Soon', ' Sci-Fi'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=Tnj9E5I3DkM', 'watch': 'https://lk21online.online/avatar-2-2021/'}, {'title': ' Eternals (2021)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/04/uRc0RTpUszMFakhXouZzK1clLsb-170x255.jpg', 'genre': ['Action', ' Adventure', ' Coming Soon', ' Fantasy', ' Sci-Fi'], 'rating': '', 'duration': '', 'quality': 'HD', 'watch': 'https://lk21online.online/eternals-2021/'}, {'title': ' The Batman (2021)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/04/mi2oVlgujK5HYcujdXyKZkt4SpU-170x255.jpg', 'genre': ['Action', ' Coming Soon', ' Crime', ' Drama', ' Mystery'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=391277390', 'watch': 'https://lk21online.online/the-batman-2021/'}, {'title': ' Coming 2 America (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/Coming-2-America-2020-170x255.jpg', 'genre': ['Comedy', ' Coming Soon'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=gYYylfwQu-s', 'watch': 'https://lk21online.online/coming-2-america-2020/'}, {'title': ' Peter Rabbit 2: The Runaway (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/cycDz68DtTjJrDJ1fV8EBq2Xdpb-170x255.jpg', 'genre': ['Adventure', ' Animation', ' Comedy', ' Coming Soon', ' Australia'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=PWBcqCz7l_c', 'watch': 'https://lk21online.online/peter-rabbit-2-the-runaway-2020/'}, {'title': ' Morbius (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/i4v4Ew7SxJSGDFCVAINtKwieEzS-170x255.jpg', 'genre': ['Action', ' Adventure', ' Coming Soon', ' Drama'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=jLMBLuGJTsA', 'watch': 'https://lk21online.online/morbius-2020/'}, {'title': ' Jungle Cruise (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/bEFFj0KKtOIYbydhcxJSDq0hzg7-170x255.jpg', 'genre': ['Action', ' Adventure', ' Comedy', ' Coming Soon'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=Zsnp3WMX3AE', 'watch': 'https://lk21online.online/jungle-cruise-2020/'}, {'title': ' Ghostbusters: Afterlife (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/fMyCgXLYehlbiQPlcu7nG98GFZU-170x255.jpg', 'genre': ['Action', ' Comedy', ' Coming Soon', ' Drama'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=BGq1chBbc30', 'watch': 'https://lk21online.online/ghostbusters-afterlife-2020/'}, {'title': ' Minions: The Rise of Gru (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/wNDfjpamXnNOtPW2DVJoDDvfz54-170x255.jpg', 'genre': ['Adventure', ' Animation', ' Comedy', ' Coming Soon', ' France', ' Japan'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=54yAKyNkK7w', 'watch': 'https://lk21online.online/minions-the-rise-of-gru-2020/'}, {'title': ' Free Guy (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/1fdLUHWXhPlTSV6rBxhc3rsXHw-170x255.jpg', 'genre': ['Action', ' Adventure', ' Comedy', ' Coming Soon'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=X2m-08cOAbc', 'watch': 'https://lk21online.online/free-guy-2020/'}, {'title': ' In the Heights (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/uyX4XtWpp7cywg1DE7cdvNHsEAt-170x255.jpg', 'genre': ['Coming Soon', ' Drama', ' Music'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=U0CL-ZSuCrQ', 'watch': 'https://lk21online.online/in-the-heights-2020/'}, {'title': ' Top Gun: Maverick (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/i0FHyNF9VvQTXOi4yKnZJ1zql1-170x255.jpg', 'genre': ['Action', ' Coming Soon', ' Drama'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=qSqVVswa420', 'watch': 'https://lk21online.online/top-gun-maverick-2020/'}, {'title': ' Antlers (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/tNule8bZ3PPU4uDHe1aAkOMu34W-170x255.jpg', 'genre': ['Coming Soon', ' Horror', ' Misteri'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=IEM5HW7q5dY', 'watch': 'https://lk21online.online/antlers-2020/'}, {'title': ' The Woman in the Window (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/gUnMWEtz07x5ZeNT7dOZpvDK8Hb-170x255.jpg', 'genre': ['Coming Soon', ' Crime', ' Drama', ' Misteri'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=J0hTmzISOlQ', 'watch': 'https://lk21online.online/the-woman-in-the-window-2020/'}, {'title': ' Fast & Furious 9 (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/01/8Qfp5l4lqqz961EOyW3yPrjXBjQ-170x255.jpg', 'genre': ['Action', ' Adventure', ' Coming Soon', ' Crime'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=B_5mSXIDb5s', 'watch': 'https://lk21online.online/fast-furious-9-2020/'}, {'title': ' No Time to Die (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2019/12/vd6w8M7ixwPHmiVauphyGVjkflA-170x255.jpg', 'genre': ['Adventure', ' Coming Soon', ' Crime', ' Thriller', ' United Kingdom'], 'rating': '', 'duration': ' null min', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=NQkO0Shirl8', 'watch': 'https://lk21online.online/no-time-to-die-2020/'}, {'title': ' The Conjuring 3 (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2019/12/7PKHmdFhC1umtsVT2fzIR3TmCzb-170x255.jpg', 'genre': ['Coming Soon', ' Horror', ' Misteri', ' Thriller'], 'rating': '', 'duration': ' null min', 'quality': 'HD', 'watch': 'https://lk21online.online/the-conjuring-3-2020/'}, {'title': ' Black Widow (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2019/12/sRhaJ6D3x6gQB0swrV0UDqMwHJu-170x255.jpg', 'genre': ['Action', ' Adventure', ' Coming Soon', ' Sci-Fi', ' Hungary', ' Norway', ' United Kingdom'], 'rating': '', 'duration': ' null min', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=RxAtuMu_ph4', 'watch': 'https://lk21online.online/black-widow-2020/'}, {'title': ' Habibie & Ainun 3 (2019)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2019/10/wdGAxdAtyjFuI4UgYebXJgiHHvi-170x255.jpg', 'genre': ['Coming Soon', ' Drama', ' Movie', ' Romance'], 'rating': '', 'duration': ' null min', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=CIP0esJ6MMs', 'watch': 'https://lk21online.online/habibie-ainun-3-2019/'}, {'title': ' The Art of Racing in the Rain (2019)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2019/08/Akx5MjXFj5KCz9QM6wWShOjN3oS-170x255.jpg', 'genre': ['Comedy', ' Coming Soon', ' Drama'], 'rating': ' 9', 'duration': ' 123 min', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=Dp2ufFO4QGg', 'watch': 'https://lk21online.online/the-art-of-racing-in-the-rain-2019/'}], 'page': 1} \ No newline at end of file From 5ae08d4b06b1385cf39ea7ac4f2dcb7240a84431 Mon Sep 17 00:00:00 2001 From: josua1111 Date: Thu, 22 Apr 2021 12:15:45 +0700 Subject: [PATCH 144/164] update Josuansef Pardede 1184091 update tugas 7 --- Chapter02/JosuansefTujuh_1184091.py | 2 +- Chapter02/josuanseff | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 Chapter02/josuanseff diff --git a/Chapter02/JosuansefTujuh_1184091.py b/Chapter02/JosuansefTujuh_1184091.py index d3b2a33..52b33cc 100644 --- a/Chapter02/JosuansefTujuh_1184091.py +++ b/Chapter02/JosuansefTujuh_1184091.py @@ -31,7 +31,7 @@ def run(self): self.readfile() self.event.wait() self.threadLock.release() - print("\n"+str(self.thread_number)+". ---> " + currentThread().getName() + "Read dan Append file Done") + print("\n"+str(self.thread_number)+". ---> " + currentThread().getName() + "Read file Done") print ("eksekusi event clear") self.event.clear() diff --git a/Chapter02/josuanseff b/Chapter02/josuanseff new file mode 100644 index 0000000..b2de42d --- /dev/null +++ b/Chapter02/josuanseff @@ -0,0 +1 @@ +{'result': [{'title': ' Tom Clancy’s Without Remorse (2021)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2021/03/s9VFcru4oAurVVK49jmpB35vVhZ-170x255.jpg', 'genre': ['Action', ' Coming Soon', ' Thriller'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=e-rw2cxFVLg', 'watch': 'https://lk21online.online/nonton-tom-clancys-without-remorse-2021-subtitle-indonesia/'}, {'title': ' Avatar 2 (2021)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/04/krOMOEjDpw3Mf2EuJb9OgmqD6ft-170x255.jpg', 'genre': ['Action', ' Adventure', ' Coming Soon', ' Sci-Fi'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=Tnj9E5I3DkM', 'watch': 'https://lk21online.online/avatar-2-2021/'}, {'title': ' Eternals (2021)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/04/uRc0RTpUszMFakhXouZzK1clLsb-170x255.jpg', 'genre': ['Action', ' Adventure', ' Coming Soon', ' Fantasy', ' Sci-Fi'], 'rating': '', 'duration': '', 'quality': 'HD', 'watch': 'https://lk21online.online/eternals-2021/'}, {'title': ' The Batman (2021)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/04/mi2oVlgujK5HYcujdXyKZkt4SpU-170x255.jpg', 'genre': ['Action', ' Coming Soon', ' Crime', ' Drama', ' Mystery'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=391277390', 'watch': 'https://lk21online.online/the-batman-2021/'}, {'title': ' Coming 2 America (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/Coming-2-America-2020-170x255.jpg', 'genre': ['Comedy', ' Coming Soon'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=gYYylfwQu-s', 'watch': 'https://lk21online.online/coming-2-america-2020/'}, {'title': ' Peter Rabbit 2: The Runaway (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/cycDz68DtTjJrDJ1fV8EBq2Xdpb-170x255.jpg', 'genre': ['Adventure', ' Animation', ' Comedy', ' Coming Soon', ' Australia'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=PWBcqCz7l_c', 'watch': 'https://lk21online.online/peter-rabbit-2-the-runaway-2020/'}, {'title': ' Morbius (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/i4v4Ew7SxJSGDFCVAINtKwieEzS-170x255.jpg', 'genre': ['Action', ' Adventure', ' Coming Soon', ' Drama'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=jLMBLuGJTsA', 'watch': 'https://lk21online.online/morbius-2020/'}, {'title': ' Jungle Cruise (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/bEFFj0KKtOIYbydhcxJSDq0hzg7-170x255.jpg', 'genre': ['Action', ' Adventure', ' Comedy', ' Coming Soon'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=Zsnp3WMX3AE', 'watch': 'https://lk21online.online/jungle-cruise-2020/'}, {'title': ' Ghostbusters: Afterlife (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/fMyCgXLYehlbiQPlcu7nG98GFZU-170x255.jpg', 'genre': ['Action', ' Comedy', ' Coming Soon', ' Drama'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=BGq1chBbc30', 'watch': 'https://lk21online.online/ghostbusters-afterlife-2020/'}, {'title': ' Minions: The Rise of Gru (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/wNDfjpamXnNOtPW2DVJoDDvfz54-170x255.jpg', 'genre': ['Adventure', ' Animation', ' Comedy', ' Coming Soon', ' France', ' Japan'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=54yAKyNkK7w', 'watch': 'https://lk21online.online/minions-the-rise-of-gru-2020/'}, {'title': ' Free Guy (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/1fdLUHWXhPlTSV6rBxhc3rsXHw-170x255.jpg', 'genre': ['Action', ' Adventure', ' Comedy', ' Coming Soon'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=X2m-08cOAbc', 'watch': 'https://lk21online.online/free-guy-2020/'}, {'title': ' In the Heights (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/uyX4XtWpp7cywg1DE7cdvNHsEAt-170x255.jpg', 'genre': ['Coming Soon', ' Drama', ' Music'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=U0CL-ZSuCrQ', 'watch': 'https://lk21online.online/in-the-heights-2020/'}, {'title': ' Top Gun: Maverick (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/i0FHyNF9VvQTXOi4yKnZJ1zql1-170x255.jpg', 'genre': ['Action', ' Coming Soon', ' Drama'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=qSqVVswa420', 'watch': 'https://lk21online.online/top-gun-maverick-2020/'}, {'title': ' Antlers (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/tNule8bZ3PPU4uDHe1aAkOMu34W-170x255.jpg', 'genre': ['Coming Soon', ' Horror', ' Misteri'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=IEM5HW7q5dY', 'watch': 'https://lk21online.online/antlers-2020/'}, {'title': ' The Woman in the Window (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/gUnMWEtz07x5ZeNT7dOZpvDK8Hb-170x255.jpg', 'genre': ['Coming Soon', ' Crime', ' Drama', ' Misteri'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=J0hTmzISOlQ', 'watch': 'https://lk21online.online/the-woman-in-the-window-2020/'}, {'title': ' Fast & Furious 9 (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/01/8Qfp5l4lqqz961EOyW3yPrjXBjQ-170x255.jpg', 'genre': ['Action', ' Adventure', ' Coming Soon', ' Crime'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=B_5mSXIDb5s', 'watch': 'https://lk21online.online/fast-furious-9-2020/'}, {'title': ' No Time to Die (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2019/12/vd6w8M7ixwPHmiVauphyGVjkflA-170x255.jpg', 'genre': ['Adventure', ' Coming Soon', ' Crime', ' Thriller', ' United Kingdom'], 'rating': '', 'duration': ' null min', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=NQkO0Shirl8', 'watch': 'https://lk21online.online/no-time-to-die-2020/'}, {'title': ' The Conjuring 3 (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2019/12/7PKHmdFhC1umtsVT2fzIR3TmCzb-170x255.jpg', 'genre': ['Coming Soon', ' Horror', ' Misteri', ' Thriller'], 'rating': '', 'duration': ' null min', 'quality': 'HD', 'watch': 'https://lk21online.online/the-conjuring-3-2020/'}, {'title': ' Black Widow (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2019/12/sRhaJ6D3x6gQB0swrV0UDqMwHJu-170x255.jpg', 'genre': ['Action', ' Adventure', ' Coming Soon', ' Sci-Fi', ' Hungary', ' Norway', ' United Kingdom'], 'rating': '', 'duration': ' null min', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=RxAtuMu_ph4', 'watch': 'https://lk21online.online/black-widow-2020/'}, {'title': ' Habibie & Ainun 3 (2019)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2019/10/wdGAxdAtyjFuI4UgYebXJgiHHvi-170x255.jpg', 'genre': ['Coming Soon', ' Drama', ' Movie', ' Romance'], 'rating': '', 'duration': ' null min', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=CIP0esJ6MMs', 'watch': 'https://lk21online.online/habibie-ainun-3-2019/'}, {'title': ' The Art of Racing in the Rain (2019)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2019/08/Akx5MjXFj5KCz9QM6wWShOjN3oS-170x255.jpg', 'genre': ['Comedy', ' Coming Soon', ' Drama'], 'rating': ' 9', 'duration': ' 123 min', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=Dp2ufFO4QGg', 'watch': 'https://lk21online.online/the-art-of-racing-in-the-rain-2019/'}], 'page': 1} \ No newline at end of file From 42466fa5e7420bb99ab598e5cdc447b7f56a4659 Mon Sep 17 00:00:00 2001 From: josua1111 Date: Thu, 22 Apr 2021 13:46:35 +0700 Subject: [PATCH 145/164] Update tugas 7 Josuansef Pardede 1184091 DS --- Chapter02/JosuansefTujuh_1184091.py | 3 +-- Chapter02/{josuanseff => josuanseff.txt} | 0 2 files changed, 1 insertion(+), 2 deletions(-) rename Chapter02/{josuanseff => josuanseff.txt} (100%) diff --git a/Chapter02/JosuansefTujuh_1184091.py b/Chapter02/JosuansefTujuh_1184091.py index 8e69f41..33e4092 100644 --- a/Chapter02/JosuansefTujuh_1184091.py +++ b/Chapter02/JosuansefTujuh_1184091.py @@ -85,5 +85,4 @@ def createfile(self, konten): f = open(self.filenya, "x") f.write(str(konten)) f.close() - print('File sudah dibuat, selanjutnya, mau eksekusi event set') - + print('File sudah dibuat, selanjutnya, mau eksekusi event set') \ No newline at end of file diff --git a/Chapter02/josuanseff b/Chapter02/josuanseff.txt similarity index 100% rename from Chapter02/josuanseff rename to Chapter02/josuanseff.txt From 917aa7346025c4e72f997105c6eb5040ec967e77 Mon Sep 17 00:00:00 2001 From: josua1111 Date: Thu, 22 Apr 2021 13:55:19 +0700 Subject: [PATCH 146/164] Update tugas 7 Josuansef Pardede 1184091 DS --- Chapter02/josuanseff.txt | 1 - test_app.py | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) delete mode 100644 Chapter02/josuanseff.txt diff --git a/Chapter02/josuanseff.txt b/Chapter02/josuanseff.txt deleted file mode 100644 index b2de42d..0000000 --- a/Chapter02/josuanseff.txt +++ /dev/null @@ -1 +0,0 @@ -{'result': [{'title': ' Tom Clancy’s Without Remorse (2021)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2021/03/s9VFcru4oAurVVK49jmpB35vVhZ-170x255.jpg', 'genre': ['Action', ' Coming Soon', ' Thriller'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=e-rw2cxFVLg', 'watch': 'https://lk21online.online/nonton-tom-clancys-without-remorse-2021-subtitle-indonesia/'}, {'title': ' Avatar 2 (2021)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/04/krOMOEjDpw3Mf2EuJb9OgmqD6ft-170x255.jpg', 'genre': ['Action', ' Adventure', ' Coming Soon', ' Sci-Fi'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=Tnj9E5I3DkM', 'watch': 'https://lk21online.online/avatar-2-2021/'}, {'title': ' Eternals (2021)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/04/uRc0RTpUszMFakhXouZzK1clLsb-170x255.jpg', 'genre': ['Action', ' Adventure', ' Coming Soon', ' Fantasy', ' Sci-Fi'], 'rating': '', 'duration': '', 'quality': 'HD', 'watch': 'https://lk21online.online/eternals-2021/'}, {'title': ' The Batman (2021)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/04/mi2oVlgujK5HYcujdXyKZkt4SpU-170x255.jpg', 'genre': ['Action', ' Coming Soon', ' Crime', ' Drama', ' Mystery'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=391277390', 'watch': 'https://lk21online.online/the-batman-2021/'}, {'title': ' Coming 2 America (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/Coming-2-America-2020-170x255.jpg', 'genre': ['Comedy', ' Coming Soon'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=gYYylfwQu-s', 'watch': 'https://lk21online.online/coming-2-america-2020/'}, {'title': ' Peter Rabbit 2: The Runaway (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/cycDz68DtTjJrDJ1fV8EBq2Xdpb-170x255.jpg', 'genre': ['Adventure', ' Animation', ' Comedy', ' Coming Soon', ' Australia'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=PWBcqCz7l_c', 'watch': 'https://lk21online.online/peter-rabbit-2-the-runaway-2020/'}, {'title': ' Morbius (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/i4v4Ew7SxJSGDFCVAINtKwieEzS-170x255.jpg', 'genre': ['Action', ' Adventure', ' Coming Soon', ' Drama'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=jLMBLuGJTsA', 'watch': 'https://lk21online.online/morbius-2020/'}, {'title': ' Jungle Cruise (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/bEFFj0KKtOIYbydhcxJSDq0hzg7-170x255.jpg', 'genre': ['Action', ' Adventure', ' Comedy', ' Coming Soon'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=Zsnp3WMX3AE', 'watch': 'https://lk21online.online/jungle-cruise-2020/'}, {'title': ' Ghostbusters: Afterlife (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/fMyCgXLYehlbiQPlcu7nG98GFZU-170x255.jpg', 'genre': ['Action', ' Comedy', ' Coming Soon', ' Drama'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=BGq1chBbc30', 'watch': 'https://lk21online.online/ghostbusters-afterlife-2020/'}, {'title': ' Minions: The Rise of Gru (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/wNDfjpamXnNOtPW2DVJoDDvfz54-170x255.jpg', 'genre': ['Adventure', ' Animation', ' Comedy', ' Coming Soon', ' France', ' Japan'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=54yAKyNkK7w', 'watch': 'https://lk21online.online/minions-the-rise-of-gru-2020/'}, {'title': ' Free Guy (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/1fdLUHWXhPlTSV6rBxhc3rsXHw-170x255.jpg', 'genre': ['Action', ' Adventure', ' Comedy', ' Coming Soon'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=X2m-08cOAbc', 'watch': 'https://lk21online.online/free-guy-2020/'}, {'title': ' In the Heights (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/uyX4XtWpp7cywg1DE7cdvNHsEAt-170x255.jpg', 'genre': ['Coming Soon', ' Drama', ' Music'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=U0CL-ZSuCrQ', 'watch': 'https://lk21online.online/in-the-heights-2020/'}, {'title': ' Top Gun: Maverick (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/i0FHyNF9VvQTXOi4yKnZJ1zql1-170x255.jpg', 'genre': ['Action', ' Coming Soon', ' Drama'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=qSqVVswa420', 'watch': 'https://lk21online.online/top-gun-maverick-2020/'}, {'title': ' Antlers (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/tNule8bZ3PPU4uDHe1aAkOMu34W-170x255.jpg', 'genre': ['Coming Soon', ' Horror', ' Misteri'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=IEM5HW7q5dY', 'watch': 'https://lk21online.online/antlers-2020/'}, {'title': ' The Woman in the Window (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/gUnMWEtz07x5ZeNT7dOZpvDK8Hb-170x255.jpg', 'genre': ['Coming Soon', ' Crime', ' Drama', ' Misteri'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=J0hTmzISOlQ', 'watch': 'https://lk21online.online/the-woman-in-the-window-2020/'}, {'title': ' Fast & Furious 9 (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/01/8Qfp5l4lqqz961EOyW3yPrjXBjQ-170x255.jpg', 'genre': ['Action', ' Adventure', ' Coming Soon', ' Crime'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=B_5mSXIDb5s', 'watch': 'https://lk21online.online/fast-furious-9-2020/'}, {'title': ' No Time to Die (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2019/12/vd6w8M7ixwPHmiVauphyGVjkflA-170x255.jpg', 'genre': ['Adventure', ' Coming Soon', ' Crime', ' Thriller', ' United Kingdom'], 'rating': '', 'duration': ' null min', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=NQkO0Shirl8', 'watch': 'https://lk21online.online/no-time-to-die-2020/'}, {'title': ' The Conjuring 3 (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2019/12/7PKHmdFhC1umtsVT2fzIR3TmCzb-170x255.jpg', 'genre': ['Coming Soon', ' Horror', ' Misteri', ' Thriller'], 'rating': '', 'duration': ' null min', 'quality': 'HD', 'watch': 'https://lk21online.online/the-conjuring-3-2020/'}, {'title': ' Black Widow (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2019/12/sRhaJ6D3x6gQB0swrV0UDqMwHJu-170x255.jpg', 'genre': ['Action', ' Adventure', ' Coming Soon', ' Sci-Fi', ' Hungary', ' Norway', ' United Kingdom'], 'rating': '', 'duration': ' null min', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=RxAtuMu_ph4', 'watch': 'https://lk21online.online/black-widow-2020/'}, {'title': ' Habibie & Ainun 3 (2019)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2019/10/wdGAxdAtyjFuI4UgYebXJgiHHvi-170x255.jpg', 'genre': ['Coming Soon', ' Drama', ' Movie', ' Romance'], 'rating': '', 'duration': ' null min', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=CIP0esJ6MMs', 'watch': 'https://lk21online.online/habibie-ainun-3-2019/'}, {'title': ' The Art of Racing in the Rain (2019)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2019/08/Akx5MjXFj5KCz9QM6wWShOjN3oS-170x255.jpg', 'genre': ['Comedy', ' Coming Soon', ' Drama'], 'rating': ' 9', 'duration': ' 123 min', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=Dp2ufFO4QGg', 'watch': 'https://lk21online.online/the-art-of-racing-in-the-rain-2019/'}], 'page': 1} \ No newline at end of file diff --git a/test_app.py b/test_app.py index 477a6fc..ed55cdb 100644 --- a/test_app.py +++ b/test_app.py @@ -413,10 +413,10 @@ def readfile(self,nfile): def test_07_josuanseftujuh1184091(self): from Chapter02.JosuansefTujuh_1184091 import Josuansef1184091Tujuh_Producer,Josuansef1184091Tujuh_Consumer - threadjosuaproducer = Josuansef1184091Tujuh_Producer("Thread utama ", 2,5,5,'josuanseff') - threadjosuaconsumer = Josuansef1184091Tujuh_Consumer("Thread baca file ", 1,'josuanseff') + threadjosuaproducer = Josuansef1184091Tujuh_Producer("Thread utama ", 2,5,5,'joss') + threadjosuaconsumer = Josuansef1184091Tujuh_Consumer("Thread baca file ", 1,'joss') threadjosuaconsumer.start() threadjosuaproducer.start() threadjosuaconsumer.join() threadjosuaproducer.join() - respon=self.readfile('./Chapter02/josuanseff.txt') \ No newline at end of file + respon=self.readfile('./Chapter02/joss.txt') \ No newline at end of file From 85eefebcd30e873866be7a083cfebe00fd69489b Mon Sep 17 00:00:00 2001 From: josua1111 Date: Thu, 22 Apr 2021 13:58:18 +0700 Subject: [PATCH 147/164] Update tugas 7 Josuansef Pardede 1184091 DS --- Chapter02/JosuansefTujuh_1184091.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Chapter02/JosuansefTujuh_1184091.py b/Chapter02/JosuansefTujuh_1184091.py index 33e4092..7daa728 100644 --- a/Chapter02/JosuansefTujuh_1184091.py +++ b/Chapter02/JosuansefTujuh_1184091.py @@ -37,7 +37,7 @@ def run(self): def readfile(self): q=queue.get() - f = open(self.filenya, "r+") + f = open(self.filenya, "r") print("Cek konten isi file : "+f.read()) print("Selesai membaca file, eksekusi queue task done \n") queue.task_done() From a31dd90a4cb85a10aef06c93d8840dc1948bfb01 Mon Sep 17 00:00:00 2001 From: josua1111 Date: Thu, 22 Apr 2021 14:01:27 +0700 Subject: [PATCH 148/164] Update tugas 7 Josuansef Pardede 1184091 DS --- test_app.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test_app.py b/test_app.py index ed55cdb..8414bec 100644 --- a/test_app.py +++ b/test_app.py @@ -419,4 +419,5 @@ def test_07_josuanseftujuh1184091(self): threadjosuaproducer.start() threadjosuaconsumer.join() threadjosuaproducer.join() - respon=self.readfile('./Chapter02/joss.txt') \ No newline at end of file + respon=self.readfile('./Chapter02/joss.txt') + self.assertNotRegex(respon, "kosong") \ No newline at end of file From dae5f75fe4d3cc3e2c089fb3fcf46f46f5cf3815 Mon Sep 17 00:00:00 2001 From: josua1111 Date: Thu, 22 Apr 2021 14:04:35 +0700 Subject: [PATCH 149/164] Update tugas 7 Josuansef Pardede 1184091 DS --- Chapter02/josuanseff.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 Chapter02/josuanseff.txt diff --git a/Chapter02/josuanseff.txt b/Chapter02/josuanseff.txt new file mode 100644 index 0000000..b2de42d --- /dev/null +++ b/Chapter02/josuanseff.txt @@ -0,0 +1 @@ +{'result': [{'title': ' Tom Clancy’s Without Remorse (2021)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2021/03/s9VFcru4oAurVVK49jmpB35vVhZ-170x255.jpg', 'genre': ['Action', ' Coming Soon', ' Thriller'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=e-rw2cxFVLg', 'watch': 'https://lk21online.online/nonton-tom-clancys-without-remorse-2021-subtitle-indonesia/'}, {'title': ' Avatar 2 (2021)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/04/krOMOEjDpw3Mf2EuJb9OgmqD6ft-170x255.jpg', 'genre': ['Action', ' Adventure', ' Coming Soon', ' Sci-Fi'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=Tnj9E5I3DkM', 'watch': 'https://lk21online.online/avatar-2-2021/'}, {'title': ' Eternals (2021)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/04/uRc0RTpUszMFakhXouZzK1clLsb-170x255.jpg', 'genre': ['Action', ' Adventure', ' Coming Soon', ' Fantasy', ' Sci-Fi'], 'rating': '', 'duration': '', 'quality': 'HD', 'watch': 'https://lk21online.online/eternals-2021/'}, {'title': ' The Batman (2021)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/04/mi2oVlgujK5HYcujdXyKZkt4SpU-170x255.jpg', 'genre': ['Action', ' Coming Soon', ' Crime', ' Drama', ' Mystery'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=391277390', 'watch': 'https://lk21online.online/the-batman-2021/'}, {'title': ' Coming 2 America (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/Coming-2-America-2020-170x255.jpg', 'genre': ['Comedy', ' Coming Soon'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=gYYylfwQu-s', 'watch': 'https://lk21online.online/coming-2-america-2020/'}, {'title': ' Peter Rabbit 2: The Runaway (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/cycDz68DtTjJrDJ1fV8EBq2Xdpb-170x255.jpg', 'genre': ['Adventure', ' Animation', ' Comedy', ' Coming Soon', ' Australia'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=PWBcqCz7l_c', 'watch': 'https://lk21online.online/peter-rabbit-2-the-runaway-2020/'}, {'title': ' Morbius (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/i4v4Ew7SxJSGDFCVAINtKwieEzS-170x255.jpg', 'genre': ['Action', ' Adventure', ' Coming Soon', ' Drama'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=jLMBLuGJTsA', 'watch': 'https://lk21online.online/morbius-2020/'}, {'title': ' Jungle Cruise (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/bEFFj0KKtOIYbydhcxJSDq0hzg7-170x255.jpg', 'genre': ['Action', ' Adventure', ' Comedy', ' Coming Soon'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=Zsnp3WMX3AE', 'watch': 'https://lk21online.online/jungle-cruise-2020/'}, {'title': ' Ghostbusters: Afterlife (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/fMyCgXLYehlbiQPlcu7nG98GFZU-170x255.jpg', 'genre': ['Action', ' Comedy', ' Coming Soon', ' Drama'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=BGq1chBbc30', 'watch': 'https://lk21online.online/ghostbusters-afterlife-2020/'}, {'title': ' Minions: The Rise of Gru (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/wNDfjpamXnNOtPW2DVJoDDvfz54-170x255.jpg', 'genre': ['Adventure', ' Animation', ' Comedy', ' Coming Soon', ' France', ' Japan'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=54yAKyNkK7w', 'watch': 'https://lk21online.online/minions-the-rise-of-gru-2020/'}, {'title': ' Free Guy (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/1fdLUHWXhPlTSV6rBxhc3rsXHw-170x255.jpg', 'genre': ['Action', ' Adventure', ' Comedy', ' Coming Soon'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=X2m-08cOAbc', 'watch': 'https://lk21online.online/free-guy-2020/'}, {'title': ' In the Heights (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/uyX4XtWpp7cywg1DE7cdvNHsEAt-170x255.jpg', 'genre': ['Coming Soon', ' Drama', ' Music'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=U0CL-ZSuCrQ', 'watch': 'https://lk21online.online/in-the-heights-2020/'}, {'title': ' Top Gun: Maverick (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/i0FHyNF9VvQTXOi4yKnZJ1zql1-170x255.jpg', 'genre': ['Action', ' Coming Soon', ' Drama'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=qSqVVswa420', 'watch': 'https://lk21online.online/top-gun-maverick-2020/'}, {'title': ' Antlers (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/tNule8bZ3PPU4uDHe1aAkOMu34W-170x255.jpg', 'genre': ['Coming Soon', ' Horror', ' Misteri'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=IEM5HW7q5dY', 'watch': 'https://lk21online.online/antlers-2020/'}, {'title': ' The Woman in the Window (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/gUnMWEtz07x5ZeNT7dOZpvDK8Hb-170x255.jpg', 'genre': ['Coming Soon', ' Crime', ' Drama', ' Misteri'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=J0hTmzISOlQ', 'watch': 'https://lk21online.online/the-woman-in-the-window-2020/'}, {'title': ' Fast & Furious 9 (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/01/8Qfp5l4lqqz961EOyW3yPrjXBjQ-170x255.jpg', 'genre': ['Action', ' Adventure', ' Coming Soon', ' Crime'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=B_5mSXIDb5s', 'watch': 'https://lk21online.online/fast-furious-9-2020/'}, {'title': ' No Time to Die (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2019/12/vd6w8M7ixwPHmiVauphyGVjkflA-170x255.jpg', 'genre': ['Adventure', ' Coming Soon', ' Crime', ' Thriller', ' United Kingdom'], 'rating': '', 'duration': ' null min', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=NQkO0Shirl8', 'watch': 'https://lk21online.online/no-time-to-die-2020/'}, {'title': ' The Conjuring 3 (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2019/12/7PKHmdFhC1umtsVT2fzIR3TmCzb-170x255.jpg', 'genre': ['Coming Soon', ' Horror', ' Misteri', ' Thriller'], 'rating': '', 'duration': ' null min', 'quality': 'HD', 'watch': 'https://lk21online.online/the-conjuring-3-2020/'}, {'title': ' Black Widow (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2019/12/sRhaJ6D3x6gQB0swrV0UDqMwHJu-170x255.jpg', 'genre': ['Action', ' Adventure', ' Coming Soon', ' Sci-Fi', ' Hungary', ' Norway', ' United Kingdom'], 'rating': '', 'duration': ' null min', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=RxAtuMu_ph4', 'watch': 'https://lk21online.online/black-widow-2020/'}, {'title': ' Habibie & Ainun 3 (2019)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2019/10/wdGAxdAtyjFuI4UgYebXJgiHHvi-170x255.jpg', 'genre': ['Coming Soon', ' Drama', ' Movie', ' Romance'], 'rating': '', 'duration': ' null min', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=CIP0esJ6MMs', 'watch': 'https://lk21online.online/habibie-ainun-3-2019/'}, {'title': ' The Art of Racing in the Rain (2019)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2019/08/Akx5MjXFj5KCz9QM6wWShOjN3oS-170x255.jpg', 'genre': ['Comedy', ' Coming Soon', ' Drama'], 'rating': ' 9', 'duration': ' 123 min', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=Dp2ufFO4QGg', 'watch': 'https://lk21online.online/the-art-of-racing-in-the-rain-2019/'}], 'page': 1} \ No newline at end of file From 8f1a6b3e78128e0737f540e535640e11c207cee0 Mon Sep 17 00:00:00 2001 From: josua1111 Date: Thu, 22 Apr 2021 14:08:52 +0700 Subject: [PATCH 150/164] Update tugas 7 Josuansef Pardede 1184091 DS --- Chapter02/{josuanseff.txt => joss.txt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Chapter02/{josuanseff.txt => joss.txt} (100%) diff --git a/Chapter02/josuanseff.txt b/Chapter02/joss.txt similarity index 100% rename from Chapter02/josuanseff.txt rename to Chapter02/joss.txt From f8e3299637bf669fcb816fd2747423ce605b8b6f Mon Sep 17 00:00:00 2001 From: josua1111 Date: Thu, 22 Apr 2021 15:25:19 +0700 Subject: [PATCH 151/164] update tugas 7 Josuansef Pardede 1184091 --- Chapter02/JosuansefTujuh_1184091.py | 7 ++++--- Chapter02/{joss.txt => joss} | 0 test_app.py | 8 ++++---- 3 files changed, 8 insertions(+), 7 deletions(-) rename Chapter02/{joss.txt => joss} (100%) diff --git a/Chapter02/JosuansefTujuh_1184091.py b/Chapter02/JosuansefTujuh_1184091.py index 7daa728..c71dbea 100644 --- a/Chapter02/JosuansefTujuh_1184091.py +++ b/Chapter02/JosuansefTujuh_1184091.py @@ -37,7 +37,7 @@ def run(self): def readfile(self): q=queue.get() - f = open(self.filenya, "r") + f = open(self.filenya, "r+") print("Cek konten isi file : "+f.read()) print("Selesai membaca file, eksekusi queue task done \n") queue.task_done() @@ -68,7 +68,7 @@ def run(self): def apijj(self): with self.rlock: - print('didalam rlock apiservice, akses web service...') + print('akses web service api...') url='https://api-lk21.herokuapp.com/comingsoon' response = requests.get(url) html=response.json() @@ -85,4 +85,5 @@ def createfile(self, konten): f = open(self.filenya, "x") f.write(str(konten)) f.close() - print('File sudah dibuat, selanjutnya, mau eksekusi event set') \ No newline at end of file + print('File sudah dibuat, selanjutnya, mau eksekusi event set') + diff --git a/Chapter02/joss.txt b/Chapter02/joss similarity index 100% rename from Chapter02/joss.txt rename to Chapter02/joss diff --git a/test_app.py b/test_app.py index 8414bec..fab4fdf 100644 --- a/test_app.py +++ b/test_app.py @@ -125,9 +125,9 @@ def readfile(self,filename): # respon=self.readfile('./nilai.txt') # self.assertNotRegex(respon, "Kosong") # - def readfile(self,nfile): - f = open(nfile, "r+") - return str(f.read()) + #def readfile(self,nfile): + # f = open(nfile, "r+") + # return str(f.read()) # def test_03_raviTiga1184040(self): # from Chapter02.raviTiga1184040 import raviTiga1184040, raviMenulis @@ -419,5 +419,5 @@ def test_07_josuanseftujuh1184091(self): threadjosuaproducer.start() threadjosuaconsumer.join() threadjosuaproducer.join() - respon=self.readfile('./Chapter02/joss.txt') + respon=self.readfile('./Chapter02/joss') self.assertNotRegex(respon, "kosong") \ No newline at end of file From ad06dcf8d2df81730543575448392ee4162ac74c Mon Sep 17 00:00:00 2001 From: josua1111 Date: Thu, 22 Apr 2021 15:37:46 +0700 Subject: [PATCH 152/164] update tugas 7 Josuansef Pardede 1184091 DS --- Chapter02/joss | 1 - 1 file changed, 1 deletion(-) delete mode 100644 Chapter02/joss diff --git a/Chapter02/joss b/Chapter02/joss deleted file mode 100644 index b2de42d..0000000 --- a/Chapter02/joss +++ /dev/null @@ -1 +0,0 @@ -{'result': [{'title': ' Tom Clancy’s Without Remorse (2021)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2021/03/s9VFcru4oAurVVK49jmpB35vVhZ-170x255.jpg', 'genre': ['Action', ' Coming Soon', ' Thriller'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=e-rw2cxFVLg', 'watch': 'https://lk21online.online/nonton-tom-clancys-without-remorse-2021-subtitle-indonesia/'}, {'title': ' Avatar 2 (2021)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/04/krOMOEjDpw3Mf2EuJb9OgmqD6ft-170x255.jpg', 'genre': ['Action', ' Adventure', ' Coming Soon', ' Sci-Fi'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=Tnj9E5I3DkM', 'watch': 'https://lk21online.online/avatar-2-2021/'}, {'title': ' Eternals (2021)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/04/uRc0RTpUszMFakhXouZzK1clLsb-170x255.jpg', 'genre': ['Action', ' Adventure', ' Coming Soon', ' Fantasy', ' Sci-Fi'], 'rating': '', 'duration': '', 'quality': 'HD', 'watch': 'https://lk21online.online/eternals-2021/'}, {'title': ' The Batman (2021)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/04/mi2oVlgujK5HYcujdXyKZkt4SpU-170x255.jpg', 'genre': ['Action', ' Coming Soon', ' Crime', ' Drama', ' Mystery'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=391277390', 'watch': 'https://lk21online.online/the-batman-2021/'}, {'title': ' Coming 2 America (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/Coming-2-America-2020-170x255.jpg', 'genre': ['Comedy', ' Coming Soon'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=gYYylfwQu-s', 'watch': 'https://lk21online.online/coming-2-america-2020/'}, {'title': ' Peter Rabbit 2: The Runaway (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/cycDz68DtTjJrDJ1fV8EBq2Xdpb-170x255.jpg', 'genre': ['Adventure', ' Animation', ' Comedy', ' Coming Soon', ' Australia'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=PWBcqCz7l_c', 'watch': 'https://lk21online.online/peter-rabbit-2-the-runaway-2020/'}, {'title': ' Morbius (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/i4v4Ew7SxJSGDFCVAINtKwieEzS-170x255.jpg', 'genre': ['Action', ' Adventure', ' Coming Soon', ' Drama'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=jLMBLuGJTsA', 'watch': 'https://lk21online.online/morbius-2020/'}, {'title': ' Jungle Cruise (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/bEFFj0KKtOIYbydhcxJSDq0hzg7-170x255.jpg', 'genre': ['Action', ' Adventure', ' Comedy', ' Coming Soon'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=Zsnp3WMX3AE', 'watch': 'https://lk21online.online/jungle-cruise-2020/'}, {'title': ' Ghostbusters: Afterlife (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/fMyCgXLYehlbiQPlcu7nG98GFZU-170x255.jpg', 'genre': ['Action', ' Comedy', ' Coming Soon', ' Drama'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=BGq1chBbc30', 'watch': 'https://lk21online.online/ghostbusters-afterlife-2020/'}, {'title': ' Minions: The Rise of Gru (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/wNDfjpamXnNOtPW2DVJoDDvfz54-170x255.jpg', 'genre': ['Adventure', ' Animation', ' Comedy', ' Coming Soon', ' France', ' Japan'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=54yAKyNkK7w', 'watch': 'https://lk21online.online/minions-the-rise-of-gru-2020/'}, {'title': ' Free Guy (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/1fdLUHWXhPlTSV6rBxhc3rsXHw-170x255.jpg', 'genre': ['Action', ' Adventure', ' Comedy', ' Coming Soon'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=X2m-08cOAbc', 'watch': 'https://lk21online.online/free-guy-2020/'}, {'title': ' In the Heights (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/uyX4XtWpp7cywg1DE7cdvNHsEAt-170x255.jpg', 'genre': ['Coming Soon', ' Drama', ' Music'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=U0CL-ZSuCrQ', 'watch': 'https://lk21online.online/in-the-heights-2020/'}, {'title': ' Top Gun: Maverick (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/i0FHyNF9VvQTXOi4yKnZJ1zql1-170x255.jpg', 'genre': ['Action', ' Coming Soon', ' Drama'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=qSqVVswa420', 'watch': 'https://lk21online.online/top-gun-maverick-2020/'}, {'title': ' Antlers (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/tNule8bZ3PPU4uDHe1aAkOMu34W-170x255.jpg', 'genre': ['Coming Soon', ' Horror', ' Misteri'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=IEM5HW7q5dY', 'watch': 'https://lk21online.online/antlers-2020/'}, {'title': ' The Woman in the Window (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/03/gUnMWEtz07x5ZeNT7dOZpvDK8Hb-170x255.jpg', 'genre': ['Coming Soon', ' Crime', ' Drama', ' Misteri'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=J0hTmzISOlQ', 'watch': 'https://lk21online.online/the-woman-in-the-window-2020/'}, {'title': ' Fast & Furious 9 (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2020/01/8Qfp5l4lqqz961EOyW3yPrjXBjQ-170x255.jpg', 'genre': ['Action', ' Adventure', ' Coming Soon', ' Crime'], 'rating': '', 'duration': '', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=B_5mSXIDb5s', 'watch': 'https://lk21online.online/fast-furious-9-2020/'}, {'title': ' No Time to Die (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2019/12/vd6w8M7ixwPHmiVauphyGVjkflA-170x255.jpg', 'genre': ['Adventure', ' Coming Soon', ' Crime', ' Thriller', ' United Kingdom'], 'rating': '', 'duration': ' null min', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=NQkO0Shirl8', 'watch': 'https://lk21online.online/no-time-to-die-2020/'}, {'title': ' The Conjuring 3 (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2019/12/7PKHmdFhC1umtsVT2fzIR3TmCzb-170x255.jpg', 'genre': ['Coming Soon', ' Horror', ' Misteri', ' Thriller'], 'rating': '', 'duration': ' null min', 'quality': 'HD', 'watch': 'https://lk21online.online/the-conjuring-3-2020/'}, {'title': ' Black Widow (2020)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2019/12/sRhaJ6D3x6gQB0swrV0UDqMwHJu-170x255.jpg', 'genre': ['Action', ' Adventure', ' Coming Soon', ' Sci-Fi', ' Hungary', ' Norway', ' United Kingdom'], 'rating': '', 'duration': ' null min', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=RxAtuMu_ph4', 'watch': 'https://lk21online.online/black-widow-2020/'}, {'title': ' Habibie & Ainun 3 (2019)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2019/10/wdGAxdAtyjFuI4UgYebXJgiHHvi-170x255.jpg', 'genre': ['Coming Soon', ' Drama', ' Movie', ' Romance'], 'rating': '', 'duration': ' null min', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=CIP0esJ6MMs', 'watch': 'https://lk21online.online/habibie-ainun-3-2019/'}, {'title': ' The Art of Racing in the Rain (2019)', 'thumbnail': 'https://lk21online.online/wp-content/uploads/2019/08/Akx5MjXFj5KCz9QM6wWShOjN3oS-170x255.jpg', 'genre': ['Comedy', ' Coming Soon', ' Drama'], 'rating': ' 9', 'duration': ' 123 min', 'quality': 'HD', 'trailer': 'https://www.youtube.com/watch?v=Dp2ufFO4QGg', 'watch': 'https://lk21online.online/the-art-of-racing-in-the-rain-2019/'}], 'page': 1} \ No newline at end of file From 8d43c488fd37f16bd37894de44eedb1dfde8d4af Mon Sep 17 00:00:00 2001 From: Vicky Safira Date: Thu, 22 Apr 2021 15:48:28 +0700 Subject: [PATCH 153/164] VickySafTujuh1184037 --- Chapter02/VickyTujuh1184037.py | 71 ++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 Chapter02/VickyTujuh1184037.py diff --git a/Chapter02/VickyTujuh1184037.py b/Chapter02/VickyTujuh1184037.py new file mode 100644 index 0000000..eec71aa --- /dev/null +++ b/Chapter02/VickyTujuh1184037.py @@ -0,0 +1,71 @@ +from threading import Thread +from queue import Queue +import os +import requests + +queue = Queue() +ayo = [] +apiurl ='https://kodepos-2d475.firebaseio.com/list_kotakab/p9.json?print=pretty' +response = requests.get(apiurl) +html=response.json() + +class vickysaf(Thread): + def __init__(self, namathread, filename): + Thread.__init__(self) + self.filename = os.path.join(os.path.dirname(__file__), filename) + self.namathread = namathread + + def mainapi(self): + string = "kertas:" + for i in range(len(html["paper"])): + sini = html["paper"][i]["buku"] + nomor = "\n"+str(i)+". " + string = string + nomor + sini + lagi.append(sini) + queue.put(lagi) + print(str(i)+". %s yg di append" % (sini)) + self.createfile(string) + self.kebelakang() + + def run(self): + print("Dimulai") + self.mainapi() + print("Selesai") + + def createfile(self, isi): + f = open(self.filename, "w") + f.write(str(isi)) + f.close() + + def read(self): + x = open(self.filename, "r") + print(x.read()) + x.close() + + def belakang(self): + kebelakang = queue.get() + dur = len(kebelakang) + while dur > 0: + print("hasil pop") + dur = dur -1 + self.read() + queue.task_done() + + + + + + + + + + + + + + + + + + + \ No newline at end of file From e92615b7a50ff53c94bbe7b0ef4d7022dde4c61d Mon Sep 17 00:00:00 2001 From: Vicky Safira Date: Thu, 22 Apr 2021 19:35:48 +0700 Subject: [PATCH 154/164] vickytujuh --- Chapter02/VickyTujuh1184037.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Chapter02/VickyTujuh1184037.py b/Chapter02/VickyTujuh1184037.py index eec71aa..add6524 100644 --- a/Chapter02/VickyTujuh1184037.py +++ b/Chapter02/VickyTujuh1184037.py @@ -4,7 +4,7 @@ import requests queue = Queue() -ayo = [] +coba = [] apiurl ='https://kodepos-2d475.firebaseio.com/list_kotakab/p9.json?print=pretty' response = requests.get(apiurl) html=response.json() @@ -21,8 +21,8 @@ def mainapi(self): sini = html["paper"][i]["buku"] nomor = "\n"+str(i)+". " string = string + nomor + sini - lagi.append(sini) - queue.put(lagi) + coba.append(sini) + queue.put(coba) print(str(i)+". %s yg di append" % (sini)) self.createfile(string) self.kebelakang() From bb57c1e74f1c376b0527b07c256942760484dc5f Mon Sep 17 00:00:00 2001 From: rizaluardi Date: Thu, 22 Apr 2021 23:29:22 +0700 Subject: [PATCH 155/164] Tugas 7 Rizaluardi1184102 --- Chapter02/RizaluardiTujuh1184102.py | 90 +++++++++++++++++++++++++++++ test_app.py | 31 ++++++---- 2 files changed, 111 insertions(+), 10 deletions(-) create mode 100644 Chapter02/RizaluardiTujuh1184102.py diff --git a/Chapter02/RizaluardiTujuh1184102.py b/Chapter02/RizaluardiTujuh1184102.py new file mode 100644 index 0000000..480f51a --- /dev/null +++ b/Chapter02/RizaluardiTujuh1184102.py @@ -0,0 +1,90 @@ +# -*- coding: utf-8 -*- +""" +Created on Thu Apr 22 21:39:32 2021 + +@author: Rizaluardi +""" +import threading +import requests +import os +from queue import Queue + +queue = Queue() +event = threading.Event() + +class RizaluardiIms(threading.Thread): + def __init__(self,name,filename): + threading.Thread.__init__(self) + self.name = name + self.threadLock = threading.Lock() + self.filename = os.path.join(os.path.dirname(__file__), filename) + + def run(self): + print("\n" + self.name + "mulai.") + self.threadLock.acquire() + print('Nama_Provinsi_Di_Indonesia') + event.wait() + print('ubah : '+self.filename) + self.bacafile() + print("data provinsi berubah") + self.buatfile() + event.clear() + self.threadLock.release() + print("\n" + threading.currentThread().getName() + "bekerja!") + + def bacafile(self): + f = open(self.filename, "r") + print("isi filenya : \n "+f.read()) + + def buatfile(self): + f = open(self.filename, "r") + buat = open(self.filename+'.txt', "w") + for line in f: + buat.write(line.replace('provinsi', 'nama')) + buat.close() + new = open(self.filename+'.txt', "r") + print(new.read()) + new.close() + +class RizaluardiTujuh1184102(threading.Thread): + def __init__(self, name, filename): + threading.Thread.__init__(self) + self.name = name + self.rlock = threading.RLock() + self.filename = os.path.join(os.path.dirname(__file__), filename) + + def run(self): + print("\n"+ self.name + " mulai.") + self.main() + qj = queue.get() + print("\n antrian queuenya") + print(qj) + queue.task_done() + event.set() + print("\n" + threading.currentThread().getName() + "selesai.") + + def webapiprovinsi(self): + with self.rlock: + print('Webservice Api Jadwal Imsyak') + apiurl='https://dev.farizdotid.com/api/daerahindonesia/provinsi' + response = requests.get(apiurl) + html=response.json() + string = "" + for i in range(len(html["provinsi"])): + baru = html["provinsi"][i] + new = "\n"+str(i)+". " + string = string+new+str(baru) + queue.put(string) + self.createfile(string) + + def main(self): + with self.rlock: + self.webapiprovinsi() + + def createfile(self,isi): + print('Create File : '+ self.filename) + f = open(self.filename, "w") + f.write(str(isi)) + f.close() + + \ No newline at end of file diff --git a/test_app.py b/test_app.py index 8e887f5..bbd6411 100644 --- a/test_app.py +++ b/test_app.py @@ -400,13 +400,24 @@ def readfile(self,nfile): # respon=self.readfile('./Chapter02/apigempa.txt') # self.assertNotRegex(respon, "kosong") - def test_07_idaTujuh1184113(self): - from Chapter02.IdaTujuh1184113 import idaTujuh1184113,Director - threadutama = idaTujuh1184113("Thread Utama ", 2,5,5,'ida') - threaddirector= Director("Thread Director ", 1,'ida') - threaddirector.start() - threadutama.start() - threaddirector.join() - threadutama.join() - respon=self.readfile('./Chapter02/ida.txt') - self.assertNotRegex(respon, "kosong") \ No newline at end of file + #def test_07_idaTujuh1184113(self): + # from Chapter02.IdaTujuh1184113 import idaTujuh1184113,Director + # threadutama = idaTujuh1184113("Thread Utama ", 2,5,5,'ida') + # threaddirector= Director("Thread Director ", 1,'ida') + # threaddirector.start() + # threadutama.start() + # threaddirector.join() + # threadutama.join() + # respon=self.readfile('./Chapter02/ida.txt') + # self.assertNotRegex(respon, "kosong") + + def test_07_rizaluarditujuh_1184102(self): + from Chapter02.RizaluardiTujuh1184102 import RizaluardiIms,RizaluardiTujuh1184102 + nganu1 = RizaluardiIms("Thread 1", 'provinsi') + nganu2 = RizaluardiTujuh1184102("Thread 2",'provinsi') + nganu1.start() + nganu2.start() + nganu1.join() + nganu2.join() + respon=self.readfile('./Chapter02/provinsi') + self.assertNotRegex(respon, "Jangan kosong datanya") \ No newline at end of file From fa4a4b1fdd01ca570c4fade3fc0c6ed320155b90 Mon Sep 17 00:00:00 2001 From: IraDwita Date: Thu, 22 Apr 2021 23:30:07 +0700 Subject: [PATCH 156/164] Perbaikan Tugas Ira --- Chapter02/ira | 1 - Chapter02/ira.txt | 1 - 2 files changed, 2 deletions(-) delete mode 100644 Chapter02/ira delete mode 100644 Chapter02/ira.txt diff --git a/Chapter02/ira b/Chapter02/ira deleted file mode 100644 index aa91386..0000000 --- a/Chapter02/ira +++ /dev/null @@ -1 +0,0 @@ -[{'breeds': [], 'id': '3sm', 'url': 'https://cdn2.thecatapi.com/images/3sm.jpg', 'width': 480, 'height': 320}] \ No newline at end of file diff --git a/Chapter02/ira.txt b/Chapter02/ira.txt deleted file mode 100644 index f1936a1..0000000 --- a/Chapter02/ira.txt +++ /dev/null @@ -1 +0,0 @@ -[{'breeds': [], 'categories': [{'id': 1, 'name': 'hats'}], 'id': '37a', 'url': 'https://cdn2.thecatapi.com/images/37a.gif', 'width': 500, 'height': 375}] \ No newline at end of file From 6e0cf39a6495ef49f943a6d25349cc3b79e87003 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 23 Apr 2021 00:34:58 +0700 Subject: [PATCH 157/164] Tugas7Diar1184083 --- Chapter02/DiarTujuh1184083.py | 89 +++++++++++++++++++++++++++++++++++ Chapter02/kodepos | 15 ++++++ Chapter02/kodepos.txt | 15 ++++++ test_app.py | 31 ++++++++---- 4 files changed, 140 insertions(+), 10 deletions(-) create mode 100644 Chapter02/DiarTujuh1184083.py create mode 100644 Chapter02/kodepos create mode 100644 Chapter02/kodepos.txt diff --git a/Chapter02/DiarTujuh1184083.py b/Chapter02/DiarTujuh1184083.py new file mode 100644 index 0000000..e59772a --- /dev/null +++ b/Chapter02/DiarTujuh1184083.py @@ -0,0 +1,89 @@ +import threading +import requests +import os +from queue import Queue + +queue = Queue() +event = threading.Event() + +class DiarQue(threading.Thread): + def __init__(self,name, filename): + threading.Thread.__init__(self) + self.name = name + self.threadLock = threading.Lock() + self.filename = os.path.join(os.path.dirname(__file__), filename) + + def run(self): + print("\n"+ self.name + "Start") + self.threadLock.acquire() + print('kodekabupaten') + event.wait() + print('ubah : '+self.filename) + self.baca() + print("kode sudah diubah") + self.buat() + event.clear() + self.threadLock.release() + print("\n" + threading.currentThread().getName() + "berhasil") + + def baca(self): + f = open(self.filename, "r") + print("isi file : \n "+f.read()) + + def buat(self): + f = open(self.filename, "r") + bikin = open(self.filename+'.txt', "w") + for line in f: + bikin.write(line.replace('kodepos', 'kabupaten')) + bikin.close() + new = open(self.filename+'.txt', "r") + print(new.read()) + new.close() + + +class DiarTujuh1184083 (threading.Thread): + def __init__(self, name, filename): + threading.Thread.__init__(self) + self.threadLock = threading.Lock() + self.name = name + self.rlock = threading.RLock() + self.filename=os.path.join(os.path.dirname(__file__), filename) + + + def run(self): + print("\n"+ self.name + " Start") + self.main() + cb = queue.get() + print("\n queuenya") + print(cb) + queue.task_done() + event.set() + print("\n" + threading.currentThread().getName() + "Finish") + + def webapi(self): + with self.rlock: + print('Webservice nya') + apiurl='https://nbc.vanmason.web.id/service/kodepos/42173' + response = requests.get(apiurl) + html=response.json() + string = "" + for i in range(len(html["kodepos"])): + baru = html["kodepos"][i]["kabupaten"] + new = "\n"+str(i)+". " + string = string+new+str(baru) + queue.put(string) + self.createfile(string) + + + def main(self): + with self.rlock: + self.webapi() + + def createfile(self,isi): + print('Create File : '+ self.filename) + f = open(self.filename, "w") + f.write(str(isi)) + f.close() + + + diff --git a/Chapter02/kodepos b/Chapter02/kodepos new file mode 100644 index 0000000..2cdb19f --- /dev/null +++ b/Chapter02/kodepos @@ -0,0 +1,15 @@ + +0. Serang +1. Serang +2. Serang +3. Serang +4. Serang +5. Serang +6. Serang +7. Serang +8. Serang +9. Serang +10. Serang +11. Serang +12. Serang +13. Serang \ No newline at end of file diff --git a/Chapter02/kodepos.txt b/Chapter02/kodepos.txt new file mode 100644 index 0000000..2cdb19f --- /dev/null +++ b/Chapter02/kodepos.txt @@ -0,0 +1,15 @@ + +0. Serang +1. Serang +2. Serang +3. Serang +4. Serang +5. Serang +6. Serang +7. Serang +8. Serang +9. Serang +10. Serang +11. Serang +12. Serang +13. Serang \ No newline at end of file diff --git a/test_app.py b/test_app.py index 8e887f5..35a094a 100644 --- a/test_app.py +++ b/test_app.py @@ -400,13 +400,24 @@ def readfile(self,nfile): # respon=self.readfile('./Chapter02/apigempa.txt') # self.assertNotRegex(respon, "kosong") - def test_07_idaTujuh1184113(self): - from Chapter02.IdaTujuh1184113 import idaTujuh1184113,Director - threadutama = idaTujuh1184113("Thread Utama ", 2,5,5,'ida') - threaddirector= Director("Thread Director ", 1,'ida') - threaddirector.start() - threadutama.start() - threaddirector.join() - threadutama.join() - respon=self.readfile('./Chapter02/ida.txt') - self.assertNotRegex(respon, "kosong") \ No newline at end of file + # def test_07_idaTujuh1184113(self): + # from Chapter02.IdaTujuh1184113 import idaTujuh1184113,Director + # threadutama = idaTujuh1184113("Thread Utama ", 2,5,5,'ida') + # threaddirector= Director("Thread Director ", 1,'ida') + # threaddirector.start() + # threadutama.start() + # threaddirector.join() + # threadutama.join() + # respon=self.readfile('./Chapter02/ida.txt') + # self.assertNotRegex(respon, "kosong") + + def test_07_DiarTujuh1184083(self): + from Chapter02.DiarTujuh1184083 import DiarQue,DiarTujuh1184083 + ti = DiarQue("Thread 1 ",'kodepos') + tl = DiarTujuh1184083("Thread 2",'kodepos') + ti.start() + tl.start() + ti.join() + tl.join() + respon=self.readfile('./Chapter02/kodepos') + self.assertNotRegex(respon, "Gak Boleh Kosong") \ No newline at end of file From f1fa8d7103478e181955e6f004019c1a37585eb8 Mon Sep 17 00:00:00 2001 From: Vicky Safira Date: Fri, 23 Apr 2021 05:51:28 +0700 Subject: [PATCH 158/164] vickytugas --- test_app.py | 108 +--------------------------------------------------- 1 file changed, 1 insertion(+), 107 deletions(-) diff --git a/test_app.py b/test_app.py index 68ce60f..4a94a87 100644 --- a/test_app.py +++ b/test_app.py @@ -34,49 +34,6 @@ def tearDown(self): # from Chapter02.Rizaluardi1184102 import main # response = main() # self.assertEqual(response, True) - - - # def test_02_zanwar_1184050(self): - # from Chapter02.Zanwar1184050 import main - # response = main() - # self.assertEqual(response, True) - - - def test_02_ferdy_1184112(self): - from Chapter02.Ferdy1184112 import main - response = main() - self.assertEqual(response, True) - - def test_02_ida_1184113(self): - from Chapter02.Ida1184113 import main - response = main() - self.assertEqual(response, True) - - def test_02_okky_1184087(self): - from Chapter02.okky1184087 import main - response = main() - self.assertEqual(response, True) - - def test_02_vicky_1184037(self): - from Chapter02.vicky1184037 import main - response = main() - - #def test_02_ferdy_1184112(self): - # from Chapter02.Ferdy1184112 import main - # response = main() - # self.assertEqual(response, True) - - #def test_02_ida_1184113(self): - # from Chapter02.Ida1184113 import main - # response = main() - # self.assertEqual(response, True) - - #def test_02_okky_1184087(self): - # from Chapter02.okky1184087 import main - # response = main() - # self.assertEqual(response, True) - - def readfile(self,filename): @@ -231,19 +188,6 @@ def readfile(self,filename): # self.assertEqual(response, True) - #def test_06_parhan_1184042(self): - # from Chapter02.ParhanEnam1184042 import main - # response = main() - # self.assertEqual(response, True) - - #def test_06_Vicky_1184037(self): - # from Chapter02.VickyEnam1184037 import main - # response = main() - # self.assertEqual(response, True) - -#<<<<<<< HEAD - - # def test_06_parhan_1184042(self): # from Chapter02.ParhanEnam1184042 import main @@ -251,7 +195,6 @@ def readfile(self,filename): # self.assertEqual(response, True) - # def test_06_parhan_1184042(self): #from Chapter02.ParhanEnam1184042 import main #response = main() @@ -275,17 +218,6 @@ def readfile(self,filename): # self.assertEqual(response, True) - #def test_06_WahyuKurniaSari_1184001(self): - # from Chapter02.WahyuKurniaSariEnam1184001 import main - # result=main() - # self.assertEqual(result, True) - - #def test_06_Vicky_1184037(self): - # from Chapter02.VickyEnam1184037 import main - # result=main() - # self.assertEqual(result, True) - - #def test_06_WahyuKurniaSari_1184001(self): @@ -295,23 +227,12 @@ def readfile(self,filename): # self.assertEqual(result, True) - #def test_06_WahyuKurniaSari_1184001(self): #from Chapter02.WahyuKurniaSariEnam1184001 import main #result=main() #self.assertEqual(result, True) - #def test_06_ira_1184024(self): - # from Chapter02.IraEnam1184024 import main - # response = main() - # self.assertEqual(response, True) - - - #from Chapter02.WahyuKurniaSariEnam1184001 import main - #result=main() - #self.assertEqual(result, True) - # def test_06_ira_1184024(self): # from Chapter02.IraEnam1184024 import main # response = main() @@ -329,12 +250,6 @@ def readfile(self,filename): # self.assertEqual(response, True) - #def test_06_rizaluardi_1184102(self): - # from Chapter02.RizaluardiEnam1184102 import main - # result=main() - # self.assertEqual(result, True) - - # def test_06_rizaluardi_1184102(self): # from Chapter02.RizaluardiEnam1184102 import main # result=main() @@ -396,12 +311,6 @@ def readfile(self,filename): # respon=self.readfile('./Chapter02/pokemon.txt') # self.assertNotRegex(respon, "Kosong") - - #def test_06_bahar_1184002(self): - # from Chapter02.baharenam1184002 import main - # response = main() - # self.assertEqual(response, True) - # def test_06_bahar_1184002(self): # from Chapter02.baharenam1184002 import main # response = main() @@ -413,7 +322,6 @@ def readfile(self,filename): # self.assertEqual(response, True) - # def test_07_raviTujuh1184040(self): # from Chapter02.raviTujuh1184040 import raviTujuh1184040,raviMenulis # threadutama = raviTujuh1184040("Thread Utama ", 2,5,5,'ravi') @@ -447,15 +355,6 @@ def readfile(self,filename): # respon=self.readfile('./Chapter02/ravi.txt') # self.assertNotRegex(respon, "kosong") - - #def test_07_AnisaTujuh1184016(self): - # from Chapter02.AnisaRosalinaTujuh1184016 import Anisa - # thread1 = Anisa("Thread Put", 1, "Cocktile") - # thread1.start() - # thread1.join() - # respon=self.readfile('./Chapter02/Cocktile.txt') - # self.assertNotRegex(respon, "Kosong") - # def test_07_AnisaTujuh1184016(self): # from Chapter02.AnisaRosalinaTujuh1184016 import Anisa # thread1 = Anisa("Thread Put", 1, "Cocktile") @@ -464,7 +363,6 @@ def readfile(self,filename): # respon=self.readfile('./Chapter02/Cocktile.txt') # self.assertNotRegex(respon, "Kosong") - # def test_07_AnisaTujuh1184016(self): # from Chapter02.AnisaRosalinaTujuh1184016 import Anisa # thread1 = Anisa("Thread Put", 1, "Cocktile") @@ -547,10 +445,6 @@ def readfile(self,filename): # threadutama.start() # threadhandling.join() # threadutama.join() - - # respon=self.readfile('./Chapter02/ida.txt') - # self.assertNotRegex(respon, "kosong") - # respon=self.readfile('./Chapter02/ira.txt') # self.assertNotRegex(respon, "kosong") @@ -560,4 +454,4 @@ def test_07_vickyTujuh1184037(self): thread1.start() thread1.join() respon=self.readfile('./Chapter02/vicky') - self.assertNotRegex(respon, "Kosong" \ No newline at end of file + self.assertNotRegex(respon, "Kosong") \ No newline at end of file From 478cc635fe75cd979cae95c640b29830fcfda22e Mon Sep 17 00:00:00 2001 From: Vicky Safira Date: Fri, 23 Apr 2021 06:07:53 +0700 Subject: [PATCH 159/164] vickybaru --- Chapter02/VickyTujuh1184037.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Chapter02/VickyTujuh1184037.py b/Chapter02/VickyTujuh1184037.py index a2cd9cc..40438c0 100644 --- a/Chapter02/VickyTujuh1184037.py +++ b/Chapter02/VickyTujuh1184037.py @@ -5,7 +5,7 @@ queue = Queue() lagi = [] -apiurl ='https://kodepos-2d475.firebaseio.com/list_kotakab/p9.json?print=pretty' +apiurl ='https://data.covid19.go.id/public/api/prov.json' response = requests.get(apiurl) html=response.json() From 9ed97c8e34df1293692d5f93c4eb40524e2d71f8 Mon Sep 17 00:00:00 2001 From: Vicky Safira Date: Fri, 23 Apr 2021 06:18:14 +0700 Subject: [PATCH 160/164] vickylagi --- Chapter02/VickyTujuh1184037.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Chapter02/VickyTujuh1184037.py b/Chapter02/VickyTujuh1184037.py index 40438c0..e0133dd 100644 --- a/Chapter02/VickyTujuh1184037.py +++ b/Chapter02/VickyTujuh1184037.py @@ -5,7 +5,7 @@ queue = Queue() lagi = [] -apiurl ='https://data.covid19.go.id/public/api/prov.json' +apiurl ='https://kodepos-2d475.firebaseio.com/list_propinsi.json?print=pretty' response = requests.get(apiurl) html=response.json() From 6f77c9328ea6d5776f3dcf016249f132983e0303 Mon Sep 17 00:00:00 2001 From: Vicky Safira Date: Fri, 23 Apr 2021 06:26:04 +0700 Subject: [PATCH 161/164] vickysafiraa --- Chapter02/tugas7 vicky.py | 62 --------------------------------------- 1 file changed, 62 deletions(-) delete mode 100644 Chapter02/tugas7 vicky.py diff --git a/Chapter02/tugas7 vicky.py b/Chapter02/tugas7 vicky.py deleted file mode 100644 index 1d34744..0000000 --- a/Chapter02/tugas7 vicky.py +++ /dev/null @@ -1,62 +0,0 @@ -from threading import Thread -from queue import Queue -import requests -import os - -queue=Queue() -coba=[] -apiurl = 'https://koreanjson.com/users' -response = requests.get(apiurl) -html = response.json() - -class vickyqueue(Thread): - def __init__(self,namathread): - Thread.__init__(self) - self.namathread=namathread - - - def webservices(self): - for i in range(len(html)): - link = html[i]["username"] - coba.append(link) - queue.put(coba) - - - def run(self): - print("queue mulai \n") - self.webservices() - - -class vickysafira(Thread): - def __init__(self,namathread,filename): - Thread.__init__(self) - self.namathread=namathread - self.filename=filename - - - def readfile(): - f = open(self.filename+".txt","r") - f.close() - - - def createfile(isi): - print('Create File : '+self.filename) - f = open(self.filename, "w") - f.write(str(isi)) - f.close() - - - def hasil(self): - for j in range(len(html)): - aku=coba.pop() - self.createfile() - queue.get() - queue.task_done() - print("baca file"+self.filename+".txt") - self.readfile() - - - def run(self): - self.hasil() - print("selesai") - From f87f0dfa1ea3e2b3de849e595a6427df2238d6e3 Mon Sep 17 00:00:00 2001 From: Vicky Safira Date: Fri, 23 Apr 2021 07:07:51 +0700 Subject: [PATCH 162/164] VickyTujuh1184037 --- Chapter02/VickyTujuh1184037.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Chapter02/VickyTujuh1184037.py b/Chapter02/VickyTujuh1184037.py index e0133dd..e11c3e3 100644 --- a/Chapter02/VickyTujuh1184037.py +++ b/Chapter02/VickyTujuh1184037.py @@ -5,7 +5,7 @@ queue = Queue() lagi = [] -apiurl ='https://kodepos-2d475.firebaseio.com/list_propinsi.json?print=pretty' +apiurl ='https://www.thecocktaildb.com/api/json/v1/1/list.php?i=list' response = requests.get(apiurl) html=response.json() @@ -16,9 +16,9 @@ def __init__(self, namathread, filename): self.namathread = namathread def mainapi(self): - string = "kertas:" - for i in range(len(html["pena"])): - sini = html["pena"][i]["strBuku"] + string = "nama kota:" + for i in range(len(html["city"])): + sini = html["city"][i]["strIngredient1"] nomor = "\n"+str(i)+". " string = string + nomor + sini lagi.append(sini) From aa6b87dbbaefb1b382c302346acb3ae90f77d722 Mon Sep 17 00:00:00 2001 From: Vicky Safira Date: Fri, 23 Apr 2021 08:05:39 +0700 Subject: [PATCH 163/164] safira --- Chapter02/VickyTujuh11840372.py | 52 +++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 Chapter02/VickyTujuh11840372.py diff --git a/Chapter02/VickyTujuh11840372.py b/Chapter02/VickyTujuh11840372.py new file mode 100644 index 0000000..3f2e76d --- /dev/null +++ b/Chapter02/VickyTujuh11840372.py @@ -0,0 +1,52 @@ +from threading import Thread +from queue import Queue +import os +import requests + +queue = Queue() +lagi = [] +apiurl ='https://www.thecocktaildb.com/api/json/v1/1/list.php?i=list' +response = requests.get(apiurl) +html=response.json() + +class vickysaf(Thread): + def _init_(self, namathread, filename): + Thread._init_(self) + self.filename = os.path.join(os.path.dirname(_file_), filename) + self.namathread = namathread + + def mainapi(self): + string = "list berbagai macam minuman yang tersedia:" + for i in range(len(html["drinks"])): + sini = html["drinks"][i]["strIngredient1"] + nomor = "\n"+str(i)+". " + string = string + nomor + sini + lagi.append(sini) + queue.put(lagi) + print(str(i)+". %s yg di append" % (sini)) + self.createfile(string) + self.belakang() + + def run(self): + print("Dimulai") + self.mainapi() + print("Selesai") + + def createfile(self, isi): + f = open(self.filename, "w") + f.write(str(isi)) + f.close() + + def read(self): + x = open(self.filename, "r") + print(x.read()) + x.close() + + def belakang(self): + kebelakang = queue.get() + dur = len(kebelakang) + while dur > 0: + print("hasil pop") + dur = dur -1 + self.read() + queue.task_done() \ No newline at end of file From 0e8d6f57a27b8d9ec2f4eab820ff9e587fd97c6f Mon Sep 17 00:00:00 2001 From: Vicky Safira Date: Fri, 23 Apr 2021 09:52:56 +0700 Subject: [PATCH 164/164] VickyTujuhh1184037 --- Chapter02/VickyTujuh11840372.py | 52 ---------------- Chapter02/vicky | 101 ++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+), 52 deletions(-) delete mode 100644 Chapter02/VickyTujuh11840372.py create mode 100644 Chapter02/vicky diff --git a/Chapter02/VickyTujuh11840372.py b/Chapter02/VickyTujuh11840372.py deleted file mode 100644 index 3f2e76d..0000000 --- a/Chapter02/VickyTujuh11840372.py +++ /dev/null @@ -1,52 +0,0 @@ -from threading import Thread -from queue import Queue -import os -import requests - -queue = Queue() -lagi = [] -apiurl ='https://www.thecocktaildb.com/api/json/v1/1/list.php?i=list' -response = requests.get(apiurl) -html=response.json() - -class vickysaf(Thread): - def _init_(self, namathread, filename): - Thread._init_(self) - self.filename = os.path.join(os.path.dirname(_file_), filename) - self.namathread = namathread - - def mainapi(self): - string = "list berbagai macam minuman yang tersedia:" - for i in range(len(html["drinks"])): - sini = html["drinks"][i]["strIngredient1"] - nomor = "\n"+str(i)+". " - string = string + nomor + sini - lagi.append(sini) - queue.put(lagi) - print(str(i)+". %s yg di append" % (sini)) - self.createfile(string) - self.belakang() - - def run(self): - print("Dimulai") - self.mainapi() - print("Selesai") - - def createfile(self, isi): - f = open(self.filename, "w") - f.write(str(isi)) - f.close() - - def read(self): - x = open(self.filename, "r") - print(x.read()) - x.close() - - def belakang(self): - kebelakang = queue.get() - dur = len(kebelakang) - while dur > 0: - print("hasil pop") - dur = dur -1 - self.read() - queue.task_done() \ No newline at end of file diff --git a/Chapter02/vicky b/Chapter02/vicky new file mode 100644 index 0000000..c574199 --- /dev/null +++ b/Chapter02/vicky @@ -0,0 +1,101 @@ +nama kota: +0. Light rum +1. Applejack +2. Gin +3. Dark rum +4. Sweet Vermouth +5. Strawberry schnapps +6. Scotch +7. Apricot brandy +8. Triple sec +9. Southern Comfort +10. Orange bitters +11. Brandy +12. Lemon vodka +13. Blended whiskey +14. Dry Vermouth +15. Amaretto +16. Tea +17. Champagne +18. Coffee liqueur +19. Bourbon +20. Tequila +21. Vodka +22. Añejo rum +23. Bitters +24. Sugar +25. Kahlua +26. demerara Sugar +27. Dubonnet Rouge +28. Watermelon +29. Lime juice +30. Irish whiskey +31. Apple brandy +32. Carbonated water +33. Cherry brandy +34. Creme de Cacao +35. Grenadine +36. Port +37. Coffee brandy +38. Red wine +39. Rum +40. Grapefruit juice +41. Ricard +42. Sherry +43. Cognac +44. Sloe gin +45. Apple juice +46. Pineapple juice +47. Lemon juice +48. Sugar syrup +49. Milk +50. Strawberries +51. Chocolate syrup +52. Yoghurt +53. Mango +54. Ginger +55. Lime +56. Cantaloupe +57. Berries +58. Grapes +59. Kiwi +60. Tomato juice +61. Cocoa powder +62. Chocolate +63. Heavy cream +64. Galliano +65. Peach Vodka +66. Ouzo +67. Coffee +68. Spiced rum +69. Water +70. Espresso +71. Angelica root +72. Orange +73. Cranberries +74. Johnnie Walker +75. Apple cider +76. Everclear +77. Cranberry juice +78. Egg yolk +79. Egg +80. Grape juice +81. Peach nectar +82. Lemon +83. Firewater +84. Lemonade +85. Lager +86. Whiskey +87. Absolut Citron +88. Pisco +89. Irish cream +90. Ale +91. Chocolate liqueur +92. Midori melon liqueur +93. Sambuca +94. Cider +95. Sprite +96. 7-Up +97. Blackberry brandy +98. Peppermint schnapps +99. Creme de Cassis \ No newline at end of file