-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Tushar Mittal <[email protected]>
- Loading branch information
1 parent
97b9a78
commit 9f421c3
Showing
5 changed files
with
79 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__pycache__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
web: gunicorn app:app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": | ||
} | ||
] | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
requests | ||
flask | ||
flask-restful | ||
beautifulsoup4 | ||
lxml | ||
gunicorn==19.7.1 |