blob: 8dc5abef4750a262377b126541c7a081ce3acd40 (
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
|
#!/usr/bin/python3
import sys
import json
import time
import subprocess
import urllib.request
import urllib.parse
import os
def main():
prefix = 'http://localhost:8080/'
with open('/tmp/endpoints.json') as json_data:
data = json.load(json_data)
endpoints = data['endpoints']
for ep in endpoints:
path = ep['url']
src = urllib.parse.urljoin(prefix, path)
if ep['method'] == 'GET':
contents = urllib.request.urlopen(src).read()
# it's okay that we can retrieve it, enough for us right now
else:
# TODO: add support for parameters?
post_fields = {'Nam': 'X', 'Msg': 'message', 'Sameday': 'on'} # Set POST fields here
request = urllib.request.Request(src, urllib.parse.urlencode(post_fields).encode())
contents = urllib.request.urlopen(request).read().decode()
if __name__ == '__main__':
main()
|