import barcode
from barcode.writer import ImageWriter
from io import StringIO # python3; python2: BytesIO
import boto3
import pandas as pd
def generate_asst(request):
df=pd.DataFrame
list_of_images = []
for i in range(10):
number = 'xxx43256'
number = number + str(i)
print(number)
EAN = barcode.get_barcode_class('Code39')
ean = EAN(number, writer=ImageWriter())
fullname = str(i) + 'barcodhhe'
# filename = ean.save(fullname)
filename = ean.save(fo)
with open(filename, 'rb') as f:
contents = f.read()
fo.close()
s3 = boto3.resource('s3')
s3_obj = s3.Object(bucket_name='bucket-name', key=fullname).put(Body=contents)
s3_client = boto3.client('s3')
response = s3_client.generate_presigned_url('get_object',
Params={'Bucket': 'bucket-name', 'Key': fullname},ExpiresIn=300
)
list_of_images.append({"imagepath":response})
print(response)
df=pd.DataFrame(list_of_images)
df=json.loads(df.to_json(orient='records'))
print(df)
# return fullname
return JsonResponse(df,safe=False)