Kodkollektivet / unitime-api

Unitime Rest API
http://api.kodkollektivet.se/unitime/
8 stars 2 forks source link

Events for multiple courses #2

Closed alperg9 closed 7 years ago

alperg9 commented 7 years ago

POST /unitime/event/{course_code}/ cannot ask for multiple courses at once.

jherrlin commented 7 years ago

This should be working, but the POST request should be to /unitime/event/.

Django is very picky about trailing slashes to remember the "/" in the end of the url.

>>> import requests
>>> from pprint import pprint as pp
>>> req = requests.post('https://api.kodkollektivet.se/unitime/event/', data={'courses': ['1dv701', '1dv702']})
>>> req.status_code
200
>>> pp(req.json())
[{'course': '1dv701',
  'events': [{'desc': '',
              'endtime': '17:00',
              'info': 'Course start',
              'room': 'D1136A_V',
              'startdate': '2017-01-17',
              'starttime': '15:15',
              'teacher': 'Morgan Ericsson, Ola Flygt'},
             {'desc': '',
              'endtime': '12:00',
              'info': 'Lecture',
              'room': 'D1136A_V',
              'startdate': '2017-01-19',
              'starttime': '10:15',
              'teacher': 'Morgan Ericsson'},
             {'desc': '',
              'endtime': '12:00',
              'info': 'Information, Laboratory lesson',
              'room': 'Newton_V',
              'startdate': '2017-01-23',
              'starttime': '10:15',
              'teacher': 'Stepan Shevtsov'},
             {'desc': '',
              'endtime': '17:00',
              'info': 'Lecture',
              'room': 'D1136A_V',
              'startdate': '2017-01-23',
              'starttime': '15:15',
              'teacher': 'Morgan Ericsson'},
             {'desc': '',
              'endtime': '15:00',
              'info': 'Laboratory lesson',
              'room': 'Datorsal D1142V (PC), Datorsal D1170A_V',
              'startdate': '2017-01-24',
              'starttime': '13:15',
              'teacher': 'Stepan Shevtsov'},
             {'desc': '',
              'endtime': '15:00',
              'info': 'Laboratory lesson',
              'room': 'Datorsal D1142V (PC), Datorsal D1170A_V',
              'startdate': '2017-01-25',
              'starttime': '13:15',
              'teacher': 'Stepan Shevtsov'},
             {'desc': '',
              'endtime': '12:00',
              'info': 'Lecture',
              'room': 'D1136A_V',
              'startdate': '2017-01-26',
              'starttime': '10:15',
              'teacher': 'Morgan Ericsson'},
             {'desc': '',
              'endtime': '15:00',
              'info': 'Laboratory lesson',
              'room': 'Datorsal D1142V (PC), Datorsal D1170A_V',
              'startdate': '2017-01-26',
              'starttime': '13:15',
              'teacher': 'Stepan Shevtsov'},
             {'desc': '',
              'endtime': '15:00',
              'info': 'Laboratory lesson',
              'room': 'Datorsal D1142V (PC), Datorsal D1170A_V',
              'startdate': '2017-01-31',
              'starttime': '13:15',
              'teacher': 'Stepan Shevtsov'},
             {'desc': '',
              'endtime': '17:00',
              'info': 'Lecture',
              'room': 'D1136A_V',
              'startdate': '2017-01-31',
              'starttime': '15:15',
              'teacher': 'Morgan Ericsson'},
             {'desc': '',
              'endtime': '15:00',
              'info': 'Laboratory lesson',
              'room': 'Datorsal D1142V (PC), Datorsal D1170A_V',
              'startdate': '2017-02-01',
              'starttime': '13:15',
              'teacher': 'Stepan Shevtsov'},
             {'desc': '',
              'endtime': '12:00',
              'info': 'Lecture',
              'room': 'D1136A_V',
              'startdate': '2017-02-02',
              'starttime': '10:15',
              'teacher': 'Morgan Ericsson'},
             {'desc': '',
              'endtime': '15:00',
              'info': 'Laboratory lesson',
              'room': 'Datorsal D1142V (PC), Datorsal D1170A_V',
              'startdate': '2017-02-02',
              'starttime': '13:15',
              'teacher': 'Stepan Shevtsov'},
             {'desc': '',
              'endtime': '15:00',
              'info': 'Laboratory lesson',
              'room': 'Datorsal D1142V (PC), Datorsal D1170A_V',
              'startdate': '2017-02-07',
              'starttime': '13:15',
              'teacher': 'Stepan Shevtsov'},
             {'desc': '',
              'endtime': '17:00',
              'info': 'Lecture',
              'room': 'D1136A_V',
              'startdate': '2017-02-07',
              'starttime': '15:15',
              'teacher': 'Morgan Ericsson'},
             {'desc': '',
              'endtime': '15:00',
              'info': 'Laboratory lesson',
              'room': 'Datorsal D1142V (PC), Datorsal D1170A_V',
              'startdate': '2017-02-08',
              'starttime': '13:15',
              'teacher': 'Stepan Shevtsov'},
             {'desc': '',
              'endtime': '12:00',
              'info': 'Lecture',
              'room': 'D1136A_V',
              'startdate': '2017-02-09',
              'starttime': '10:15',
              'teacher': 'Morgan Ericsson'},
             {'desc': '',
              'endtime': '15:00',
              'info': 'Laboratory lesson',
              'room': 'Datorsal D1142V (PC), Datorsal D1170A_V',
              'startdate': '2017-02-09',
              'starttime': '13:15',
              'teacher': 'Stepan Shevtsov'},
             {'desc': '',
              'endtime': '15:00',
              'info': 'Laboratory lesson',
              'room': 'Datorsal D1142V (PC), Datorsal D1170A_V',
              'startdate': '2017-02-14',
              'starttime': '13:15',
              'teacher': 'Stepan Shevtsov'},
             {'desc': '',
              'endtime': '17:00',
              'info': 'Lecture',
              'room': 'D1136A_V',
              'startdate': '2017-02-14',
              'starttime': '15:15',
              'teacher': 'Morgan Ericsson'},
             {'desc': '',
              'endtime': '15:00',
              'info': 'Laboratory lesson',
              'room': 'Datorsal D1142V (PC), Datorsal D1170A_V',
              'startdate': '2017-02-15',
              'starttime': '13:15',
              'teacher': 'Stepan Shevtsov'},
             {'desc': '',
              'endtime': '12:00',
              'info': 'Lecture',
              'room': 'D1136A_V',
              'startdate': '2017-02-16',
              'starttime': '10:15',
              'teacher': 'Ola Flygt'},
             {'desc': '',
              'endtime': '15:00',
              'info': 'Laboratory lesson',
              'room': 'Datorsal D1142V (PC), Datorsal D1170A_V',
              'startdate': '2017-02-16',
              'starttime': '13:15',
              'teacher': 'Stepan Shevtsov'},
             {'desc': '',
              'endtime': '15:00',
              'info': 'Laboratory lesson',
              'room': 'Datorsal D1142V (PC), Datorsal D1170A_V',
              'startdate': '2017-02-21',
              'starttime': '13:15',
              'teacher': 'Stepan Shevtsov'},
             {'desc': '',
              'endtime': '17:00',
              'info': 'Lecture',
              'room': 'D1136A_V',
              'startdate': '2017-02-21',
              'starttime': '15:15',
              'teacher': 'Ola Flygt'},
             {'desc': '',
              'endtime': '15:00',
              'info': 'Laboratory lesson',
              'room': 'Datorsal D1142V (PC), Datorsal D1170A_V',
              'startdate': '2017-02-22',
              'starttime': '13:15',
              'teacher': 'Stepan Shevtsov'},
             {'desc': '',
              'endtime': '12:00',
              'info': 'Lecture',
              'room': 'D1136A_V',
              'startdate': '2017-02-23',
              'starttime': '10:15',
              'teacher': 'Ola Flygt'},
             {'desc': '',
              'endtime': '15:00',
              'info': 'Laboratory lesson',
              'room': 'Datorsal D1142V (PC), Datorsal D1170A_V',
              'startdate': '2017-02-23',
              'starttime': '13:15',
              'teacher': 'Stepan Shevtsov'},
             {'desc': '',
              'endtime': '15:00',
              'info': 'Laboratory lesson',
              'room': 'Datorsal D1142V (PC), Datorsal D1170A_V',
              'startdate': '2017-02-28',
              'starttime': '13:15',
              'teacher': 'Stepan Shevtsov'},
             {'desc': '',
              'endtime': '17:00',
              'info': 'Lecture',
              'room': 'D1136A_V',
              'startdate': '2017-02-28',
              'starttime': '15:15',
              'teacher': 'Morgan Ericsson'},
             {'desc': '',
              'endtime': '15:00',
              'info': 'Laboratory lesson',
              'room': 'Datorsal D1142V (PC), Datorsal D1170A_V',
              'startdate': '2017-03-01',
              'starttime': '13:15',
              'teacher': 'Stepan Shevtsov'},
             {'desc': '',
              'endtime': '12:00',
              'info': 'Lecture',
              'room': 'D1136A_V',
              'startdate': '2017-03-02',
              'starttime': '10:15',
              'teacher': 'Morgan Ericsson'},
             {'desc': '',
              'endtime': '15:00',
              'info': 'Laboratory lesson',
              'room': 'Datorsal D1142V (PC), Datorsal D1170A_V',
              'startdate': '2017-03-02',
              'starttime': '13:15',
              'teacher': 'Stepan Shevtsov'},
             {'desc': '',
              'endtime': '15:00',
              'info': 'Laboratory lesson',
              'room': 'Datorsal D1142V (PC), Datorsal D1170A_V',
              'startdate': '2017-03-07',
              'starttime': '13:15',
              'teacher': 'Stepan Shevtsov'},
             {'desc': '',
              'endtime': '17:00',
              'info': 'Lecture',
              'room': 'D1136A_V',
              'startdate': '2017-03-07',
              'starttime': '15:15',
              'teacher': 'Ola Flygt'},
             {'desc': '',
              'endtime': '15:00',
              'info': 'Laboratory lesson',
              'room': 'Datorsal D1142V (PC), Datorsal D1170A_V',
              'startdate': '2017-03-08',
              'starttime': '13:15',
              'teacher': 'Stepan Shevtsov'},
             {'desc': '',
              'endtime': '12:00',
              'info': 'Lecture',
              'room': 'D1136A_V',
              'startdate': '2017-03-09',
              'starttime': '10:15',
              'teacher': 'Ola Flygt'},
             {'desc': '',
              'endtime': '15:00',
              'info': 'Laboratory lesson',
              'room': 'Datorsal D1142V (PC), Datorsal D1170A_V',
              'startdate': '2017-03-09',
              'starttime': '13:15',
              'teacher': 'Stepan Shevtsov'},
             {'desc': '',
              'endtime': '15:00',
              'info': 'Laboratory lesson',
              'room': 'Datorsal D1142V (PC), Datorsal D1170A_V',
              'startdate': '2017-03-14',
              'starttime': '13:15',
              'teacher': 'Stepan Shevtsov'},
             {'desc': '',
              'endtime': '15:00',
              'info': 'Laboratory lesson',
              'room': 'Datorsal D1142V (PC), Datorsal D1170A_V',
              'startdate': '2017-03-15',
              'starttime': '13:15',
              'teacher': 'Stepan Shevtsov'},
             {'desc': '',
              'endtime': '15:00',
              'info': 'Laboratory lesson',
              'room': 'Datorsal D1142V (PC), Datorsal D1170A_V',
              'startdate': '2017-03-16',
              'starttime': '13:15',
              'teacher': 'Stepan Shevtsov'},
             {'desc': '',
              'endtime': '19:00',
              'info': 'Exam',
              'room': 'Please note! Register for exam TUESDAY THE WEEK BEFORE '
                      'AT THE LATEST: tentamen.lnu.se. Place is announced '
                      'later by e-mail.',
              'startdate': '2017-03-17',
              'starttime': '14:00',
              'teacher': 'Ola Flygt'},
             {'desc': '',
              'endtime': '17:00',
              'info': 'Reexamination',
              'room': 'Please note! Register for exam TUESDAY THE WEEK BEFORE '
                      'AT THE LATEST: tentamen.lnu.se. Place is announced '
                      'later by e-mail.',
              'startdate': '2017-05-06',
              'starttime': '12:00',
              'teacher': 'Ola Flygt'}]},
 {'course': '1dv702',
  'events': [{'desc': '',
              'endtime': '12:00',
              'info': 'Course start',
              'room': 'D1173A_V',
              'startdate': '2017-03-20',
              'starttime': '10:15',
              'teacher': 'Gästlärare FTK, Ola Flygt'},
             {'desc': '',
              'endtime': '15:00',
              'info': 'Lecture',
              'room': 'D1167V',
              'startdate': '2017-03-22',
              'starttime': '13:15',
              'teacher': 'Gästlärare FTK'},
             {'desc': '',
              'endtime': '12:00',
              'info': 'Lecture',
              'room': 'D1173A_V',
              'startdate': '2017-03-27',
              'starttime': '10:15',
              'teacher': 'Gästlärare FTK'},
             {'desc': '',
              'endtime': '15:00',
              'info': 'Lecture',
              'room': 'D1167V',
              'startdate': '2017-03-29',
              'starttime': '13:15',
              'teacher': 'Gästlärare FTK'},
             {'desc': '',
              'endtime': '12:00',
              'info': 'Lecture',
              'room': 'D1173A_V',
              'startdate': '2017-04-03',
              'starttime': '10:15',
              'teacher': 'Gästlärare FTK'},
             {'desc': '',
              'endtime': '15:00',
              'info': 'Lecture',
              'room': 'D1167V',
              'startdate': '2017-04-05',
              'starttime': '13:15',
              'teacher': 'Gästlärare FTK'},
             {'desc': '',
              'endtime': '12:00',
              'info': 'Lecture',
              'room': 'D1173A_V',
              'startdate': '2017-04-10',
              'starttime': '10:15',
              'teacher': 'Gästlärare FTK'},
             {'desc': '',
              'endtime': '15:00',
              'info': 'Lecture',
              'room': 'D1167V',
              'startdate': '2017-04-12',
              'starttime': '13:15',
              'teacher': 'Gästlärare FTK'},
             {'desc': '',
              'endtime': '15:00',
              'info': 'Lecture',
              'room': 'D1167V',
              'startdate': '2017-04-19',
              'starttime': '13:15',
              'teacher': 'Gästlärare FTK'},
             {'desc': '',
              'endtime': '12:00',
              'info': 'Lecture',
              'room': 'D1173A_V',
              'startdate': '2017-04-24',
              'starttime': '10:15',
              'teacher': 'Gästlärare FTK'},
             {'desc': '',
              'endtime': '15:00',
              'info': 'Lecture',
              'room': 'D1167V',
              'startdate': '2017-04-26',
              'starttime': '13:15',
              'teacher': 'Gästlärare FTK'},
             {'desc': '',
              'endtime': '15:00',
              'info': 'Lecture',
              'room': 'D1167V',
              'startdate': '2017-05-03',
              'starttime': '13:15',
              'teacher': 'Gästlärare FTK'},
             {'desc': '',
              'endtime': '12:00',
              'info': 'Lecture',
              'room': 'D1172V',
              'startdate': '2017-05-08',
              'starttime': '10:15',
              'teacher': 'Gästlärare FTK'},
             {'desc': '',
              'endtime': '15:00',
              'info': 'Lecture',
              'room': 'D1167V',
              'startdate': '2017-05-10',
              'starttime': '13:15',
              'teacher': 'Gästlärare FTK'},
             {'desc': '',
              'endtime': '12:00',
              'info': 'Lecture',
              'room': 'D1173A_V',
              'startdate': '2017-05-15',
              'starttime': '10:15',
              'teacher': 'Gästlärare FTK'},
             {'desc': '',
              'endtime': '15:00',
              'info': 'Lecture',
              'room': 'D1167V',
              'startdate': '2017-05-17',
              'starttime': '13:15',
              'teacher': 'Gästlärare FTK'},
             {'desc': '',
              'endtime': '12:00',
              'info': 'Lecture',
              'room': 'D1173A_V',
              'startdate': '2017-05-22',
              'starttime': '10:15',
              'teacher': 'Gästlärare FTK'},
             {'desc': '',
              'endtime': '15:00',
              'info': 'Lecture',
              'room': 'D1167V',
              'startdate': '2017-05-24',
              'starttime': '13:15',
              'teacher': 'Gästlärare FTK'},
             {'desc': '',
              'endtime': '12:00',
              'info': 'Lecture',
              'room': 'D1173A_V',
              'startdate': '2017-05-29',
              'starttime': '10:15',
              'teacher': 'Gästlärare FTK'},
             {'desc': '',
              'endtime': '15:00',
              'info': 'Lecture',
              'room': 'D1167V',
              'startdate': '2017-05-31',
              'starttime': '13:15',
              'teacher': 'Gästlärare FTK'}]}]
alperg9 commented 7 years ago

For one course it works. However, whenever I add multiple courses (i.e: 1DV507,1DV508), it returns an empty array. I observe that the string i send is not regarded as multiple courses. Instead, it interprets "1DV507,1DV508" as one course

[ { "course": "1DV507,1DV508", "events": [] } ]

jherrlin commented 7 years ago

This is the correct way of sending it.

{'courses': ['1DV507', '1DV508']}

When "1DV507,1DV508" is is sent API think that its one course with the wrong formating.

jherrlin commented 7 years ago

@alperg9 Made a case for the Alamonfire framework.

The request looks like this:

requests.post('https://api.kodkollektivet.se/unitime/alamon/event/', data={'courses': '1dv507,1dv702'})