|
9 | 9 | api = maproulette.Task(config) |
10 | 10 |
|
11 | 11 | # Setting a challenge ID in which we'll place our cooperative task |
12 | | -challenge_id = "1234" |
| 12 | +challenge_id = 14452 |
13 | 13 |
|
14 | 14 | # We'll start by creating some 'child' operations to apply to the target objects add them to a list: |
15 | 15 | child_operations_list = [maproulette.ChildOperationModel(operation="setTags", |
|
25 | 25 | # will be applied: |
26 | 26 | test_parent_relation = [maproulette.ParentOperationModel(operation_type="modifyElement", |
27 | 27 | element_type="way", |
28 | | - osm_id="31110737", |
| 28 | + osm_id="175208404", |
29 | 29 | child_operations=child_operations_list).to_dict()] |
30 | 30 |
|
31 | 31 | # The below flags error when handling is in the constructor, but not when in the setter: |
32 | 32 | test_2 = maproulette.ParentOperationModel(operation_type="modifyElement", |
33 | 33 | element_type="way", |
34 | | - osm_id="31110737", |
| 34 | + osm_id="175208404", |
35 | 35 | child_operations=child_operations_list) |
36 | 36 |
|
37 | 37 |
|
|
46 | 46 | with open('data/Example_Geometry.geojson', 'r') as data_file: |
47 | 47 | data = json.loads(data_file.read()) |
48 | 48 |
|
49 | | -test_task = maproulette.TaskModel(name="Test_Coop_Task", |
| 49 | +test_task = maproulette.TaskModel(name="Test_Coop_Task_Kastellet", |
50 | 50 | parent=challenge_id, |
51 | 51 | geometries=data, |
52 | 52 | cooperative_work=test_cooperative_work).to_dict() |
|
56 | 56 | # endpoint, creating this new task with our cooperative work model applied |
57 | 57 | print(json.dumps(api.create_task(test_task), indent=4, sort_keys=True)) |
58 | 58 |
|
| 59 | + |
| 60 | +# Alternatively, cooperative work can be populated as in-progress edits via an OSM changefile (osc file) |
| 61 | +# as 'type 2' cooperative work: |
| 62 | +with open('data/ExampleChangefile.osc', 'rb') as data_file: |
| 63 | + osc_file = base64.b64encode(data_file.read()).decode('ascii') |
| 64 | + |
| 65 | +test_osc_cooperative_work = maproulette.CooperativeWorkModel(type=2, |
| 66 | + content=osc_file).to_dict() |
| 67 | + |
| 68 | +test_osc_task = maproulette.TaskModel(name="Test_Coop_Task_Kastellet_OSC_2", |
| 69 | + parent=challenge_id, |
| 70 | + geometries=data, |
| 71 | + cooperative_work=test_osc_cooperative_work).to_dict() |
| 72 | + |
| 73 | +print(json.dumps(api.create_task(test_osc_task), indent=4, sort_keys=True)) |
| 74 | + |
0 commit comments