Skip to content

Commit

Permalink
Add files
Browse files Browse the repository at this point in the history
Signed-off-by: Tushar Mittal <[email protected]>
  • Loading branch information
techytushar committed Sep 14, 2019
1 parent 97b9a78 commit 9f421c3
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pycache__
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: gunicorn app:app
35 changes: 33 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,33 @@
# meetup_api
Alternate API to get events from the Meetup website
# Meetup API

Alternate API to get events from the Meetup website. Send a POST request with the URL of the event page of the meetup group for which you want the information.

## How to use

* Install the requirements using `pip install -r requirements.txt`

* Run the app using `gunicorn -b localhost:8000 app:app`

* Send POST request using:

```bash
curl -X POST http://localhost:8000/get_events -d "url=https://www.meetup.com/pydelhi/events/"
```

## Expected Resopnse

The API will return a JSON with `all_events` containing a list of all events. Example response is shown below:

```json
{
"all_events": [
{
"link": ,
"title": ,
"datetime": ,
"datetime_str": ,
"location":
}
]
}
```
38 changes: 38 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import requests
from bs4 import BeautifulSoup
from flask import Flask, request, url_for
from flask_restful import Resource, Api, reqparse


def get_events(url):
all_events = []
source = requests.get(url).content
soup = BeautifulSoup(source, 'lxml')
events = soup.find_all('div', {'class':'card'})
for event in events:
event_desc = {}
event_desc['link'] = 'https://meetup.com'+event.find('a')['href']
event_desc['title'] = event.find('a', {'class':'eventCardHead--title'}).text
event_desc['datetime'] = event.find('time')['datetime']
event_desc['datetime_str'] = event.find('time').text
event_desc['location'] = event.find('address').text
all_events.append(event_desc)
return {'all_events':all_events}

parser = reqparse.RequestParser()
parser.add_argument('url', type=str, help='The URL of the event page of the meetup')

class Home(Resource):
def get(self):
return {"Usage":"Send a POST request with the event page URL to /get_events"}

class Events(Resource):
def post(self):
args = parser.parse_args()
url = args['url']
return get_events(url)

app = Flask(__name__)
api = Api(app)
api.add_resource(Home, '/')
api.add_resource(Events, '/get_events')
6 changes: 6 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
requests
flask
flask-restful
beautifulsoup4
lxml
gunicorn==19.7.1

0 comments on commit 9f421c3

Please sign in to comment.