joeni

Add PingPing functionality to footer

Author
Maarten Vangeneugden
Date
July 27, 2018, 2:23 a.m.
Hash
015753254f1b81e3c319e549207e88c033ce4319
Parent
a3fb35864ba011aed6baeb537a35e263284690df
Modified files
docs/voorstel/pingping.py
joeni/templates/joeni/footer.djhtml
joeni/templatetags/joeni_org.py

docs/voorstel/pingping.py

1 addition and 1 deletion.

View changes Hide changes
1
1
# public API.
2
2
# Given the account number and password/passphrase, this script returns the
3
3
# remaining budget associated with the account.
4
4
#
5
5
# This is a proof of concept; it's extremely barebones and doesn't include tests
6
6
# or anything. Requires Python 3 and the Requests library in order to work.
7
7
import requests
8
8
9
9
link = "https://uhasselt-pxl.mynetpay.be/Account/Login"
10
10
# Get CSRF token
11
11
first_call = requests.get(link)
12
12
text = first_call.text
13
13
begin = text.find('__RequestVerificationToken')
14
14
begin = text.find('value="', begin)
15
15
end = text.find('" ', begin)
16
16
token = text[begin+len('value="'):end]
17
17
cookies = first_call.cookies
18
18
19
19
username = ""
20
20
password = ""
21
21
22
22
response = requests.post(link, data={
23
23
    'Username':username,
24
24
    'LoginType':'Student',
25
25
    'Password':password,
26
26
    '__RequestVerificationToken':token,
27
27
    }, cookies=cookies)
28
28
29
29
html_response = response.text
30
30
start = html_response.find(": € ")
31
31
offset = len(": € ")
32
32
print(html_response[start+offset:start+offset+4])
33
-
+
33

joeni/templates/joeni/footer.djhtml

3 additions and 2 deletions.

View changes Hide changes
1
1
{% load static %}
2
2
{% get_media_prefix as media %}
+
3
{% get_media_prefix as media %}
3
4
<img src="{% static "logos/joeni/simple-black.svg" %}" alt="◀ Joeni /▶" />
4
5
{#<img src="{% static "logos/uhasselt/medium.svg" %}" alt="▶▶ UHasselt" />#}
5
6
{% blocktrans %}
6
7
    The digital platform of Hasselt University, designed with an
7
-
    emphasis on web standards, simplicity, and the day to day needs of its students, by students.
8
-
{% endblocktrans %}
+
8
{% endblocktrans %}
9
9
+
10

joeni/templatetags/joeni_org.py

28 additions and 0 deletions.

View changes Hide changes
1
1
from django.utils.safestring import mark_safe
2
2
import subprocess  # To call Pandoc
3
3
+
4
4
5
register = template.Library()
5
6
6
7
@register.filter
7
8
def org(value):
8
9
    """ Takes an input, and transpiles it as org-mode syntax to HTML syntax. """
9
10
    # TODO Write bug handling code and exception handling
10
11
    f = open('/tmp/django-temp.org', 'w')
11
12
    f.write(value)
12
13
13
14
    f.close()
14
15
    f = open('/tmp/django-temp.org', 'r')
15
16
    #f2 = open('/tmp/django-output.html', 'w+')
16
17
    subprocess.run(["pandoc", "--from=org", "--to=html", "-o" "/tmp/django-output.html"], stdin=f)
17
18
    #f2.close()
18
19
    f2 = open('/tmp/django-output.html', 'r')
19
20
    result = f2.read()
20
21
    f.close()
21
22
    f2.close()
22
23
    return mark_safe(result)
23
24
    #print("OK!")
24
25
    #return mark_safe(subprocess.check_output(["iconv", "-t", "utf-8", "/tmp/django-temp.org", "|", "pandoc", "--from=org", "--to=html"]))#, "/tmp/django-temp.org"]))
25
26
#return mark_safe(subprocess.check_output(["pandoc", "--from=org", "--to=html", value]))
26
27
+
28
@register.simple_tag
+
29
def pingping():
+
30
    link = "https://uhasselt-pxl.mynetpay.be/Account/Login"
+
31
    # Get CSRF token
+
32
    first_call = requests.get(link)
+
33
    text = first_call.text
+
34
    begin = text.find('__RequestVerificationToken')
+
35
    begin = text.find('value="', begin)
+
36
    end = text.find('" ', begin)
+
37
    token = text[begin+len('value="'):end]
+
38
    cookies = first_call.cookies
+
39
+
40
    username = ""
+
41
    password = ""
+
42
+
43
    response = requests.post(link, data={
+
44
        'Username':username,
+
45
        'LoginType':'Student',
+
46
        'Password':password,
+
47
        '__RequestVerificationToken':token,
+
48
        }, cookies=cookies)
+
49
+
50
    html_response = response.text
+
51
    start = html_response.find(": &euro; ")
+
52
    offset = len(": &euro; ")
+
53
    return html_response[start+offset:start+offset+5]
+
54