-
Notifications
You must be signed in to change notification settings - Fork 2
/
explore.py
executable file
·71 lines (54 loc) · 1.72 KB
/
explore.py
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
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python
import os
import requests
from requests_hawk import HawkAuth
path = '/accept'
webhook = 'https://webhook.site/229e69b2-4bbf-4d47-be56-1a341e7e5bae'
negative_uri = webhook
positive_uri = webhook
positive_email = 'mbrandt@mozilla.com'
# stage vars
if 'HAWK_KEY' not in os.environ:
raise Exception('You need to set the HAWK_KEY environ')
url = 'https://watchdogproxy-default.stage.mozaws.net'
id = 'demouser'
key = os.environ.get('HAWK_KEY')
# dev vars
# url = 'https://watchdogproxy-default.dev.mozaws.net'
# id = 'devuser'
# key = 'devkey'
form_data = {
'negative_uri': negative_uri,
'positive_uri': positive_uri,
'positive_email': positive_email,
}
def _get_bits(image):
with open(image, 'rb') as f:
return f.read()
def _list_files(dir):
for path, subdirs, files in os.walk(dir):
return files
def _file_data(filename):
image_data = _get_bits(filename)
return {'image': (filename, image_data)}
def submit_image(file):
auth = HawkAuth(id=id, key=key)
return requests.post(url + path,
data=form_data, files=_file_data(file),
auth=auth)
def inspect_negative_request():
img_pos = 'images/img_negative.jpg'
auth = HawkAuth(id=id, key=key)
req = requests.Request('POST', url, data=form_data,
files=_file_data(img_pos), auth=auth)
prepared = req.prepare()
print('Prepared request:' + str(prepared.body[:800]))
resp = submit_image(img_pos)
print(resp.json())
def test_sumbit_sample_images():
dir = 'images/sample_images/'
files = _list_files(dir)
for file in files:
submit_image(dir + file)
if __name__ == '__main__':
inspect_negative_request()