Ejemplo n.º 1
0
def send_smg(nid1, nid2, msg):
    node1=SendMessage.get_node_byID(nid1)
    node2=SendMessage.get_node_byID(nid2)
    path=find_message_path(node1,node2)
    msg=message(node1.nid,node2.nid,msg,path)
    global_v.msg_buffer.append(msg)
    return path
def refind_path(nid1,nid2):
    node1=SendMessage.get_node_byID(nid1)
    if node1==None: return None
    node2=SendMessage.get_node_byID(nid2)
    if node2==None: return None
    path=find_message_path(node1,node2)
    return path
Ejemplo n.º 3
0
def run(interval,random):
    while True:
        try:
            # sleep for the remaining seconds of interval
            time_remaining = interval-time.time()%interval
            print SendMessage.randomly_inactive_node(random)
            time.sleep(time_remaining)
        except Exception, e:
            print e
def generate_graph():
    mydb.open()
    graph= dict()
    query = 'select * from edge'
    result = mydb.query_db(query, one = False)
    mydb.close_db()
    inactive_pid_list=SendMessage.find_all_inactive_pid()
    if not result==None:
        for r in result:
            f=r['_from']
            t=r['_to']
            if not f in inactive_pid_list and not t in inactive_pid_list:
                # if the key is not exist in the graph
                if f not in graph:
                   graph[f]=[t]
                else:
                   temp_List=graph[f]
                   temp_List.append(t)
                if t not in graph:
                    graph[t]=[f]
                else:
                    temp_List=graph[t]
                    temp_List.append(f)
                # print str(r['_from'])+' to '+ str(r['_to'])
    return graph
def send_msg(nid1, nid2, msg, msgId):
    node1=SendMessage.get_node_byID(nid1)
    if node1==None: return 'from node does not exist'
    node2=SendMessage.get_node_byID(nid2)
    if node2==None: return 'destination node does not exist'

    #  If it is failed msg to be resend , delete it from failed msg list first
    senderId=node1.nid
    path=find_message_path(node1,node2)
    for msg_obj in global_v.failed_msg:
        if msgId==msg_obj.msgId:
            senderId=msg_obj.sender
            global_v.failed_msg.remove(msg_obj)
            break
    msg_pending=message(node1.nid,node2.nid, msg, path,None,senderId, int(msgId))
    global_v.msg_buffer.append(msg_pending)
    return path
Ejemplo n.º 6
0
		try: 
			res.raise_for_status()
		except requests.exceptions.HTTPError:
			text = 'Invalid arguments "{0}" and "{1}"'.format(self.stations['depart'], self.stations['arrive'])
			
		trainSoup = bs4.BeautifulSoup(res.text, 'html5lib')	
		trainElem = trainSoup.select('tr[class="wtt call_public"]')
		
		for elem in trainElem:		
			if elem.find_all('td', class_='realtime')[0].getText() == 'Cancel':
				text += '\n{0} to {1} is cancelled. '.format(elem.find_all('td', class_='time public')[0].getText() , elem.find_all('td', class_='location')[1].getText())
			elif self.all == True:
				text += '\n{0} to {1} is not cancelled. '.format(elem.find_all('td', class_='time public')[0].getText() , elem.find_all('td', class_='location')[1].getText())
		
		if text == '' and self.all == True:
			text = 'No data found.'

		return text
	
if __name__ == '__main__':
	trainStatus = TrainStatus(True)
	
	trainStatus.setDefaultStations()
	trainStatus.setDate()
	
	trainStatus.buildUrl()
	text = trainStatus.scrapeRTT()
	
	if text != '':
		SendMessage.sendMessage(text)
Ejemplo n.º 7
0
import os
import time, SendMessage

def run(interval,random):
    while True:
        try:
            # sleep for the remaining seconds of interval
            time_remaining = interval-time.time()%interval
            print SendMessage.randomly_inactive_node(random)
            time.sleep(time_remaining)
        except Exception, e:
            print e

if __name__=="__main__":
    SendMessage.active_all_Nodes()
    random=60
    run(2,random)