-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathfanobject.py
111 lines (99 loc) · 3.3 KB
/
fanobject.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
from cmd import PROMPT
import fandom
import requests
from bs4 import BeautifulSoup
import os
from dotenv import load_dotenv
import webbrowser
def get_fanobject():
load_dotenv()
content = {}
fandom.set_wiki(os.getenv("WIKI"))
fanobject_chosen = fandom.page(title=os.getenv("PROMPT"))
fanobject_body = fanobject_chosen.plain_text
fanobject_body_split = fanobject_body.split("\n")
del fanobject_body_split[0]
if len(fanobject_body_split) < 40:
j = fanobject_body_split
else:
j = fanobject_body_split[:40]
for i in range(len(j)):
print(f"{i}: {fanobject_body_split[i]}")
unnecesary = input(
"Please provide the number of the unnecesary lines in the beginning: ")
if not unnecesary == "":
unnecesary = unnecesary.split(",")
unnecesary = [int(x) for x in unnecesary]
for i in range(len(unnecesary)):
del j[int(unnecesary[i])]
unnecesary = [x-1 for x in unnecesary]
j = " ".join(j)
j = j.split('. ')
del j[len(j)-1]
if not os.getenv("INTRO") == "":
j.insert(0, os.getenv("INTRO"))
for i in range(len(j)):
print(f"{i}: {j[i]}")
try:
content["body"] = j
content["elements"] = len(j)
except AttributeError as e:
pass
return content
def get_pictures():
load_dotenv()
fandom.set_wiki(os.getenv("WIKI"))
fanobject_chosen = fandom.page(title=os.getenv("PROMPT"))
html_page = fanobject_chosen.html
images = []
soup = BeautifulSoup(html_page, 'html.parser')
warning = soup.find("div", class_="mw-parser-output")
if len(warning.findAll("img")) < 40:
j = warning.findAll("img")
else:
j = warning.findAll("img")[:40]
for links in j:
link = links.get("src")
if type(link) is str and not link.startswith("data"):
v: int = link.find("revision")
link = link[0:v]
try:
images.index(link)
continue
except ValueError:
images.append(link)
print(link)
for links in j:
link = links.get("data-src")
if type(link) is str and not link.startswith("data"):
v: int = link.find("revision")
link = link[0:v]
try:
images.index(link)
continue
except ValueError:
images.append(link)
print(link)
dir = "png/"
for f in os.listdir(dir):
os.remove(os.path.join(dir, f))
n = 0
for imgs in range(len(images)):
if images[imgs]:
response = requests.get(images[imgs])
if response.status_code:
fp = open(f"png/{n}.jpg", "wb")
fp.write(response.content)
fp.close()
n += 1
path = "png"
path = os.path.realpath(path)
webbrowser.open(path)
chosen_pictures = input(
f"From the newly opened window, please choose the pictures you would like to use in the video and write them here in order, comma separated (e.g.: 0,3,4,6): ")
chosen_pictures = chosen_pictures.split(",")
final_images = []
for i in range(len(chosen_pictures)):
final_images.append(images[int(chosen_pictures[i])])
n = len(chosen_pictures)
return n, chosen_pictures