-
Notifications
You must be signed in to change notification settings - Fork 0
/
toonily.py
139 lines (123 loc) · 4.88 KB
/
toonily.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
"""Get email notifications of latest chapter of a manhwa/manga from toonily.com
using ezgmail module"""
import ctypes
import datetime
import os
import re
import time
import requests
import ezgmail
import pyperclip
# pylint: disable=no-else-break
class EndedManhwa(Exception):
"Manhwa ended already exception"
class ValidManhwa(Exception):
"""Manhwa is not valid exception"""
def main(link, chapter):
"""Main link chapter check"""
try:
req = requests.get(link, stream=True)
except requests.exceptions.RequestException:
return "Error trying again in 300 sec"
try:
if chapter in req.text:
# print(r.text)
return True
return False
except requests.exceptions.ChunkedEncodingError:
return False
def send_email(my_email, subject, body):
"""send email notification"""
while 1:
date_email = datetime.datetime.now().strftime("%b-%d-%Y %I:%M:%S %p")
try:
ezgmail.send(my_email, subject, body)
print(f'Success sending email {date_email}')
return
except ezgmail.EZGmailException:
print(f"Error Trying again in 10 sec, {date_email}")
time.sleep(10)
def check_valid(link):
"""check if manhwa is valid on toonily site"""
check_status = requests.get(link, stream=True)
if check_status.ok:
return
raise ValidManhwa(f"Not valid manhwa/manga link, make sure the manhwa url is valid\n",
f"{link}")
def is_ended(link, num):
"""check if manwha already ended"""
check_end = re.compile(r"Chapter \d* - The End")
try:
req = requests.get(link, stream=True).text
except requests.exceptions.RequestException:
return
result = check_end.search(req)
if result:
print(f"Manhwa homepage: {link}\n")
result = result.group()
req = result.split()
num_end = req[1]
if int(num) <= int(num_end):
ch_link = f"{link}chapter-{num}"
print("The link of the chapter number you entered below is copied\n")
print(ch_link)
ctypes.windll.user32.MessageBoxW(0, f"{ch_link}\nClose this window to finish copying",
f" the link",
f"Copying Chapter {num}", 0)
pyperclip.copy(ch_link)
else:
print(f"Invalid chapter {num}")
link = f"{link}chapter-{num_end}"
ctypes.windll.user32.MessageBoxW(0, f"Invalid chapter {num}, manhwa already ended ",
f"at chapter {num_end}\n",
f"{link}\nClose this window to finish ",
f"copying the link",
f"Copying Chapter {num_end}", 0)
pyperclip.copy(link)
raise EndedManhwa(f"Manhwa supposedly ended at chapter {num_end}, link: {link}")
return
if __name__ == '__main__':
import argparse
PATH = r"YOUR CLIENTCONFIG DIRECTORY PATH"
os.chdir(PATH)
PARSER = argparse.ArgumentParser()
PARSER.add_argument("-m", "--manhwa", required=True, help="enter the link of the "
"manga/manhwa")
PARSER.add_argument("-c", "--chapter", required=True, help="enter the chapter number")
PARSER.add_argument("-e", "--email", required=True, help="enter the email to send"
" notifications")
ARGS = vars(PARSER.parse_args())
MANWHA_LINK = ARGS['manhwa']
NUM = ARGS['chapter']
CHAPTER = "Chapter " + NUM
MY_EMAIL = ARGS['email']
# uncomment the block below if you don't want to use argparse
# and instead want to edit it directly
# manhwa_link = "https://toonily.com/webtoon/peerless-dad/"
# num = "100"
# chapter = "Chapter " + num
# my_email = "[email protected]"
MANHWA_NAME = MANWHA_LINK.split("/")[-2]
MANHWA_NAME = " ".join(MANHWA_NAME.split('-')).title()
# check if valid manhwa name or/and uploaded to toonily
check_valid(MANWHA_LINK)
# else check if manhwa already ended
CH_LINK = f"{MANWHA_LINK}chapter-{NUM}/"
is_ended(CH_LINK, NUM)
# else continue
while 1:
DT = datetime.datetime.now().strftime("%b-%d-%Y %I:%M:%S %p")
ANS = main(CH_LINK, CHAPTER)
if ANS is True:
SUBJECT = f"{MANHWA_NAME} {CHAPTER}"
BODY = f"{MANHWA_NAME} {CHAPTER} is updated {DT}, link: {CH_LINK}"
print(BODY)
is_ended(CH_LINK, NUM) # check if it already ended
send_email(my_email=MY_EMAIL, subject=SUBJECT, body=BODY)
break
elif ANS is False:
print(f"{MANHWA_NAME} {CHAPTER} is NOT updated yet {DT}")
else:
print(f"{ANS} date {DT}")
print("-" * 75)
time.sleep(300)