Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
myfolder - -------- | - application (внутри лежит psi)-------- | - psiStart.app....
-----------------------------57648741364
Content-Disposition: form-data; name="Filedata"; filename="5e7kqHg.jpg"
Content-Type: image/jpeg
яШяа.....



on run
set TOKEN to "2d1da421fdd3404318e81c0a0442105e"
set ALBUM to "http://api-fotki.yandex.ru/api/users/mylogin/photos/"
tell application "Finder"
set selectedFiles to (get selection)
if (count of selectedFiles) > 0 then
repeat with i from 1 to the count of selectedFiles
set filePath to POSIX path of (item i of selectedFiles as alias)
set responseCode to do shell script "curl -sL -w %{http_code} --header \"Authorization: FimpToken realm=\"fotki.yandex.ru\", token=" & TOKEN & "\" -F \"image=@" & filePath & "\" --request POST " & ALBUM & " -o /dev/null"
if (responseCode is not "201") then
display alert "Произошла ошибка:" message "Не удалось загрузить: " & filePath
end if
end repeat
display notification "Загрузка картинок завершена" with title "fotki.yandex.ru"
end if
end tell
end run
#!/bin/sh
### config
USERNAME=mylogin
PASSWORD=mypassword
CURRENT_DIR=$(pwd)
PATH_TO_ENCRYPT="$CURRENT_DIR/encrypt"
### yandex.magic
YAMRSA_CODE=0
while [ $YAMRSA_CODE -ne 200 ]; do
echo "Get new public RSA key from Yandex..."
YAMRSA_CODE=$(curl -sL -w %{http_code} http://auth.mobile.yandex.ru/yamrsa/key/ -o yamrsa.txt)
sleep 2
done;
KEY=$(cat yamrsa.txt | grep key | awk -F "<key>" '{print $2}' | awk -F "</key>" '{print $1}')
REQUEST_ID=$(cat yamrsa.txt | grep request_id | awk -F "<request_id>" '{print $2}' | awk -F "</request_id>" '{print $1}')
CREDENTIAL=$($PATH_TO_ENCRYPT $KEY "<credentials login=\"$USERNAME\" password=\"$PASSWORD\"/>")
echo "RSA: $KEY"
echo "REQUEST_ID: $REQUEST_ID"
echo "CREDENTIAL: $CREDENTIAL"
TOKEN_CODE=502
while [ $TOKEN_CODE -eq 502 ]; do
echo "Get new token from Yandex..."
TOKEN_CODE=$(curl -sL -w %{http_code} -d request_id=$REQUEST_ID --data-urlencode credentials=$CREDENTIAL --request POST http://auth.mobile.yandex.ru/yamrsa/token/ -o token.txt)
sleep 2
done;
TOKEN=$(cat token.txt | grep token | awk -F "<token>" '{print $2}' | awk -F "</token>" '{print $1}')
echo "TOKEN: $TOKEN"
TOKEN is 2d1da421fdd3404318e81c0a0442105eset ALBUM to "http://api-fotki.yandex.ru/api/users/mylogin/photos/"set ALBUM to "http://api-fotki.yandex.ru/api/users/mylogin/album/200491/photos/"
Скрипт Automator, загружающий изображения на Habrastorage