| Total Complexity | 0 |
| Total Lines | 47 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | #!/usr/bin/env python |
||
| 2 | |||
| 3 | from config import config |
||
| 4 | import pycurl, cStringIO, hashlib, json |
||
| 5 | |||
| 6 | buf = cStringIO.StringIO() |
||
| 7 | |||
| 8 | record = { |
||
| 9 | 'record_id': hashlib.sha1().hexdigest()[:16], |
||
| 10 | 'first_name': 'First', |
||
| 11 | 'last_name': 'Last', |
||
| 12 | 'address': '123 Cherry Lane\nNashville, TN 37015', |
||
| 13 | 'telephone': '(615) 255-4000', |
||
| 14 | 'email': '[email protected]', |
||
| 15 | 'dob': '1972-08-10', |
||
| 16 | 'age': 43, |
||
| 17 | 'ethnicity': 1, |
||
| 18 | 'race': 4, |
||
| 19 | 'sex': 1, |
||
| 20 | 'height': 180, |
||
| 21 | 'weight': 105, |
||
| 22 | 'bmi': 31.4, |
||
| 23 | 'comments': 'comments go here', |
||
| 24 | 'redcap_event_name': 'events_2_arm_1', |
||
| 25 | 'basic_demography_form_complete': '2', |
||
| 26 | } |
||
| 27 | |||
| 28 | data = json.dumps([record]) |
||
| 29 | |||
| 30 | fields = { |
||
| 31 | 'token': config['api_token'], |
||
| 32 | 'content': 'record', |
||
| 33 | 'format': 'json', |
||
| 34 | 'type': 'flat', |
||
| 35 | 'data': data, |
||
| 36 | } |
||
| 37 | |||
| 38 | ch = pycurl.Curl() |
||
| 39 | ch.setopt(ch.URL, config['api_url']) |
||
| 40 | ch.setopt(ch.HTTPPOST, fields.items()) |
||
| 41 | ch.setopt(ch.WRITEFUNCTION, buf.write) |
||
| 42 | ch.perform() |
||
| 43 | ch.close() |
||
| 44 | |||
| 45 | print buf.getvalue() |
||
| 46 | buf.close() |
||
| 47 |