-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
123 lines (95 loc) · 4.23 KB
/
main.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
from os import getenv
from time import time
from dotenv import load_dotenv
from rich.progress import track
from rich.console import Console
from services import Sheet, Table, delete_webpage, list_webpages
from services.crawlers import CrawlerAnimesGratis
from services.crawlers import CrawlerAnimesOnline
from services.crawlers import CrawlerGoyabu
from services.crawlers import CrawlerBakashiTv
from services.crawlers import CrawlerAssistirAnimes
from services.crawlers import CrawlerAnimesHouse
load_dotenv()
# ------------------------------ Constants ----------------------------------- #
USER_NAME = getenv("USER_NAME")
SHEET_LINK = getenv("SHEET_LINK")
# ---------------------------------------------------------------------------- #
console = Console()
table = Table()
try:
sheet = Sheet()
except ValueError as ve:
print()
console.print(ve, style="bold red")
exit()
start = time()
animes_urls = sheet.get_anime_urls()
my_episodes = sheet.get_my_episodes()
last_episodesSheet = sheet.get_last_episodes()
last_episodesUpdated = []
last_episodesUrlsUpdated = []
for i in track(range(0, len(animes_urls)), description="[cyan]Atualizando..."):
# Verifica qual é o site que está sendo utilizado para assistir o anime.
if (animes_urls[i].find("animesonline") != -1):
crawler_animes_online = CrawlerAnimesOnline()
last_episode = crawler_animes_online.get_last_episode(animes_urls[i])
last_episode_url = crawler_animes_online.get_last_episode_url(animes_urls[i])
elif (animes_urls[i].find("animesgratis") != -1):
crawler_animes_gratis = CrawlerAnimesGratis()
last_episode = crawler_animes_gratis.get_last_episode(animes_urls[i])
last_episode_url = crawler_animes_gratis.get_last_episode_url(animes_urls[i])
elif (animes_urls[i].find("animeshouse")):
crawler_animes_house = CrawlerAnimesHouse()
last_episode = crawler_animes_house.get_last_episode(animes_urls[i])
last_episode_url = crawler_animes_house.get_last_episode_url(animes_urls[i])
elif (animes_urls[i].find("goyabu") != -1):
crawler_goyabu = CrawlerGoyabu()
last_episode = crawler_goyabu.get_last_episode(animes_urls[i])
last_episode_url = crawler_goyabu.get_last_episode_url(animes_urls[i])
elif (animes_urls[i].find("bakashi") != -1):
crawler_bakashi_tv = CrawlerBakashiTv()
last_episode = crawler_bakashi_tv.get_last_episode(animes_urls[i])
last_episode_url = crawler_bakashi_tv.get_last_episode_url(animes_urls[i])
elif (animes_urls[i].find("assistiranimes") != -1):
crawler_assistir_animes = CrawlerAssistirAnimes()
last_episode = crawler_assistir_animes.get_last_episode(animes_urls[i])
last_episode_url = crawler_assistir_animes.get_last_episode_url(animes_urls[i])
else:
print("Erro! Site não suportado.")
exit()
last_episodesUpdated.append(last_episode)
last_episodesUrlsUpdated.append(last_episode_url)
try:
# Evita escritas desnecessárias.
if (last_episodesSheet[i] != last_episode):
sheet.set_last_episode(i, last_episode)
sheet.set_last_episode_url(i, last_episode_url)
except IndexError:
if (my_episodes[i]):
sheet.set_last_episode(i, last_episode)
sheet.set_last_episode_url(i, last_episode_url)
sheet.change_cell_background_color(float(my_episodes[i]), float(last_episode), i)
# Remove as páginas web baixadas
for webpage in list_webpages():
delete_webpage(webpage)
# Preenchendo a tabela.
table.fill_table(
names = sheet.get_anime_names(),
seasons = sheet.get_anime_seasons(),
urls = animes_urls,
my_episodes = my_episodes,
last_episodes = last_episodesUpdated,
last_episodesUrls = last_episodesUrlsUpdated,
broadcasts = sheet.get_anime_broadcasts()
)
end = time()
execution_time = end - start
console.print(f"Tempo de execução: {execution_time:.2f}s\n", style="bold green")
if (USER_NAME != ""):
console.print(f"Planilha de animes atualizada com sucesso {USER_NAME}!", style="bold")
if (SHEET_LINK != ""):
print(f"Link: {SHEET_LINK}")
# Exibindo a tabela.
table.show_table()
print()