-
Notifications
You must be signed in to change notification settings - Fork 3
Feature/scrape #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Feature/scrape #17
Changes from 5 commits
0dffbd1
81857ad
e0e6260
df876a2
637875d
5b42aea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,26 +1,8 @@ | ||
| # lista de eventos que no queremos que aparezcan (separados por coma) | ||
| # 19155277 = Infobyte (https://www.meetup.com/infobyte/) | ||
| BLACK_LIST=19155277 | ||
|
|
||
| # 15 minutos de tiempo de vida para los pedidos cacheados | ||
| CACHE_EXPIRATION=900000 | ||
|
|
||
| # 34 = Tecnología | ||
| # en el caso de querer usar más de 1, separarlos por coma | ||
| CATEGORIES=34 | ||
|
|
||
| # latitud y longitud que apuntan a Cabildo y Juan B. Justo | ||
| LAT=-34.578175 | ||
| LON=-58.426516 | ||
|
|
||
| # https://secure.meetup.com/meetup_api/key/ | ||
| MEETUP_API_KEY=1234567890 | ||
|
|
||
| NODE_ENV=development | ||
|
|
||
| # rango en millas (partiendo desde latitud y longitud) que se va a tener en cuenta | ||
| # para buscar meetups | ||
| RADIUS=10 | ||
|
|
||
| # lista de eventos a buscar que sabemos que no entran en el rango (separados por coma) | ||
| # WHITE_LIST= | ||
| RADIUS=10 |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| const cheerio = require('cheerio') | ||
| const got = require('got') | ||
| const moment = require('moment') | ||
| let yup = require('yup') | ||
|
|
||
| let schema = yup.array().of( | ||
| yup.object().shape({ | ||
| date: yup.date().required(), | ||
| eventName: yup.string().required(), | ||
| eventLink: yup.string().url().required(), | ||
| place: yup.string() | ||
| }) | ||
| ) | ||
|
|
||
| module.exports = async function scrapeEvents() { | ||
durancristhian marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| try { | ||
| const { RADIUS } = process.env | ||
| const { body } = await got( | ||
| `https://www.meetup.com/es-ES/find/events/tech/?allMeetups=false&radius=${RADIUS}&userFreeform=buenos+ai&mcId=c1000296&mcName=Buenos+Aires%2C+AR` | ||
| ) | ||
| const $ = cheerio.load(body) | ||
| const days = $('li.event-listing-container-li') | ||
| const dayInfo = $('li.date-indicator') | ||
| const eventsArray = [] | ||
| days.each((dayIndex, li) => { | ||
| const events = $(li).find('ul.event-listing-container > li') | ||
| events.each((_, li) => { | ||
| $(li).each((_, e) => { | ||
| const eventDateElement = dayInfo.get(dayIndex) | ||
| let eventDate | ||
| if (eventDateElement) { | ||
| const { | ||
| 'data-year': year, | ||
| 'data-month': month, | ||
| 'data-day': day | ||
| } = dayInfo.get(dayIndex).attribs | ||
| eventDate = `${year}-${month}-${day}` | ||
| } else { | ||
| eventDate = moment().format('YYYY-MM-DD') | ||
| } | ||
| eventsArray.push({ | ||
| date: | ||
| moment.utc( | ||
| `${eventDate} ${$(e).find('div a').first().text().trim()}`, | ||
| 'YYYY-MM-DD HH:mm' | ||
| ), | ||
| eventName: | ||
| `${$(e).find('div[itemprop="location"]').text().trim()} - ${$(e).find('a.event span[itemprop="name"]').text().trim()}`, | ||
| eventLink: $(e).find('a.event').prop('href'), | ||
| place: '' | ||
| }) | ||
| }) | ||
| }) | ||
| }) | ||
| const isValid = schema.isValidSync(eventsArray) | ||
| console.log('schema valido: ', isValid) | ||
| if (isValid) { | ||
| return eventsArray | ||
| } else { | ||
| return [] | ||
| } | ||
| } catch (e) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hagamos un console.error con el error, además de devolver el array vacío
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sino no vamos a saber por que rompe, que van a ser la mayoría de los casos |
||
| return [] | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.