23HQ.com – skrypty do uploadu zdjęć z poziomu konsoli

23_getfrob – do pobierania frob’a. Froba należy zwalidować przez www.

1
2
3
#!/bin/sh
curl -F api_key=DEMO -F method=auth.getFrob http://www.23hq.com/services/rest/
echo "validate: http://www.23hq.com/services/auth/?api_key=DEMO&frob=...";

23_gettoken – do pobierania tokena.

1
2
3
4
5
6
#!/bin/sh
if [ -z $1 ]; then
        echo "usage: 23_gettoken [FROB]";
else
        curl -F api_key=DEMO -F method=auth.getToken -F frob=$1 http://www.23hq.com/services/rest/
fi

Teraz uzyskany token można wykorzystać (podając jako parametr do skryptu 23_upload), żeby wrzucić zdjęcia na swoje konto w 23HQ.com.
23_upload:

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
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/sh
 
if [ -z $1  ] || [ -z "$2" ] || [ -z "$3" ]; then
        echo "usage: 23_upload <token> <\"album name\"> <\"file(s)\"> [<\"tag1 tag2 ...\">]";
else
 
        tags="";
        if [ -n "$4" ]; then
                tags=$4
        fi
 
        # znajdz album o nazwie
        photoset_id=`curl -s -F api_key=DEMO -F auth_token=$1 -F method=photosets.getList http://www.23hq.com/services/rest/ | grep -B 1 "<title>$2" | grep -o '<photoset id="[^"]*' | grep -o '[^"]*$'`
 
        if [ -z $photoset_id ]; then
                echo -n "creating photoset \"$2\"... ";
                #create album
                photoset_id=`curl -s -F api_key=DEMO -F auth_token=$1 -F method=photosets.create -F title="$2" http://www.23hq.com/services/rest/ |    grep -o '<photoset id="[^"]*' | grep -o '[^"]*$'`
                # echo $photoset_id;
                echo "done.";
        else
                echo "existing photoset_id $photoset_id";
        fi
 
        #upload
 
        i=0;
        for ph in $3; do
                let i=$i+1;
        done
 
        j=0;
        for ph in $3; do
 
                let j=$j+1;
                echo " ";
                echo "uploading \"$ph\" ($j of $i)... ";
                photo_id=`curl -F api_key=DEMO -F auth_token=$1 -F photo=@"$ph" -F is_public=0 -F hidden=0 http://www.23hq.com/services/upload/ | grep -o '<photoid>[^<"]*' | grep -o '[^\>]*$'`
                echo "done.";
 
                #add photo to album
                echo "adding to photoset... ";
                curl -s -F api_key=DEMO -F auth_token=$1 -F method=photosets.addPhoto -F photoset_id=$photoset_id -F photo_id=$photo_id http://www.23hq.com/services/rest/
                echo "done.";
 
                if [ -n "$tags" ]; then
                        #add tags to photo
                        echo "adding tags... ";
                        curl -s -F api_key=DEMO -F auth_token=$1 -F method=photos.addTags -F photo_id=$photo_id -F tags="$tags" http://www.23hq.com/services/rest/
                        echo "done.";
                fi
 
        done
 
fi

Leave a Reply

Your email address will not be published. Required fields are marked *