From 4ded88e56b132b0765cadf5f2425d9e6f85fc747 Mon Sep 17 00:00:00 2001 From: Maria Luiza de Souza MArinho Date: Fri, 23 Oct 2020 19:42:46 -0300 Subject: [PATCH 01/20] =?UTF-8?q?altera=C3=A7=C3=B5es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/api.py | 1 - api/src/services/scheduleService.py | 28 ++++++++++++++---- api/src/services/testes.py | 45 +++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 6 deletions(-) create mode 100644 api/src/services/testes.py diff --git a/api/api.py b/api/api.py index 408ec7d..671708e 100644 --- a/api/api.py +++ b/api/api.py @@ -1,7 +1,6 @@ from flask import Flask from flask import jsonify from src.routes import ping_blueprint, scheduler_blueprint, status_blueprint - app = Flask(__name__) app.register_blueprint(scheduler_blueprint) app.register_blueprint(ping_blueprint) diff --git a/api/src/services/scheduleService.py b/api/src/services/scheduleService.py index ae2c527..df93d7d 100644 --- a/api/src/services/scheduleService.py +++ b/api/src/services/scheduleService.py @@ -1,8 +1,26 @@ +import paramiko +import requests +from bs4 import BeautifulSoup +from datetime import date +from ..services.testes import * + + def scheduleService(): LCC1 = [] - LCC2 = [ - { "course" : "Lab. de Prog2", "startTime": "10:00", "endTime": "12:00" }, - { "course" : "Prog1", "startTime": "08:00", "endTime": "10:00" } - ] + LCC2 = [ ] LCC3 = [] - return {"LCC1": LCC1, "LCC2": LCC2, "LCC3": LCC3} \ No newline at end of file + return {"LCC1": LCC1, "LCC2": LCC2, "LCC3": LCC3} + +site = {"LCC1": "https://calendar.google.com/calendar/u/0/htmlembed?src=computacao.ufcg.edu.br_9u9fch5o55dbgrschdeduq348c@group.calendar.google.com&dates=" + SiteUrl(), +"LCC2": "https://calendar.google.com/calendar/u/0/htmlembed?src=computacao.ufcg.edu.br_80qc5chl59nmv2268aef8hp528@group.calendar.google.com&dates=" + SiteUrl(), +"LCC3": "https://calendar.google.com/calendar/u/0/htmlembed?src=computacao.ufcg.edu.br_noalttgqttm3c5pm94k3ttbj1k@group.calendar.google.com&dates=" + SiteUrl() } + + +events = get_events(site) +today = date.today() +curr_day = today.strftime('%d/%m/%Y') +new_event = SpecificEvent(events, curr_day) + +LCC1 = new_event +LCC2 = new_event +LCC3 = new_event \ No newline at end of file diff --git a/api/src/services/testes.py b/api/src/services/testes.py new file mode 100644 index 0000000..305a9d1 --- /dev/null +++ b/api/src/services/testes.py @@ -0,0 +1,45 @@ +import requests +from bs4 import BeautifulSoup +from datetime import date + +def date_decode(date): + day = "%s/%s/%s" % (date[6:8], date[4:6], date[0:4]) + hour = "%02d:%s" % (int(date[9:11]) - 3, date[11:13]) + return [day, hour] + +def get_events(site): + page = requests.get(site) + soup = BeautifulSoup(page.content, 'lxml') + + events = [] + courses = soup.find_all('a', attrs={'class': 'event-link'}) + + for name in courses: + print(name) + getcourseurl = lambda name: "https://calendar.google.com/calendar/" + name['href'] + page = BeautifulSoup(requests.get(getcourseurl(name)).content, 'lxml') + event = { 'course': page.title.text } + + for time in page.find_all('time'): + event[time.attrs['itemprop']] = date_decode(time['datetime']) + + events.append(event) + return events + +def SpecificEvent(events, day): + new_event = [event for event in events if event['startDate'][0] == day] + return new_event + +def SiteUrl(): + curr_year = date.today().year + curr_month = date.today().month + + startdate = str(curr_year) + str(curr_month) + '01' + enddate = str(curr_year) + str(1 + curr_month) + '01' + + if curr_month == 12: + enddate = str(curr_year) + '01' + '01' + return '%s/%s'%(startdate,enddate) + + + From e937cf94318f1d0b22263961b8231e64e87d24fd Mon Sep 17 00:00:00 2001 From: Maria Luiza de Souza MArinho Date: Sun, 25 Oct 2020 10:25:39 -0300 Subject: [PATCH 02/20] =?UTF-8?q?=20dados=20reais=20dos=20hor=C3=A1rios=20?= =?UTF-8?q?dos=20lcc's?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/src/services/scheduleService.py | 89 ++++++++++++++++++++++------- api/src/services/testes.py | 45 --------------- 2 files changed, 67 insertions(+), 67 deletions(-) delete mode 100644 api/src/services/testes.py diff --git a/api/src/services/scheduleService.py b/api/src/services/scheduleService.py index df93d7d..d6c323f 100644 --- a/api/src/services/scheduleService.py +++ b/api/src/services/scheduleService.py @@ -1,26 +1,71 @@ -import paramiko import requests from bs4 import BeautifulSoup from datetime import date -from ..services.testes import * - - + +def date_decode(date): + day = "%s/%s/%s" % (date[6:8], date[4:6], date[0:4]) + hour = "%02d:%s" % (int(date[9:11]) - 3, date[11:13]) + return [day, hour] + +def get_events(site): + page = requests.get(site) + soup = BeautifulSoup(page.content, 'lxml') + + events = [] + courses = soup.find_all('a', attrs={'class': 'event-link'}) + + for name in courses: + getcourseurl = lambda name: "https://calendar.google.com/calendar/" + name['href'] + page = BeautifulSoup(requests.get(getcourseurl(name)).content, 'lxml') + event = { 'course': page.title.text } + + for time in page.find_all('time'): + event[time.attrs['itemprop']] = date_decode(time['datetime']) + + events.append(event) + return events + +def SpecificEvent(events, day): + new_event = [event for event in events if event['startDate'][0] == day] + return new_event + +def SiteUrl(): + curr_year = date.today().year + curr_month = date.today().month + + startdate = '%d%02d01' % (curr_year, curr_month) + enddate = '%d%02d01' % (curr_year, curr_month + 1) + + if curr_month == 12: + enddate = str(curr_year) + '01' + '01' + return '%s/%s'%(startdate,enddate) + def scheduleService(): - LCC1 = [] - LCC2 = [ ] - LCC3 = [] - return {"LCC1": LCC1, "LCC2": LCC2, "LCC3": LCC3} - -site = {"LCC1": "https://calendar.google.com/calendar/u/0/htmlembed?src=computacao.ufcg.edu.br_9u9fch5o55dbgrschdeduq348c@group.calendar.google.com&dates=" + SiteUrl(), -"LCC2": "https://calendar.google.com/calendar/u/0/htmlembed?src=computacao.ufcg.edu.br_80qc5chl59nmv2268aef8hp528@group.calendar.google.com&dates=" + SiteUrl(), -"LCC3": "https://calendar.google.com/calendar/u/0/htmlembed?src=computacao.ufcg.edu.br_noalttgqttm3c5pm94k3ttbj1k@group.calendar.google.com&dates=" + SiteUrl() } - - -events = get_events(site) -today = date.today() -curr_day = today.strftime('%d/%m/%Y') -new_event = SpecificEvent(events, curr_day) - -LCC1 = new_event -LCC2 = new_event -LCC3 = new_event \ No newline at end of file + sites = {"LCC1": "https://calendar.google.com/calendar/u/0/htmlembed?src=computacao.ufcg.edu.br_9u9fch5o55dbgrschdeduq348c@group.calendar.google.com&dates=" + SiteUrl(), + "LCC2": "https://calendar.google.com/calendar/u/0/htmlembed?src=computacao.ufcg.edu.br_80qc5chl59nmv2268aef8hp528@group.calendar.google.com&dates=" + SiteUrl(), + "LCC3": "https://calendar.google.com/calendar/u/0/htmlembed?src=computacao.ufcg.edu.br_noalttgqttm3c5pm94k3ttbj1k@group.calendar.google.com&dates=" + SiteUrl() } + + dicEvents = {} + for lcc in sites: + site = sites[lcc] + + events = get_events(site) + today = date.today() + curr_day = today.strftime('%d/%m/%Y') + new_event = SpecificEvent(events, curr_day) + dicEvents[lcc] = new_event + + dicEvents2 = { } + for lcc in dicEvents: + listaDeAulas = dicEvents[lcc] + novaListaDeAulas = [] + for aula in listaDeAulas: + aulaNova = { + "course": aula['course'], + "startTime": aula['startDate'][1], + "endTime": aula['endDate'][1] + } + novaListaDeAulas.append(aulaNova) + dicEvents2[lcc] = novaListaDeAulas + + return dicEvents2 \ No newline at end of file diff --git a/api/src/services/testes.py b/api/src/services/testes.py deleted file mode 100644 index 305a9d1..0000000 --- a/api/src/services/testes.py +++ /dev/null @@ -1,45 +0,0 @@ -import requests -from bs4 import BeautifulSoup -from datetime import date - -def date_decode(date): - day = "%s/%s/%s" % (date[6:8], date[4:6], date[0:4]) - hour = "%02d:%s" % (int(date[9:11]) - 3, date[11:13]) - return [day, hour] - -def get_events(site): - page = requests.get(site) - soup = BeautifulSoup(page.content, 'lxml') - - events = [] - courses = soup.find_all('a', attrs={'class': 'event-link'}) - - for name in courses: - print(name) - getcourseurl = lambda name: "https://calendar.google.com/calendar/" + name['href'] - page = BeautifulSoup(requests.get(getcourseurl(name)).content, 'lxml') - event = { 'course': page.title.text } - - for time in page.find_all('time'): - event[time.attrs['itemprop']] = date_decode(time['datetime']) - - events.append(event) - return events - -def SpecificEvent(events, day): - new_event = [event for event in events if event['startDate'][0] == day] - return new_event - -def SiteUrl(): - curr_year = date.today().year - curr_month = date.today().month - - startdate = str(curr_year) + str(curr_month) + '01' - enddate = str(curr_year) + str(1 + curr_month) + '01' - - if curr_month == 12: - enddate = str(curr_year) + '01' + '01' - return '%s/%s'%(startdate,enddate) - - - From 0df4ff4cc1228db3157c4062d0935b735db60c2e Mon Sep 17 00:00:00 2001 From: Maria Luiza de Souza MArinho Date: Mon, 9 Nov 2020 15:35:08 -0300 Subject: [PATCH 03/20] initial commit --- api/src/services/procfile | 1 + api/src/services/requeriments.txt | 6 ++++++ 2 files changed, 7 insertions(+) create mode 100644 api/src/services/procfile create mode 100644 api/src/services/requeriments.txt diff --git a/api/src/services/procfile b/api/src/services/procfile new file mode 100644 index 0000000..aa11dea --- /dev/null +++ b/api/src/services/procfile @@ -0,0 +1 @@ +web: gunicorn guardians-bot-api.wsgi \ No newline at end of file diff --git a/api/src/services/requeriments.txt b/api/src/services/requeriments.txt new file mode 100644 index 0000000..02a4298 --- /dev/null +++ b/api/src/services/requeriments.txt @@ -0,0 +1,6 @@ +click==6.7 +Flask==0.12.2 +beautifulsoup4==4.9.3 +discord.py==1.4.1 +gunicorn==20.0.4 +requests==2.24.0 \ No newline at end of file From 04a9cfe5e3e2cbacb7c561324504967e3be8395d Mon Sep 17 00:00:00 2001 From: Maria Luiza de Souza MArinho Date: Wed, 11 Nov 2020 19:42:12 -0300 Subject: [PATCH 04/20] =?UTF-8?q?=20arquivos=20necess=C3=A1rios=20heroku?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Procfile | 1 + api/src/services/procfile | 1 - bot/src/services/scheduleService.py | 2 +- api/src/services/requeriments.txt => requeriments.txt | 2 -- 4 files changed, 2 insertions(+), 4 deletions(-) create mode 100644 Procfile delete mode 100644 api/src/services/procfile rename api/src/services/requeriments.txt => requeriments.txt (71%) diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..d5ed279 --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +web: python api/api.py \ No newline at end of file diff --git a/api/src/services/procfile b/api/src/services/procfile deleted file mode 100644 index aa11dea..0000000 --- a/api/src/services/procfile +++ /dev/null @@ -1 +0,0 @@ -web: gunicorn guardians-bot-api.wsgi \ No newline at end of file diff --git a/bot/src/services/scheduleService.py b/bot/src/services/scheduleService.py index c060db7..e2bd2d5 100644 --- a/bot/src/services/scheduleService.py +++ b/bot/src/services/scheduleService.py @@ -4,7 +4,7 @@ def horarios(mensagem, args): instrucao = '!horarios' - req_schedule = requests.get('http://127.0.0.1:5000/schedule') + req_schedule = requests.get('') dic = req_schedule.json() embed = discord.Embed(title="LCC Bot", descripition="Aulas do dia:") diff --git a/api/src/services/requeriments.txt b/requeriments.txt similarity index 71% rename from api/src/services/requeriments.txt rename to requeriments.txt index 02a4298..23c6c25 100644 --- a/api/src/services/requeriments.txt +++ b/requeriments.txt @@ -1,6 +1,4 @@ -click==6.7 Flask==0.12.2 beautifulsoup4==4.9.3 discord.py==1.4.1 -gunicorn==20.0.4 requests==2.24.0 \ No newline at end of file From 1028ed6a07d5d4b65042436feaf0287746c2a1b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=BAlio=20Carvalho?= Date: Wed, 11 Nov 2020 20:03:13 -0300 Subject: [PATCH 05/20] added api.py to root folder --- api.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 api.py diff --git a/api.py b/api.py new file mode 100644 index 0000000..d39b051 --- /dev/null +++ b/api.py @@ -0,0 +1,10 @@ +from flask import Flask +from flask import jsonify +from api.src.routes import ping_blueprint, scheduler_blueprint, status_blueprint +app = Flask(__name__) +app.register_blueprint(scheduler_blueprint) +app.register_blueprint(ping_blueprint) +app.register_blueprint(status_blueprint) + +if __name__ == "__main__": + app.run() \ No newline at end of file From 67d0c78658d6c66cd23f371e772c0ed5cc27a9e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=BAlio=20Carvalho?= Date: Wed, 11 Nov 2020 20:04:59 -0300 Subject: [PATCH 06/20] wip: changed api.py name and references in procfile --- Procfile | 2 +- app.py | 10 ++++++++++ requeriments.txt | 3 ++- 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 app.py diff --git a/Procfile b/Procfile index d5ed279..ca6e941 100644 --- a/Procfile +++ b/Procfile @@ -1 +1 @@ -web: python api/api.py \ No newline at end of file +web: gunicorn app:app diff --git a/app.py b/app.py new file mode 100644 index 0000000..d39b051 --- /dev/null +++ b/app.py @@ -0,0 +1,10 @@ +from flask import Flask +from flask import jsonify +from api.src.routes import ping_blueprint, scheduler_blueprint, status_blueprint +app = Flask(__name__) +app.register_blueprint(scheduler_blueprint) +app.register_blueprint(ping_blueprint) +app.register_blueprint(status_blueprint) + +if __name__ == "__main__": + app.run() \ No newline at end of file diff --git a/requeriments.txt b/requeriments.txt index 23c6c25..0e34413 100644 --- a/requeriments.txt +++ b/requeriments.txt @@ -1,4 +1,5 @@ Flask==0.12.2 beautifulsoup4==4.9.3 discord.py==1.4.1 -requests==2.24.0 \ No newline at end of file +requests==2.24.0 +gunicorn==20.0.4 From d5f60184f3b6cf9a07ea07df8c1f50cddb97b71f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=BAlio=20Carvalho?= Date: Wed, 11 Nov 2020 20:21:07 -0300 Subject: [PATCH 07/20] wip --- api.py | 10 ---------- requeriments.txt | 10 +++++----- runtime.txt | 1 + 3 files changed, 6 insertions(+), 15 deletions(-) delete mode 100644 api.py create mode 100644 runtime.txt diff --git a/api.py b/api.py deleted file mode 100644 index d39b051..0000000 --- a/api.py +++ /dev/null @@ -1,10 +0,0 @@ -from flask import Flask -from flask import jsonify -from api.src.routes import ping_blueprint, scheduler_blueprint, status_blueprint -app = Flask(__name__) -app.register_blueprint(scheduler_blueprint) -app.register_blueprint(ping_blueprint) -app.register_blueprint(status_blueprint) - -if __name__ == "__main__": - app.run() \ No newline at end of file diff --git a/requeriments.txt b/requeriments.txt index 0e34413..17d8c40 100644 --- a/requeriments.txt +++ b/requeriments.txt @@ -1,5 +1,5 @@ -Flask==0.12.2 -beautifulsoup4==4.9.3 -discord.py==1.4.1 -requests==2.24.0 -gunicorn==20.0.4 +Flask +beautifulsoup4 +discord.py +requests +gunicorn diff --git a/runtime.txt b/runtime.txt new file mode 100644 index 0000000..6919bf9 --- /dev/null +++ b/runtime.txt @@ -0,0 +1 @@ +python-3.7.6 From 3411366c5a448c67f85a1db3dd0c66664f38032c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=BAlio=20Carvalho?= Date: Wed, 11 Nov 2020 20:25:09 -0300 Subject: [PATCH 08/20] renamed requirements --- Procfile | 2 +- requeriments.txt => requirements.txt | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename requeriments.txt => requirements.txt (100%) diff --git a/Procfile b/Procfile index ca6e941..1a6d833 100644 --- a/Procfile +++ b/Procfile @@ -1 +1 @@ -web: gunicorn app:app +web: gunicorn app:app --log-file diff --git a/requeriments.txt b/requirements.txt similarity index 100% rename from requeriments.txt rename to requirements.txt From 46136a19513dedfce353fe9723c840fa684b722c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=BAlio=20Carvalho?= Date: Wed, 11 Nov 2020 20:27:15 -0300 Subject: [PATCH 09/20] changed procfile --- Procfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Procfile b/Procfile index 1a6d833..ca6e941 100644 --- a/Procfile +++ b/Procfile @@ -1 +1 @@ -web: gunicorn app:app --log-file +web: gunicorn app:app From 567e128898ee8c42c6231a901d21fef506c60277 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=BAlio=20Carvalho?= Date: Wed, 11 Nov 2020 20:29:03 -0300 Subject: [PATCH 10/20] added paramiko to requirements --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 17d8c40..ad99f3c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,5 @@ Flask beautifulsoup4 discord.py requests +paramiko gunicorn From 4d2141fd77495d786e338ef86c006c93aac7ad93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=BAlio=20Carvalho?= Date: Wed, 11 Nov 2020 20:32:37 -0300 Subject: [PATCH 11/20] added lxml to requirements --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index ad99f3c..05c3ff0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,3 +4,4 @@ discord.py requests paramiko gunicorn +lxml From f64e1957f23f29f4489ef2847ac287dd0821d911 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=BAlio=20Carvalho?= Date: Wed, 11 Nov 2020 20:58:28 -0300 Subject: [PATCH 12/20] wip: adding bot to heroku --- Procfile | 1 + api/src/services/scheduleService.py | 118 +++++++++++++++------------- api/src/services/statusService.py | 23 +++--- bot.py | 32 ++++++++ bot/src/services/scheduleService.py | 33 ++++---- 5 files changed, 129 insertions(+), 78 deletions(-) create mode 100644 bot.py diff --git a/Procfile b/Procfile index ca6e941..7394444 100644 --- a/Procfile +++ b/Procfile @@ -1 +1,2 @@ web: gunicorn app:app +bot: python bot.py \ No newline at end of file diff --git a/api/src/services/scheduleService.py b/api/src/services/scheduleService.py index d6c323f..36645f1 100644 --- a/api/src/services/scheduleService.py +++ b/api/src/services/scheduleService.py @@ -1,71 +1,83 @@ -import requests +import requests from bs4 import BeautifulSoup from datetime import date - + + def date_decode(date): day = "%s/%s/%s" % (date[6:8], date[4:6], date[0:4]) hour = "%02d:%s" % (int(date[9:11]) - 3, date[11:13]) return [day, hour] - + + def get_events(site): page = requests.get(site) - soup = BeautifulSoup(page.content, 'lxml') - + soup = BeautifulSoup(page.content, "lxml") + events = [] - courses = soup.find_all('a', attrs={'class': 'event-link'}) - + courses = soup.find_all("a", attrs={"class": "event-link"}) + for name in courses: - getcourseurl = lambda name: "https://calendar.google.com/calendar/" + name['href'] - page = BeautifulSoup(requests.get(getcourseurl(name)).content, 'lxml') - event = { 'course': page.title.text } - - for time in page.find_all('time'): - event[time.attrs['itemprop']] = date_decode(time['datetime']) - + getcourseurl = ( + lambda name: "https://calendar.google.com/calendar/" + name["href"] + ) + page = BeautifulSoup(requests.get(getcourseurl(name)).content, "lxml") + event = {"course": page.title.text} + + for time in page.find_all("time"): + event[time.attrs["itemprop"]] = date_decode(time["datetime"]) + events.append(event) - return events - + return events + + def SpecificEvent(events, day): - new_event = [event for event in events if event['startDate'][0] == day] + new_event = [event for event in events if event["startDate"][0] == day] return new_event - + + def SiteUrl(): curr_year = date.today().year curr_month = date.today().month - - startdate = '%d%02d01' % (curr_year, curr_month) - enddate = '%d%02d01' % (curr_year, curr_month + 1) - + + startdate = "%d%02d01" % (curr_year, curr_month) + enddate = "%d%02d01" % (curr_year, curr_month + 1) + if curr_month == 12: - enddate = str(curr_year) + '01' + '01' - return '%s/%s'%(startdate,enddate) - + enddate = str(curr_year) + "01" + "01" + return "%s/%s" % (startdate, enddate) + + def scheduleService(): - sites = {"LCC1": "https://calendar.google.com/calendar/u/0/htmlembed?src=computacao.ufcg.edu.br_9u9fch5o55dbgrschdeduq348c@group.calendar.google.com&dates=" + SiteUrl(), - "LCC2": "https://calendar.google.com/calendar/u/0/htmlembed?src=computacao.ufcg.edu.br_80qc5chl59nmv2268aef8hp528@group.calendar.google.com&dates=" + SiteUrl(), - "LCC3": "https://calendar.google.com/calendar/u/0/htmlembed?src=computacao.ufcg.edu.br_noalttgqttm3c5pm94k3ttbj1k@group.calendar.google.com&dates=" + SiteUrl() } - - dicEvents = {} - for lcc in sites: - site = sites[lcc] - - events = get_events(site) - today = date.today() - curr_day = today.strftime('%d/%m/%Y') - new_event = SpecificEvent(events, curr_day) - dicEvents[lcc] = new_event - - dicEvents2 = { } - for lcc in dicEvents: - listaDeAulas = dicEvents[lcc] - novaListaDeAulas = [] - for aula in listaDeAulas: - aulaNova = { - "course": aula['course'], - "startTime": aula['startDate'][1], - "endTime": aula['endDate'][1] - } - novaListaDeAulas.append(aulaNova) - dicEvents2[lcc] = novaListaDeAulas - - return dicEvents2 \ No newline at end of file + sites = { + "LCC1": "https://calendar.google.com/calendar/u/0/htmlembed?src=computacao.ufcg.edu.br_9u9fch5o55dbgrschdeduq348c@group.calendar.google.com&dates=" + + SiteUrl(), + "LCC2": "https://calendar.google.com/calendar/u/0/htmlembed?src=computacao.ufcg.edu.br_80qc5chl59nmv2268aef8hp528@group.calendar.google.com&dates=" + + SiteUrl(), + "LCC3": "https://calendar.google.com/calendar/u/0/htmlembed?src=computacao.ufcg.edu.br_noalttgqttm3c5pm94k3ttbj1k@group.calendar.google.com&dates=" + + SiteUrl(), + } + + dicEvents = {} + for lcc in sites: + site = sites[lcc] + + events = get_events(site) + today = date.today() + curr_day = today.strftime("%d/%m/%Y") + new_event = SpecificEvent(events, curr_day) + dicEvents[lcc] = new_event + + dicEvents2 = {} + for lcc in dicEvents: + listaDeAulas = dicEvents[lcc] + novaListaDeAulas = [] + for aula in listaDeAulas: + aulaNova = { + "course": aula["course"], + "startTime": aula["startDate"][1], + "endTime": aula["endDate"][1], + } + novaListaDeAulas.append(aulaNova) + dicEvents2[lcc] = novaListaDeAulas + + return dicEvents2 diff --git a/api/src/services/statusService.py b/api/src/services/statusService.py index 49ed0d6..9bfdf44 100644 --- a/api/src/services/statusService.py +++ b/api/src/services/statusService.py @@ -1,14 +1,15 @@ import paramiko + def statusByHost(host): - status = True - try: - ssh = paramiko.SSHClient() - ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) - ssh.connect(hostname=host, port=23456) - ssh.close() - except paramiko.AuthenticationException: - pass - except Exception as e: - status = False - return status \ No newline at end of file + status = True + try: + ssh = paramiko.SSHClient() + ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) + ssh.connect(hostname=host, port=23456) + ssh.close() + except paramiko.AuthenticationException: + pass + except Exception as e: + status = False + return status diff --git a/bot.py b/bot.py new file mode 100644 index 0000000..a7a19f1 --- /dev/null +++ b/bot.py @@ -0,0 +1,32 @@ +import discord +import requests +from bot.src.services.scheduleService import * +import json + +client = discord.Client() + +with open("config.json") as f: + CONFIG = json.load(f) + + +@client.event +async def on_ready(): + print("Efetuamos o login como {0.user}".format(client)) + + +@client.event +async def on_message(message): + if message.author == client.user: + return + + if message.content.lower().startswith(CONFIG["PREFIX"] + "horarios"): + msg = message.content + embed = horarios(msg, _getArgs(msg)) + await message.channel.send(embed=embed) + + +client.run(CONFIG["TOKEN"]) + + +def _getArgs(mensagem): + return mensagem.split(" ")[1:] diff --git a/bot/src/services/scheduleService.py b/bot/src/services/scheduleService.py index e2bd2d5..de45e47 100644 --- a/bot/src/services/scheduleService.py +++ b/bot/src/services/scheduleService.py @@ -1,29 +1,34 @@ import requests import discord + def horarios(mensagem, args): - instrucao = '!horarios' + instrucao = "!horarios" + + req_schedule = requests.get("https://lcc-bot-mvp.herokuapp.com/schedule") + dic = req_schedule.json() - req_schedule = requests.get('') - dic = req_schedule.json() + embed = discord.Embed(title="LCC Bot", descripition="Aulas do dia:") + shouldCheckLcc = lambda lcc: lcc.lower() in args or len(args) == 0 - embed = discord.Embed(title="LCC Bot", descripition="Aulas do dia:") - shouldCheckLcc = lambda lcc : lcc.lower() in args or len(args) == 0 + for lcc in dic: + if shouldCheckLcc(lcc): + aulas = _getAulasByLcc(lcc, dic) + embed.add_field(name=lcc.upper(), value=(aulas), inline=False) - for lcc in dic: - if shouldCheckLcc(lcc): - aulas = _getAulasByLcc(lcc, dic) - embed.add_field(name = lcc.upper(), value=(aulas), inline= False) + embed.set_footer(text="Guardians-DSC") + return embed - embed.set_footer(text="Guardians-DSC") - return embed def _getAulasByLcc(lcc, dic): - aulas = '' + aulas = "" if len(dic[lcc]) == 0: aulas += " - Hoje não haverá aula" else: - aulas = '' + aulas = "" for aula in dic[lcc]: - aulas += " - Hoje tem aula de %s ás %s horas.\n\n" % (aula['course'], aula['startTime']) + aulas += " - Hoje tem aula de %s ás %s horas.\n\n" % ( + aula["course"], + aula["startTime"], + ) return aulas \ No newline at end of file From 24ed5bd86a1ca98487b99f82f5f726ddcc611187 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=BAlio=20Carvalho?= Date: Wed, 11 Nov 2020 21:00:50 -0300 Subject: [PATCH 13/20] wip bot.py --- bot.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bot.py b/bot.py index a7a19f1..90e7757 100644 --- a/bot.py +++ b/bot.py @@ -1,5 +1,4 @@ import discord -import requests from bot.src.services.scheduleService import * import json @@ -25,7 +24,7 @@ async def on_message(message): await message.channel.send(embed=embed) -client.run(CONFIG["TOKEN"]) +client.run("NzU0ODQ3ODI4Mjk5NDgxMDg4.X16s0g.BvA6vtgT03JosE42hwX2B0wNCT" + "8") def _getArgs(mensagem): From 632f168c905d1e5df31f49b3c2fd6752b882e80b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=BAlio=20Carvalho?= Date: Wed, 11 Nov 2020 21:03:40 -0300 Subject: [PATCH 14/20] changed bot dir in procfile --- Procfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Procfile b/Procfile index 7394444..743f5d5 100644 --- a/Procfile +++ b/Procfile @@ -1,2 +1,2 @@ web: gunicorn app:app -bot: python bot.py \ No newline at end of file +bot: python bot/bot.py \ No newline at end of file From 9c984cf2566c7f3348829bab20f681a726e60362 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=BAlio=20Carvalho?= Date: Wed, 11 Nov 2020 21:05:18 -0300 Subject: [PATCH 15/20] added config.json --- bot/config.json | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 bot/config.json diff --git a/bot/config.json b/bot/config.json new file mode 100644 index 0000000..90cd53a --- /dev/null +++ b/bot/config.json @@ -0,0 +1,4 @@ +{ + "TOKEN": "NzU0ODQ3ODI4Mjk5NDgxMDg4.X16s0g.BvA6vtgT03JosE42hwX2B0wNCT8", + "PREFIX": "!" +} \ No newline at end of file From cbcf3bb9b6fdd147df9fa7fa308d4afa306591ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=BAlio=20Carvalho?= Date: Wed, 11 Nov 2020 21:06:02 -0300 Subject: [PATCH 16/20] removed config from root --- bot.py | 31 ------------------------------- bot/bot.py | 12 ++++++++---- 2 files changed, 8 insertions(+), 35 deletions(-) delete mode 100644 bot.py diff --git a/bot.py b/bot.py deleted file mode 100644 index 90e7757..0000000 --- a/bot.py +++ /dev/null @@ -1,31 +0,0 @@ -import discord -from bot.src.services.scheduleService import * -import json - -client = discord.Client() - -with open("config.json") as f: - CONFIG = json.load(f) - - -@client.event -async def on_ready(): - print("Efetuamos o login como {0.user}".format(client)) - - -@client.event -async def on_message(message): - if message.author == client.user: - return - - if message.content.lower().startswith(CONFIG["PREFIX"] + "horarios"): - msg = message.content - embed = horarios(msg, _getArgs(msg)) - await message.channel.send(embed=embed) - - -client.run("NzU0ODQ3ODI4Mjk5NDgxMDg4.X16s0g.BvA6vtgT03JosE42hwX2B0wNCT" + "8") - - -def _getArgs(mensagem): - return mensagem.split(" ")[1:] diff --git a/bot/bot.py b/bot/bot.py index 9fb85ad..403da28 100644 --- a/bot/bot.py +++ b/bot/bot.py @@ -5,24 +5,28 @@ client = discord.Client() -with open('config.json') as f: +with open("config.json") as f: CONFIG = json.load(f) + @client.event async def on_ready(): print("Efetuamos o login como {0.user}".format(client)) + @client.event async def on_message(message): if message.author == client.user: return - if message.content.lower().startswith(CONFIG['PREFIX'] + 'horarios'): + if message.content.lower().startswith(CONFIG["PREFIX"] + "horarios"): msg = message.content embed = horarios(msg, _getArgs(msg)) await message.channel.send(embed=embed) -client.run(CONFIG['TOKEN']) + +client.run(CONFIG["TOKEN"]) + def _getArgs(mensagem): - return mensagem.split(' ')[1:] \ No newline at end of file + return mensagem.split(" ")[1:] From 6f0e7889cfff7bb4c7896f5d0c467d50b49e81bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=BAlio=20Carvalho?= Date: Wed, 11 Nov 2020 21:08:03 -0300 Subject: [PATCH 17/20] changed gitignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 7199a87..18d49a5 100644 --- a/.gitignore +++ b/.gitignore @@ -137,4 +137,3 @@ dmypy.json # Cython debug symbols cython_debug/ .vscode/ -config.json \ No newline at end of file From e7c4c35d91f5cf100be5890aa1c90b496ff7f236 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=BAlio=20Carvalho?= Date: Wed, 11 Nov 2020 21:10:29 -0300 Subject: [PATCH 18/20] removed loading of config.json --- bot/bot.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/bot/bot.py b/bot/bot.py index 403da28..9f01b08 100644 --- a/bot/bot.py +++ b/bot/bot.py @@ -5,9 +5,6 @@ client = discord.Client() -with open("config.json") as f: - CONFIG = json.load(f) - @client.event async def on_ready(): @@ -19,13 +16,13 @@ async def on_message(message): if message.author == client.user: return - if message.content.lower().startswith(CONFIG["PREFIX"] + "horarios"): + if message.content.lower().startswith("!" + "horarios"): msg = message.content embed = horarios(msg, _getArgs(msg)) await message.channel.send(embed=embed) -client.run(CONFIG["TOKEN"]) +client.run("NzU0ODQ3ODI4Mjk5NDgxMDg4.X16s0g.BvA6vtgT03JosE42hwX2B0wNCT" + "8") def _getArgs(mensagem): From 1c3ab8776cad27c52baaa48555edd928c2b93a72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=BAlio=20Carvalho?= Date: Wed, 11 Nov 2020 21:12:39 -0300 Subject: [PATCH 19/20] fixed minor bug --- bot/bot.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bot/bot.py b/bot/bot.py index 9f01b08..4e36a67 100644 --- a/bot/bot.py +++ b/bot/bot.py @@ -6,6 +6,10 @@ client = discord.Client() +def _getArgs(mensagem): + return mensagem.split(" ")[1:] + + @client.event async def on_ready(): print("Efetuamos o login como {0.user}".format(client)) @@ -23,7 +27,3 @@ async def on_message(message): client.run("NzU0ODQ3ODI4Mjk5NDgxMDg4.X16s0g.BvA6vtgT03JosE42hwX2B0wNCT" + "8") - - -def _getArgs(mensagem): - return mensagem.split(" ")[1:] From d3a05e152cd5ffbfd19da95e36eff877804fef53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=BAlio=20Carvalho?= Date: Wed, 11 Nov 2020 21:16:18 -0300 Subject: [PATCH 20/20] removed token --- bot/bot.py | 7 +++++-- bot/config.json | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/bot/bot.py b/bot/bot.py index 4e36a67..9b5e3d8 100644 --- a/bot/bot.py +++ b/bot/bot.py @@ -5,6 +5,9 @@ client = discord.Client() +with open("config.json") as f: + CONFIG = json.load(f) + def _getArgs(mensagem): return mensagem.split(" ")[1:] @@ -20,10 +23,10 @@ async def on_message(message): if message.author == client.user: return - if message.content.lower().startswith("!" + "horarios"): + if message.content.lower().startswith(CONFIG["PREFIX"] + "horarios"): msg = message.content embed = horarios(msg, _getArgs(msg)) await message.channel.send(embed=embed) -client.run("NzU0ODQ3ODI4Mjk5NDgxMDg4.X16s0g.BvA6vtgT03JosE42hwX2B0wNCT" + "8") +client.run(CONFIG["TOKEN"]) diff --git a/bot/config.json b/bot/config.json index 90cd53a..c5f2c43 100644 --- a/bot/config.json +++ b/bot/config.json @@ -1,4 +1,4 @@ { - "TOKEN": "NzU0ODQ3ODI4Mjk5NDgxMDg4.X16s0g.BvA6vtgT03JosE42hwX2B0wNCT8", + "TOKEN": "", "PREFIX": "!" } \ No newline at end of file