Skip to content

Commit

Permalink
add readme, and clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Dangerfield committed Oct 16, 2017
1 parent 3d4a1e6 commit c5f7777
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 47 deletions.
7 changes: 7 additions & 0 deletions config.example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// See readme for details
exports.config = {
mapsAPIKey: 'YOUR_KEY_HERE',
auth: 'YOUR_FAMILY_SEARCH_AUTHORIZATION_HERE',
cookie: `YOUR_FAMILY_SEARCH_COOKIE_HERE`,
rootPersonId: 'YOUR_FAMILY_SEARCH_PERSON_ID_HERE',
}
Binary file added images/example-screenshot.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"description": "Get all details about family tree",
"main": "getDetails.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "webpack-dev-server --hot --open --inline",
"build": "rm -rf dist && webpack -p"
"build": "rm -rf dist && webpack -p",
"fetchData": "node ./src/getData/getDetails.js && node ./src/getData/extractBurialPlace.js"
},
"author": "",
"license": "ISC",
Expand Down
23 changes: 23 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Family Search Grave Mapper

![Example of the result](./images/example-screenshot.PNG)

This web app creates a visualization of where your ancestors are buried. You can use this to find ancestors buried near you so you can visit their grave sites. Have fun!

## Setting up config.js
Create a file, called config.js, with these properties exported on a variable called config:

### mapsAPIKey
API key for the Google Maps Javscript API. You can get one [here](https://developers.google.com/maps/documentation/javascript/)

### rootPersonId
The family search person id of the person who's ancestors you want to get burial data for. This will probably be yourself, so you can see ancestors with burial sites near you.

### auth
Go to www.familysearch.org/tree/, and open the chrome developer tools. Go to the **network** tab, and click on **XHR** to only show XHR requests. Click on a random person on your tree to make their info card pop up. In the network tab, you should see a request to the `card` endpoint. Click on that request to show its details, and copy everything listed in the `authorization` property under **Request Headers**.

### cookie
Follow the steps above, and copy the `cookie` property under **Request Headers**.

## Run it
First, run `npm install`, and then `npm run fetchData` to download all the ancestor's data from family search. Then, run `npm start` to start the web app, and go to a browser. It should automatically open the app in a new tab.
5 changes: 2 additions & 3 deletions src/getData/extractBurialPlace.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ const promises = withBurial.map(id => {
.catch(console.error);
});
Promise.all(promises).then(details => {
fs.writeFileSync('simplifiedPersonDetails.json', JSON.stringify(details));
console.log('Wrote file');
fs.writeFileSync('peopleWithBurialInfo.json', JSON.stringify(details));
console.log('Dumped data to file.');
});
// console.log(details.filter(detail => detail.burialPlace.match(/minnesota/i)))
82 changes: 50 additions & 32 deletions src/getData/getDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,61 @@ const fs = require('fs');
const request = require('request-promise-native');

const config = require('../../config.js').config;
const personIds = require('./familyData.json');

const fileName = 'fetchedData.json';
fs.appendFileSync(fileName, '{\n\t');

let currentIndex = 0;
function getAncestorsPersonIds() {
const uri = `https://www.familysearch.org/tree/proxy/tree-data/portrait-pedigree/flat/${config.rootPersonId}?numGenerations=9`
return request({
method: 'GET',
uri,
headers: {
accept: 'application/json',
authorization: config.auth,
cookie: config.cookie,
dnt: 1
},
json: true
}).then(res => Object.keys(res.persons))
.catch(console.error)
}

getNextPerson();
getAncestorsPersonIds().then(personIds => {
console.log(`Getting details for ${personIds.length} person ids`)
let currentIndex = 0;

function getNextPerson() {
if (currentIndex < personIds.length) {
let uri = `https://www.familysearch.org/tree/v8/proxy/tree-data/v8/person/${personIds[
currentIndex++
]}/card?locale=en`;
request({
method: 'GET',
uri,
headers: {
accept: 'application/json',
authorization: config.auth,
cookie: config.cookie,
dnt: 1
},
json: true
})
.then(data => {
console.info('Got details for', data.name);
fs.appendFileSync(
fileName,
`"${data.id}": ${JSON.stringify(data)},\n\t`
);
const fetchedPeople = []
getNextPerson();

setTimeout(getNextPerson, 3500);
function getNextPerson() {
if (currentIndex < 5) {
let uri = `https://www.familysearch.org/tree/v8/proxy/tree-data/v8/person/${personIds[
currentIndex++
]}/card?locale=en`;
request({
method: 'GET',
uri,
headers: {
accept: 'application/json',
authorization: config.auth,
cookie: config.cookie,
dnt: 1
},
json: true
})
.catch(err => {
console.error('Error!', err);
process.exit(1);
});
.then(data => {
console.log('Got details for', data.name);
fetchedPeople.push(data)

setTimeout(getNextPerson, 3500);
})
.catch(err => {
console.error('Error!', err);
process.exit(1);
});
} else {
console.log(`Done! Dumping data to file ${fileName}`)
fs.writeFileSync(fileName, JSON.stringify(fetchedPeople))
}
}
}
})
16 changes: 7 additions & 9 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
document.body.innerHTML = require('./map.html');
const loadGoogleMapsAPI = require('load-google-maps-api');
const people = require('./getData/simplifiedPersonDetails.json');
const people = require('./getData/peopleWithBurialInfo.json');
const apiKey = require('../config.js').mapsAPIKey;

loadGoogleMapsAPI({
key: apiKey
}).then(googleMaps => {
const map = new googleMaps.Map(document.getElementById('map'), {
zoom: 4,
zoom: 3,
center: { lat: 0, lng: 0 }
});

Expand All @@ -20,13 +20,11 @@ loadGoogleMapsAPI({
const personInfo = `<h1>${person.name}</h1>
<h2><em>${person.lifespan}</em></h2>
<div>
<a href="https://www.familysearch.org/tree/person/${person.id}/details">Family Search Link</a>
<a href="https://www.familysearch.org/tree/person/${person.id}/details">
Family Search Link
</a>
</div>`;
const infowindow = new googleMaps.InfoWindow({
content: personInfo
});
marker.addListener('click', function() {
infowindow.open(map, marker);
});
const infowindow = new googleMaps.InfoWindow({ content: personInfo });
marker.addListener('click', () => infowindow.open(map, marker));
});
});
1 change: 0 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ module.exports = {
filename: '[name].bundle.js',
path: path.resolve(__dirname, 'dist')
},
devtool: 'inline-source-map',
devServer: {
contentBase: './dist',
},
Expand Down

0 comments on commit c5f7777

Please sign in to comment.