|
7 | 7 | # Create an API objects with the above config object: |
8 | 8 | api = maproulette.Challenge(config) |
9 | 9 |
|
10 | | -# Creating a test challenge model with name and child task |
| 10 | +# Fetching a challenge based on challenge ID is easy. Specify the ID of the challenge you want: |
| 11 | +challenge_id = '12974' |
| 12 | + |
| 13 | +# Printing response |
| 14 | +print(json.dumps(api.get_challenge_by_id(challenge_id), indent=4, sort_keys=True)) |
| 15 | + |
| 16 | +# We can also access a challenge by specifying the parent project ID and the challenge name: |
| 17 | +challenge_name = 'Test_Challenge' |
| 18 | +project_id = '2491' |
| 19 | +print(json.dumps(api.get_challenge_by_name(project_id=project_id, |
| 20 | + challenge_name=challenge_name), indent=4, sort_keys=True)) |
| 21 | + |
| 22 | +# We can access challenge statistics as well: |
| 23 | +print(json.dumps(api.get_challenge_statistics_by_id(challenge_id))) |
| 24 | + |
| 25 | +# Accessing a challenge's tasks is easy too. Specify the ID of the challenge you want: |
| 26 | +print(json.dumps(api.get_challenge_tasks(challenge_id), indent=4, sort_keys=True)) |
| 27 | + |
| 28 | +# In order to create a new challenge, we can make our lives easier by using the Challenge Model |
11 | 29 | challenge_data = maproulette.ChallengeModel(name='Test_Challenge_Name') |
12 | 30 |
|
13 | 31 | # Adding example description |
|
29 | 47 | # Adding example overpass QL input for challenge |
30 | 48 | challenge_data.overpassQL = open('data/Example_OverpassQL_Query', 'r').read() |
31 | 49 |
|
32 | | -print(challenge_data.overpassQL) |
33 | | - |
34 | 50 | # Create challenge |
35 | 51 | print(json.dumps(api.create_challenge(challenge_data))) |
| 52 | + |
| 53 | +# If we want to add tasks to an existing challenge we can specify the challenge ID: |
| 54 | +challenge_id = 'TEST_ID' |
| 55 | + |
| 56 | +# Provide a GeoJSON of the task data: |
| 57 | +with open('data/Example_Geometry.geojson', 'r') as data_file: |
| 58 | + data = json.loads(data_file.read()) |
| 59 | + |
| 60 | +# Printing response: |
| 61 | +print(api.add_tasks_to_challenge(data, challenge_id)) |
0 commit comments