Skip to content

Instantly share code, notes, and snippets.

@bancek
Created March 29, 2013 08:48
Show Gist options
  • Save bancek/5269574 to your computer and use it in GitHub Desktop.
Save bancek/5269574 to your computer and use it in GitHub Desktop.
Login for FRI ucilnica
# pip install requests
import re
import requests
UCILNICA_LOGIN_URL = 'https://ucilnica.fri.uni-lj.si/login/index.php'
UCILNICA_LOGGEDIN_URL = 'https://ucilnica.fri.uni-lj.si/'
def ucilnica_login(username, password):
"""Check login for FRI ucilnica
Usage:
from ucilnica import ucilnica_login
user_info = ucilnica_login(username, password)
if user_info:
name = user_info['name']
"""
try:
resp = requests.post(UCILNICA_LOGIN_URL, dict(username=username, password=password), verify=False)
if resp.url == UCILNICA_LOGGEDIN_URL:
match = re.search('<a href="https://ucilnica.fri.uni-lj.si/user/profile.php\?id=(\d+)">(.*?)</a>', resp.content)
if match:
ucilnica_id = int(match.group(1))
name = match.group(2).decode('utf8')
return {
'ucilnica_id': ucilnica_id,
'name': name
}
except Exception, e:
print 'Ucilnica login error: ', e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment