私は基本的にSQSに.jsonファイルを書き込もうとしている以下のコードを持っています
import json
import uuid
import time
import boto.sqs
import boto
from boto.sqs.connection import SQSConnection
from boto.sqs.message import Message
from boto.sqs.message import RawMessage
sqs = boto.sqs.connect_to_region("ap-southeast-1")
queue = sqs.get_queue("Demon")
json_fileone=open("emp.json") ## this is only one JSON file
dataone=json.load(json_fileone)
print dataone
[queue.write(queue.new_message(i)) for i in dataone]
print "File sent successfully to queue"
これで目的のempがアップロードされます。私はSQSにemp1.json、emp2.json、emp3.json、emp4.jsonを持っているのでjsonファイル、私がする必要があるのはファイルの数のループを実行することです、そしてデフォルトでBOTOは送信する前にBASE64エンコーディングをします..私は同じフォーマットでこれらのファイルを送る必要があります、すなわち、 "。json"
回答:
回答№1は0あなたの質問と私たちのコメントによると、あなたは使う必要があります グロブ.
import glob
json_files = glob.glob("*.json")
for json_file in json_files:
process_file(json_file)
プロセスを機能に移す process_file
。その間使用 with
ファイルを処理するステートメント
def process_file(json_file):
sqs = boto.sqs.connect_to_region("ap-southeast-1")
queue = sqs.get_queue("Demon")
with open("emp.json") as json_fileone:
dataone=json.load(json_fileone)
.....