https://github.com/lukem512/freecycle
A scraper for Freecycle
https://github.com/lukem512/freecycle
data-mining freecycle scraper
Last synced: about 1 month ago
JSON representation
A scraper for Freecycle
- Host: GitHub
- URL: https://github.com/lukem512/freecycle
- Owner: lukem512
- Created: 2019-07-16T17:50:27.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-07-19T22:02:55.000Z (almost 6 years ago)
- Last Synced: 2025-01-21T05:42:17.176Z (3 months ago)
- Topics: data-mining, freecycle, scraper
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/freecycle
- Size: 17.6 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# freecycle
A scraper for Freecycle.
## Installation
You can install the scraper via NPM or yarn.
`npm install --save freecycle`
## Usage
Import `freecycle` into your project to begin scraping. You can use the `getPosts` method to retrieve latest posts from a specified Freecycle group.
```js
const freecycle = require('freecycle')
const GROUP_NAME = 'CambridgeUK'freecycle.getPosts(GROUP_NAME, (err, posts) => {
if (err) {
return console.err('Could not retrieve posts', err)
}
posts.forEach(post => {
console.log('Post: ', post.name)
})
})
```The `posts` array is an array of objects with the following `string` fields:
```js
{
name,
url,
location
}
```More detail about each post can be retrieved using the `getPostById` and `getPostByURL` functions. Passing the `url` field (from an array item returned by the `getPosts` method) into `getPostByURL` is the easiest way to retrieve further information about a post.
```js
freecycle.getPostById(GROUP_NAME, '73086860', (err, post) => {
if (err) {
return console.err('Could not retrieve post details', err)
}
console.log('Post: ', post.title, post.description)
})
```The `post` object, returned by either `getPostBy` function, contains the following `string` fields:
```js
{
id,
type,
title,
location,
date,
description,
image,
}
```The `image` field is `undefined` or the URL of the post image.
### Groups
There is also a `Group` object, available by importing `freecycle/group`. This abstracts the notion of an individual Freecycle group and allows multiple to be queried independently.
```js
const Group = require('freecycle/group')
const group = new Group('CambridgeUK')group.getPosts((err, posts) => {
if (err) {
return console.error(err)
}
console.log(posts)
})
```See the 'multi.js' example for more details.
## License
MIT