From 6036a17a4abb698dc830d204846a1c085b77e0f9 Mon Sep 17 00:00:00 2001 From: Cinabre Date: Mon, 13 Jul 2020 18:17:59 +0200 Subject: [PATCH] Creation du programme --- calcul.py | 28 ++++++++++++++++++++++++++++ config.py | 5 +++++ discord.py | 28 ++++++++++++++++++++++++++++ fetch_today_date.py | 9 +++++++++ run.py | 32 ++++++++++++++++++++++++++++++++ 5 files changed, 102 insertions(+) create mode 100644 calcul.py create mode 100644 config.py create mode 100644 discord.py create mode 100644 fetch_today_date.py create mode 100644 run.py diff --git a/calcul.py b/calcul.py new file mode 100644 index 0000000..ebb3095 --- /dev/null +++ b/calcul.py @@ -0,0 +1,28 @@ + +from datetime import date +from config import information +from fetch_today_date import get_date + + +date_dest = information['date'] + +def calcul(date, d_date): + + delta = d_date - date + if 0 > delta.days : + result = delta.days * (-1) + else : + result = delta.days + return result + + +def main(): + print("Test du programme pour calculer le nombre de jour") + today = get_date(date.today()) + dest = get_date(date_dest) + + print(calcul(today, dest)) + + +if __name__ == '__main__': + main() diff --git a/config.py b/config.py new file mode 100644 index 0000000..9c4c5c4 --- /dev/null +++ b/config.py @@ -0,0 +1,5 @@ +from datetime import date +information = { + 'date' : '2021-02-18', + 'webhook' : 'xxxxx' +} diff --git a/discord.py b/discord.py new file mode 100644 index 0000000..3324c22 --- /dev/null +++ b/discord.py @@ -0,0 +1,28 @@ +import requests +from config import information +import json + +def webhook(message): + url = information['webhook'] + data = {} +#for all params, see https://discordapp.com/developers/docs/resources/webhook#execute-webhook + data["content"] = "temps avant la sortie de FC6" + +#leave this out if you dont want an embed + data["embeds"] = [] + embed = {} +#for all params, see https://discordapp.com/developers/docs/resources/channel#embed-object + embed["description"] = message + embed["title"] = "FARCRY6 DAYCOUNTER" + data["embeds"].append(embed) + + result = requests.post(url, data=json.dumps(data), headers={"Content-Type": "application/json"}) + + +def main(): + print("test message") + webhook("test message") + + +if __name__ == '__main__': + main() diff --git a/fetch_today_date.py b/fetch_today_date.py new file mode 100644 index 0000000..5a70091 --- /dev/null +++ b/fetch_today_date.py @@ -0,0 +1,9 @@ +from datetime import date + + +def get_date(data): + data = str(data) + assert type(data) == str + data = data.split('-') + info = date(int(data[0]), int(data[1]), int(data[2])) + return info diff --git a/run.py b/run.py new file mode 100644 index 0000000..18aa4ef --- /dev/null +++ b/run.py @@ -0,0 +1,32 @@ +from datetime import date +import time +from fetch_today_date import get_date +from calcul import calcul +from config import information +from discord import webhook +import sys + +date_dest = information['date'] + +def main(): + while 1 : + print("FarCry 6 daycounter") + today = date.today() + dest = get_date(date_dest) + temps = calcul(today, dest) + + if temps == 0 : + print("Mon role est maintenant terminé... je peux partir en paix..") + webhook(u" FARCRY sort aujourd'hui ! Bandes de puuuutes. ") + sys.exit(0) + else : + message = "Il reste " + str(temps) + " jours, avant la mort de la vie sociale d'adrien" + webhook(message) + time.sleep(86400) + + +if __name__ == '__main__': + try : + main() + except KeyboardInterrupt : + print("Fermeture du programme...")