mirror of
https://gitlab.com/oloturia/buonanotte.git
synced 2025-01-08 22:47:20 +01:00
added some languages
This commit is contained in:
parent
9adb052869
commit
cb8dfebc47
1 changed files with 35 additions and 9 deletions
|
@ -8,24 +8,48 @@ import csv
|
||||||
|
|
||||||
API_URL = "https://botsin.space"
|
API_URL = "https://botsin.space"
|
||||||
regex = re.compile("([0-1]\d|[2][0-3]):[0-5]\d")
|
regex = re.compile("([0-1]\d|[2][0-3]):[0-5]\d")
|
||||||
|
languages = {
|
||||||
|
"it":["Ciao @"," ti ricorderò di andare a dormire alle ore "," è ora di andare a dormire! Buonanotte!"],
|
||||||
|
"es":["Hola @"," te recordaré que te vayas a dormir a las "," es hora de ir a dormir, buenas noches!"],
|
||||||
|
"fr":["Salut @"," je vais te rappeler d'aller dormir à "," il est temps de dormir! Bonne nuit!"],
|
||||||
|
"pt":["Ola' @"," vou lembrá-lo a dormir as "," é hora de ir dormir! Boa noite!"],
|
||||||
|
"de":["Hallo @"," ich werde Sie daran erinnern um Uhr "," es ist Zeit zu schlafen! Gute Nacht!"],
|
||||||
|
"en":["Hello @"," I'll remind you to go to sleep at "," time to go to bed! Good night!"]
|
||||||
|
}
|
||||||
|
|
||||||
class goodListener(StreamListener):
|
class goodListener(StreamListener):
|
||||||
|
|
||||||
def on_notification(self,notification):
|
def on_notification(self,notification):
|
||||||
print("Notification received")
|
try:
|
||||||
account = notification["account"]["acct"]
|
account = notification["account"]["acct"]
|
||||||
content = notification["status"]["content"]
|
content = notification["status"]["content"]
|
||||||
goodNight = regex.search(content)
|
goodNight = regex.search(content)
|
||||||
|
print(content)
|
||||||
|
if content.find("dormire") != -1:
|
||||||
|
lang = 'it'
|
||||||
|
elif content.find("dormiria") != -1:
|
||||||
|
lang = 'es'
|
||||||
|
elif content.find("dormir") != -1:
|
||||||
|
lang = 'fr'
|
||||||
|
elif content.find("dormia") != -1:
|
||||||
|
lang = 'pt'
|
||||||
|
elif content.find("schlafen") != -1:
|
||||||
|
lang = 'de'
|
||||||
|
else:
|
||||||
|
lang = 'en'
|
||||||
|
greet = languages[lang][0]
|
||||||
|
reminder = languages[lang][1]
|
||||||
|
except KeyError:
|
||||||
|
return
|
||||||
try:
|
try:
|
||||||
result = goodNight.group()
|
result = goodNight.group()
|
||||||
with open("schedule.csv","a") as file:
|
with open("schedule.csv","a") as file:
|
||||||
row = [result,account]
|
row = [result,account,lang]
|
||||||
writer = csv.writer(file)
|
writer = csv.writer(file)
|
||||||
writer.writerow(row)
|
writer.writerow(row)
|
||||||
mastodon.toot("Ciao @"+account+", ti ricordero' di andare a dormire alle ore "+result)
|
mastodon.toot(greet+account+reminder+result)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
mastodon.toot("Ciao @"+account+", non ho capito a che ora vorresti andare a dormire")
|
return
|
||||||
|
|
||||||
def handle_heartbeat(self):
|
def handle_heartbeat(self):
|
||||||
with open("schedule.csv","r") as file:
|
with open("schedule.csv","r") as file:
|
||||||
|
@ -33,7 +57,9 @@ class goodListener(StreamListener):
|
||||||
sentToBed = []
|
sentToBed = []
|
||||||
for line,row in enumerate(reader):
|
for line,row in enumerate(reader):
|
||||||
if parser.parse(row[0]) < datetime.datetime.now():
|
if parser.parse(row[0]) < datetime.datetime.now():
|
||||||
mastodon.toot("Ciao @"+row[1]+" e' ora di andare a dormire! Buonanotte!")
|
greet = languages[row[2]][0]
|
||||||
|
goodnight = languages[row[2]][2]
|
||||||
|
mastodon.toot(greet+row[1]+goodnight)
|
||||||
sentToBed.append(line)
|
sentToBed.append(line)
|
||||||
if (len(sentToBed) > 0):
|
if (len(sentToBed) > 0):
|
||||||
with open("schedule.csv","r") as file:
|
with open("schedule.csv","r") as file:
|
||||||
|
|
Loading…
Reference in a new issue