Skip to content

Commit

Permalink
Merge pull request #1 from daithihearn/spanish_translations
Browse files Browse the repository at this point in the history
Adding Spanish translations
  • Loading branch information
daithihearn authored Mar 27, 2023
2 parents e2722ce + 8902ba1 commit 203613d
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 24 deletions.
30 changes: 25 additions & 5 deletions CheapPriceNotifier.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,35 @@

import os
from services.SmsService import send_sms
from services.PriceService import get_current_price, get_max_price, get_min_price
import i18n
from dotenv import load_dotenv

load_dotenv()

TWILIO_RECIPIENTS = os.getenv('TWILIO_RECIPIENTS')

curr_price = get_current_price()
min_price = get_min_price()
max_price = get_max_price()

if curr_price.value == min_price.value:
send_sms('Put the washing machine on!!\n - Min: ' +
min_price.value_euro + '@' + min_price.hour + '\n - Max: ' + max_price.value_euro + '@' + max_price.hour +
'\n - Current: ' + curr_price.value_euro + '@' + curr_price.hour)
i18n.load_path.append('i18n')
messageEn = i18n.t('text.cheap_price',
min_price=str(min_price.value_euro+'@'+min_price.hour),
max_price=str(max_price.value_euro+'@'+max_price.hour),
cur_price=str(curr_price.value_euro+'@'+curr_price.hour))

i18n.set('locale', 'es')
messageEs = i18n.t('text.cheap_price',
min_price=str(min_price.value_euro+'@'+min_price.hour),
max_price=str(max_price.value_euro+'@'+max_price.hour),
cur_price=str(curr_price.value_euro+'@'+curr_price.hour))

for recipient in TWILIO_RECIPIENTS.split(","):
if recipient.startswith('+34'):
send_sms(messageEs, recipient)
else:
send_sms(messageEn, recipient)
else:
print('No need to put the washing machine on. Min price is ' +
min_price.value_euro+', max price is' + max_price.value_euro+', current price is '+curr_price.value_euro+'.')
min_price.value_euro+', max price is ' + max_price.value_euro+', current price is '+curr_price.value_euro+'.')
25 changes: 19 additions & 6 deletions DailyPriceNotifier.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@

import os
from services.SmsService import send_sms
from services.PriceService import get_max_price, get_min_price
import i18n
from dotenv import load_dotenv

load_dotenv()

TWILIO_RECIPIENTS = os.getenv('TWILIO_RECIPIENTS')

i18n.load_path.append('i18n')

min_price = get_min_price()
max_price = get_max_price()

message = 'Prices today:\n - Min: '+min_price.value_euro + '@' + \
min_price.hour + '\n - Max: ' + \
max_price.value_euro + '@' + max_price.hour
messageEn = i18n.t('text.daily_price', min_price=str(min_price.value_euro +
'@'+min_price.hour), max_price=str(max_price.value_euro+'@'+max_price.hour))

print(message)
i18n.set('locale', 'es')
messageEs = i18n.t('text.daily_price', min_price=str(min_price.value_euro +
'@'+min_price.hour), max_price=str(max_price.value_euro+'@'+max_price.hour))

send_sms(message)
for recipient in TWILIO_RECIPIENTS.split(","):
if recipient.startswith('+34'):
send_sms(messageEs, recipient)
else:
send_sms(messageEn, recipient)
28 changes: 24 additions & 4 deletions ExpensivePriceNotifier.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,35 @@

import os
from services.SmsService import send_sms
from services.PriceService import get_current_price, get_max_price, get_min_price
import i18n
from dotenv import load_dotenv

load_dotenv()

TWILIO_RECIPIENTS = os.getenv('TWILIO_RECIPIENTS')

curr_price = get_current_price()
min_price = get_min_price()
max_price = get_max_price()

if curr_price.value == max_price.value:
send_sms('Turn everything off!!\n - Min: ' +
min_price.value_euro + '@' + min_price.hour + '\n - Max: ' + max_price.value_euro + '@' + max_price.hour +
'\n - Current: ' + curr_price.value_euro + '@' + curr_price.hour)
i18n.load_path.append('i18n')
messageEn = i18n.t('text.expensive_price',
min_price=str(min_price.value_euro+'@'+min_price.hour),
max_price=str(max_price.value_euro+'@'+max_price.hour),
cur_price=str(curr_price.value_euro+'@'+curr_price.hour))

i18n.set('locale', 'es')
messageEs = i18n.t('text.expensive_price',
min_price=str(min_price.value_euro+'@'+min_price.hour),
max_price=str(max_price.value_euro+'@'+max_price.hour),
cur_price=str(curr_price.value_euro+'@'+curr_price.hour))

for recipient in TWILIO_RECIPIENTS.split(","):
if recipient.startswith('+34'):
send_sms(messageEs, recipient)
else:
send_sms(messageEn, recipient)
else:
print('No need to warn about the price. Min price is ' +
min_price.value_euro+', max price is' + max_price.value_euro+', current price is '+curr_price.value_euro+'.')
15 changes: 15 additions & 0 deletions i18n/text.en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
en:
daily_price: |
Prices today:
- Min: %{min_price}
- Max: %{max_price}
expensive_price: |
Turn everything off!!
- Min: %{min_price}
- Max: %{max_price}
- Current: %{cur_price}
cheap_price: |
Put the washing machine on!!
- Min: %{min_price}
- Max: %{max_price}
- Current: %{cur_price}
15 changes: 15 additions & 0 deletions i18n/text.es.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
es:
daily_price: |
Precios hoy:
- Min: %{min_price}
- Max: %{max_price}
expensive_price: |
Apaga todo!!
- Min: %{min_price}
- Max: %{max_price}
- Actual: %{cur_price}
cheap_price: |
Enciende la lavadora!!
- Min: %{min_price}
- Max: %{max_price}
- Actual: %{cur_price}
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ python-dotenv
twilio
asyncio
meross_iot==0.4.5.9
python-i18n[YAML]
16 changes: 7 additions & 9 deletions services/SmsService.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@
TWILIO_ACCOUNT_SSID = os.getenv('TWILIO_ACCOUNT_SSID')
TWILIO_AUTH_TOKEN = os.getenv('TWILIO_AUTH_TOKEN')
TWILIO_FROM_NUMBER = os.getenv('TWILIO_FROM_NUMBER')
TWILIO_RECIPIENTS = os.getenv('TWILIO_RECIPIENTS')


def send_sms(message):
def send_sms(message, recipient):
client = Client(TWILIO_ACCOUNT_SSID, TWILIO_AUTH_TOKEN)

for to in TWILIO_RECIPIENTS.split(","):
client.messages.create(
body=message,
from_=TWILIO_FROM_NUMBER,
to=to
)
print('SMS sent successfully to '+to)
client.messages.create(
body=message,
from_=TWILIO_FROM_NUMBER,
to=recipient
)
print('SMS sent successfully to '+recipient)

0 comments on commit 203613d

Please sign in to comment.