1from apify_client import ApifyClient
2
3
4
5client = ApifyClient("<YOUR_API_TOKEN>")
6
7
8run_input = {
9 "pathToImageUrls": "images",
10 "fileNameFunction": "({url, md5}) => md5(url)",
11 "uploadTo": "zip-file",
12 "preDownloadFunction": """/* Example: We get rid of the items with price 0
13({ data }) => data.filter((item) => item.price > 0)
14*/""",
15 "postDownloadFunction": """/* Example: We remove items without any successfully uploaded images.
16 We also remove any image URLs that were not uploaded
17
18 ({ data, state }) => {
19 return data.reduce((newData, item) => {
20 const downloadedImages = item.images.filter((imageUrl) => {
21 return state[imageUrl] && state[imageUrl].imageUploaded;
22 });
23
24 if (downloadedImages.length === 0) {
25 return newData;
26 }
27
28 return newData.concat({ ...item, images: downloadedImages });
29 }, []);
30}
31*/""",
32 "imageCheckType": "content-type",
33 "proxyConfiguration": { "useApifyProxy": True },
34}
35
36
37run = client.actor("lukaskrivka/images-download-upload").call(run_input=run_input)
38
39
40print("💾 Check your data here: https://console.apify.com/storage/datasets/" + run["defaultDatasetId"])
41for item in client.dataset(run["defaultDatasetId"]).iterate_items():
42 print(item)
43
44