Skip to content

Commit

Permalink
Aggiunto .env e refactoring delle variabili
Browse files Browse the repository at this point in the history
  • Loading branch information
MattiaOldani committed Aug 4, 2023
1 parent d9e1a34 commit 5bac74a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 10 deletions.
10 changes: 10 additions & 0 deletions generator/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Form
FORM_API_KEY=
FORM_ENDPOINT=
ANIMATORS_PER_SLOT=
MAX_NUMBER_DAILY_SLOTS=
MAX_REPETITION_SAME_SLOT=

# Telegram
CHANNEL_ID=
TELEGRAM_API_KEY=
18 changes: 12 additions & 6 deletions generator/form/form.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
import base64
import os
import requests

from dotenv import load_dotenv

from utils.days import Days
from utils.slots import Slots


def generate_dat_file():
ENDPOINT = "http://USERNAME.wufoo.com/api/v3/forms/FORM_HASH/entries.json?pageSize=100"
FORM_API_KEY = "API_KEY"
load_dotenv()
environment = os.environ

FORM_ENDPOINT = environment["FORM_ENDPOINT"]
FORM_API_KEY = environment["FORM_API_KEY"]

authcode = base64.b64encode(f"{FORM_API_KEY}:ciao".encode()).decode()
headers = {"Authorization" : f"Basic {authcode}"}

entries = requests.get(ENDPOINT, headers=headers).json()["Entries"]
entries = requests.get(FORM_ENDPOINT, headers=headers).json()["Entries"]

PRE = ["Field105", "Field106", "Field107", "Field108", "Field109"]
MENSA = ["Field305", "Field306", "Field307", "Field309"]
Expand Down Expand Up @@ -62,15 +68,15 @@ def generate_dat_file():
result = result.strip() + ";\n\n"
f.write(result)

ANIMATORS_PER_SLOT = -1
ANIMATORS_PER_SLOT = environment["ANIMATORS_PER_SLOT"]
f.write(f"param AnimatoriPerTurno := {ANIMATORS_PER_SLOT};\n\n")

MAX_REPETITION_SAME_SLOT = -1
MAX_REPETITION_SAME_SLOT = environment["MAX_REPETITION_SAME_SLOT"]
f.write(
f"param MassimaRipetizioneStessoTurno := {MAX_REPETITION_SAME_SLOT};\n\n"
)

MAX_NUMBER_DAILY_SLOTS = -1
MAX_NUMBER_DAILY_SLOTS = environment["MAX_NUMBER_DAILY_SLOTS"]
f.write(f"param MassimoNumeroTurniGiornalieri := {MAX_NUMBER_DAILY_SLOTS};\n")


Expand Down
13 changes: 9 additions & 4 deletions generator/telegram/telegram.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
import os
import telebot

from dotenv import load_dotenv

API_KEY = "API_KEY"
CHANNEL_ID = -1

load_dotenv()
environment = os.environ
TELEGRAM_API_KEY = environment["TELEGRAM_API_KEY"]
CHANNEL_ID = environment["CHANNEL_ID"]


def send_pdf(filename):
bot = telebot.TeleBot(API_KEY)
bot = telebot.TeleBot(TELEGRAM_API_KEY)

with open(filename, "rb") as f:
caption = "*Turni della settimana*"
bot.send_document(CHANNEL_ID, f, caption=caption, parse_mode="markdown")


def send_turns(turns):
bot = telebot.TeleBot(API_KEY)
bot = telebot.TeleBot(TELEGRAM_API_KEY)

counts = turns.get_animators_turns_counts(sort=True)
message = '\n'.join(
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
python-dotenv
pyTelegramBotAPI
requests

0 comments on commit 5bac74a

Please sign in to comment.