Skip to content

Commit

Permalink
barcode-maker and csv-to-excel
Browse files Browse the repository at this point in the history
  • Loading branch information
AKmahim committed Apr 27, 2024
1 parent 23d5416 commit 1bc538a
Show file tree
Hide file tree
Showing 17 changed files with 488,233 additions and 19 deletions.
19 changes: 0 additions & 19 deletions Discord-bot/discord-2.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,3 @@ def save_messages_to_csv(output_data, csv_filename):
writer.writerow([content, author_username, message_date])


# messages = get_message_from_channel(CHANNEL_ID,authorID,before,after)


# # print(messages)
# csv_filename = "discord_messages.csv"
# save_messages_to_csv(messages, csv_filename)
# print("Data saved to", csv_filename)




# for messages_list in messages:
# for message in messages_list:
# content = message['content']
# author_username = message['author']['username']
# message_date = datetime.datetime.strptime(message['timestamp'], "%Y-%m-%dT%H:%M:%S.%f+00:00")
# print("Content:", content)
# print("Author Username:", author_username)
# print("Message Date:", message_date)
1 change: 1 addition & 0 deletions barcode-maker/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
barcodes
Binary file added barcode-maker/__pycache__/barcode.cpython-310.pyc
Binary file not shown.
Binary file added barcode-maker/barcodes.xlsx
Binary file not shown.
78 changes: 78 additions & 0 deletions barcode-maker/test-1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# import barcode
# from barcode.writer import ImageWriter
# from openpyxl import Workbook
# from openpyxl.drawing.image import Image

# # Function to generate barcode images
# def generate_barcodes(start_value, end_value):
# barcodes = []
# for value in range(start_value, end_value + 1):
# barcode_value = str(value).zfill(5) # Zero-fill to make it 5 digits
# code128 = barcode.get_barcode_class('code128')
# barcode_instance = code128(barcode_value, writer=ImageWriter())
# filename = f'barcode_{barcode_value}'
# barcode_instance.save(filename)
# barcodes.append((barcode_value, f'{filename}.png'))
# return barcodes

# # Generate barcodes from 10000 to 10020
# start_value = 10000
# end_value = 10020
# barcodes = generate_barcodes(start_value, end_value)

# # Write barcodes to an Excel file
# wb = Workbook()
# ws = wb.active
# ws.append(["Barcode Value", "Barcode Image"])

# for barcode_value, image_filename in barcodes:
# img = Image(image_filename)
# ws.append([barcode_value, barcode_value])
# ws.add_image(img, f'B2')

# output_file = "barcodes.xlsx"
# wb.save(output_file)
# print(f"Barcodes exported to {output_file}")



import os
import barcode
from barcode.writer import ImageWriter
from openpyxl import Workbook
from openpyxl.drawing.image import Image

# Function to generate barcode images
def generate_barcodes(start_value, end_value):
barcodes = []
barcode_folder = "barcodes"
if not os.path.exists(barcode_folder):
os.makedirs(barcode_folder)

for value in range(start_value, end_value + 1):
barcode_value = str(value).zfill(5) # Zero-fill to make it 5 digits
code128 = barcode.get_barcode_class('code128')
barcode_instance = code128(barcode_value, writer=ImageWriter())
filename = os.path.join(barcode_folder, f'barcode_{barcode_value}')
barcode_instance.save(filename)
barcodes.append((barcode_value, f'{filename}.png'))
return barcodes

# Generate barcodes from 10000 to 10020
start_value = 10000
end_value = 20000
barcodes = generate_barcodes(start_value, end_value)

# Write barcodes to an Excel file
wb = Workbook()
ws = wb.active
ws.append(["Barcode Value", "Barcode Image"])

for i, (barcode_value, image_filename) in enumerate(barcodes, start=2):
img = Image(image_filename)
ws.append([barcode_value, barcode_value])
ws.add_image(img, f'B{i}')

output_file = "barcodes.xlsx"
wb.save(output_file)
print(f"Barcodes exported to {output_file}")
Loading

0 comments on commit 1bc538a

Please sign in to comment.