Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#custom
resources/*_firebase_cert.json
resources/editions/*/data.json
resources/editions/*/*.pdf
_out_/
*.pdf

Expand Down
17 changes: 9 additions & 8 deletions Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

TEST = False

EDITION='2022'
EDITION='2022_firaMaker'
EDITIONS_FOLDER = 'editions'

DB_PATH_T = 'hackeps-'+EDITION+'/dev/users'
Expand All @@ -25,16 +25,17 @@
BAK_FILE = 'plantilla.png'
BAK_PATH = path.join(RES_PATH, EDITIONS_FOLDER, EDITION, BAK_FILE)

# FONT_FILE = 'Montserrat-Regular.ttf'
FONT_FILE = 'SpaceMono-Bold.ttf'
FONT_PATH = path.join(RES_PATH, FONT_FILE)
TYPE_FONT_SIZE = 18
NAME_FONT_SIZE = 12
FONT_FILE = 'DIN-Regular.ttf'
BOLD_FONT_FILE = 'DIN-Bold.ttf'
FONT_FOLDER = 'fonts'
FONT_PATH = path.join(RES_PATH, FONT_FOLDER, FONT_FILE)
BOLD_FONT_PATH = path.join(RES_PATH, FONT_FOLDER, BOLD_FONT_FILE)
TYPE_FONT_SIZE = 80
NAME_FONT_SIZE = 70
FONT_COLOR = (0,0,0)
WHITE_FONT_COLOR = (255,255,255)
TYPE_FONT = ImageFont.truetype(FONT_PATH, TYPE_FONT_SIZE)
TYPE_FONT = ImageFont.truetype(BOLD_FONT_PATH, TYPE_FONT_SIZE)
NAME_FONT = ImageFont.truetype(FONT_PATH, NAME_FONT_SIZE)
# FONT = ImageFont.truetype("Symbola.ttf", 60, encoding='unic')

MAIN_COLOR = (31, 33, 36)
BAK_COLOR = (247, 247, 242)
165 changes: 35 additions & 130 deletions Model.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@
import Config
import Tools

# expositor, organitzador o voluntari

class Card:
QR_PIX_SIZE = 1
QR_POS = (1301, 172)
QR_SIZE = (723, 723)
QR_BORDER_SIZE = 0
TYPE_POS = (0, 155)
TYPE_POS = (0, 500)
# NAME_POS = (500, 1250)
NAME_POS = (140, 120)
NICK_POS = (1198, 870)
NAME_POS = (0, 330)
COMP_NAME_POS = (0, 200)
# LOGO_POS = (920, 250)
# LOGO_SIZE = (550, 350)

Expand Down Expand Up @@ -47,7 +48,10 @@ def generate_qr(self, crypt_id=False):

def generate_card(self, rgb_back=(255, 255, 255)):
self.card = Image.open(Config.BAK_PATH)
Tools.draw_text(self.card, self.type, Card.TYPE_POS, Config.TYPE_FONT, Config.WHITE_FONT_COLOR)
Tools.draw_text(self.card, self.type, Card.TYPE_POS, Config.TYPE_FONT, Config.FONT_COLOR)
img = Image.new('RGB', (1062, 762),(255,255,255))
img.paste(self.card, (0,0))
self.card = img

@staticmethod
def get_data():
Expand All @@ -61,167 +65,68 @@ def get_data():
break
return res


class Guest(Assistant):
class Volunteer(Assistant):
__ID = 1
__TYPE = 'INVITADO'
__DATA = 'guests'
__LOGO_PATH = os.path.join(Config.RES_PATH, 'editions', Config.EDITION, 'images', 'logogran.png')
__TYPE = 'VOLUNTARI'
__DATA = 'volunteers'

def __init__(self, name, mtype=None, has_qr=False):
super().__init__('HackEPS_Guest_' + str(Guest.__ID), (mtype, Guest.__TYPE)[mtype is None], name)
Guest.__ID += 1
self.has_qr = has_qr
if has_qr:
self.generate_qr(True)
def __init__(self):
super().__init__('V' + str(Volunteer.__ID), Volunteer.__TYPE)
Volunteer.__ID += 1

def generate_card(self, rgb_back=(255, 255, 255)):
super().generate_card(rgb_back)
if self.has_qr:
self.card.paste(self.qr, Card.QR_POS)
Tools.draw_text(self.card, self.name, Card.NAME_POS, Config.NAME_FONT, Config.WHITE_FONT_COLOR)

@staticmethod
def get_data(name=None):
res = []
data = Tools.DataFile.get_content(Guest._DATA_FILE, 'JSON')
for u in data[Guest.__DATA]:
if name is None or u['name'] == name:
res.append(Guest(u['name'], u['type'], u['qr']))
if Config.TEST or (name is not None and u['name'] == name):
break
return res
pass


class Company(Assistant):
class Expositor(Assistant):
__ID = 1
__TYPE = ''
# __LOGO_PATH = os.path.join(Config.RES_PATH, 'editions', Config.EDITION, 'images', 'logogran.png')
__TYPE = 'EXPOSITOR'
__DATA = 'companies'

def __init__(self, name, image):
super().__init__('C' + str(Company.__ID), Company.__TYPE, name)
Company.__ID += 1
self.logopath = os.path.join(Config.RES_PATH, Config.EDITIONS_FOLDER, Config.EDITION, 'images', image)
def __init__(self):
super().__init__('E' + str(Expositor.__ID), Expositor.__TYPE)
Expositor.__ID += 1

def generate_card(self, rgb_back=(255, 255, 255)):
super().generate_card(rgb_back)
Tools.draw_text(self.card, self.name, Card.NAME_POS, Config.NAME_FONT, Config.WHITE_FONT_COLOR)
image = Image.open(self.logopath).convert("RGBA") # .resize((550,350), Image.ANTIALIAS)
image = Tools.scale(image, Card.QR_SIZE)
self.card.paste(image, Card.QR_POS)

@staticmethod
def get_data(name=None):
res = []
data = Tools.DataFile.get_content(Company._DATA_FILE, 'JSON')
for u in data[Company.__DATA]:
for _ in range(u['number_of_cards']):
if name is None or u['name'] == name:
res.append(Company(u['name'], u['logo']))
if Config.TEST:
break
if Config.TEST or (name is not None and u['name'] == name):
break
return res

pass

class Volunteer(Assistant):
class Colaborator(Assistant):
__ID = 1
__LOGO_PATH = os.path.join(Config.RES_PATH, 'editions', Config.EDITION, 'images', 'logogran.png')
__TYPE = 'VOLUNTARIA/O'
__DATA = 'volunteers'
__TYPE = 'COL·LABORADOR'
__DATA = 'companies'

def __init__(self, name):
super().__init__('V' + str(Volunteer.__ID), Volunteer.__TYPE, name)
Volunteer.__ID += 1
def __init__(self):
super().__init__('C' + str(Colaborator.__ID), Colaborator.__TYPE)
Colaborator.__ID += 1

def generate_card(self, rgb_back=(255, 255, 255)):
super().generate_card(rgb_back)
image = Image.open(Volunteer.__LOGO_PATH).convert("RGBA")
image = Tools.scale(image, Card.QR_SIZE)
self.card.paste(image, Card.QR_POS)
Tools.draw_text(self.card, self.name, Card.NAME_POS, Config.NAME_FONT, Config.WHITE_FONT_COLOR)

@staticmethod
def get_data(name=None):
res = []
data = Tools.DataFile.get_content(Volunteer._DATA_FILE, 'JSON')
for u in data[Volunteer.__DATA]:
if name is None or name == u['name']:
res.append(Volunteer(u['name']))
if Config.TEST or (name is not None and name == u['name']):
break
return res

pass

class Organizer(Assistant):
__ID = 1
__LOGO_PATH = os.path.join(Config.RES_PATH, 'editions', Config.EDITION, 'images', 'logogran.png')
__TYPE = 'ORGANIZACIÓN'
__DATA = 'organizers'
__TYPE = 'ORGANITZADOR'
__DATA = 'companies'

def __init__(self, name):
super().__init__('O' + str(Organizer.__ID), Organizer.__TYPE, name)
def __init__(self):
super().__init__('O' + str(Organizer.__ID), Organizer.__TYPE)
Organizer.__ID += 1

def generate_card(self, rgb_back=(255, 255, 255)):
super().generate_card(rgb_back)
image = Image.open(Organizer.__LOGO_PATH).convert("RGBA")
image = Tools.scale(image, Card.QR_SIZE)
self.card.paste(image, Card.QR_POS)
Tools.draw_text(self.card, self.name, Card.NAME_POS, Config.NAME_FONT, Config.WHITE_FONT_COLOR, False)

@staticmethod
def get_data(name=None):
res = []
print(Organizer._DATA_FILE)
data = Tools.DataFile.get_content(Organizer._DATA_FILE, 'JSON')
for u in data[Organizer.__DATA]:
if name is None or u['name'] == name:
res.append(Organizer(u['name']))
if Config.TEST or (name is not None and u['name'] == name):
break
return res


class Contestant(Assistant):
__CRYPT_ID = False
__TYPE = 'HACKER'
__FIREBASE = None
__FIRE_PATH = Config.DB_PATH

def __init__(self, id, data):
super().__init__(id, Contestant.__TYPE)
self.generate_qr()
self.name = data['fullName']
self.nick = '\"' + data['nickname'] + '\"'
if Config.TEST:
Contestant.__FIRE_PATH = Config.DB_PATH_T

def generate_card(self, rgb_back=(255, 255, 255)):
super().generate_card(rgb_back)
self.card.paste(self.qr, Card.QR_POS)
Tools.draw_text(self.card, self.name, Card.NAME_POS, Config.NAME_FONT, Config.WHITE_FONT_COLOR, False)
# Tools.draw_text(self.card, self.nick, Card.NICK_POS, Config.FONT)

@staticmethod
def __firebase_init(cred):
if Contestant.__FIREBASE is None:
Contestant.__FIREBASE = firebase_admin.initialize_app(cred)
return Contestant.__FIREBASE

@staticmethod
def get_data(id=None, name=None):
cred = firebase_admin.credentials.Certificate(Config.DB_CERT_PATH)
Contestant.__firebase_init(cred)
db = firestore.client()
users_ref = db.collection(Contestant.__FIRE_PATH)
usrs = users_ref.stream()
users = []
for usr in usrs:
if (id is None and name is None) or (id is not None and usr.id == id) or (
name is not None and name == usr.to_dict()['fullName']):
users.append(Contestant(usr.id, usr.to_dict()))
if Config.TEST or (id is not None and usr.id == id) or (
name is not None and name == usr.to_dict()['fullName']):
break
return users
pass
15 changes: 13 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

users = []
# users += Model.Contestant.get_data()
users += Model.Organizer.get_data()
# users += Model.Organizer.get_data()
# users += Model.Volunteer.get_data()
# users += Model.Company.get_data()
# users += Model.Guest.get_data()
Expand All @@ -15,7 +15,18 @@
Tools.create_dir(Config.OUT_PATH)
Tools.empty_dir(Config.OUT_PATH)


#create 4 cars on each type
users=[]
for i in range(4):
users.append(Model.Colaborator())
users.append(Model.Organizer())
users.append(Model.Volunteer())
users.append(Model.Expositor())

for u in users:
u.generate_card()
u.save()
break
# break


Binary file added resources/editions/2022_firaMaker/plantilla.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/fonts/DIN-Bold.ttf
Binary file not shown.
Binary file added resources/fonts/DIN-Regular.ttf
Binary file not shown.
File renamed without changes.
File renamed without changes.