From 5774875e09642055d700044726714180622dc5f4 Mon Sep 17 00:00:00 2001
From: Christian Strappazzon <cstrap@users.noreply.github.com>
Date: Mon, 2 Oct 2017 13:42:08 +0200
Subject: [PATCH 1/3] Update search events on eventbrite

---
 app.py           | 57 ++++++++++++++++++++++--------------------------
 requirements.txt |  8 +++----
 2 files changed, 30 insertions(+), 35 deletions(-)

diff --git a/app.py b/app.py
index 785cd38..6ca7f3d 100644
--- a/app.py
+++ b/app.py
@@ -6,50 +6,45 @@
 import os
 
 import arrow
-import requests
 from box import Box
 from flask import Flask, jsonify
 from flask_cors import cross_origin
+from eventbrite import Eventbrite
 
 app = Flask(__name__)
 
-EVENTBRITE_API = 'https://www.eventbriteapi.com/v3/events/search/?token={token}&organizer.id={organizer_id}'
-
-EVENTBRITE_SETTINGS = {
-    'token': os.environ['EB_TOKEN'],
-    'organizer_id': os.environ['EB_ORGANIZER_ID'],
-}
+eb_client = Eventbrite(os.environ['EB_TOKEN'])
 
 MONTHS = ['', 'GENNAIO', 'FEBBRAIO', 'MARZO', 'APRILE', 'MAGGIO', 'GIUGNO',
           'LUGLIO', 'AGOSTO', 'SETTEMBRE', 'OTTOBRE', 'NOVEMBRE', 'DICEMBRE']
 
 
-def get_results(response, index=0):
+def return_value():
     """ Transform JSON to return dict """
 
-    obj = Box(response.json()).events[index]
-    date = arrow.get(obj.start.local)
-
-    return {
-        'topic': obj.name.text,
-        'day': date.day,
-        'month': MONTHS[date.month],
-        'link': obj.url,
-    }
-
-
-def return_value():
-    """ API call """
-
-    response = requests.get(EVENTBRITE_API.format_map(EVENTBRITE_SETTINGS))
-    if response.status_code == 200 and response.json():
-        return get_results(response)
-    return {
-        'topic': 'TBA',
-        'day': 'NA',
-        'month': 'NA',
-        'link': '#',
-    }
+    try:
+        events = Box(eb_client.event_search(**{'organizer.id': os.environ['EB_ORGANIZER_ID']}))
+    except:
+        return {
+            'topic': 'TBA',
+            'day': 'NA',
+            'month': 'NA',
+            'link': '#',
+        }
+    else:
+        obj = events.events[0]
+        if events.pagination.object_count > 1:
+            ev = {ev.start.local: idx for idx, ev in enumerate(events.events)}
+            obj = events.events[ev[min(ev.keys())]]
+
+        date = arrow.get(obj.start.local)
+
+        return {
+            'topic': obj.name.text,
+            'day': date.day,
+            'month': MONTHS[date.month],
+            'link': obj.url,
+        }
 
 
 @app.route('/meetup.js')
diff --git a/requirements.txt b/requirements.txt
index f501f78..fd23b58 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,9 +1,9 @@
 arrow==0.10.0
+eventbrite==3.3.3
 flake8==3.4.1
 Flask==0.12.2
 Flask-Cors==3.0.3
 gunicorn==19.7.1
-pylint==1.7.2
-python-box==3.0.1
-python-dateutil==2.6.1
-requests==2.18.4
+pylint==1.7.4
+python-box==3.1.1
+python-dateutil==2.6.1
\ No newline at end of file

From 1b8b98d1ed8723c6276ce3d4e81ce5c11267fd2e Mon Sep 17 00:00:00 2001
From: cstrap <lab@strap.it>
Date: Wed, 23 Oct 2019 10:15:31 +0200
Subject: [PATCH 2/3] Update packages

---
 requirements.txt | 14 +++++++-------
 runtime.txt      |  2 +-
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/requirements.txt b/requirements.txt
index fd23b58..1591a8f 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,9 +1,9 @@
 arrow==0.10.0
 eventbrite==3.3.3
-flake8==3.4.1
-Flask==0.12.2
-Flask-Cors==3.0.3
-gunicorn==19.7.1
-pylint==1.7.4
-python-box==3.1.1
-python-dateutil==2.6.1
\ No newline at end of file
+flake8==3.7.8
+Flask==1.1.1
+Flask-Cors==3.0.8
+gunicorn==19.9.0
+pylint==2.4.3
+python-box==3.4.5
+python-dateutil==2.8.0
\ No newline at end of file
diff --git a/runtime.txt b/runtime.txt
index cfa5aa5..5c517d3 100644
--- a/runtime.txt
+++ b/runtime.txt
@@ -1 +1 @@
-python-3.6.2
+python-3.6.9

From 3f924e7cbed76f77ebe6f102199f8c4e92d6d485 Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Thu, 6 May 2021 18:58:51 +0000
Subject: [PATCH 3/3] Bump flask-cors from 3.0.8 to 3.0.9

Bumps [flask-cors](https://github.com/corydolphin/flask-cors) from 3.0.8 to 3.0.9.
- [Release notes](https://github.com/corydolphin/flask-cors/releases)
- [Changelog](https://github.com/corydolphin/flask-cors/blob/master/CHANGELOG.md)
- [Commits](https://github.com/corydolphin/flask-cors/compare/3.0.8...3.0.9)

Signed-off-by: dependabot[bot] <support@github.com>
---
 requirements.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/requirements.txt b/requirements.txt
index 1591a8f..1d85fad 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -2,7 +2,7 @@ arrow==0.10.0
 eventbrite==3.3.3
 flake8==3.7.8
 Flask==1.1.1
-Flask-Cors==3.0.8
+Flask-Cors==3.0.9
 gunicorn==19.9.0
 pylint==2.4.3
 python-box==3.4.5
