Beispiel #1
0
def update_all_stocks_sheets(
        unsubscribe_url='Bad Developer... Always supply this.'):
    """
    Get new stock prices, alert users, and update spreadsheets.
    :param unsubscribe_url: Url that will be put in alert emails allowing users to unsubscribe.
    """

    sheet_prices_dict, sheet_alerts_dict = db.update_stock_prices(alerts=True)

    user_alerts_dict = db.get_user_alerts(sheet_alerts_dict)

    l = emails.get_emails(user_alerts_dict, unsubscribe_url)
    emails.send_emails(l)

    for ssheet_id, prices in sheet_prices_dict.items():
        credentials = db.get_credentials(ssheet_id=ssheet_id)
        h = credentials.authorize(httplib2.Http())
        # TODO(jalex): Implement using GAE's task queues (https://cloud.google.com/appengine/docs/python/taskqueue/)
        if USE_THREADS:
            t = threading.Thread(target=sheets.set_prices,
                                 args=(ssheet_id, prices, h))
            t.daemon = True
            t.start()
        else:
            sheets.set_prices(ssheet_id, prices, h)
Beispiel #2
0
def oauth2callback():
    """
    Endpoint for both oauth steps.
    :return: Response to authorize or response to exchange auth code for access token.
    """
    flow = client.flow_from_clientsecrets(
        FILEPATH_CREDENTIALS,
        scope=SCOPE,
        redirect_uri=flask.url_for('oauth2callback', _external=True))
    if 'code' not in flask.request.args:
        flow.params['access_type'] = 'offline'
        flow.params['approval_prompt'] = 'force'
        auth_uri = flow.step1_get_authorize_url()
        return flask.redirect(auth_uri)
    else:
        auth_code = flask.request.args.get('code')
        credentials = flow.step2_exchange(auth_code)
        user_info = _get_user_info(credentials)
        user_id, user_email = user_info['id'], user_info['email']
        if credentials.refresh_token is not None:
            db.store_user_credentials(user_id, credentials, email=user_email)
        else:
            credentials = db.get_credentials(user_id=user_id)
            assert credentials.refresh_token is not None
        flask.session['credentials'] = credentials.to_json()
        flask.session['user_id'] = user_id
        func_name = flask.session.get('original_func_name', 'index')
        return flask.redirect(flask.url_for(func_name))
Beispiel #3
0
def oauth2callback():
    """
    Endpoint for both oauth steps.
    :return: Response to authorize or response to exchange auth code for access token.
    """
    flow = client.flow_from_clientsecrets(FILEPATH_CREDENTIALS,
                                          scope=SCOPE,
                                          redirect_uri=flask.url_for('oauth2callback', _external=True))
    if 'code' not in flask.request.args:
        flow.params['access_type'] = 'offline'
        flow.params['approval_prompt'] = 'force'
        auth_uri = flow.step1_get_authorize_url()
        return flask.redirect(auth_uri)
    else:
        auth_code = flask.request.args.get('code')
        credentials = flow.step2_exchange(auth_code)
        user_info = _get_user_info(credentials)
        user_id, user_email = user_info['id'], user_info['email']
        if credentials.refresh_token is not None:
            db.store_user_credentials(user_id, credentials, email=user_email)
        else:
            credentials = db.get_credentials(user_id=user_id)
            assert credentials.refresh_token is not None
        flask.session['credentials'] = credentials.to_json()
        flask.session['user_id'] = user_id
        func_name = flask.session.get('original_func_name', 'index')
        return flask.redirect(flask.url_for(func_name))
Beispiel #4
0
def marks(bot, update, args):
	chat_id = update.message.chat_id
	reg_status = db.is_registered(chat_id)
	if (not reg_status):
		error_message ="Are you registered?"
		reply(bot,update,error_message)
		return
	registration_number,password = db.get_credentials(chat_id)
	marks_message = scraper.scrape(registration_number,dec(str(password)),'marks',args)
	reply(bot,update,marks_message)
	return
Beispiel #5
0
def attendance(bot, update, args):
	chat_id = update.message.chat_id
	reg_status = db.is_registered(chat_id)
	if (not reg_status):
		error_message = "Are you registered?"
		logger.info("%s tried to fetch attendance without registering",chat_id)
		reply(bot,update,error_message)
		return
	registration_number,password = db.get_credentials(chat_id)
	attendance_message = scraper.scrape(registration_number,dec(str(password)),'attendance',args)
	logger.info("%s was sent attendance",registration_number)
	reply(bot,update,attendance_message);
	return
Beispiel #6
0
def timetable(bot, update, args):
	chat_id = update.message.chat_id
	reg_status = db.is_registered(chat_id)
	if (not reg_status):
		error_message = "Are you registered?"
		reply(bot,update,error_message)
		return
	timetable_message = db.get_timetable(chat_id)
	if (timetable_message):
		reply(bot,update,timetable_message)
		return
	registration_number,password = db.get_credentials(chat_id)
	timetable_message = scraper.scrape(registration_number,dec(str(password)),'timetable',args)
	db.set_timetable(chat_id,timetable_message,hashlib.sha1(timetable_message).hexdigest())
	reply(bot,update,timetable_message)
	return
Beispiel #7
0
def update_all_stocks_sheets(unsubscribe_url='Bad Developer... Always supply this.'):
    """
    Get new stock prices, alert users, and update spreadsheets.
    :param unsubscribe_url: Url that will be put in alert emails allowing users to unsubscribe.
    """

    sheet_prices_dict, sheet_alerts_dict = db.update_stock_prices(alerts=True)

    user_alerts_dict = db.get_user_alerts(sheet_alerts_dict)

    l = emails.get_emails(user_alerts_dict, unsubscribe_url)
    emails.send_emails(l)

    for ssheet_id, prices in sheet_prices_dict.items():
        credentials = db.get_credentials(ssheet_id=ssheet_id)
        h = credentials.authorize(httplib2.Http())
        # TODO(jalex): Implement using GAE's task queues (https://cloud.google.com/appengine/docs/python/taskqueue/)
        if USE_THREADS:
            t = threading.Thread(target=sheets.set_prices, args=(ssheet_id, prices, h))
            t.daemon = True
            t.start()
        else:
            sheets.set_prices(ssheet_id, prices, h)
Beispiel #8
0
sessionNumber = "1171"

#make database to store jobs
initialize_database()

#creates file that will store all jobs
with open("ShortListJobs.txt", "w") as myfile:
    myfile.write("\n=============================Jobs Added To Short List=============================")
myfile.close()


credentials = prompt_credentials()


print('getting credentials now...')
print(db.get_credentials())


connection=sqlite3.connect("jobs.db")
c = connection.cursor()

session = requests.Session()
params = {'userid': str(credentials[0]), 'pwd': str(credentials[1])} #timezoneOffset and submit are unnecessary but also submitted

#===============login
s = session.post('https://jobmine.ccol.uwaterloo.ca/psp/ES/?cmd=login&languageCd=ENG&sessionId= ', params)

#=================go to Job Inquiry, the get method must exist before using a post
s = session.get("https://jobmine.ccol.uwaterloo.ca/psc/ES/EMPLOYEE/WORK/c/UW_CO_STUDENTS.UW_CO_JOBSRCH.GBL?pslnkid=UW_CO_JOBSRCH_LINK&FolderPath=PORTAL_ROOT_OBJECT.UW_CO_JOBSRCH_LINK&IsFolder=false&IgnoreParamTempl=FolderPath%2cIsFolder&PortalActualURL=https%3a%2f%2fjobmine.ccol.uwaterloo.ca%2fpsc%2fES%2fEMPLOYEE%2fWORK%2fc%2fUW_CO_STUDENTS.UW_CO_JOBSRCH.GBL%3fpslnkid%3dUW_CO_JOBSRCH_LINK&PortalContentURL=https%3a%2f%2fjobmine.ccol.uwaterloo.ca%2fpsc%2fES%2fEMPLOYEE%2fWORK%2fc%2fUW_CO_STUDENTS.UW_CO_JOBSRCH.GBL%3fpslnkid%3dUW_CO_JOBSRCH_LINK&PortalContentProvider=WORK&PortalCRefLabel=Job%20Inquiry&PortalRegistryName=EMPLOYEE&PortalServletURI=https%3a%2f%2fjobmine.ccol.uwaterloo.ca%2fpsp%2fES%2f&PortalURI=https%3a%2f%2fjobmine.ccol.uwaterloo.ca%2fpsc%2fES%2f&PortalHostNode=WORK&NoCrumbs=yes&PortalKeyStruct=yes")

try:
Beispiel #9
0
def login():
    credentials = db.get_credentials()
    params = {'userid': str(credentials[0]), 'pwd': str(credentials[1]) }
    session = requests.Session()
    session.post('https://jobmine.ccol.uwaterloo.ca/psp/ES/?cmd=login&languageCd=ENG&sessionId= ', params)
    return session