Mercurial > hg > orthanc
comparison Resources/Samples/Python/ChangesLoop.py @ 340:61f6a3d66b85
changes loop sample
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 17 Jan 2013 15:54:02 +0100 |
parents | |
children | b51c67f28b33 |
comparison
equal
deleted
inserted
replaced
339:639272ef7615 | 340:61f6a3d66b85 |
---|---|
1 #!/usr/bin/python | |
2 | |
3 import time | |
4 import sys | |
5 import RestToolbox | |
6 | |
7 if len(sys.argv) != 3: | |
8 print(""" | |
9 Sample script that continuously monitors the arrival of new DICOM | |
10 images into Orthanc (through the Changes API). | |
11 | |
12 Usage: %s [hostname] [HTTP port] | |
13 For instance: %s localhost 8042 | |
14 """ % (sys.argv[0], sys.argv[0])) | |
15 exit(-1) | |
16 | |
17 URL = 'http://%s:%d' % (sys.argv[1], int(sys.argv[2])) | |
18 | |
19 | |
20 def NewInstanceReceived(path): | |
21 print 'New instance received: "%s"' % path | |
22 | |
23 | |
24 URL = 'http://localhost:8042' | |
25 current = 0 | |
26 while True: | |
27 r = RestToolbox.DoGet(URL + '/changes', { | |
28 'since' : current, | |
29 'limit' : 4 | |
30 }) | |
31 | |
32 for change in r['Changes']: | |
33 if change['ChangeType'] == 'NewInstance': | |
34 path = change['Path'] | |
35 NewInstanceReceived(path) | |
36 RestToolbox.DoDelete(URL + path) | |
37 | |
38 current = r['Last'] | |
39 | |
40 if r['Done']: | |
41 print "Everything has been processed: Waiting..." | |
42 time.sleep(1) |