-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetch.py
43 lines (30 loc) · 1 KB
/
fetch.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
import os
from datetime import datetime
from decouple import config
from tqdm.contrib.concurrent import thread_map
from utils import KindPortaalFetcher, clean_filename
SESSID = config('SESSID')
BASE_URL = config('BASE_URL')
START_MONTH = config('START_MONTH')
try:
start_date = datetime.strptime(START_MONTH, '%Y-%m')
except:
print("Invalid START_MONTH (try something like 2020-01)")
exit(1)
OUTPUT_FOLDER = 'output/'
if not os.path.exists(OUTPUT_FOLDER):
os.makedirs(OUTPUT_FOLDER)
kpf = KindPortaalFetcher(SESSID, BASE_URL, start_date)
photos = kpf.fetch_image_id_list()
def process_photo(photo_id):
meta = kpf.fetch_photo_meta(photo_id)
date_created = meta['MEDIA_DAG'] # 2022-06-10T13:20:39
date_created = datetime.strptime(date_created, '%Y-%m-%dT%H:%M:%S')
filename = f'{OUTPUT_FOLDER}'+clean_filename(photo_id)+'.jpg'
if not os.path.exists(filename):
kpf.fetch_photo(photo_id, filename, date_created)
thread_map(
process_photo,
photos,
max_workers=4
)