Ejemplo n.º 1
0
def socket_client(data):
    client = socket(AF_INET, SOCK_STREAM)
    client.connect(ADDR)

    try:
        client.send(data.encode('utf8'))
    except Exception, e:
        log.error("send message error, reason is : %s" % e)
Ejemplo n.º 2
0
 async def make_request(self, session):
     """This method loads json data about all currencies"""
     try:
         async with session.get(RATES_BASE_URL) as response:
             if response.status == 200:
                 responce_data = await response.text()
                 responce_data_dict = json.loads(responce_data)
                 if self.is_debug_mode:
                     print(response)
             else:
                 logging.error(response.status, "Получен код ошибки")
                 return None
             await session.close()
             return responce_data_dict["Valute"]
     except ClientConnectionError as error:
         logging.error(error)
Ejemplo n.º 3
0
def upload():

    if request.method == 'POST':
        f = request.files['file']
        basepath = os.path.dirname(__file__)  # 当前文件所在路径
        upload_path = os.path.join(basepath, 'static\uploads',
                                   secure_filename(f.filename))
        # upload_path = os.path.join('C:\Users\hp\Documents\Neo4j\default.graphdb\import')
        log.info('go+++++++++++++++++++++++:%s' % upload_path)
        # upload_path = os.path.join(basepath)
        # 注意:没有的文件夹一定要先创建,不然会提示没有该路径
        try:
            f.save(upload_path)
        except Exception, e:
            log.error('write the msg into file error, reason is: %s' % e)
            return '写入失败,因为:%s' % e
        return redirect(url_for('upload'))
Ejemplo n.º 4
0
def broadcast_message(message):
    global connectionlist
    message_utf_8 = message.encode('utf-8')
    log.info('connectlist array is: %s' % connectionlist)
    for connection in connectionlist.values():
        back_str = []
        back_str.append('\x81')
        data_length = len(message_utf_8)

        if data_length <= 125:
            back_str.append(chr(data_length))
        elif data_length <= 65535:
            back_str.append(struct.pack('b', 126))
            back_str.append(struct.pack('>h', data_length))
            # back_str.append(chr(data_length >> 8))
            # back_str.append(chr(data_length & 0xFF))
            # a = struct.pack('>h', data_length)
            # b = chr(data_length >> 8)
            # c = chr(data_length & 0xFF)
        elif data_length <= (2 ^ 64 - 1):
            # back_str.append(chr(127))
            back_str.append(struct.pack('b', 127))
            back_str.append(struct.pack('>q', data_length))
            # back_str.append(chr(data_length >> 8))
            # back_str.append(chr(data_length & 0xFF))
        else:
            print('太长了')
        msg = ''
        for c in back_str:
            msg += c
        back_str = str(msg) + message_utf_8  # encode('utf-8')
        # connection.send(str.encode(str(u"\x00%s\xFF\n\n" % message))) #这个是旧版
        # print (u'send message:' +  message)
        if back_str is not None and len(back_str) > 0:
            print(back_str)
            try:
                connection.send(back_str)
            except Exception, e:
                log.error('send error, reason is: %s' % e)
Ejemplo n.º 5
0
from py2neo import Graph
from igraph import Graph as IGraph
graph = Graph("http://localhost:7474", username="******", password="******")
query = '''
MATCH (c1:person)-[r:rel]->(c2:person)
RETURN c1.name, c2.name, r.property1 AS weight
'''
ig = IGraph.TupleList(graph.run(query), weights=True)

# 社区发现
if __name__ == '__main__':
    try:
        log.info('ig is: type(%s)' % type(ig))
        clusters = IGraph.community_walktrap(ig, weights=None).as_clustering()
    except Exception, e:
        log.error('error.....:%s' % e)
        raise
    nodes = [{"name": node["name"]} for node in ig.vs]
    for node in nodes:
        idx = ig.vs.find(name=node["name"]).index
        node["community"] = clusters.membership[idx]
    write_clusters_query = '''
    UNWIND {nodes} AS n
    MATCH (c:person) WHERE c.name = n.name
    SET c.community = toInt(n.community)
    '''
    graph.run(write_clusters_query, nodes=nodes)
    # 在Neo4j中查询有多少个社区以及每个社区的成员数:
    # '''
    # MATCH (c:person)
    # WITH c.community AS cluster, collect(c.name) AS  members
Ejemplo n.º 6
0
    return raw_str


def socket_client(data):
    client = socket(AF_INET, SOCK_STREAM)
    client.connect(ADDR)

    try:
        client.send(data.encode('utf8'))
    except Exception, e:
        log.error("send message error, reason is : %s" % e)

    try:
        data = client.recv(BUFSIZ)
    except Exception, e:
        log.error("recv the message error, reason is: %s" % e)

    log.info(data.decode('utf8'))

    return data


# 广播用
def broadcast_message(message):
    global connectionlist
    message_utf_8 = message.encode('utf-8')
    log.info('connectlist array is: %s' % connectionlist)
    for connection in connectionlist.values():
        back_str = []
        back_str.append('\x81')
        data_length = len(message_utf_8)