예제 #1
0
파일: cmd.py 프로젝트: cuimuxi/gtalkbot
def send_to_msg(stanza, to, body):
    frm = stanza.get_from()
    email = '%s@%s' % (frm.node, frm.domain)
    nick = get_nick(email)
    add_history(email, to, body)
    body = "[%s 悄悄对你说] %s" % (nick, body)
    return send_msg(stanza, to, body)
예제 #2
0
파일: cmd.py 프로젝트: cuimuxi/gtalkbot
def send_all_msg(stanza, body):
    frm = stanza.get_from()
    email = '%s@%s' % (frm.node, frm.domain)
    nick = get_nick(email)
    add_history(email, 'all', body)
    tos = get_members(email)
    ms = []
    if '@' in body:
        r = re.findall(r'@<(.*?)>', body)
        mem = [get_member(nick=n) for n in r if get_member(nick = n)]
        if mem:
            if body.startswith('@<'):
                b = re.sub(r'^@<.*?>', '', body)
                return send_to_msg(stanza, mem[0], b)
            b = '%s 提到了你说: %s' % (nick, body)
            ml = [send_to_msg(stanza, to, b) for to in mem]
            ms += ml
    elif body.strip() == 'help':
        return send_command(stanza, '$help')
    body = "[%s] %s" % (nick, body)
    for to in tos:
        m = send_msg(stanza, to, body)
        ms.append(m)
    return ms
예제 #3
0
def sign_in(event, context):

	data = json.loads(event['body'])


	# expects to get a json object as such...
	# {
	# 	"name" : string,
	# 	"castMember" : string,
	# 	"session" : string,
	# 	"comments": string,
	# 	"geolocation" : object
	# }

	# first run geolocation check on it
	try:

		geo_check_result = utils.check_geolocation(data['geolocation'], work_from_home=data['workFromHome'])

	except:

		response = {
			"body" : json.dumps({"error": True, "message" : "Error while processing timestamp and geolocation.  Try refreshing the page."}),
			"statusCode" : 200,
			"headers" : {
	           "Access-Control-Allow-Origin" : "*",
			   "Access-Control-Allow-Methods" : "GET, POST, DELETE"
	        },
		}

		return response



	if geo_check_result['error']:

		response = {
			"body" : json.dumps(geo_check_result),
			"statusCode" : 200,
			"headers" : {
	           "Access-Control-Allow-Origin" : "*",
			   "Access-Control-Allow-Methods" : "GET, POST, DELETE"
	        },
		}

		return response

	else:

		history_dict = {

			"name" : data['name'],
			"session" : data['session'],
			"comments" : data['comments'],
			"datestamp" : utils.make_datestamp(data['geolocation']['timestamp'], is_JS=True),
			"cast_member" : data['castMemberName'],
			"type" : "sign_in",
			"remote" : data['workFromHome'],
			"elapsed_hours" : "N/A"
		}

		db.add_history(data['castMemberId'], history_dict)

		success_result = db.insert(data)

		response = {
			"body" : json.dumps(success_result),
			"statusCode" : 200,
			"headers" : {
	           "Access-Control-Allow-Origin" : "*",
			   "Access-Control-Allow-Methods" : "GET, POST, DELETE"
	        },
		}

		return response
예제 #4
0
def process_sign_out(event, context):

	data = json.loads(event['body'])

	# first run geolocation check on it
	try:

		geo_check_result = utils.check_geolocation(data['geolocation'], work_from_home=data['workFromHome'])

	except:

		response = {
			"body" : json.dumps({"error": True, "message" : "Error while processing timestamp and geolocation.  Try refreshing the page."}),
			"statusCode" : 200,
			"headers" : {
	           "Access-Control-Allow-Origin" : "*",
			   "Access-Control-Allow-Methods" : "GET, POST, DELETE"
	        },
		}

		return response


	if geo_check_result['error']:

		response = {
			"body" : json.dumps(geo_check_result),
			"statusCode" : 200,
			"headers" : {
	           "Access-Control-Allow-Origin" : "*",
			   "Access-Control-Allow-Methods" : "GET, POST, DELETE"
	        },
		}

		return response


	sign_in = db.get_single_sign_in(data['activeId'])

	# sample sign_in shown below

	# {
	# 	'_id': ObjectId('5a03b6c3b915df000104d56e'),
	# 	'name': 'Wesl', 'castMemberName':
	# 	'Amy Basinger', 'castMemberId':
	# 	'undefined', 'session': 'SP18 - Beauty and the Beast',
	# 	'comments': 'sdf',
	# 	'geolocation': {
	# 		'latitude': 32.6034122,
	# 		'longitude': -96.86327759999999,
	# 		'timestamp': 1510192829544
	# 	}
	# }

	# get_rounded_hours takes a javascript timestamp
	rounded_hours = utils.get_rounded_hours(sign_in['geolocation']['timestamp'])

	result = db.add_hours(sign_in['castMemberId'], rounded_hours)

	response = {
		"statusCode" : 200,
		"headers" : {
           "Access-Control-Allow-Origin" : "*",
		   "Access-Control-Allow-Methods" : "GET, POST, DELETE"
        },
	}

	if result['success']:

		result = db.delete_active(data['activeId'])

		history_dict = {

			"name" : sign_in['name'],
			"session" : sign_in['session'],
			"comments" : sign_in['comments'],
			"datestamp" : utils.make_datestamp(time(), is_JS=False),
			"cast_member" : sign_in['castMemberName'],
			"type" : "sign_out",
			"remote" : data['workFromHome'],
			"elapsed_hours" : rounded_hours
		}

		db.add_history(sign_in['castMemberId'], history_dict)

		if result['success']:

			response['body'] = json.dumps({"success" : True, "message" : "Hours added."})

		else:

			response['body'] = json.dumps({"success" : False, "message" : "Deletion failed."})

	else:

		response['body'] = json.dumps({"success" : False, "message" : result['message']})



	return response
예제 #5
0
                        top_genres.append({
                            'key': key,
                            'date': entry[0][0],
                            'genre': genre,
                            'count': 1
                        })
                    else:
                        node['count'] = int(node['count']) + 1

                key = ('%s:%s' % (entry[0][0], entry[0][1]))
                node = helpers.get_node(top_artists, 'key', key)
                if (node == None):
                    top_artists.append({
                        'key':
                        key,
                        'date':
                        entry[0][0],
                        'artist':
                        entry[0][1],
                        'minutes':
                        float(((entry[1] / 100) / 60))
                    })
                else:
                    node['minutes'] = float(node['minutes']) + float(
                        ((entry[1] / 100) / 60))

    db.add_history(streaming_history)
    db.add_top_artists(top_artists)
    db.add_top_genres(top_genres)

    print('Done getting streaming history!')