-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
45 lines (37 loc) · 1.22 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import json
from sanic import Sanic
from sanic import response
import aiohttp
import requests
from bs4 import BeautifulSoup
app = Sanic(__name__)
async def scrappy(session):
async with session as response:
req = requests.get('https://www.meetup.com/gdgmanagua/')
content = req.content
soup = BeautifulSoup(content, 'html.parser')
data = json.loads(soup.find_all('script', {'data-react-helmet': 'true'})[1].text)[0]
return {
'name': data['name'],
'url': data['url'],
'start_date': data['startDate'],
'end_date': data['endDate'],
'description': data['description'],
'location': {
'name': data['location']['name'],
'lat': data['location']['geo']['latitude'],
'lon': data['location']['geo']['longitude']
}
}
@app.route('/')
async def handle_request(request):
async with aiohttp.ClientSession() as session:
data = await scrappy(session)
return response.json(
data,
headers={
'Access-Control-Allow-Origin': '*'
},
)
if __name__ == '__main__':
app.run(host="0.0.0.0", port=8000)