예제 #1
0
	def news(self, news_id):
		news           = {"title": "", "body": "", "attached": {"url": "", "filename": ""}}
		html           = urllib2.urlopen("https://www.vklass.se/SchoolNews.aspx?id=%i" % news_id).read()
		news['body']   = cre.prettify(cre.between('<span id="ctl00_ContentPlaceHolder2_newsShortLabel">', '</span>', html))
		news['title']  = cre.prettify(cre.between('<span id="ctl00_ContentPlaceHolder2_nameLabel">', '</span>', html))
		attached_file_html_chunk = cre.between('<a id="ctl00_ContentPlaceHolder2_NewsAttachmentLink" href="', '</a>', html)
		if attached_file_html_chunk != "":
			news['attached']['url'] = attached_file_html_chunk.split('">')[0]
			news['attached']['filename'] = attached_file_html_chunk.split('">')[1]

		return news
예제 #2
0
	def domains(self):
		html    = urllib2.urlopen("https://customerzone.loopia.se/domains/properties/index/domain/").read()
		options = cre.all_between("<option", '</option>', html)
		domains = []
		for option in options:
			label = cre.between('label="', '"', option)
			name  = option.split(">")[-1]
			id    = cre.between('value="', '"', option)
			if name == label and "." in name:
				domains.append({'id': id, 'name': name})
		return domains
예제 #3
0
	def profile_info(self, profile_id):
		info = None
		initial_profile_id = profile_id
		client.log("Looking up info for profile id %s" % str(profile_id))
		query        = "SELECT * FROM users WHERE profile_id = %i" % int(profile_id)
		self.cursor.execute(query)
		dbresult = self.cursor.fetchone()
		if dbresult:
			client.log("Returning info from db")
			profile_id       = dbresult[1]
			profile_id2      = dbresult[2]
			profile_name     = dbresult[3]
			profile_class    = dbresult[4]
			age              = dbresult[5]
			msn              = dbresult[6]
			email            = dbresult[7]
			cellphone_number = dbresult[8]
			school           = dbresult[9]
			avatar_filename  = dbresult[10]
		elif profile_id == 0 and self.my_profile_info != None:
			client.log("Already fetched info for this account")
			return self.my_profile_info
		else:
			lookup_url = "%s/User.aspx?id=%s" % (self.base_url, str(profile_id))
			client.log("No info in db. Fetching from %s" % lookup_url)
			try:
				profile_data     = urllib2.urlopen(lookup_url).read()
				profile_id       = int(cre.between('href="Guestbook.aspx\?id=', '"', profile_data))
				profile_id2      = cre.between('frameborder="0" src="https://user.vklass.se/presentation/', '"', profile_data)
				profile_name     = cre.between('<li><span id="ctl00_ContentPlaceHolder2_nameLabel">Namn: ', '</span></li>', profile_data)
				profile_class    = cre.between('<li><span id="ctl00_ContentPlaceHolder2_classLabel">Klass: ', '</span></li>', profile_data)
				age              = cre.between('<li><span id="ctl00_ContentPlaceHolder2_ageLabel">', '</span></li>', profile_data)
				msn              = cre.between('<li><span id="ctl00_ContentPlaceHolder2_msnLabel">MSN: ', '</span></li>', profile_data)
				email            = cre.between('<li><span id="ctl00_ContentPlaceHolder2_mailLabel">Email: ', '</span></li>', profile_data)
				cellphone_number = cre.between('<li><span id="ctl00_ContentPlaceHolder2_mobileLabel">Mobil: ', '</span></li>', profile_data)
				school           = cre.between('<li>Skola: ', '<', profile_data)
				avatar_filename  = cre.between('https://user.vklass.se/photo/large/', '" target="', profile_data)
		
				self.cursor.execute("INSERT INTO users (profile_id, profile_id2, name, class, age, msn, email, cellphone_number, school, avatar_filename) VALUES(%i, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')" % (profile_id, profile_id2, profile_name, profile_class, age, msn, email, cellphone_number, school, avatar_filename))
				self.dbc.commit()
				client.ensure_dir(self.profile_picture_dir)
				if avatar_filename:
					client.download('%s/photo/large/%s' % (self.base_url, avatar_filename, self.profile_picture_dir + "/" + avatar_filename))
				info = {"profile_id" : profile_id, "profile_id2": profile_id2, "name" : profile_name, "class" : profile_class, "age" : age, "msn" : msn, "email" : email, "cellphone_number" : cellphone_number, "school" : school, "avatar_filename" : avatar_filename}
			except:
				client.log("Could not fetch data from %s" % lookup_url)

		if self.my_profile_info == None and initial_profile_id == 0:
			self.my_profile_info = info
		return info
예제 #4
0
	def update_dns(self, domain, type, target):
		#Type can be either A or CNAME
		client.log("Updating DNS settings for %s. Pointing %s --> %s" % (domain['name'], domain['name'], target))
		html     = urllib2.urlopen("https://customerzone.loopia.se/domains/properties/index/domain/%s" % domain['id']).read()
		hash     = cre.between('<input type="hidden" name="hash" value="', '"', html)
		settings = urllib.urlencode({'type': type, 'target': target, 'hash': hash})
		urllib2.urlopen("https://customerzone.loopia.se/domains/properties/dns/domain/%s/subdomain/0/synchronize/1/context/json" % domain['id'], settings).read()
예제 #5
0
	def logged_in(self):
		client.log("Validating login")
		html = urllib2.urlopen("https://customerzone.loopia.se/").read()
		if '<div class="logged-in-user">' in html:
			client.log("Logged in as %s" % cre.between('<div class="logged-in-user">', '</div>', html))
			return True
		client.log("Not logged in")
		return False
예제 #6
0
	def message(self, message_id):
		html                           = urllib2.urlopen("%s/Messaging/MessageRead.aspx?id=%i" % (self.base_url, message_id)).read()
		message                        = {"attachments": [], "participants": [], "posts": []}
		message['owner']               = self.username
		message['body']                = cre.prettify(cre.all_between('<span id="ctl00_ContentPlaceHolder2_postRepeater_ctl.._textLabel">', '</span>', html)[-1])
		message['title']               = cre.prettify(cre.between('<span id="ctl00_ContentPlaceHolder2_topicLabel">', '</span>', html))
		message['created']             = cre.prettify(cre.between('<span id="ctl00_ContentPlaceHolder2_dateLabel">', '</span>', html))
		trash                          = cre.all_between('<span id="ctl00_ContentPlaceHolder2_postRepeater_ctl.._posterLabel">', '</p>', html)
		del trash[-1]
		for trash in trash:
			username                   = trash.split("</span>")[0]
			body                       = trash.split("</span>")[-2].split('_textLabel">')[-1]
			date                       = cre.between('<span id="ctl00_ContentPlaceHolder2_postRepeater_ctl.._Label1">', '</span>', trash)
			post = {"username": username, "date": date, "body": body}
			message['posts'].append(post)

		trash                          = cre.between('<a id="ctl00_ContentPlaceHolder2_creatorLink" href="/User.aspx\?id=', '</a></h3>', html).split('">')
		message['creator']             = {'user_id': int(trash[0]), "name": trash[1]}
		participants_dirty_html_chunks = cre.between('<h3>Deltagare: ', '</h3>', html).split(', ')
		for dirty_participant_chunk in participants_dirty_html_chunks:
			user_id                    = int(cre.between('<a href="/User.aspx\?id=', '">', dirty_participant_chunk))
			username                   = cre.between('">', '</a>', dirty_participant_chunk)
			participant                = {"user_id": user_id, "username": username}
			message['participants'].append(participant)
			for post_id in range(len(message['posts'])):
				if message['posts'][post_id]['username'] == username:
					message['posts'][post_id]['user_id'] = user_id
		
		dirty_attachment_html_chunks   = cre.all_between('_AttachmentLink" href="', '</a></li>', html)
		for chunk in dirty_attachment_html_chunks:
			attachment                 = {"url": chunk.split('"')[0], "filename": chunk.split('">')[-1]}
			message['attachments'].append(attachment)

		return message
예제 #7
0
	def login(self, username, password):
		client.log("Logging in to %s as %s" % (self.base_url, username))
		self.username     = username
		self.password     = password
		vklass_cj         = cookielib.CookieJar()
		vklass_opener     = urllib2.build_opener(urllib2.HTTPCookieProcessor(vklass_cj))
		vklass_opener.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.10) Gecko/20100922 Ubuntu/10.10 (maverick) Firefox/3.6.11')]
		urllib2.install_opener(vklass_opener)

		index           = urllib2.urlopen(self.base_url).read()
		eventvalidation = cre.between('<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="', '" />', index)
		viewstate       = cre.between('<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="', '" />', index)
		login_data      = urllib.urlencode({'__EVENTTARGET' : 'Button1', '__EVENTARGUMENT' : '', '__VIEWSTATE' : viewstate, '__EVENTVALIDATION' : eventvalidation, 'tb_username' : username, 'tb_password' : password, 'ThemeSelect' : 'Vklass', 'RadWindow1_ClientState' : '', 'RadWindowManager1_ClientState' : ''})
		login = urllib2.urlopen(self.base_url + '/login.aspx?cookieCheck=true', login_data)
		if 'title="Logga ut' in urllib2.urlopen("%s/default.aspx" % self.base_url).read():
			client.log("Login successfull")
			return True
		client.log("Login failed")
		return False
예제 #8
0
	def time_summary(self):
		# Presence the latest 30 days
		html     = urllib2.urlopen("%s/Results/default.aspx" % self.base_url).read()
		trash    = cre.between('<span id="ctl00_ContentPlaceHolder2_attendanceMinutesLabel">', '</span>', html).split(" ")
		time = {"present": {}, "absent": {}}
		time['scheduled_minutes'] = int(trash[6])

		time['present']['percentage'] = int(trash[0])
		time['present']['minutes'] = int(trash[3])

		time['absent']['minutes'] = time['scheduled_minutes'] - time['present']['minutes']
		time['absent']['late_arrival_minutes'] = int(trash[10])
		time['absent']['approved_percentage'] = int(trash[14])
		time['absent']['unapproved_percentage'] = int(trash[18])
		
		return time
예제 #9
0
	def exam_statistics(self, exam_id):
		# The exam_id seems to increment by one for every new exam and they start at 1 and is 2011-04-16 around 8000.

		html                        = urllib2.urlopen("%s/ExamStatistics.aspx?id=%i" % (self.base_url, exam_id)).read()
		critical_error_messages = ["existerar ej"]
		for error_message in critical_error_messages:
			if error_message in html:
				return None
		else:
			exam                        = {"possible_grades": None, "exam_participants": None, "course_participants": None, "grades": None}
			exam['name']                = cre.between('<span id="ctl00_ContentPlaceHolder2_nameLabel">', '</span>', html)
			exam['course']              = cre.between('<span id="ctl00_ContentPlaceHolder2_courseLabel">', '</span>', html)
			exam['type']                = cre.between('<span id="ctl00_ContentPlaceHolder2_typeLabel">', '</span>', html).replace("  ", "")
			exam['date']                = cre.between('<span id="ctl00_ContentPlaceHolder2_dateLabel">', '</span>', html)
			if "ej statistik" not in html:
				exam['possible_grades']     = cre.between('<span id="ctl00_ContentPlaceHolder2_gradingLabel">', '</span>', html).split("/")
				exam['exam_participants']   = cre.between('<span id="ctl00_ContentPlaceHolder2_numberLabel">', '</span>', html).split(" ")[0]
				exam['course_participants'] = cre.between('<span id="ctl00_ContentPlaceHolder2_numberLabel">', '</span>', html).split(" ")[2]
				exam['grades']              = {}
				for offset in range(len(exam['possible_grades'])):
					exam['grades'][exam['possible_grades'][offset]] = cre.between('<span id="ctl00_ContentPlaceHolder2_infoLabel">', '</span>', html).replace(" ", "").split(":")[1 + offset].split("<")[0]
	
			return exam
예제 #10
0
	def current_schedule(self):
		# Will show the current schedule for this week. Ugly and hackish, fix later..
		html     = urllib2.urlopen("%s/schema.aspx" % self.base_url).read()
		lessons  = {"monday": [], "tuesday": [], "wednesday": [], "thursday": [], "friday": []}
		for chunk in cre.all_between('<div class="LessonInfoContainer"', '</td>', html):
			name = chunk.split("<br />")[-3].split("<span>")[-1]
			room = chunk.replace("</span></div>", "").split(">")[-1]
			for thingie in room.split(" "):
				try:
					room = int(thingie)
				except:
					pass
			time             = cre.between('px;">', "<br />", chunk)
			day              = time.split(" ")[0]
			from_hour        = time.split(" ")[1]
			to_hour          = time.split(" ")[3]
			day_replacements = [["M", "monday"], ["Ti", "tuesday"], ["Ons", "wednesday"], ["To", "thursday"], ["F", "friday"]] 
			for replacement in day_replacements:
				if day.startswith(replacement[0]):
					day = replacement[1]
			lesson = {"name": name, "room": room, "from": from_hour, "to": to_hour}
			lessons[day].append(lesson)
		return lessons
예제 #11
0
	def class_uid(self):
		html      = urllib2.urlopen("%s/classlist.aspx" % self.base_url).read()
		class_uid = cre.between("classUID=\" \+ '", "'\)", html)

		return class_uid
예제 #12
0
def external_ip():
	return cre.between("<title>What's My IP - Your IP is: ", "</title>", urllib2.urlopen("http://whatsmyip.net/").read())