'use strict';
const Promise = require('bluebird');
Promise.map(urls, async function (url, index) {
try {
// Здесь ваш код, который берет url и сохраняет изображение
// Об async/await можно почитаь здесь - https://learn.javascript.ru/async-await
} catch (e) {
console.error(e);
}
}, { concurrency: 10 }).catch(console.error);
#!/bin/bash
COLUMN=1 # csv column to extract
RENAME=false # if we should rename the file, note that is was really specific for my problem.
THREADS=16 # threads to use by parallel
#Set Script Name variable
SCRIPT=`basename ${BASH_SOURCE[0]}`
#Set fonts for Help.
NORM=`tput sgr0`
BOLD=`tput bold`
REV=`tput smso`
# Help function
function HELP {
echo -e \\n"Help documentation for ${SCRIPT}."\\n
echo -e "Basic usage: ./$SCRIPT"\\n
echo "Command line switches are optional. The following switches are recognized."
echo "-f csv file = required should be last argument"
echo "-c column, default $COLUMN"
echo "-t threads, default $THREADS"
echo "-r renamd, should be renamed - work in progress here because this is really specific renaming"
echo -e "-h --Displays this help message. No further functions are performed."\\n
echo -e "Example: ./${BOLD}$SCRIPT -rc 2 -f file.csv"\\n
exit 1
}
#Check the number of arguments. If none are passed, print help and exit.
NUMARGS=$#
if [ $NUMARGS -eq 0 ]; then
HELP
exit 1
fi
while getopts ::c::r:h:f FLAG; do
case $FLAG in
t)
THREADS=$OPTARG
;;
c)
COLUMN=$OPTARG
;;
r)
RENAME=true
;;
h) #show help
HELP
;;
\?)
echo -e \\n"Option -${BOLD}$OPTARG${NORM} not allowed."
HELP
;;
esac
done
shift $((OPTIND-1))
FILE=$1
# shift ops, all optional args are now removed $1 will have to be the filename
if [ "$RENAME" = true ]; then
mkdir -p images && cat $FILE | tail -n +2 | cut -d ',' -f$COLUMN | grep http | sed -e 's/^[ \t\r]*//' | \
(cd images; parallel -j$THREADS -d'\r\n' --gnu 'wget {}; mv {/} `echo "{/}" | tr "." "_" | cut -d "_" -f1,3 | tr "_" "."`')
else
mkdir -p images && cat $FILE | tail -n +2 | cut -d ',' -f$COLUMN | grep http | sed -e 's/^[ \t\r]*//' | \
(cd images; parallel -j$THREADS -d'\r\n' --gnu 'wget {};')
fi
Насколько плохо использовать POST для получения данных и в боди передавать параметры?
setDate(1)
, setMonth(0)
и прибавлять по 1 дню. Месяца перевернутся автомагически.mm/dd/yyyy
можно использовать локальный формат дат для США, указав в опциях, что даты и месяц выводить как 2-цифры.const dates = [];
const options = { year: 'numeric', month: '2-digit', day: '2-digit' };
const d = new Date();
d.setMonth(0);
d.setDate(1);
const year = d.getFullYear();
while(d.getFullYear() === year) {
dates.push(d.toLocaleDateString('en-US', options));
d.setDate(d.getDate() + 1);
}
/*
01/01/2019
01/02/2019
01/03/2019
01/04/2019
01/05/2019
01/06/2019
01/07/2019
01/08/2019
01/09/2019
01/10/2019
...
*/