summaryrefslogtreecommitdiff
path: root/get_data.py
blob: 0e26b4632e4ee835f73a0bb97e742a6d2622db45 (plain)
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
56
57
58
#!/usr/bin/python2.7
import requests, sys
import re
import simplejson as json
URL_BASE = "http://asdf.us/im"

IMAGES_I_LIKE = [
    "http://i.asdf.us/im/de/imgrid_1326006923_xx_abridged___.png",
    "http://i.asdf.us/im/b7/imgrid_1328122947_xx_abridged___.png",
    "http://i.asdf.us/im/13/imgrid_1327739154_imgrid_1327738736_xx_abridged___pepper_pepper.png",
    "http://i.asdf.us/im/3a/imgrid_1328122609__1328122055_.gif",
    "http://i.asdf.us/im/29/imgrid_1347748334_xx_abridged___pepper.png",
    "http://i.asdf.us/im/af/imGrid_1435899447_dmgk.png",
    "http://i.asdf.us/im/da/imGrid_1435899431_dmgk.png",
    "http://i.asdf.us/im/e1/Over_1435899330_dmgk.png",
    "http://i.asdf.us/im/49/imGrid_1435898499_dmgk.png",
    "http://i.asdf.us/im/dd/imGradientyellow-blue_1435898433_.png",
]


def post_request(url, data):
    r = requests.post(url, data=data)
    if r.status_code != 200:
        sys.stderr.write("ERROR: %s\n" % r.status_code)
        sys.stderr.write("REASON: %s\n" % r.reason)
        sys.exit(1)
    return json.loads(r.text)


def get_request(url, params={}):
    r = requests.get(url, params=params)
    if r.status_code != 200:
        sys.stderr.write("ERROR: %s\n" % r.status_code)
        sys.stderr.write("REASON: %s\n" % r.reason)
        sys.exit(1)
    try:
        return json.loads(r.text)
    except Exception as e:
        sys.stderr.write("%s\n" % r.text)
        sys.stderr.write("%s\n" % e )


def test(api_name, params):
    return get_request("%s/%s" % (URL_BASE, api_name), params=params)


if __name__ == "__main__":
    for i in IMAGES_I_LIKE:
        newfile = re.search(r'/([^/]+)$', i).groups()[0]
        try:
            print test(
                "data",
                {
                    "newfile": newfile
                }
            )
        except Exception as e:
            print "nope"