Exemple #1
0
	def send_chat(self, to, message):
		client.log("Sending message: %s, to: %s" % (message, self.info_by_id2(to)['UserName']))
		chat_url = "%s/Handler/chathandler.ashx?action=sendchat" % self.base_url
		request  = urllib.urlencode({'to': to, 'message': message})
		result   = urllib2.urlopen(chat_url, request).read()
		self.cursor.execute("INSERT INTO chat (from_id, to_id, message, time) VALUES('%s', '%s', '%s', %i)" % ('0', to, message.replace("'", "''"), int(time.time())))
		self.dbc.commit()
	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()
Exemple #3
0
	def loop(self):
		self.ensure_configuration_files()
		pygmail.login(self.conf()['accounts']['mail']['username'], self.conf()['accounts']['mail']['password'])

		for account in self.conf()['accounts']['vklass']:
			client.log("Spawning vklass session with username: %s, email: %s" % (account['username'], account['email']))
			vklass_session = pyvklass.Vklass()
			vklass_session.notification_email = account['email']
			vklass_session.login(account['username'], account['password'])
			self.sessions.append(vklass_session)
		
		while self.running:
			for session in self.sessions:
				for message in session.first_messages():
					if json.dumps(message) not in self.saved_messages():
						subject = message['title']
						body    = message['body']
						if len(message['posts']) > 0:
							body += "\n Posts: \n"
						for post in message['posts']:
							body += "  |  %s  |  %s  |\n" % (post['date'], post['username'])
							body += "  --> %s" % post['body']

						pygmail.send(session.notification_email, subject, body)
						client.append(self.conf()['files']['saved_messages'], json.dumps(message) + "\n")
			time.sleep(120)
	def login(self, username, password):
		client.log("Logging in as %s" % username)
		cookiejar                 = cookielib.CookieJar()
		loopia_opener             = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar))
		loopia_opener.add_headers = [('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.10')]
		login_query               = urllib.urlencode({'username': username, 'password': password, 'action': 'submit', 'submit.x': '0', 'submit.y': '0', 'new': 0})
		urllib2.install_opener(loopia_opener)
		urllib2.urlopen("https://www.loopia.com/login", login_query)
Exemple #5
0
	def do_exam(self, exam_id):
		try:
			exam_id = int(exam_id)
		except:
			client.log("Please enter an exam id as an argument")
			return False
			
		self.print_exam(self.v.exam_statistics(exam_id))
Exemple #6
0
	def create_tables(self):
		client.log("Creating tables")
		try:
			self.cursor.execute("CREATE TABLE users (id integer primary key autoincrement, profile_id integer, profile_id2 text, name text, class text, age text, msn text, email text, cellphone_number text, school text, avatar_filename text)")
			self.cursor.execute("CREATE TABLE chat (id integer primary key autoincrement, from_id text, to_id text, message text, time integer)")
			self.dbc.commit()
		except:
			client.log("Failed. Do they already exist?")
Exemple #7
0
	def login_from_file(self):
		if os.path.exists(self.configuration_file):
			f = open(self.configuration_file, 'r')
			conf = json.loads(f.read())
			f.close()
			try:
				self.login(conf['account']['username'], conf['account']['password'])
			except:
				client.log("Could not log in to %s with the credentials in %s" % (self.base_url, self.configuration_file))
Exemple #8
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
Exemple #9
0
	def do_news(self, args):
		client.log("Fetching news")
		for news in self.v.all_news():
			client.log(news['title'])
			if news['body'] != "":
				client.log(news['body'])
			if news['attached']['url'] != "":
				client.log("Attached: %s | URL: %s" % (news['attached']['filename'], news['attached']['url']))
			print ""
Exemple #10
0
	def print_message(self, message):
		client.log("|   %s   |   %s   |   %s   |" % (message['title'], message['creator']['name'], message['created']))
		client.log(message['body'])
		client.log("")
		if len(message['posts']) > 0:
			client.log("Posts:")
			for post in message['posts']:
				print "  |  %s  |  %s  |" % (post['date'], post['username'])
				print "  --> %s" % post['body']
Exemple #11
0
def make_auction_invoice(sender, **kwargs):
    auction = sender
    client.log("auction_finished_signal")
    if auction.winner:

        from bidding.models import AuctionInvoice

        invoice = AuctionInvoice()
        invoice.auction = auction
        invoice.member = auction.winner
        invoice.uid = uuid.uuid4()
        invoice.save()

        #winnner for fun earns retail price in tokens!
        if auction.bid_type == 'token':
            mem = auction.winner
            mem.tokens_left += int(auction.item.retail_price)
            mem.save()

            client.callReverse(mem.facebook_id, 'reloadTokens')
	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
Exemple #13
0
def send(to, subject, message):
	global username, password
	client.log("Sending email to %s" % to)
	try:
		server = smtplib.SMTP('smtp.gmail.com:587')  
		server.starttls()  
		server.login(username,password)  
	except:
		client.log("Authentication error!")
		return False
	try:
		server.sendmail(username, to, "Subject: %s\r\n%s" % (subject,message))  
		server.quit()
		client.log("Email sent to %s" % to)
	except:
		client.log("Could not send email to %s" % to)
Exemple #14
0
def send_win_email(sender, **kwargs):
    try:
        client.log("auction_finished_signal")
        logger.debug("Sending mail")
        auction = sender
        user = auction.winner

        if user and auction.bid_type == 'bid':
            print "sending email"

            subject = render_to_string('bidding/auction_won_subject.txt', {
                'user': user,
                'item': auction.item
            }).replace('\n', '')
            from_email = settings.DEFAULT_FROM_EMAIL
            to = user.email

            html_content = render_to_string(
                'bidding/mail_winner.html', {
                    'user': user,
                    'auction': auction,
                    'site': settings.SITE_NAME,
                    'images_site': settings.IMAGES_SITE
                })
            text_content = strip_tags(
                html_content
            )  # this strips the html, so people will have the text as well.

            # create the email, and attach the HTML version as well.
            msg = EmailMultiAlternatives(subject, text_content, from_email,
                                         [to])
            msg.attach_alternative(html_content, "text/html")
            msg.send()

    except Exception:
        logging.info('signal.send_win_email', exc_info=True)
        raise
Exemple #15
0
	def do_messages(self, args):
		if len(self.messages) == 0:
			self.do_fetch_messages("")
		
		for message_id in range(len(self.messages)):
			client.log("[%i] %s" % (message_id, self.messages[message_id]['title']))
			client.log("  * From: %s" % self.messages[message_id]['creator']['name'])
			client.log("  * Date: %s" % self.messages[message_id]['created'])
			print ""

		message_id = int(client.input("Message id: "))
		self.print_message(self.messages[message_id])
Exemple #16
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
Exemple #17
0
	def do_status(self, args):
		status = self.v.status()
		client.log("Guestbook: %s | Messages: %s | Forum: %s | Friend requests: %s" % (status['guestbook'], status['messages'], status['forum'], status['friends']))
Exemple #18
0
# -*- coding: utf-8 -*-
from linepy import *
from datetime import datetime
from bs4 import BeautifulSoup
from threading import Thread
from googletrans import Translator
from gtts import gTTS
from time import strftime
import time, random, sys, json, codecs, threading, glob, urllib, urllib3, re, ast, os, subprocess, requests, tempfile, html5lib, wikipedia, goslate, profile, client, timeit

client = LineClient()
#client = LineClient(id='*****@*****.**', passwd='zaswdc12')
#client = LineClient(authToken='')
client.log("Auth Token : " + str(client.authToken))

channel = LineChannel(client)
client.log("Channel Access Token : " + str(channel.channelAccessToken))
cl = client
poll = LinePoll(client)
HelpMessagelist = """
"""
KAC = [cl]
mid = cl.getProfile().mid
Bots = [mid]
admin = [
    "u2b37602c4f9f8d54917de47b09749130", "u64fd0e930e2133c26491c4409e28af03",
    mid
]
owner = [
    "u2b37602c4f9f8d54917de47b09749130", "u64fd0e930e2133c26491c4409e28af03",
    mid
Exemple #19
0
	def do_lunch_menu(self, args):
		menu = self.v.food_menu()
		for day in self.days:
			client.log("%s: %s" % (day, menu[day]))
Exemple #20
0
	def do_time_summary(self, args):
		summary = self.v.time_summary()
		client.log("Time summary for the past 30 days")
		client.log("Present: ")
		client.log("  * %i minutes" % summary['present']['minutes'])
		client.log("  * %i%%" % summary['present']['percentage'])

		client.log("Absent: ")
		client.log("  * %i minutes" % summary['absent']['minutes'])
		client.log("  * Approved   %i%% " % summary['absent']['approved_percentage'])
		client.log("  * Unapproved %i%% " % summary['absent']['unapproved_percentage'])
Exemple #21
0
	def do_courses(self, args):
		client.log("Courses:")
		for course in self.v.courses():
			client.log("  * %s" % course)
Exemple #22
0
	def do_profile_visitors(self, args):
		client.log("Latest profile visitors:")
		for visitor in self.v.latest_profile_visitors():
			client.log("  * %s | %s" % (visitor['time'], visitor['name']))
Exemple #23
0
	def do_schedule(self, args):
		schedule = self.v.current_schedule()
		for day in self.days:
			client.log(day)
			for lesson in schedule[day]: 
				client.log("  * %s --> %s %s %s" % (lesson['from'], lesson['to'], lesson['room'], lesson['name']))
Exemple #24
0
	def stay_logged_in(self):
		if 'title="Logga ut' not in urllib2.urlopen("%s/default.aspx" % self.base_url).read():
			client.log("Got logged out")
			self.login(self.username, self.password)
Exemple #25
0
	def do_class_exams(self, args):
		client.log("Exams listed in the class calendar:")
		for exam in self.v.class_calendar_exams():
			self.print_exam(exam)
			print ""
Exemple #26
0
	def print_exam(self, exam):
		client.log("Name:    %s" % exam['name'])
		client.log("Course:  %s" % exam['course'])
		client.log("Type:    %s" % exam['type'])
		client.log("Date:    %s" % exam['date'])
		if exam['grades'] != None: # There's statistics available
			possible_grades = ""
			for possible_grade in exam['possible_grades']:
				possible_grades += possible_grade + "/"
			client.log("Achievable grades: %s" % possible_grades)
			client.log("Participants: %s/%s" % (exam['exam_participants'], exam['course_participants']))
			results = "Statistics: "
			for grade, amount in exam['grades'].items():
				results += "%s: %s | " % (grade, amount)
			client.log(results)
		else:
			client.log("No statistics available")
Exemple #27
0
	def do_class_events(self, args):
		client.log("Events listed in the class calendar:")
		for event in self.v.class_events():
			client.log("  > " + event['name'])
			client.log("  * " + event['description'])
			print ""