38 lines
1.3 KiB
Python
38 lines
1.3 KiB
Python
import pika
|
||
import json
|
||
|
||
credentials = pika.PlainCredentials('admin', '123456') # mq用户名和密码
|
||
# 虚拟队列需要指定参数 virtual_host,如果是默认的可以不填。
|
||
connection = pika.BlockingConnection(pika.ConnectionParameters(host = '192.168.40.7',port = 5672,virtual_host = 'test',credentials = credentials))
|
||
channel=connection.channel()
|
||
# 声明消息队列,消息将在这个队列传递,如不存在,则创建
|
||
result = channel.queue_declare(queue = 'ios-idfa', durable=True)
|
||
|
||
|
||
|
||
with open("/Users/mac/0820us-ios.txt", 'r') as f:
|
||
i = 0
|
||
messages = []
|
||
for line in f:
|
||
i = i + 1
|
||
print(str(i))
|
||
if i < 21312514:
|
||
continue
|
||
if line.strip() == '':
|
||
continue
|
||
|
||
print(line)
|
||
idfa = {}
|
||
rowdata = line.split('|')
|
||
idfa['idfa'] = rowdata[0].strip()
|
||
idfa['ua'] = rowdata[1].strip()
|
||
idfa['ip'] = rowdata[2].strip()
|
||
idfa['ios'] = rowdata[4].strip()
|
||
messages.append(idfa)
|
||
if len(messages) >= 500:
|
||
channel.basic_publish(exchange = '',routing_key = 'ios-idfa',body = json.dumps(messages))
|
||
messages = []
|
||
print("Sent 1000 messages")
|
||
if (len(messages) > 0):
|
||
channel.basic_publish(exchange = '',routing_key = 'ios-idfa',body = json.dumps(messages))
|
||
connection.close() |