FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Updated documentation for timetable_utils · mrtncode/python-webuntis@cdbd945 · GitHub

Commit cdbd945

Browse files
committed
Updated documentation for timetable_utils
1 parent 63e81b5 commit cdbd945

4 files changed

Lines changed: 72 additions & 69 deletions

File tree

‎examples/credentials.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import webuntis
2+
import logging
3+
4+
logging.basicConfig(level=logging.DEBUG)
5+
6+
# Testserver from Grupet
7+
# Used by all examples
8+
9+
s = webuntis.Session(
10+
username='api',
11+
password='api',
12+
server='webuntis.grupet.at:8080',
13+
useragent='foo',
14+
school='demo_inf'
15+
)
16+
17+
s.login()

‎examples/html_timetable.py‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from credentials import s
2+
import datetime
3+
import logging
4+
5+
# ***DO NOT USE THIS EXAMPLE AS-IS***
6+
# Properties that are printed here may contain arbitrary
7+
# *unescaped* HTML. That is not expected, but you should not trust
8+
# input from remote sources in general.
9+
10+
logging.basicConfig(level=logging.DEBUG)
11+
12+
today = datetime.datetime.today()
13+
14+
monday = today - datetime.timedelta(days=today.weekday())
15+
friday = monday + datetime.timedelta(days=4)
16+
17+
klasse = s.klassen().filter(name='1A')[0]
18+
table = s.timetable(klasse=klasse, start=monday, end=friday).to_table()
19+
20+
21+
print('<table border="1"><thead><th>Time</th>')
22+
for weekday in ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday']:
23+
print('<th>' + str(weekday) + '</th>')
24+
25+
print('</thead><tbody>')
26+
for time, row in table:
27+
print('<tr>')
28+
print('<td>{}</td>'.format(time.strftime('%H:%M')))
29+
for date, cell in row:
30+
print('<td>')
31+
for period in cell:
32+
print(', '.join(su.name for su in period.subjects))
33+
print('</td>')
34+
35+
print('</tr>')
36+
37+
print('</tbody></table>')

‎webuntis/objects.py‎

Lines changed: 11 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -320,79 +320,22 @@ def to_table(self, dates=None, times=None):
320320
Creates a table-like structure out of the periods. Useful for rendering
321321
timetables in HTML and other markup languages.
322322
323-
:param width: Optionally, a fixed width for the table. The function
324-
will create empty columns until that width is met. If the timetable
325-
is too big, it will raise a ``ValueError``.
323+
Check out the example from the repository for clarification.
324+
325+
:param dates: An iterable of :py:class:`datetime.date` objects that
326+
definetly should be included in the table. If this parameter is
327+
``None``, the timetable is just as wide as it has to be, leaving
328+
out days without periods.
329+
330+
:param times: An iterable of :py:class:`datetime.time` objects that
331+
definetly should be included in the table. If this parameter is
332+
``None``, the timetable is just as tall as it has to be, leaving
333+
out hours without periods.
326334
327335
:returns: A list containing "rows", which in turn contain "hours",
328336
which contain :py:class:`webuntis.objects.PeriodObject` instances
329337
which are happening at the same time.
330338
331-
Example::
332-
333-
today = datetime.datetime.today()
334-
monday = today - datetime.timedelta(days=today.weekday())
335-
friday = monday + datetime.timedelta(days=4)
336-
337-
table = s.timetable(klasse=878, start=monday, end=friday) \\
338-
.to_table(width=5)
339-
340-
# DON'T USE THIS EXAMPLE AS-IS
341-
# Properties that are printed here may contain arbitrary
342-
# *unescaped* HTML. That is not expected, but you should not trust
343-
# input from remote sources in general.
344-
345-
print('<table><thead>')
346-
for weekday in range(5):
347-
print('<th>' + str(weekday) + '</th>')
348-
349-
print('</thead><tbody>')
350-
for time, row in table:
351-
print('<tr>')
352-
for date, cell in row:
353-
print('<td>')
354-
for period in cell:
355-
print('<div>')
356-
print(', '.join(su.name for su in period.subjects))
357-
print('</div>')
358-
359-
print('</td>')
360-
361-
print('</tr>')
362-
363-
print('</tbody></table>')
364-
365-
Gives you HTML like this:
366-
367-
+--------+--------+--------+--------+--------+
368-
| 0 | 1 | 2 | 3 | 4 |
369-
+========+========+========+========+========+
370-
| ME | M | PH | M | GSK |
371-
+--------+--------+--------+--------+--------+
372-
| M | BU | D | FRA | D |
373-
| | | | LAT | |
374-
| | | | SPA | |
375-
+--------+--------+--------+--------+--------+
376-
| E | BU | FRA | BU | E |
377-
| | | LAT | | |
378-
| | | SPA | | |
379-
+--------+--------+--------+--------+--------+
380-
| RK | GSK | E | ME | GWK |
381-
| RISL | | | | |
382-
+--------+--------+--------+--------+--------+
383-
| D | BE | M | PH | PH |
384-
+--------+--------+--------+--------+--------+
385-
| FRA | | | | |
386-
| LAT | | | | |
387-
| SPA | | | | |
388-
+--------+--------+--------+--------+--------+
389-
| INF+ | | | | |
390-
+--------+--------+--------+--------+--------+
391-
| INF+ | | | | |
392-
+--------+--------+--------+--------+--------+
393-
| BSP | RKO | | | |
394-
+--------+--------+--------+--------+--------+
395-
396339
'''
397340

398341
return timetable_utils.table(self, dates=dates, times=times)

‎webuntis/session.py‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,13 @@ def timetable(self, start, end, **type_and_id):
178178
room or student parameter containing the id or the object of the thing
179179
you want to get a timetable about::
180180
181-
schoolclass = s.klassen().filter(id=1)[0] # schoolclass #1
181+
import datetime
182+
today = datetime.date.today()
183+
monday = today - datetime.timedelta(days=today.weekday())
184+
friday = monday + datetime.timedelta(days=4)
185+
186+
klasse = s.klassen().filter(id=1)[0] # schoolclass #1
187+
tt = s.timetable(klasse=klasse, start=monday, end=friday)
182188
183189
:raises: :exc:`ValueError`, :exc:`TypeError`
184190
'''

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL