ios-hooks/import_idfa.py
2025-09-05 18:48:22 +08:00

38 lines
1.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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()