-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutils.py
34 lines (28 loc) · 906 Bytes
/
utils.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
from os.path import join
from urllib.request import urlretrieve
def read_pages_from_env(replace_locale=True):
""" LOADING & PARSING PAGES FROM .ENV """
raw_pages = loads(getenv("pages"))
pages = []
for raw_page in raw_pages:
page_type = raw_page[0].lower().strip()
url = raw_page[1]
match page_type:
case "page":
func = parse_page
case "community":
func = parse_community
case _: # Default
func = parse_page
if replace_locale:
# Specify localisation
url = facebook_www_to_locale(url)
pages.append((func, url))
return pages
def save_image(event, image_url, img_dir):
if ".png" in image_url:
ext = ".png"
else:
ext = ".jpg"
print(event.uid)
urlretrieve(image_url, join(img_dir, event.uid + ext))