From 4664e82243311f65e8ddec933fe117e201e3ba6c Mon Sep 17 00:00:00 2001 From: ComicalBanana Date: Fri, 17 Jun 2022 22:06:44 +0700 Subject: [PATCH 1/4] Menambahkan testing --- testing/testing.py | 56 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 testing/testing.py diff --git a/testing/testing.py b/testing/testing.py new file mode 100644 index 0000000..f8752dc --- /dev/null +++ b/testing/testing.py @@ -0,0 +1,56 @@ +import unittest +import function.Scrapper as scrap +from tkinter import Widget +from unittest import IsolatedAsyncioTestCase +from asyncio import events + +class TestStringMethods(unittest.TestCase): + + def test_upper(self): + self.assertEqual('foo'.upper(), 'FOO') + + def test_isupper(self): + self.assertTrue('FOO'.isupper()) + self.assertFalse('Foo'.isupper()) + + def test_split(self): + s = 'hello world' + self.assertEqual(s.split(), ['hello', 'world']) + #check that s.split falls when the separator is not a string + with self.assertRaises(TypeError): + s.split(2) + + def test_decode(self): + self.assertEqual(scrap.decode_based64("dGVzdGluZw=="), 'testing') + + def test_episode(self): + self.assertEqual(scrap.selectEpisode("https://anoboy.online/episode/heroine-tarumono-kiraware-heroine-to-naisho-no-oshigoto-episode-001#")) + + def test_default_widget_size(self): + widget = Widget('The widget') + self.assertEqual(widget.size(), (1000, 800)) + + def setUp(self): + self.widget = Widget('The widget') + + def test_default_widget_size(self): + self.assertEqual(self.widget.size(), (50,50), + 'incorrect default size') + + def test_widget_resize(self): + self.widget.resize(100,150) + self.assertEqual(self.widget.size(), (100,150), + 'wrong size after resize') + + async def test_response(self): + events.append("test_response") + response = await self._async_connection.get("https://anoboy.online/") + self.assertEqual(response.status_code, 200) + self.addAsyncCleanup(self.on_cleanup) + + #def test_query(self): + # self.assertEqual(scrap.querySearch("1")) + +if __name__ == '__main__': + unittest.main() + \ No newline at end of file From 03244a6f52a77e14a312701fcab5774448fbb2e6 Mon Sep 17 00:00:00 2001 From: ComicalBanana Date: Fri, 24 Jun 2022 08:32:26 +0700 Subject: [PATCH 2/4] Menambahkan komen --- Anilistpars (1).py | 157 +++++++++++++++++++++++++++++++++++ testing/scrapper_test.py | 49 ++++++++--- testing/testing.py | 69 +++++---------- testing/web_scrapper_test.py | 25 +++--- 4 files changed, 229 insertions(+), 71 deletions(-) create mode 100644 Anilistpars (1).py diff --git a/Anilistpars (1).py b/Anilistpars (1).py new file mode 100644 index 0000000..50a7f82 --- /dev/null +++ b/Anilistpars (1).py @@ -0,0 +1,157 @@ +import os +import requests +import re, json +from sys import prefix +from html import unescape +from function.objectClass import Anime +from function import Scrapper +base_url = "https://anoboy.online/" + + +def login(): + print("LOGIN WITH ANILIST") + os.system(r'open "https://anilist.co/api/v2/oauth/authorize?client_id=7201&response_type=token"') + print("Open this url in the browser:\nhttps://anilist.co/api/v2/oauth/authorize?client_id=7201&response_type=token") + return input("Paste token here : ") + +def getUserId(token): + query = """ + query { + Viewer{ + id + name + } + } + """ + header = {'Authorization': 'Bearer ' + token, 'Content-Type': 'application/json', 'Accept': 'application/json'} + return requests.post('https://graphql.anilist.co',headers=header,json={'query' : query}) + +def saveMediaListEntry(id,token,status,episode): + query = """ + mutation ($mediaId: Int, $status: MediaListStatus, $episode : Int) { + SaveMediaListEntry (mediaId: $mediaId, status: $status, progress : $episode) { + media{ + title{ + userPreferred + } + } + status + progress + } + } + """ + var = { + "mediaId" : id, + "status" : status, + "episode" : episode + } + + header = {'Authorization': 'Bearer ' + token, 'Content-Type': 'application/json', 'Accept': 'application/json'} + return requests.post('https://graphql.anilist.co',headers=header,json={'query' : query, 'variables' : var}) + +def searchAnime(title,page=False): + if page: + query = """ + query ($title: String) { + Page(perPage:10){ + media (search: $title, type: ANIME){ + id + title { + romaji + english + } + description + status + nextAiringEpisode{ + airingAt + } + } + } + + } + """ + else: + query = """ + query ($title: String) { + Media (search: $title, type: ANIME){ + id + title { + romaji + english + } + description + status + nextAiringEpisode{ + airingAt + } + } + } + """ + variable = {'title' : title} + return requests.post(base_url, json={'query': query, 'variables': variable}) + +def searchAnimeId(id): + query = """ + query ($id: Int) { + Media (id: $id, type: ANIME){ + id + title { + romaji + english + } + description + status + nextAiringEpisode{ + airingAt + } + } + } + """ + variable = {'id' : id} + return requests.post(base_url, json={'query': query, 'variables': variable}) + +def getListOfAnime(user,status): + query = """ + query ($user: String, $status : [MediaListStatus]) { + MediaListCollection(userName : $user,status_in: $status, type : ANIME) { + lists{ + entries{ + media{ + title { + romaji + english + native + userPreferred + } + status + id + nextAiringEpisode{ + airingAt + } + } + progress + } + } + } + } + """ + variable = {'user' : user, 'status' : status} + return requests.post(base_url, json={'query': query, 'variables': variable}).content + +def checkMediaInUser(user,title): + title = searchAnime(title) + title = eval(title.content) + mediaId = title['data']['Media']['id'] + query = """ + query ($user: String, $mediaId : Int) { + MediaList(userName : $user, mediaId : $mediaId){ + media{ + title{ + userPreferred + } + } + } + } + """ + variable = {'user' : user, 'mediaId' : mediaId} + return requests.post(base_url, json={'query': query, 'variables': variable}) \ No newline at end of file diff --git a/testing/scrapper_test.py b/testing/scrapper_test.py index f544d8a..40bfbc9 100644 --- a/testing/scrapper_test.py +++ b/testing/scrapper_test.py @@ -1,24 +1,49 @@ import unittest import function.Scrapper as scrap +import function.Scrapper as Scrapper +import os class TestStringMethods(unittest.TestCase): - + + #Berfungsi untuk mengetes fungsi decode_base64 def test_decode(self): self.assertEqual(scrap.decode_base64("dGVzdGluZw=="), 'testing') - + + #Berfungsi untuk mengetes fungsi parse_web def test_parse(self): page = scrap.parse_web("https://example.com/") self.assertEqual(page.find('h1').text, "Example Domain") - # def test_isupper(self): - # self.assertTrue('FOO'.isupper()) - # self.assertFalse('Foo'.isupper()) - - # def test_split(self): - # s = 'hello world' - # self.assertEqual(s.split(), ['hello', 'world']) - # # check that s.split fails when the separator is not a string - # with self.assertRaises(TypeError): - # s.split(2) + + #Berfungsi untuk mengetes apakah bisa mendownload file + #apabila gambarnya tersedia + def test_downloadFilePictureExist(self): + dl = scrap.downloadFile("https://image.tmdb.org/t/p/original/oz5upj4Be6u0WVKFUOObEggNcJ5.jpg", './tmp/') + self.assert_(os.path.isfile("./tmp/oz5upj4Be6u0WVKFUOObEggNcJ5.jpg")) + + #Berfungsi untuk mengetes apakah bisa mendownload file + #apabila gambarnya tidak tersedia + def test_downloadFilePictureNotExist(self): + os.remove("./tmp/oz5upj4Be6u0WVKFUOObEggNcJ5.jpg") + dl = scrap.downloadFile("https://image.tmdb.org/t/p/original/oz5upj4Be6u0WVKFUOObEggNcJ5.jpg", './tmp/') + self.assert_(os.path.isfile("./tmp/oz5upj4Be6u0WVKFUOObEggNcJ5.jpg")) + + #Berfungsi untuk mengetes apakah bisa mendownload file + #apabila tidak ada gambarnya + def test_downloadFileNotPicture(self): + dl = scrap.downloadFile("https://github.com/RPL-Project-TelU/Ani-Scrap", "./tmp/") + self.assertEqual(dl, '') + + + '''data = { + "page" : 0, + "limit" : 21, + "action" : "load_search_movie", + "keyword" : "testing", + } + + page = Scrapper.urlEncode("https://anoboy.online/",data) + print(page)''' + if __name__ == '__main__': unittest.main() \ No newline at end of file diff --git a/testing/testing.py b/testing/testing.py index f8752dc..f84d60a 100644 --- a/testing/testing.py +++ b/testing/testing.py @@ -1,56 +1,29 @@ import unittest +import os import function.Scrapper as scrap -from tkinter import Widget -from unittest import IsolatedAsyncioTestCase -from asyncio import events +#import urllib.parse, os +#import cloudscraper,re,base64,requests,random +#from bs4 import BeautifulSoup + class TestStringMethods(unittest.TestCase): - - def test_upper(self): - self.assertEqual('foo'.upper(), 'FOO') + #Testing untuk api_get + '''def test_api(self)->requests.Response: + page = scrap.api_get()''' - def test_isupper(self): - self.assertTrue('FOO'.isupper()) - self.assertFalse('Foo'.isupper()) - - def test_split(self): - s = 'hello world' - self.assertEqual(s.split(), ['hello', 'world']) - #check that s.split falls when the separator is not a string - with self.assertRaises(TypeError): - s.split(2) - - def test_decode(self): - self.assertEqual(scrap.decode_based64("dGVzdGluZw=="), 'testing') - - def test_episode(self): - self.assertEqual(scrap.selectEpisode("https://anoboy.online/episode/heroine-tarumono-kiraware-heroine-to-naisho-no-oshigoto-episode-001#")) + def Test_downloadFile(self): + dl = scrap.downloadFile('https://image.tmdb.org/t/p/original/jjS7HGtulytWf4JQD5H53ou3RcM.jpg',"./tmp/") + self.assertEqual(dl, "jjS7HGtulytWf4JQD5H53ou3RcM.jpg") + + - def test_default_widget_size(self): - widget = Widget('The widget') - self.assertEqual(widget.size(), (1000, 800)) - def setUp(self): - self.widget = Widget('The widget') - - def test_default_widget_size(self): - self.assertEqual(self.widget.size(), (50,50), - 'incorrect default size') - - def test_widget_resize(self): - self.widget.resize(100,150) - self.assertEqual(self.widget.size(), (100,150), - 'wrong size after resize') - - async def test_response(self): - events.append("test_response") - response = await self._async_connection.get("https://anoboy.online/") - self.assertEqual(response.status_code, 200) - self.addAsyncCleanup(self.on_cleanup) - - #def test_query(self): - # self.assertEqual(scrap.querySearch("1")) -if __name__ == '__main__': - unittest.main() - \ No newline at end of file + + def testing_urlEncode(self)-> str: + self.assertEqual(scrap.urlEncode('https://anoboy.online/series/healer-girl')) + + + #Testing + + # Testing untuk apa \ No newline at end of file diff --git a/testing/web_scrapper_test.py b/testing/web_scrapper_test.py index ba6566c..acd20b1 100644 --- a/testing/web_scrapper_test.py +++ b/testing/web_scrapper_test.py @@ -1,19 +1,22 @@ import unittest import function.Scrapper as scrap -class TestStringMethods(unittest.TestCase): - pass - # def test_isupper(self): - # self.assertTrue('FOO'.isupper()) - # self.assertFalse('Foo'.isupper()) +class TestStringMethods(unittest.TestCase): - # def test_split(self): - # s = 'hello world' - # self.assertEqual(s.split(), ['hello', 'world']) - # # check that s.split fails when the separator is not a string - # with self.assertRaises(TypeError): - # s.split(2) + #Berfungsi untuk mengetes fungsi selectEpisode + def test_selectEpisode(self): + self.assertEqual(scrap.selectEpisode,"https://anoboy.online/episode/yuusha-yamemasu-episode-001") + + #Berfungsi untuk mengetes fungsi selectMirror + def test_selectMirror(self): + self.assertEqual(scrap.selectMirror,"https://core.arc.io/broker.html?94c5673") + + + + + + if __name__ == '__main__': unittest.main() \ No newline at end of file From fafb79ac6b6b5826259503d6f9ab9cfa5effa9bf Mon Sep 17 00:00:00 2001 From: Muhammad Rovino Sanjaya Date: Sat, 2 Jul 2022 01:57:31 +0700 Subject: [PATCH 3/4] Delete Anilistpars (1).py tidak masuk testing --- Anilistpars (1).py | 157 --------------------------------------------- 1 file changed, 157 deletions(-) delete mode 100644 Anilistpars (1).py diff --git a/Anilistpars (1).py b/Anilistpars (1).py deleted file mode 100644 index 50a7f82..0000000 --- a/Anilistpars (1).py +++ /dev/null @@ -1,157 +0,0 @@ -import os -import requests -import re, json -from sys import prefix -from html import unescape -from function.objectClass import Anime -from function import Scrapper -base_url = "https://anoboy.online/" - - -def login(): - print("LOGIN WITH ANILIST") - os.system(r'open "https://anilist.co/api/v2/oauth/authorize?client_id=7201&response_type=token"') - print("Open this url in the browser:\nhttps://anilist.co/api/v2/oauth/authorize?client_id=7201&response_type=token") - return input("Paste token here : ") - -def getUserId(token): - query = """ - query { - Viewer{ - id - name - } - } - """ - header = {'Authorization': 'Bearer ' + token, 'Content-Type': 'application/json', 'Accept': 'application/json'} - return requests.post('https://graphql.anilist.co',headers=header,json={'query' : query}) - -def saveMediaListEntry(id,token,status,episode): - query = """ - mutation ($mediaId: Int, $status: MediaListStatus, $episode : Int) { - SaveMediaListEntry (mediaId: $mediaId, status: $status, progress : $episode) { - media{ - title{ - userPreferred - } - } - status - progress - } - } - """ - var = { - "mediaId" : id, - "status" : status, - "episode" : episode - } - - header = {'Authorization': 'Bearer ' + token, 'Content-Type': 'application/json', 'Accept': 'application/json'} - return requests.post('https://graphql.anilist.co',headers=header,json={'query' : query, 'variables' : var}) - -def searchAnime(title,page=False): - if page: - query = """ - query ($title: String) { - Page(perPage:10){ - media (search: $title, type: ANIME){ - id - title { - romaji - english - } - description - status - nextAiringEpisode{ - airingAt - } - } - } - - } - """ - else: - query = """ - query ($title: String) { - Media (search: $title, type: ANIME){ - id - title { - romaji - english - } - description - status - nextAiringEpisode{ - airingAt - } - } - } - """ - variable = {'title' : title} - return requests.post(base_url, json={'query': query, 'variables': variable}) - -def searchAnimeId(id): - query = """ - query ($id: Int) { - Media (id: $id, type: ANIME){ - id - title { - romaji - english - } - description - status - nextAiringEpisode{ - airingAt - } - } - } - """ - variable = {'id' : id} - return requests.post(base_url, json={'query': query, 'variables': variable}) - -def getListOfAnime(user,status): - query = """ - query ($user: String, $status : [MediaListStatus]) { - MediaListCollection(userName : $user,status_in: $status, type : ANIME) { - lists{ - entries{ - media{ - title { - romaji - english - native - userPreferred - } - status - id - nextAiringEpisode{ - airingAt - } - } - progress - } - } - } - } - """ - variable = {'user' : user, 'status' : status} - return requests.post(base_url, json={'query': query, 'variables': variable}).content - -def checkMediaInUser(user,title): - title = searchAnime(title) - title = eval(title.content) - mediaId = title['data']['Media']['id'] - query = """ - query ($user: String, $mediaId : Int) { - MediaList(userName : $user, mediaId : $mediaId){ - media{ - title{ - userPreferred - } - } - } - } - """ - variable = {'user' : user, 'mediaId' : mediaId} - return requests.post(base_url, json={'query': query, 'variables': variable}) \ No newline at end of file From 8a7996826b0dfb372372a732c235e8f6aa33213a Mon Sep 17 00:00:00 2001 From: Muhammad Rovino Sanjaya Date: Sat, 2 Jul 2022 01:58:24 +0700 Subject: [PATCH 4/4] Delete scrapper_test.py sudah lengkap untuk file ini --- testing/scrapper_test.py | 49 ---------------------------------------- 1 file changed, 49 deletions(-) delete mode 100644 testing/scrapper_test.py diff --git a/testing/scrapper_test.py b/testing/scrapper_test.py deleted file mode 100644 index 40bfbc9..0000000 --- a/testing/scrapper_test.py +++ /dev/null @@ -1,49 +0,0 @@ -import unittest -import function.Scrapper as scrap -import function.Scrapper as Scrapper -import os - -class TestStringMethods(unittest.TestCase): - - #Berfungsi untuk mengetes fungsi decode_base64 - def test_decode(self): - self.assertEqual(scrap.decode_base64("dGVzdGluZw=="), 'testing') - - #Berfungsi untuk mengetes fungsi parse_web - def test_parse(self): - page = scrap.parse_web("https://example.com/") - self.assertEqual(page.find('h1').text, "Example Domain") - - #Berfungsi untuk mengetes apakah bisa mendownload file - #apabila gambarnya tersedia - def test_downloadFilePictureExist(self): - dl = scrap.downloadFile("https://image.tmdb.org/t/p/original/oz5upj4Be6u0WVKFUOObEggNcJ5.jpg", './tmp/') - self.assert_(os.path.isfile("./tmp/oz5upj4Be6u0WVKFUOObEggNcJ5.jpg")) - - #Berfungsi untuk mengetes apakah bisa mendownload file - #apabila gambarnya tidak tersedia - def test_downloadFilePictureNotExist(self): - os.remove("./tmp/oz5upj4Be6u0WVKFUOObEggNcJ5.jpg") - dl = scrap.downloadFile("https://image.tmdb.org/t/p/original/oz5upj4Be6u0WVKFUOObEggNcJ5.jpg", './tmp/') - self.assert_(os.path.isfile("./tmp/oz5upj4Be6u0WVKFUOObEggNcJ5.jpg")) - - #Berfungsi untuk mengetes apakah bisa mendownload file - #apabila tidak ada gambarnya - def test_downloadFileNotPicture(self): - dl = scrap.downloadFile("https://github.com/RPL-Project-TelU/Ani-Scrap", "./tmp/") - self.assertEqual(dl, '') - - - '''data = { - "page" : 0, - "limit" : 21, - "action" : "load_search_movie", - "keyword" : "testing", - } - - page = Scrapper.urlEncode("https://anoboy.online/",data) - print(page)''' - - -if __name__ == '__main__': - unittest.main() \ No newline at end of file