I use a python script to generate a QR code per row. Which really works without any problems.
But my QR Codes should be the exact row URL, so I can scan it to find this entry.
Unfortunately I don’t know where I can find a kind of dictionary how to name such easy things, so I’m lost.
The way I can do this is by copying the each url and paste it in a column and the use this column in my python script.
But there should be a faster way than copy-paste 200 url
Thank you for any help
Here is the python script I use:
import os
import time
import qrcode
from seatable_api import Base, context
api_token = context.api_token or “…”
server_url = context.server_url or “https://cloud.seatable.io”
STRING_COLUMN = “link” # text column which is expected to be transferred into qrcode
# but instead I want to directly refer to the url
IMAGE_COLUMN = “QR Code”
TABLE_NAME = “2023_CRM”
OVERWRITE = True # set to True to overwrite existing barcode images
base = Base(api_token, server_url)
base.auth()
qr = qrcode.QRCode(
version=2,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=40,
border=8
)
def get_time_stamp():
return str(int(time.time() * 100000))
def main():
for row in base.list_rows(TABLE_NAME):
if not OVERWRITE and row.get(IMAGE_COLUMN):
print(“Skipping row. Image already exists.”)
continue
try:
row_id = row.get('_id')
message = row.get(STRING_COLUMN) # what can I write here to use the row url directly without copy-paste it beforehand in this column?
if not message:
print("Skipping row. Empty message.")
continue
# clear, add data and make an qrcode object
qr.clear()
qr.add_data(str(message))
qr.make()
img = qr.make_image(fill_color="black", back_color="white")
save_name = f"{row_id}_{get_time_stamp()}"
img.save(f"/tmp/{save_name}.png")
# temporarily saved as an image
info_dict = base.upload_local_file(f"/tmp/{save_name}.png", name=None, file_type='image', replace=True)
img_url = info_dict.get('url')
base.update_row(TABLE_NAME, row_id, {IMAGE_COLUMN: [img_url]})
# remove the image file which is saved temporarily
os.remove(f"/tmp/{save_name}.png")
except Exception as exception:
print("Error occurred during Image generation:", exception)
continue
if name == “main”:
main()